]> Projects (at) Tadryanom (dot) Me - AdrOS.git/commitdiff
feat: sigaltstack syscall (86) — alternate signal stack per-process (ss_sp/ss_size...
authorTulio A M Mendes <[email protected]>
Thu, 12 Feb 2026 04:00:34 +0000 (01:00 -0300)
committerTulio A M Mendes <[email protected]>
Fri, 13 Feb 2026 02:20:50 +0000 (23:20 -0300)
include/process.h
include/syscall.h
src/kernel/syscall.c
user/ulibc/include/signal.h
user/ulibc/include/syscall.h
user/ulibc/src/signal.c

index 8c2ace63720a2304837e233b45c125e1d0167128..fee54f5a709790aac0e94689f5852e572be0eafc 100644 (file)
@@ -72,6 +72,9 @@ struct process {
     struct sigaction sigactions[PROCESS_MAX_SIG];
     uint32_t sig_blocked_mask;
     uint32_t sig_pending_mask;
+    uintptr_t ss_sp;            /* alternate signal stack pointer */
+    uint32_t  ss_size;          /* alternate signal stack size */
+    uint32_t  ss_flags;         /* SS_DISABLE etc. */
 
     // For SIGSEGV: last page fault address (CR2) captured in ring3.
     uintptr_t last_fault_addr;
index f1b67dc9a0b7b5454572ee15c75b46035be8de58..9f16ebcd12e44a976c9bfbec7944b0694ab58378 100644 (file)
@@ -109,6 +109,7 @@ enum {
     SYSCALL_ALARM     = 83,
     SYSCALL_TIMES     = 84,
     SYSCALL_FUTEX     = 85,
+    SYSCALL_SIGALTSTACK = 86,
 };
 
 #endif
index d0821f2b5ebb3b2340d6c9704166eb36e2ac1205..c2940b70086a76d734cbd792729078f8d07e6de5 100644 (file)
@@ -2272,7 +2272,8 @@ void syscall_handler(struct registers* regs) {
         return;
     }
 
-    if (syscall_no == SYSCALL_TIMES || syscall_no == SYSCALL_FUTEX) {
+    if (syscall_no == SYSCALL_SIGALTSTACK ||
+        syscall_no == SYSCALL_TIMES || syscall_no == SYSCALL_FUTEX) {
         posix_ext_syscall_dispatch(regs, syscall_no);
         return;
     }
@@ -2453,6 +2454,41 @@ static void posix_ext_syscall_dispatch(struct registers* regs, uint32_t syscall_
         return;
     }
 
+    if (syscall_no == SYSCALL_SIGALTSTACK) {
+        if (!current_process) { regs->eax = (uint32_t)-EINVAL; return; }
+        #ifndef SS_DISABLE
+        #define SS_DISABLE 2
+        #endif
+        uint32_t* user_old = (uint32_t*)regs->ecx;
+        uint32_t* user_new = (uint32_t*)regs->ebx;
+        if (user_old) {
+            uint32_t old_ss[3];
+            old_ss[0] = (uint32_t)current_process->ss_sp;
+            old_ss[1] = current_process->ss_flags;
+            old_ss[2] = current_process->ss_size;
+            if (copy_to_user(user_old, old_ss, 12) < 0) {
+                regs->eax = (uint32_t)-EFAULT; return;
+            }
+        }
+        if (user_new) {
+            uint32_t new_ss[3];
+            if (copy_from_user(new_ss, user_new, 12) < 0) {
+                regs->eax = (uint32_t)-EFAULT; return;
+            }
+            if (new_ss[1] & SS_DISABLE) {
+                current_process->ss_sp = 0;
+                current_process->ss_size = 0;
+                current_process->ss_flags = SS_DISABLE;
+            } else {
+                current_process->ss_sp = (uintptr_t)new_ss[0];
+                current_process->ss_flags = new_ss[1];
+                current_process->ss_size = new_ss[2];
+            }
+        }
+        regs->eax = 0;
+        return;
+    }
+
     if (syscall_no == SYSCALL_FUTEX) {
         #define FUTEX_WAIT 0
         #define FUTEX_WAKE 1
index f6816c6de629a1fda8d36ab5a739f8db4b6ace2c..68dc55387133db24abd3405d707accdef3901fdc 100644 (file)
@@ -53,4 +53,13 @@ int sigprocmask(int how, const uint32_t* set, uint32_t* oldset);
 int sigpending(uint32_t* set);
 int sigsuspend(const uint32_t* mask);
 
+#define SS_DISABLE 2
+typedef struct {
+    void*    ss_sp;
+    int      ss_flags;
+    unsigned ss_size;
+} stack_t;
+
+int sigaltstack(const stack_t* ss, stack_t* old_ss);
+
 #endif
index ebc3bccafc1b59373147c36679d9a2a9b43ef004..568e79fabfb9e7817492f1353df9721e6ef007b4 100644 (file)
@@ -68,6 +68,7 @@ enum {
     SYS_ALARM = 83,
     SYS_TIMES = 84,
     SYS_FUTEX = 85,
+    SYS_SIGALTSTACK = 86,
 };
 
 /* Raw syscall wrappers — up to 5 args via INT 0x80 */
index 2b20fa600896f7d500da7e3a754d3f27497e0391..625c69d919a87623524bafeb06cda93b6f531263 100644 (file)
@@ -21,3 +21,7 @@ int sigpending(uint32_t* set) {
 int sigsuspend(const uint32_t* mask) {
     return __syscall_ret(_syscall1(SYS_SIGSUSPEND, (int)mask));
 }
+
+int sigaltstack(const stack_t* ss, stack_t* old_ss) {
+    return __syscall_ret(_syscall2(SYS_SIGALTSTACK, (int)ss, (int)old_ss));
+}