diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2022-08-17 15:21:22 +0000 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2022-08-17 15:21:22 +0000 |
commit | c8e25d2a18c0395431abc5818a1d2f0561b0181f (patch) | |
tree | a087f5850d7374b5cfd624244237e97b7937d5fe /sys/src/9 | |
parent | 7828ffb8a486e188b61394436a434e8cae4fd487 (diff) |
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.
Diffstat (limited to 'sys/src/9')
-rw-r--r-- | sys/src/9/bcm64/trap.c | 33 | ||||
-rw-r--r-- | sys/src/9/cycv/trap.c | 33 | ||||
-rw-r--r-- | sys/src/9/imx8/trap.c | 33 | ||||
-rw-r--r-- | sys/src/9/kw/syscall.c | 36 | ||||
-rw-r--r-- | sys/src/9/mtx/trap.c | 33 | ||||
-rw-r--r-- | sys/src/9/omap/syscall.c | 36 | ||||
-rw-r--r-- | sys/src/9/pc/trap.c | 35 | ||||
-rw-r--r-- | sys/src/9/pc64/trap.c | 36 | ||||
-rw-r--r-- | sys/src/9/port/portfns.h | 1 | ||||
-rw-r--r-- | sys/src/9/port/proc.c | 42 | ||||
-rw-r--r-- | sys/src/9/ppc/trap.c | 34 | ||||
-rw-r--r-- | sys/src/9/sgi/trap.c | 36 | ||||
-rw-r--r-- | sys/src/9/teg2/syscall.c | 36 | ||||
-rw-r--r-- | sys/src/9/xen/trap.c | 37 | ||||
-rw-r--r-- | sys/src/9/zynq/trap.c | 33 |
15 files changed, 103 insertions, 391 deletions
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; diff --git a/sys/src/9/cycv/trap.c b/sys/src/9/cycv/trap.c index 98fb56715..3d2ca3b2e 100644 --- a/sys/src/9/cycv/trap.c +++ b/sys/src/9/cycv/trap.c @@ -285,9 +285,8 @@ syscall(Ureg *ureg) int notify(Ureg *ureg) { - int l; ulong s, sp; - Note *n; + char *msg; if(up->procctl) procctl(); @@ -302,32 +301,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-15) /* " pc=0x12345678\0" */ - l = ERRMAX-15; - sprint(n->msg+l, " pc=0x%.8lux", 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); @@ -345,7 +325,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; *(ulong*)(sp+2*BY2WD) = sp+3*BY2WD; *(ulong*)(sp+1*BY2WD) = (ulong)up->ureg; @@ -353,11 +333,6 @@ notify(Ureg *ureg) ureg->sp = sp; ureg->pc = (uintptr) up->notify; ureg->r14 = 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; diff --git a/sys/src/9/imx8/trap.c b/sys/src/9/imx8/trap.c index 60f7d1937..e450139bf 100644 --- a/sys/src/9/imx8/trap.c +++ b/sys/src/9/imx8/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; diff --git a/sys/src/9/kw/syscall.c b/sys/src/9/kw/syscall.c index 521f519c1..d97aacfa5 100644 --- a/sys/src/9/kw/syscall.c +++ b/sys/src/9/kw/syscall.c @@ -98,11 +98,10 @@ noted(Ureg* cur, uintptr arg0) int notify(Ureg* ureg) { - int l; - Note *n; u32int s; uintptr sp; NFrame *nf; + char *msg; if(up->procctl) procctl(); @@ -113,33 +112,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; - snprint(n->msg + l, sizeof n->msg - l, " pc=%#lux", 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 == nil){ - qunlock(&up->debug); - pexit(n->msg, n->flag != NDebug); - } + if(!okaddr((uintptr)up->notify, 1, 0)){ qunlock(&up->debug); pprint("suicide: notify function address %#p\n", up->notify); @@ -157,7 +136,7 @@ notify(Ureg* ureg) memmove(&nf->ureg, ureg, sizeof(Ureg)); nf->old = up->ureg; up->ureg = nf; - memmove(nf->msg, up->note[0].msg, ERRMAX); + memmove(nf->msg, msg, ERRMAX); nf->arg1 = nf->msg; nf->arg0 = &nf->ureg; nf->ip = 0; @@ -166,11 +145,6 @@ notify(Ureg* ureg) ureg->pc = (uintptr)up->notify; ureg->r0 = (uintptr)nf->arg0; - 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); diff --git a/sys/src/9/mtx/trap.c b/sys/src/9/mtx/trap.c index 962401dd4..8e97dc7f6 100644 --- a/sys/src/9/mtx/trap.c +++ b/sys/src/9/mtx/trap.c @@ -677,9 +677,8 @@ syscall(Ureg* ureg) int notify(Ureg* ur) { - int l; ulong s, sp; - Note *n; + char *msg; if(up->procctl) procctl(); @@ -688,32 +687,13 @@ notify(Ureg* ur) 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-15) /* " pc=0x12345678\0" */ - l = ERRMAX-15; - sprint(n->msg+l, " pc=0x%.8lux", ur->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(ur); + if(msg == nil){ qunlock(&up->debug); splhi(); return 0; } - if(!up->notify) { - qunlock(&up->debug); - pexit(n->msg, n->flag!=NDebug); - } sp = ur->usp & ~(BY2V-1); sp -= sizeof(Ureg); @@ -728,7 +708,7 @@ notify(Ureg* ur) *(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; *(ulong*)(sp+2*BY2WD) = sp+3*BY2WD; /* arg 2 is string */ ur->r1 = (long)up->ureg; /* arg 1 is ureg* */ @@ -736,11 +716,6 @@ notify(Ureg* ur) ((ulong*)sp)[0] = 0; /* arg 0 is pc */ ur->usp = sp; ur->pc = (ulong)up->notify; - 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; diff --git a/sys/src/9/omap/syscall.c b/sys/src/9/omap/syscall.c index c97ce591c..91e27fa5f 100644 --- a/sys/src/9/omap/syscall.c +++ b/sys/src/9/omap/syscall.c @@ -98,11 +98,10 @@ noted(Ureg* cur, uintptr arg0) int notify(Ureg* ureg) { - int l; - Note *n; u32int s; uintptr sp; NFrame *nf; + char *msg; if(up->procctl) procctl(); @@ -113,33 +112,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; - snprint(n->msg + l, sizeof n->msg - l, " pc=%#lux", 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 == nil){ - qunlock(&up->debug); - pexit(n->msg, n->flag != NDebug); - } + if(!okaddr((uintptr)up->notify, 1, 0)){ qunlock(&up->debug); pprint("suicide: notify function address %#p\n", up->notify); @@ -157,7 +136,7 @@ notify(Ureg* ureg) memmove(&nf->ureg, ureg, sizeof(Ureg)); nf->old = up->ureg; up->ureg = nf; - memmove(nf->msg, up->note[0].msg, ERRMAX); + memmove(nf->msg, msg, ERRMAX); nf->arg1 = nf->msg; nf->arg0 = &nf->ureg; nf->ip = 0; @@ -166,11 +145,6 @@ notify(Ureg* ureg) ureg->pc = (uintptr)up->notify; ureg->r0 = (uintptr)nf->arg0; - 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); diff --git a/sys/src/9/pc/trap.c b/sys/src/9/pc/trap.c index eb1e8c5fe..92def96d8 100644 --- a/sys/src/9/pc/trap.c +++ b/sys/src/9/pc/trap.c @@ -565,9 +565,8 @@ syscall(Ureg* ureg) int notify(Ureg* ureg) { - int l; ulong s, sp; - Note *n; + char *msg; if(up->procctl) procctl(); @@ -582,37 +581,18 @@ 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-15) /* " pc=0x12345678\0" */ - l = ERRMAX-15; - sprint(n->msg+l, " pc=0x%.8lux", 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->usp; sp -= 256; /* debugging: preserve context causing problem */ sp -= sizeof(Ureg); if(0) print("%s %lud: notify %.8lux %.8lux %.8lux %s\n", - up->text, up->pid, ureg->pc, ureg->usp, sp, n->msg); + up->text, up->pid, ureg->pc, ureg->usp, sp, msg); if(!okaddr((uintptr)up->notify, 1, 0) || !okaddr(sp-ERRMAX-4*BY2WD, sizeof(Ureg)+ERRMAX+4*BY2WD, 1)){ @@ -625,7 +605,7 @@ if(0) print("%s %lud: notify %.8lux %.8lux %.8lux %s\n", *(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; *(ulong*)(sp+2*BY2WD) = sp+3*BY2WD; /* arg 2 is string */ *(ulong*)(sp+1*BY2WD) = (ulong)up->ureg; /* arg 1 is ureg* */ @@ -634,11 +614,6 @@ if(0) print("%s %lud: notify %.8lux %.8lux %.8lux %s\n", ureg->pc = (ulong)up->notify; ureg->cs = UESEL; ureg->ss = ureg->ds = ureg->es = UDSEL; - 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; diff --git a/sys/src/9/pc64/trap.c b/sys/src/9/pc64/trap.c index e18790c33..44379160d 100644 --- a/sys/src/9/pc64/trap.c +++ b/sys/src/9/pc64/trap.c @@ -554,9 +554,8 @@ syscall(Ureg* ureg) int notify(Ureg* ureg) { - int l; uintptr sp; - Note *n; + char *msg; if(up->procctl) procctl(); @@ -564,39 +563,18 @@ notify(Ureg* ureg) return 0; 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-15) /* " pc=0x12345678\0" */ - l = ERRMAX-15; - sprint(n->msg+l, " pc=%#p", ureg->pc); - } - - if(n->flag!=NUser && (up->notified || up->notify==0)){ - qunlock(&up->debug); - if(n->flag == NDebug){ - up->fpstate &= ~FPillegal; - 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); if(0) print("%s %lud: notify %#p %#p %#p %s\n", - up->text, up->pid, ureg->pc, ureg->sp, sp, n->msg); + up->text, up->pid, ureg->pc, ureg->sp, sp, msg); if(!okaddr((uintptr)up->notify, 1, 0) || !okaddr(sp-ERRMAX-4*BY2WD, sizeof(Ureg)+ERRMAX+4*BY2WD, 1)){ @@ -610,7 +588,7 @@ if(0) print("%s %lud: notify %#p %#p %#p %s\n", *(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] = sp + 3*BY2WD; /* arg2 string */ ((uintptr*)sp)[1] = (uintptr)up->ureg; /* arg1 is ureg* */ @@ -620,10 +598,6 @@ if(0) print("%s %lud: notify %#p %#p %#p %s\n", ureg->bp = (uintptr)up->ureg; /* arg1 passed in RARG */ ureg->cs = UESEL; ureg->ss = UDSEL; - 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); splhi(); if(up->fpstate == FPactive){ diff --git a/sys/src/9/port/portfns.h b/sys/src/9/port/portfns.h index 5fe9fd437..9a4f1824d 100644 --- a/sys/src/9/port/portfns.h +++ b/sys/src/9/port/portfns.h @@ -235,6 +235,7 @@ ulong pidalloc(Proc*); #define waserror() setlabel(&up->errlab[up->nerrlab++]) #define poperror() up->nerrlab-- void portcountpagerefs(ulong*, int); +char* popnote(Ureg*); int postnote(Proc*, int, char*, int); int pprint(char*, ...); int preempted(void); diff --git a/sys/src/9/port/proc.c b/sys/src/9/port/proc.c index 1fad45853..f0822f575 100644 --- a/sys/src/9/port/proc.c +++ b/sys/src/9/port/proc.c @@ -899,6 +899,48 @@ wakeup(Rendez *r) } /* + * pop a note from the calling process or suicide if theres + * no note handler or notify during note handling. + * Called from notify() with up->debug lock held. + */ +char* +popnote(Ureg *u) +{ + assert(!canqlock(&up->debug)); + + up->notepending = 0; + if(up->nnote == 0) + return nil; + assert(up->nnote > 0); + + /* hold off user notes during note handling */ + if(up->notified && up->note[0].flag == NUser) + return nil; + + memmove(&up->lastnote, &up->note[0], sizeof(Note)); + if(--up->nnote) + memmove(&up->note[0], &up->note[1], up->nnote*sizeof(Note)); + + if(u != nil && strncmp(up->lastnote.msg, "sys:", 4) == 0){ + int l = strlen(up->lastnote.msg); + assert(l < ERRMAX); + snprint(up->lastnote.msg+l, ERRMAX-l, " pc=%#p", u->pc); + } + + if(up->notify == nil || up->notified){ + qunlock(&up->debug); + if(up->lastnote.flag == NDebug){ + up->fpstate &= ~FPillegal; + pprint("suicide: %s\n", up->lastnote.msg); + } + pexit(up->lastnote.msg, up->lastnote.flag!=NDebug); + } + up->notified = 1; + + return up->lastnote.msg; +} + +/* * if waking a sleeping process, this routine must hold both * p->rlock and r->lock. However, it can't know them in * the same order as wakeup causing a possible lock ordering diff --git a/sys/src/9/ppc/trap.c b/sys/src/9/ppc/trap.c index 1aa5862d3..8c7965481 100644 --- a/sys/src/9/ppc/trap.c +++ b/sys/src/9/ppc/trap.c @@ -666,9 +666,8 @@ syscall(Ureg* ureg) int notify(Ureg* ur) { - int l; ulong s, sp; - Note *n; + char *msg; if(up->procctl) procctl(); @@ -683,33 +682,13 @@ notify(Ureg* ur) 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-15) /* " pc=0x12345678\0" */ - l = ERRMAX-15; - sprint(n->msg+l, " pc=0x%.8lux", ur->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(ur); + if(msg == nil){ qunlock(&up->debug); splhi(); return 0; } - if(!up->notify) { - qunlock(&up->debug); - pexit(n->msg, n->flag!=NDebug); - } - sp = ur->usp & ~(BY2V-1); sp -= sizeof(Ureg); @@ -724,7 +703,7 @@ notify(Ureg* ur) *(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; *(ulong*)(sp+2*BY2WD) = sp+3*BY2WD; /* arg 2 is string */ ur->r1 = (long)up->ureg; /* arg 1 is ureg* */ @@ -732,11 +711,6 @@ notify(Ureg* ur) ((ulong*)sp)[0] = 0; /* arg 0 is pc */ ur->usp = sp; ur->pc = (ulong)up->notify; - 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; diff --git a/sys/src/9/sgi/trap.c b/sys/src/9/sgi/trap.c index c97ee7d08..da1542752 100644 --- a/sys/src/9/sgi/trap.c +++ b/sys/src/9/sgi/trap.c @@ -470,9 +470,9 @@ dumpregs(Ureg *ur) int notify(Ureg *ur) { - int l, s; + int s; ulong sp; - Note *n; + char *msg; if(up->procctl) procctl(); @@ -487,34 +487,13 @@ notify(Ureg *ur) 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-15) /* " pc=0x12345678\0" */ - l = ERRMAX-15; - - seprint(n->msg+l, &n->msg[sizeof n->msg], " pc=%#lux", ur->pc); - } - - if(n->flag != NUser && (up->notified || up->notify==0)) { - if(n->flag == NDebug) - pprint("suicide: %s\n", n->msg); - - qunlock(&up->debug); - pexit(n->msg, n->flag!=NDebug); - } - - if(up->notified) { + msg = popnote(ur); + if(msg == nil){ qunlock(&up->debug); splx(s); return 0; } - if(!up->notify) { - qunlock(&up->debug); - pexit(n->msg, n->flag!=NDebug); - } sp = ur->usp & ~(BY2V-1); sp -= sizeof(Ureg); @@ -530,7 +509,7 @@ notify(Ureg *ur) up->ureg = (void*)sp; sp -= BY2WD+ERRMAX; - memmove((char*)sp, up->note[0].msg, ERRMAX); /* push err string */ + memmove((char*)sp, msg, ERRMAX); /* push err string */ sp -= 3*BY2WD; *(ulong*)(sp+2*BY2WD) = sp+3*BY2WD; /* arg 2 is string */ @@ -544,11 +523,6 @@ notify(Ureg *ur) */ ur->pc = (ulong)up->notify; - 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; diff --git a/sys/src/9/teg2/syscall.c b/sys/src/9/teg2/syscall.c index 6d5c6ba1f..ad84ffa30 100644 --- a/sys/src/9/teg2/syscall.c +++ b/sys/src/9/teg2/syscall.c @@ -104,11 +104,10 @@ noted(Ureg* cur, uintptr arg0) int notify(Ureg* ureg) { - int l; - Note *n; u32int s; uintptr sp; NFrame *nf; + char *msg; if(up->procctl) procctl(); @@ -119,33 +118,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; - snprint(n->msg + l, sizeof n->msg - l, " pc=%#lux", 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 == nil){ - qunlock(&up->debug); - pexit(n->msg, n->flag != NDebug); - } + if(!okaddr((uintptr)up->notify, 1, 0)){ qunlock(&up->debug); pprint("suicide: notify function address %#p\n", up->notify); @@ -163,7 +142,7 @@ notify(Ureg* ureg) memmove(&nf->ureg, ureg, sizeof(Ureg)); nf->old = up->ureg; up->ureg = nf; - memmove(nf->msg, up->note[0].msg, ERRMAX); + memmove(nf->msg, msg, ERRMAX); nf->arg1 = nf->msg; nf->arg0 = &nf->ureg; nf->ip = 0; @@ -172,11 +151,6 @@ notify(Ureg* ureg) ureg->pc = (uintptr)up->notify; ureg->r0 = (uintptr)nf->arg0; - 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); diff --git a/sys/src/9/xen/trap.c b/sys/src/9/xen/trap.c index 7527461fc..6faf1ccbf 100644 --- a/sys/src/9/xen/trap.c +++ b/sys/src/9/xen/trap.c @@ -480,9 +480,8 @@ syscall(Ureg* ureg) int notify(Ureg* ureg) { - int l; ulong s, sp; - Note *n; + char *msg; if(up->procctl) procctl(); @@ -497,39 +496,20 @@ 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-15) /* " pc=0x12345678\0" */ - l = ERRMAX-15; - sprint(n->msg+l, " pc=0x%.8lux", ureg->pc); - } - - if(n->flag!=NUser && (up->notified || up->notify==0)){ - if(n->flag == NDebug) - pprint("suicide: %s\n", n->msg); - qunlock(&up->debug); - 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->usp; sp -= sizeof(Ureg); if(!okaddr((ulong)up->notify, 1, 0) || !okaddr(sp-ERRMAX-4*BY2WD, sizeof(Ureg)+ERRMAX+4*BY2WD, 1)){ - pprint("suicide: bad address in notify\n"); qunlock(&up->debug); + pprint("suicide: bad address in notify\n"); pexit("Suicide", 0); } @@ -538,18 +518,13 @@ 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; *(ulong*)(sp+2*BY2WD) = sp+3*BY2WD; /* arg 2 is string */ *(ulong*)(sp+1*BY2WD) = (ulong)up->ureg; /* arg 1 is ureg* */ *(ulong*)(sp+0*BY2WD) = 0; /* arg 0 is pc */ ureg->usp = sp; ureg->pc = (ulong)up->notify; - 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; diff --git a/sys/src/9/zynq/trap.c b/sys/src/9/zynq/trap.c index c245be526..0fc34a573 100644 --- a/sys/src/9/zynq/trap.c +++ b/sys/src/9/zynq/trap.c @@ -285,9 +285,8 @@ syscall(Ureg *ureg) int notify(Ureg *ureg) { - int l; ulong s, sp; - Note *n; + char *msg; if(up->procctl) procctl(); @@ -302,32 +301,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-15) /* " pc=0x12345678\0" */ - l = ERRMAX-15; - sprint(n->msg+l, " pc=0x%.8lux", 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); @@ -345,7 +325,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; *(ulong*)(sp+2*BY2WD) = sp+3*BY2WD; *(ulong*)(sp+1*BY2WD) = (ulong)up->ureg; @@ -353,11 +333,6 @@ notify(Ureg *ureg) ureg->sp = sp; ureg->pc = (uintptr) up->notify; ureg->r14 = 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; |