]> 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 173034c39cc93cae7fbf8337088c474b267cd18d..f9e6d64a79616dfe9449ef55840906ef38593afe 100644 (file)
@@ -81,6 +81,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 f8d964cde09156777d42432cf0d61e4e8255fb75..b8380e48c21b582ccdad89bb138a94f804aef963 100644 (file)
@@ -118,6 +118,7 @@ enum {
     SYSCALL_ALARM     = 83,
     SYSCALL_TIMES     = 84,
     SYSCALL_FUTEX     = 85,
+    SYSCALL_SIGALTSTACK = 86,
 };
 
 #endif
index 8434ca430590e96a4a28df3a5db3af7694ad8d8e..e346592c53e1a283bae7ad14a84f0f0a8cea9055 100644 (file)
@@ -2281,7 +2281,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;
     }
@@ -2462,6 +2463,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 64b4a80a0e0ddfb05e8174a543b21de96d1273aa..7391fbeaf8a959b1b4cef97e4acbe71069078c20 100644 (file)
@@ -62,4 +62,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 ef02a53e8786a95a3147e5026a8aa7db983ded10..51ec5a77e8fc86515a85da483362af734017c554 100644 (file)
@@ -77,6 +77,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 1834291a6b422207cc7d9f93ce153e7c15aacd48..23733ad34c895f22530d126f7712c3572cecb4c5 100644 (file)
@@ -30,3 +30,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));
+}