From: Minep Date: Wed, 15 Jun 2022 20:55:55 +0000 (+0100) Subject: Merge branch 'master' into signal-dev X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/commitdiff_plain/509574b18a3373030cd0d7b979499499ff06dd9b?hp=94a87fe25c5ec021daf16edd64058ed6a37aba7d Merge branch 'master' into signal-dev --- diff --git a/lunaix-os/includes/lunaix/ds/llist.h b/lunaix-os/includes/lunaix/ds/llist.h index 79fa991..1a6ec9b 100644 --- a/lunaix-os/includes/lunaix/ds/llist.h +++ b/lunaix-os/includes/lunaix/ds/llist.h @@ -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 diff --git a/lunaix-os/includes/lunaix/process.h b/lunaix-os/includes/lunaix/process.h index e429060..28cb76b 100644 --- a/lunaix-os/includes/lunaix/process.h +++ b/lunaix-os/includes/lunaix/process.h @@ -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; }; diff --git a/lunaix-os/includes/lunaix/status.h b/lunaix-os/includes/lunaix/status.h index db33da2..f3309ab 100644 --- a/lunaix-os/includes/lunaix/status.h +++ b/lunaix-os/includes/lunaix/status.h @@ -7,5 +7,6 @@ #define LXOUTOFMEM -(3) #define LXINVLDPID -(4) #define LXSEGFAULT -(5) +#define LXINVL -(6) #endif /* __LUNAIX_CODE_H */ diff --git a/lunaix-os/includes/lunaix/syscall.h b/lunaix-os/includes/lunaix/syscall.h index 9cb7764..3a6e2eb 100644 --- a/lunaix-os/includes/lunaix/syscall.h +++ b/lunaix-os/includes/lunaix/syscall.h @@ -24,12 +24,6 @@ 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 diff --git a/lunaix-os/kernel/process.c b/lunaix-os/kernel/process.c index 87a7413..64f2654 100644 --- a/lunaix-os/kernel/process.c +++ b/lunaix-os/kernel/process.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -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 diff --git a/lunaix-os/kernel/sched.c b/lunaix-os/kernel/sched.c index 7f124c4..8e5eecb 100644 --- a/lunaix-os/kernel/sched.c +++ b/lunaix-os/kernel/sched.c @@ -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);