refactor: add a async read/write variant to device ops, with allow async io to be...
[lunaix-os.git] / lunaix-os / kernel / process / signal.c
index d00e75755cf16136481e6e1213ebe7865d70abd4..8b66663a676faa743390e7be02aa2f359c2c65a6 100644 (file)
@@ -6,15 +6,19 @@
 #include <lunaix/syscall.h>
 #include <lunaix/syslog.h>
 
 #include <lunaix/syscall.h>
 #include <lunaix/syslog.h>
 
-LOG_MODULE("SIG")
-
 #include <klibc/string.h>
 
 #include <klibc/string.h>
 
+#include <sys/mm/mempart.h>
+
+LOG_MODULE("SIG")
+
 extern struct scheduler sched_ctx; /* kernel/sched.c */
 
 #define UNMASKABLE (sigset(SIGKILL) | sigset(SIGTERM))
 #define TERMSIG (sigset(SIGSEGV) | sigset(SIGINT) | UNMASKABLE)
 #define CORE (sigset(SIGSEGV))
 extern struct scheduler sched_ctx; /* kernel/sched.c */
 
 #define UNMASKABLE (sigset(SIGKILL) | sigset(SIGTERM))
 #define TERMSIG (sigset(SIGSEGV) | sigset(SIGINT) | UNMASKABLE)
 #define CORE (sigset(SIGSEGV))
+#define within_kstack(addr)                                                    \
+    (KERNEL_STACK <= (addr) && (addr) <= KERNEL_STACK_END)
 
 static inline void
 signal_terminate(int errcode)
 
 static inline void
 signal_terminate(int errcode)
@@ -35,7 +39,7 @@ signal_dispatch()
     struct sigact* prev_working = psig->inprogress;
     sigset_t mask = psig->sig_mask | (prev_working ? prev_working->sa_mask : 0);
 
     struct sigact* prev_working = psig->inprogress;
     sigset_t mask = psig->sig_mask | (prev_working ? prev_working->sa_mask : 0);
 
-    int sig_selected = 31 - __builtin_clz(psig->sig_pending & ~mask);
+    int sig_selected = 31 - clz(psig->sig_pending & ~mask);
 
     sigset_clear(psig->sig_pending, sig_selected);
 
 
     sigset_clear(psig->sig_pending, sig_selected);
 
@@ -57,13 +61,13 @@ signal_dispatch()
 
     ptr_t ustack = __current->ustack_top;
 
 
     ptr_t ustack = __current->ustack_top;
 
-    if ((int)(ustack - USTACK_END) < (int)sizeof(struct proc_sig)) {
+    if ((int)(ustack - USR_STACK) < (int)sizeof(struct proc_sig)) {
         // 用户栈没有空间存放信号上下文
         return 0;
     }
 
     struct proc_sig* sigframe =
         // 用户栈没有空间存放信号上下文
         return 0;
     }
 
     struct proc_sig* sigframe =
-      (struct proc_sig*)((ustack - sizeof(struct proc_sig)) & ~0xf);
+        (struct proc_sig*)((ustack - sizeof(struct proc_sig)) & ~0xf);
 
     sigframe->sig_num = sig_selected;
     sigframe->sigact = action->sa_actor;
 
     sigframe->sig_num = sig_selected;
     sigframe->sigact = action->sa_actor;
@@ -77,6 +81,12 @@ signal_dispatch()
     return sigframe;
 }
 
     return sigframe;
 }
 
+void
+proc_clear_signal(struct proc_info* proc)
+{
+    memset(&proc->sigctx, 0, sizeof(proc->sigctx));
+}
+
 void
 proc_setsignal(struct proc_info* proc, int signum)
 {
 void
 proc_setsignal(struct proc_info* proc, int signum)
 {
@@ -101,7 +111,7 @@ signal_send(pid_t pid, int signum)
     } else if (!pid) {
         proc = __current;
         goto send_grp;
     } else if (!pid) {
         proc = __current;
         goto send_grp;
-    } else if (pid < -1) {
+    } else if (pid < 0) {
         proc = get_process(-pid);
         goto send_grp;
     } else {
         proc = get_process(-pid);
         goto send_grp;
     } else {
@@ -168,14 +178,8 @@ __DEFINE_LXSYSCALL1(int, sigreturn, struct proc_sig, *sig_ctx)
     return 0;
 }
 
     return 0;
 }
 
-__DEFINE_LXSYSCALL3(int,
-                    sigprocmask,
-                    int,
-                    how,
-                    const sigset_t,
-                    *set,
-                    sigset_t,
-                    *oldset)
+__DEFINE_LXSYSCALL3(
+    int, sigprocmask, int, how, const sigset_t, *set, sigset_t, *oldset)
 {
     struct sighail* sh = &__current->sigctx;
     *oldset = sh->sig_mask;
 {
     struct sighail* sh = &__current->sigctx;
     *oldset = sh->sig_mask;