Skip to content

Commit

Permalink
rework signal handling
Browse files Browse the repository at this point in the history
JIRA: RTOS-539
  • Loading branch information
lukileczo committed Aug 10, 2023
1 parent c83868a commit 489685c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 73 deletions.
18 changes: 8 additions & 10 deletions arch/armv7a/signal.S
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@
.globl _signal_trampoline
.type _signal_trampoline, %function
_signal_trampoline:
// stack: return address, signal number
push {r0-r3,r9,r12,lr}
mrs r0, apsr
push {r0}
ldr r0, [sp, #32]
blx _signal_handler
/* Get signal number from stack */
pop {r0}
msr apsr_nzcvqg, r0
pop {r0-r3,r9,r12,lr}
add sp, #4
pop {pc}
blx _signal_handler

/* Old signal mask in r0 */
pop {r1} /* cpu context * */
pop {r2} /* pc */
pop {r3} /* sp */
bl sigreturn
.size _signal_trampoline, .-_signal_trampoline
21 changes: 6 additions & 15 deletions arch/ia32/signal.S
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,13 @@
.globl _signal_trampoline
.type _signal_trampoline, %function
_signal_trampoline:
// stack: return address, signal number
xchgl (%esp), %eax
push %ebx
push %ecx
push %edx
pushf

push %eax
/* Signal number on stack */
call _signal_handler
addl $4, %esp

popf
pop %edx
pop %ecx
pop %ebx
pop %eax
ret
addl $4, %esp
/* Put old mask on stack */
push %eax
/* cpu context *, eip, esp on stack */
call sigreturn
.size _signal_trampoline, .-_signal_trampoline

53 changes: 8 additions & 45 deletions arch/riscv64/signal.S
Original file line number Diff line number Diff line change
Expand Up @@ -20,51 +20,14 @@
.globl _signal_trampoline
.type _signal_trampoline, %function
_signal_trampoline:

// stack: return address, signal number
addi sp, sp, -136
sd x1, (sp) /* ra */
sd x3, 8(sp) /* gp */
sd x5, 16(sp) /* t0 */
sd x6, 24(sp) /* t1 */
sd x7, 32(sp) /* t2 */
sd x10, 40(sp) /* a0 */
sd x11, 48(sp) /* a1 */
sd x12, 56(sp) /* a2 */
sd x13, 64(sp) /* a3 */
sd x14, 72(sp) /* a4 */
sd x15, 80(sp) /* a5 */
sd x16, 88(sp) /* a6 */
sd x17, 96(sp) /* a7 */
sd x28, 104(sp) /* t3 */
sd x29, 112(sp) /* t4 */
sd x30, 120(sp) /* t5 */
sd x31, 128(sp) /* t6 */

ld a0, 136(sp) /* signal number is 1st argument */
/* Get signal number from stack */
lw a0, (sp)
call _signal_handler

ld x1, (sp) /* ra */
ld x3, 8(sp) /* gp */
ld x5, 16(sp) /* t0 */
ld x6, 24(sp) /* t1 */
ld x7, 32(sp) /* t2 */
ld x10, 40(sp) /* a0 */
ld x11, 48(sp) /* a1 */
ld x12, 56(sp) /* a2 */
ld x13, 64(sp) /* a3 */
ld x14, 72(sp) /* a4 */
ld x15, 80(sp) /* a5 */
ld x16, 88(sp) /* a6 */
ld x17, 96(sp) /* a7 */
ld x28, 104(sp) /* t3 */
ld x29, 112(sp) /* t4 */
ld x30, 120(sp) /* t5 */
ld x31, 128(sp) /* t6 */
addi sp, sp, 144 /* saved state, signal number and return address on stack */

/* TODO correct this, it is wrong, we need a way to load pc without touching any other register */
ld t4, -8(sp)
jr t4

/* Old signal mask in a0 */
ld a1, 8(sp) /* cpu context * */
ld a2, 16(sp) /* sepc */
ld a3, 24(sp) /* sp */
addi sp, sp, 32
call sigreturn
.size _signal_trampoline, .-_signal_trampoline
8 changes: 5 additions & 3 deletions signal/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ static int _signal_ismutable(int sig)
}


void _signal_handler(int phxsig)
unsigned int _signal_handler(int phxsig)
{
int sig;
unsigned int oldmask;

if (phxsig < 0 || phxsig >= NSIG) {
/* Don't know what to do, ignore it */
return;
return signalMask(0U, 0U);
}

/* Received Phoenix signal, need to convert it to POSIX signal */
Expand All @@ -141,7 +141,9 @@ void _signal_handler(int phxsig)
/* Invoke handler */
(signal_common.sightab[sig])(sig);

signalMask(oldmask, 0xffffffffUL);
/* Mask restored by sigreturn */

return oldmask;
}


Expand Down

0 comments on commit 489685c

Please sign in to comment.