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)
1  2 
lunaix-os/includes/lunaix/process.h
lunaix-os/includes/lunaix/syscall.h
lunaix-os/kernel/sched.c

index e429060ab5f785b9ffdcec9f12c6cb534bfc48aa,32b74dff5397e2fe29ce13eab3ef89ea3191f317..28cb76b97a797089cdceacac9a3323c373c0760a
@@@ -4,7 -4,6 +4,7 @@@
  #include <arch/x86/interrupts.h>
  #include <lunaix/clock.h>
  #include <lunaix/mm/mm.h>
 +#include <lunaix/signal.h>
  #include <lunaix/timer.h>
  #include <lunaix/types.h>
  #include <stdint.h>
@@@ -27,32 -26,21 +27,34 @@@ struct proc_m
      struct mm_region* regions;
  };
  
 +struct proc_sig
 +{
 +    void* signal_handler;
 +    int sig_num;
 +    isr_param prev_context;
 +};
 +
 +#define PROC_SIG_SIZE sizeof(struct proc_sig) // size=84
 +
  struct proc_info
  {
      pid_t pid;
      struct proc_info* parent;
 -    isr_param intr_ctx;
 +    isr_param intr_ctx; // size=76
 +    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;
      uint8_t state;
      int32_t exit_code;
      int32_t k_status;
 +    sigset_t sig_pending;
 +    sigset_t sig_mask;
 +    void* sig_handler[_SIG_NUM];
+     pid_t pgid;
      struct lx_timer* timer;
  };
  
index 9cb77647fcad0c1839802cc934486f6d141bd21b,37aa852bebfd6e0a627a34c7e5c4abbf983ff7cc..3a6e2eba10285ed8f84726ab543f5d40a52a0b50
  #define __SYSCALL__exit 8
  #define __SYSCALL_wait 9
  #define __SYSCALL_waitpid 10
 +#define __SYSCALL_sigreturn 11
 +#define __SYSCALL_sigprocmask 12
 +#define __SYSCALL_signal 13
 +#define __SYSCALL_pause 14
  
  #define __SYSCALL_MAX 0x100
  
  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
@@@ -56,7 -46,7 +50,7 @@@
      asmlinkage rettype __lxsys_##name(__PARAM_MAP3(t1, p1, t2, p2, t3, p3))
  
  #define __DEFINE_LXSYSCALL4(rettype, name, t1, p1, t2, p2, t3, p3, t4, p4)     \
 -    asmlinkage rettype __lxsys_##nam                                         \
 +    asmlinkage rettype __lxsys_##name(                                         \
        __PARAM_MAP4(t1, p1, t2, p2, t3, p3, t4, p4))
  
  #define __LXSYSCALL(rettype, name)                                             \
diff --combined lunaix-os/kernel/sched.c
index 7f124c428bccd9cf908e268e0bccda4c2ae990fe,e7bcd9a6d3fc5fb3a7e8b5577e9592f4ab8f8a1c..8e5eecbd342c511c29c2069aab8a6ec930947f19
@@@ -1,14 -1,12 +1,14 @@@
  #include <arch/x86/interrupts.h>
  #include <arch/x86/tss.h>
 +
  #include <hal/apic.h>
  #include <hal/cpu.h>
 +
  #include <lunaix/mm/kalloc.h>
  #include <lunaix/mm/vmm.h>
  #include <lunaix/process.h>
  #include <lunaix/sched.h>
 -
 +#include <lunaix/signal.h>
  #include <lunaix/spike.h>
  #include <lunaix/status.h>
  #include <lunaix/syscall.h>
@@@ -60,8 -58,6 +60,8 @@@ run(struct proc_info* proc
  
      apic_done_servicing();
  
 +    signal_dispatch();
 +
      asm volatile("pushl %0\n"
                   "jmp soft_iret\n" ::"r"(&__current->intr_ctx)
                   : "memory");
@@@ -149,11 -145,12 +149,12 @@@ _wait(pid_t wpid, int* status, int opti
          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 -206,10 +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);