]> git.corax.cc Git - corax/commitdiff
Add an argument to process_create() so the caller may request the process to be creat...
authorMatthias Kruk <m@m10k.eu>
Mon, 28 Oct 2019 09:35:32 +0000 (18:35 +0900)
committerMatthias Kruk <m@m10k.eu>
Mon, 28 Oct 2019 09:35:32 +0000 (18:35 +0900)
kernel/core/process.c
kernel/include/process.h

index 7b9b8aeb606d2bfb4f44034d71473c6806dc0dbc..e4fb4721b5079fbc94b2554ee03164168f9421ea 100644 (file)
@@ -75,12 +75,30 @@ static inline int DQ(process_t *p)
        return(ret_val);
 }
 
-int process_create(process_t **dst, u32_t ppl, void *entry)
+int process_create(process_t **dst, pid_t pid, u32_t ppl, void *entry)
 {
        int ret_val;
        process_t *proc;
 
        ret_val = -ENOMEM;
+       proc = NULL;
+
+       /* was a specific pid requested? */
+       if(pid != PID_ANY) {
+               /* may only request pids in [2..100] */
+
+               if(pid < 2 || pid >= 100) {
+                       ret_val = -EINVAL;
+                       goto cleanup;
+               }
+
+               /* check if pid is already taken */
+               if(process_lookup(pid)) {
+                       ret_val = -EALREADY;
+                       goto cleanup;
+               }
+       }
+
        proc = kmalloc(sizeof(*proc));
 
        if(proc) {
@@ -106,7 +124,13 @@ int process_create(process_t **dst, u32_t ppl, void *entry)
                }
 
                proc->p_privl = ppl;
-               proc->p_id = _next_pid++;
+
+               if(pid == PID_ANY) {
+                       /* no specific pid requested */
+                       proc->p_id = _next_pid++;
+               } else {
+                       proc->p_id = pid;
+               }
 
                task_prepare(proc->p_tasks, (u32_t)pdbr, (u32_t)entry,
                                         (u32_t)kstack + CONFIG_KERNEL_STACK_SIZE,
index 6ec428608e13de37cd3d19489c706b6b210a128f..ca42c6e6851fc5f4787dd4e20174402ff62ca7fc 100644 (file)
@@ -24,7 +24,7 @@
 
 typedef struct process process_t;
 
-int process_create(process_t**, u32_t, void*);
+int process_create(process_t**, pid_t, u32_t, void*);
 int process_switch(process_t*);
 
 int process_falloc(process_t*, int);