Merge branch 'master' into signal-dev
authorMinep <zelong56@gmail.com>
Wed, 15 Jun 2022 20:55:55 +0000 (21:55 +0100)
committerMinep <zelong56@gmail.com>
Wed, 15 Jun 2022 20:55:55 +0000 (21:55 +0100)
lunaix-os/includes/lunaix/ds/llist.h
lunaix-os/includes/lunaix/process.h
lunaix-os/includes/lunaix/status.h
lunaix-os/includes/lunaix/syscall.h
lunaix-os/kernel/process.c
lunaix-os/kernel/sched.c

index 79fa99173003797fe8dfa6f0a805576a4d506151..1a6ec9b5fc6a8377e84d7096bbdf149a8cbeff17 100644 (file)
@@ -57,8 +57,8 @@ llist_delete(struct llist_header* elem)
     elem->next->prev = elem->prev;
 
     // make elem orphaned
-    // elem->prev = elem;
-    // elem->next = elem;
+    elem->prev = elem;
+    elem->next = elem;
 }
 
 static inline int
index e429060ab5f785b9ffdcec9f12c6cb534bfc48aa..28cb76b97a797089cdceacac9a3323c373c0760a 100644 (file)
@@ -44,6 +44,7 @@ struct proc_info
     uintptr_t ustack_top;
     struct llist_header siblings;
     struct llist_header children;
+    struct llist_header grp_member;
     struct proc_mm mm;
     void* page_table;
     time_t created;
@@ -53,6 +54,7 @@ struct proc_info
     sigset_t sig_pending;
     sigset_t sig_mask;
     void* sig_handler[_SIG_NUM];
+    pid_t pgid;
     struct lx_timer* timer;
 };
 
index db33da2d9a9697504e3fd51fbadb362c89017f5e..f3309ab3207f31f04bfda353862989b02f8ececc 100644 (file)
@@ -7,5 +7,6 @@
 #define LXOUTOFMEM -(3)
 #define LXINVLDPID -(4)
 #define LXSEGFAULT -(5)
+#define LXINVL -(6)
 
 #endif /* __LUNAIX_CODE_H */
index 9cb77647fcad0c1839802cc934486f6d141bd21b..3a6e2eba10285ed8f84726ab543f5d40a52a0b50 100644 (file)
 void
 syscall_install();
 
-static void*
-syscall(unsigned int callcode)
-{
-    asm volatile("int %0" ::"i"(LUNAIX_SYS_CALL), "D"(callcode) : "eax");
-}
-
 #define asmlinkage __attribute__((regparm(0)))
 
 #define __PARAM_MAP1(t1, p1) t1 p1
index 87a7413c963f0db793f22f842c5c59bdaf491e50..64f2654af6a0d1b621e2cc7e1d1f71657a5fae8f 100644 (file)
@@ -5,6 +5,7 @@
 #include <lunaix/mm/vmm.h>
 #include <lunaix/process.h>
 #include <lunaix/spike.h>
+#include <lunaix/status.h>
 #include <lunaix/syscall.h>
 #include <lunaix/syslog.h>
 
@@ -90,6 +91,36 @@ __DEFINE_LXSYSCALL(pid_t, getppid)
     return __current->parent->pid;
 }
 
+__DEFINE_LXSYSCALL(pid_t, getpgid)
+{
+    return __current->pgid;
+}
+
+__DEFINE_LXSYSCALL2(int, setpgid, pid_t, pid, pid_t, pgid)
+{
+    struct proc_info* proc = pid ? get_process(pid) : __current;
+
+    if (!proc) {
+        __current->k_status = LXINVL;
+        return -1;
+    }
+
+    pgid = pgid ? pgid : proc->pid;
+
+    llist_delete(&proc->grp_member);
+    struct proc_info* gruppenfuhrer = get_process(pgid);
+
+    if (!gruppenfuhrer) {
+        __current->k_status = LXINVL;
+        return -1;
+    }
+
+    llist_append(&gruppenfuhrer->grp_member, &proc->grp_member);
+
+    proc->pgid = pgid;
+    return 0;
+}
+
 void
 init_proc(struct proc_info* pcb)
 {
@@ -98,6 +129,7 @@ init_proc(struct proc_info* pcb)
     pcb->pid = alloc_pid();
     pcb->created = clock_systime();
     pcb->state = PROC_CREATED;
+    pcb->pgid = pcb->pid;
 }
 
 pid_t
index 7f124c428bccd9cf908e268e0bccda4c2ae990fe..8e5eecbd342c511c29c2069aab8a6ec930947f19 100644 (file)
@@ -149,11 +149,12 @@ _wait(pid_t wpid, int* status, int options)
         return -1;
     }
 
+    wpid = wpid ? wpid : -__current->pgid;
     cpu_enable_interrupt();
 repeat:
     llist_for_each(proc, n, &__current->children, siblings)
     {
-        if (!~wpid || proc->pid == wpid) {
+        if (!~wpid || proc->pid == wpid || proc->pgid == -wpid) {
             if (proc->state == PROC_TERMNAT && !options) {
                 status_flags |= PROCTERM;
                 goto done;
@@ -209,8 +210,10 @@ push_process(struct proc_info* process)
 
     process = &sched_ctx._procs[index];
 
-    // make sure the address is in the range of process table
+    // make sure the reference is relative to process table
     llist_init_head(&process->children);
+    llist_init_head(&process->grp_member);
+
     // every process is the child of first process (pid=1)
     if (process->parent) {
         llist_append(&process->parent->children, &process->siblings);