[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Lost] [Patch 2/3] kernel2: Syscall pm_create



+ kernel2: Syscall pm_create (Prozess erzeugen)
Index: trunk/src/kernel2/include/syscall.h
===================================================================
--- trunk.orig/src/kernel2/include/syscall.h
+++ trunk/src/kernel2/include/syscall.h
@@ -96,6 +96,11 @@ int syscall_pm_p(void);
 /// Kritischen Abschnitt verlassen
 int syscall_pm_v(pid_t pid);
 
+/// Prozess erstellen
+pid_t syscall_pm_create_process(vaddr_t start, uid_t uid,
+    const char* cmdline, pid_t parent_pid);
+
+
 // RPC
 /// RPC-Handler registrieren
 void syscall_set_rpc_handler(vaddr_t address);
Index: trunk/src/kernel2/src/syscall.c
===================================================================
--- trunk.orig/src/kernel2/src/syscall.c
+++ trunk/src/kernel2/src/syscall.c
@@ -60,6 +60,8 @@ void syscall_init()
     syscall_register(SYSCALL_PM_P, (void*) &syscall_pm_p, 0);
     syscall_register(SYSCALL_PM_V, (void*) &syscall_pm_v, 1);
 
+    syscall_register(SYSCALL_PM_CREATE_PROCESS, &syscall_pm_create_process, 4);
+
     syscall_register(SYSCALL_SET_RPC_HANDLER, (void*) &syscall_set_rpc_handler,
         1);
 
Index: trunk/src/kernel2/src/syscalls/pm.c
===================================================================
--- trunk.orig/src/kernel2/src/syscalls/pm.c
+++ trunk/src/kernel2/src/syscalls/pm.c
@@ -42,6 +42,30 @@
 #include "cpu.h"
 
 /**
+ * Neuen Prozess mit einem Thread erstellen. Der neue Task wird blockiert, bis
+ * er vom Ersteller entblockt wird.
+ *
+ * @param start Start-Adresse
+ * @param uid User-Id
+ * @param cmdline Kommandozeile mit der der Prozess gestartet wurde
+ * @param parent_pid PID des Elternprozesses
+ *
+ * @return PID des neuen Tasks
+ */
+pid_t syscall_pm_create_process(vaddr_t start, uid_t uid, const char* cmdline,
+    pid_t parent_pid)
+{
+    // Eltern-Prozess holen
+    pm_process_t* parent = pm_get(parent_pid);
+    // TODO: UID?
+    pm_process_t* process = pm_create(parent, cmdline);
+    pm_thread_create(process, start);
+//    kprintf("pm_create_process %d\n", process->pid);
+    return process->pid;
+}
+
+
+/**
  * PID des aktuellen Prozesses ausfindig machen
  *
  * @return PID
Index: trunk/src/kernel2/src/tasks/pm.c
===================================================================
--- trunk.orig/src/kernel2/src/tasks/pm.c
+++ trunk/src/kernel2/src/tasks/pm.c
@@ -216,7 +216,7 @@ bool pm_unblock(pm_process_t* process)
         pm_thread_unblock(thread);
     }
 
-    process->status = PM_STATUS_RUNNING;
+    process->status = PM_STATUS_READY;
 
     return TRUE;
 }
Index: trunk/src/kernel2/src/tasks/scheduler.c
===================================================================
--- trunk.orig/src/kernel2/src/tasks/scheduler.c
+++ trunk/src/kernel2/src/tasks/scheduler.c
@@ -120,8 +120,9 @@ void pm_scheduler_refresh()
     // Die Liste mit den Threads durchsuchen
     while ((thread = list_get_element_at(threads_available, i))) {
         // Der thread wird nur eingeplant, wenn er lauffaehig ist
-        if ((locked(&thread->lock) == FALSE) && (thread->status == 
-            PM_STATUS_READY))
+        if ((locked(&thread->lock) == FALSE)
+            && (thread->status == PM_STATUS_READY)
+            && (thread->process->status == PM_STATUS_READY))
         {
             list_push(threads_scheduled, thread);
             // kprintf("ok: 0x%x\n", thread->kernel_stack);
Index: trunk/src/kernel2/src/tasks/modules.c
===================================================================
--- trunk.orig/src/kernel2/src/tasks/modules.c
+++ trunk/src/kernel2/src/tasks/modules.c
@@ -107,6 +107,7 @@ static void load_module(struct multiboot
 
     //load_module_bin(multiboot_module_mapped, cmdline);
     init_process = pm_create(NULL, cmdline);
+    pm_unblock(init_process);
     if (loader_load_image(init_process->pid, (vaddr_t) image_start, image_size)
         == FALSE)
     {