From c8e25d2a18c0395431abc5818a1d2f0561b0181f Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Wed, 17 Aug 2022 15:21:22 +0000 Subject: kernel: simplify notify() adding common popnote() function Handlin notes is common for all architectures except how the note has to be pushed on the user stack. This change adds a popnote() function that returns only the note string or nil if the process should not be notified (no notes or user notes hold off). Popnote() also handles common errors like notify during note handling or missing note handler and will suicide the process in that case. --- sys/src/9/bcm64/trap.c | 33 ++++----------------------------- 1 file changed, 4 insertions(+), 29 deletions(-) (limited to 'sys/src/9/bcm64') diff --git a/sys/src/9/bcm64/trap.c b/sys/src/9/bcm64/trap.c index 60f7d1937..e450139bf 100644 --- a/sys/src/9/bcm64/trap.c +++ b/sys/src/9/bcm64/trap.c @@ -274,9 +274,8 @@ syscall(Ureg *ureg) int notify(Ureg *ureg) { - int l; uintptr s, sp; - Note *n; + char *msg; if(up->procctl) procctl(); @@ -290,32 +289,13 @@ notify(Ureg *ureg) s = spllo(); qlock(&up->debug); - up->notepending = 0; - n = &up->note[0]; - if(strncmp(n->msg, "sys:", 4) == 0){ - l = strlen(n->msg); - if(l > ERRMAX-23) /* " pc=0x0123456789abcdef\0" */ - l = ERRMAX-23; - sprint(n->msg+l, " pc=%#p", ureg->pc); - } - - if(n->flag!=NUser && (up->notified || up->notify==0)){ - qunlock(&up->debug); - if(n->flag == NDebug) - pprint("suicide: %s\n", n->msg); - pexit(n->msg, n->flag!=NDebug); - } - - if(up->notified){ + msg = popnote(ureg); + if(msg == nil){ qunlock(&up->debug); splhi(); return 0; } - if(!up->notify){ - qunlock(&up->debug); - pexit(n->msg, n->flag!=NDebug); - } sp = ureg->sp; sp -= 256; /* debugging: preserve context causing problem */ sp -= sizeof(Ureg); @@ -335,7 +315,7 @@ notify(Ureg *ureg) *(Ureg**)(sp-BY2WD) = up->ureg; /* word under Ureg is old up->ureg */ up->ureg = (void*)sp; sp -= BY2WD+ERRMAX; - memmove((char*)sp, up->note[0].msg, ERRMAX); + memmove((char*)sp, msg, ERRMAX); sp -= 3*BY2WD; *(uintptr*)(sp+2*BY2WD) = sp+3*BY2WD; *(uintptr*)(sp+1*BY2WD) = (uintptr)up->ureg; @@ -343,11 +323,6 @@ notify(Ureg *ureg) ureg->sp = sp; ureg->pc = (uintptr) up->notify; ureg->link = 0; - up->notified = 1; - up->nnote--; - memmove(&up->lastnote, &up->note[0], sizeof(Note)); - memmove(&up->note[0], &up->note[1], up->nnote*sizeof(Note)); - qunlock(&up->debug); splx(s); return 1; -- cgit v1.2.3