From 3d4300dd8282a8eef4a78c440fa2137a42b76de9 Mon Sep 17 00:00:00 2001 From: Greg Haerr Date: Sun, 19 Jan 2025 17:38:08 -0700 Subject: [PATCH 1/2] [libc] Fix longstanding signal handling bug with improperly set DS register --- elks/arch/i86/kernel/process.c | 1 + libc/system/signalcb.S | 4 ++++ libc/watcom/asm/signalcb.asm | 2 ++ 3 files changed, 7 insertions(+) diff --git a/elks/arch/i86/kernel/process.c b/elks/arch/i86/kernel/process.c index 95740bd4e..18b8ad7e5 100644 --- a/elks/arch/i86/kernel/process.c +++ b/elks/arch/i86/kernel/process.c @@ -132,6 +132,7 @@ void arch_setup_user_stack (register struct task_struct * t, word_t entry) void arch_setup_sighandler_stack(register struct task_struct *t, __kern_sighandler_t addr,unsigned signr) { + printk("SIGCB %d: DS %x SS %x\n", t->pid, t->t_regs.ds, t->t_regs.ss); debug("Stack %x:%x was %x %x %x %x\n", _FP_SEG(addr), _FP_OFF(addr), get_ustack(t,0), get_ustack(t,2), get_ustack(t,4), get_ustack(t,6)); put_ustack(t, -6, (int)get_ustack(t,0)); diff --git a/libc/system/signalcb.S b/libc/system/signalcb.S index 17ce5116f..4cf5b223c 100644 --- a/libc/system/signalcb.S +++ b/libc/system/signalcb.S @@ -20,7 +20,10 @@ _signal_cbhandler: push %dx push %si push %di + push %ds push %es + mov %ss,%ax + mov %ax,%ds mov 6(%bp),%bx #ifndef __IA16_CALLCVT_REGPARMCALL @@ -43,6 +46,7 @@ _signal_cbhandler: #endif pop %es + pop %ds pop %di pop %si pop %dx diff --git a/libc/watcom/asm/signalcb.asm b/libc/watcom/asm/signalcb.asm index 765956d22..ca0be81c3 100644 --- a/libc/watcom/asm/signalcb.asm +++ b/libc/watcom/asm/signalcb.asm @@ -20,6 +20,8 @@ __signal_cbhandler proc far push di push ds push es + mov ax,ss ; ensure valid DS (=SS) + mov ds,ax mov ax,6[bp] ; get signal # callf _signal_wchandler_ ; call user function from C From 05337536f24bbbccf161dce72d960e990f6ec0c5 Mon Sep 17 00:00:00 2001 From: Greg Haerr Date: Sun, 19 Jan 2025 17:52:19 -0700 Subject: [PATCH 2/2] Cleanup --- elks/arch/i86/kernel/process.c | 1 - 1 file changed, 1 deletion(-) diff --git a/elks/arch/i86/kernel/process.c b/elks/arch/i86/kernel/process.c index 18b8ad7e5..95740bd4e 100644 --- a/elks/arch/i86/kernel/process.c +++ b/elks/arch/i86/kernel/process.c @@ -132,7 +132,6 @@ void arch_setup_user_stack (register struct task_struct * t, word_t entry) void arch_setup_sighandler_stack(register struct task_struct *t, __kern_sighandler_t addr,unsigned signr) { - printk("SIGCB %d: DS %x SS %x\n", t->pid, t->t_regs.ds, t->t_regs.ss); debug("Stack %x:%x was %x %x %x %x\n", _FP_SEG(addr), _FP_OFF(addr), get_ustack(t,0), get_ustack(t,2), get_ustack(t,4), get_ustack(t,6)); put_ustack(t, -6, (int)get_ustack(t,0));