From: cinap_lenrek Date: Mon, 20 Jan 2014 01:16:42 +0000 (+0100) Subject: kernel: various cleanups X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=ad1eefb3556354b0fdf58faa3b4f5498d99a1f23;p=plan9front.git kernel: various cleanups --- diff --git a/sys/src/9/alphapc/trap.c b/sys/src/9/alphapc/trap.c index 0861abbce..a879ab6ca 100644 --- a/sys/src/9/alphapc/trap.c +++ b/sys/src/9/alphapc/trap.c @@ -562,7 +562,7 @@ notify(Ureg *ur) sp = ur->usp & ~(BY2V-1); sp -= sizeof(Ureg); - if(!okaddr((ulong)up->notify, BY2WD, 0) + if(!okaddr((uintptr)up->notify, BY2WD, 0) || !okaddr(sp-ERRMAX-6*BY2WD, sizeof(Ureg)+ERRMAX-6*BY2WD, 1)) { qunlock(&up->debug); pprint("suicide: bad address or sp in notify\n"); @@ -627,7 +627,7 @@ noted(Ureg *kur, Ureg **urp, ulong arg0) oureg = (ulong)nur; if((oureg & (BY2V-1)) - || !okaddr((ulong)oureg-BY2WD, BY2WD+sizeof(Ureg), 0)){ + || !okaddr(oureg-BY2WD, BY2WD+sizeof(Ureg), 0)){ qunlock(&up->debug); pprint("bad ureg in noted or call to noted() when not notified\n"); pexit("Suicide", 0); diff --git a/sys/src/9/bitsy/trap.c b/sys/src/9/bitsy/trap.c index d71d96664..fd0644f6b 100644 --- a/sys/src/9/bitsy/trap.c +++ b/sys/src/9/bitsy/trap.c @@ -616,7 +616,7 @@ noted(Ureg* ureg, ulong arg0) /* sanity clause */ oureg = (ulong)nureg; - if(!okaddr((ulong)oureg-BY2WD, BY2WD+sizeof(Ureg), 0)){ + if(!okaddr(oureg-BY2WD, BY2WD+sizeof(Ureg), 0)){ qunlock(&up->debug); pprint("bad ureg in noted or call to noted when not notified\n"); pexit("Suicide", 0); @@ -714,7 +714,7 @@ notify(Ureg* ureg) sp = ureg->sp; sp -= sizeof(Ureg); - if(!okaddr((ulong)up->notify, 1, 0) + if(!okaddr((uintptr)up->notify, 1, 0) || !okaddr(sp-ERRMAX-4*BY2WD, sizeof(Ureg)+ERRMAX+4*BY2WD, 1)){ qunlock(&up->debug); pprint("suicide: bad address in notify\n"); diff --git a/sys/src/9/kw/fpiarm.c b/sys/src/9/kw/fpiarm.c index 8d5a20e52..8735f87ba 100644 --- a/sys/src/9/kw/fpiarm.c +++ b/sys/src/9/kw/fpiarm.c @@ -648,7 +648,7 @@ casemu(ulong pc, ulong op, Ureg *ur) rn = rp[op>>0 & 0x7]; rd = rp + (op>>12 & 0x7); rp = (ulong*)*rd; - validaddr((ulong)rp, 4, 1); + validaddr((uintptr)rp, 4, 1); splhi(); if(*rd = (*rp == ro)) *rp = rn; @@ -667,7 +667,7 @@ ldrex(ulong pc, ulong op, Ureg *ur) rp = (ulong*)ur; rd = rp + (op>>16 & 0x7); addr = (ulong*)*rd; - validaddr((ulong)addr, 4, 0); + validaddr((uintptr)addr, 4, 0); ldrexvalid = 1; rp[op>>12 & 0x7] = *addr; if(fpemudebug) @@ -686,7 +686,7 @@ strex(ulong pc, ulong op, Ureg *ur) rd = rp + (op>>16 & 0x7); rn = rp[op>>0 & 0x7]; addr = (ulong*)*rd; - validaddr((ulong)addr, 4, 1); + validaddr((uintptr)addr, 4, 1); splhi(); if(ldrexvalid){ if(fpemudebug) diff --git a/sys/src/9/mtx/trap.c b/sys/src/9/mtx/trap.c index d0a16225f..022ec4903 100644 --- a/sys/src/9/mtx/trap.c +++ b/sys/src/9/mtx/trap.c @@ -736,7 +736,7 @@ notify(Ureg* ur) sp = ur->usp & ~(BY2V-1); sp -= sizeof(Ureg); - if(!okaddr((ulong)up->notify, BY2WD, 0) || + if(!okaddr((uintptr)up->notify, BY2WD, 0) || !okaddr(sp-ERRMAX-4*BY2WD, sizeof(Ureg)+ERRMAX+4*BY2WD, 1)) { qunlock(&up->debug); pprint("suicide: bad address or sp in notify\n"); @@ -787,7 +787,7 @@ noted(Ureg* ureg, ulong arg0) /* sanity clause */ oureg = (ulong)nureg; - if(!okaddr((ulong)oureg-BY2WD, BY2WD+sizeof(Ureg), 0)){ + if(!okaddr(oureg-BY2WD, BY2WD+sizeof(Ureg), 0)){ qunlock(&up->debug); pprint("bad ureg in noted or call to noted when not notified\n"); pexit("Suicide", 0); diff --git a/sys/src/9/omap/fpiarm.c b/sys/src/9/omap/fpiarm.c index 8d5a20e52..8735f87ba 100644 --- a/sys/src/9/omap/fpiarm.c +++ b/sys/src/9/omap/fpiarm.c @@ -648,7 +648,7 @@ casemu(ulong pc, ulong op, Ureg *ur) rn = rp[op>>0 & 0x7]; rd = rp + (op>>12 & 0x7); rp = (ulong*)*rd; - validaddr((ulong)rp, 4, 1); + validaddr((uintptr)rp, 4, 1); splhi(); if(*rd = (*rp == ro)) *rp = rn; @@ -667,7 +667,7 @@ ldrex(ulong pc, ulong op, Ureg *ur) rp = (ulong*)ur; rd = rp + (op>>16 & 0x7); addr = (ulong*)*rd; - validaddr((ulong)addr, 4, 0); + validaddr((uintptr)addr, 4, 0); ldrexvalid = 1; rp[op>>12 & 0x7] = *addr; if(fpemudebug) @@ -686,7 +686,7 @@ strex(ulong pc, ulong op, Ureg *ur) rd = rp + (op>>16 & 0x7); rn = rp[op>>0 & 0x7]; addr = (ulong*)*rd; - validaddr((ulong)addr, 4, 1); + validaddr((uintptr)addr, 4, 1); splhi(); if(ldrexvalid){ if(fpemudebug) diff --git a/sys/src/9/omap4/trap.c b/sys/src/9/omap4/trap.c index 14e4ee0ad..26de7ac8d 100644 --- a/sys/src/9/omap4/trap.c +++ b/sys/src/9/omap4/trap.c @@ -170,7 +170,7 @@ notify(Ureg *ureg) } sp = ureg->sp; sp -= 256 + sizeof(Ureg); - if(!okaddr((ulong)up->notify, 1, 0) + if(!okaddr((uintptr)up->notify, 1, 0) || !okaddr(sp - ERRMAX - 4 * BY2WD, sizeof(Ureg) + ERRMAX + 4 * BY2WD, 1)){ qunlock(&up->debug); pprint("suicide: bad address in notify\n"); @@ -216,7 +216,7 @@ noted(Ureg *ureg, ulong arg0) nureg = up->ureg; oureg = (ulong) nureg; - if(!okaddr((ulong) oureg - BY2WD, BY2WD + sizeof(Ureg), 0)){ + if(!okaddr(oureg - BY2WD, BY2WD + sizeof(Ureg), 0)){ qunlock(&up->debug); pprint("bad ureg in noted or call to noted when not notified\n"); pexit("Suicide", 0); diff --git a/sys/src/9/pc/trap.c b/sys/src/9/pc/trap.c index c8a43bbb5..cf85bcad6 100644 --- a/sys/src/9/pc/trap.c +++ b/sys/src/9/pc/trap.c @@ -867,7 +867,7 @@ notify(Ureg* ureg) if(0) print("%s %lud: notify %.8lux %.8lux %.8lux %s\n", up->text, up->pid, ureg->pc, ureg->usp, sp, n->msg); - if(!okaddr((ulong)up->notify, 1, 0) + if(!okaddr((uintptr)up->notify, 1, 0) || !okaddr(sp-ERRMAX-4*BY2WD, sizeof(Ureg)+ERRMAX+4*BY2WD, 1)){ qunlock(&up->debug); pprint("suicide: bad address in notify\n"); @@ -920,7 +920,7 @@ noted(Ureg* ureg, ulong arg0) /* sanity clause */ oureg = (ulong)nureg; - if(!okaddr((ulong)oureg-BY2WD, BY2WD+sizeof(Ureg), 0)){ + if(!okaddr(oureg-BY2WD, BY2WD+sizeof(Ureg), 0)){ qunlock(&up->debug); pprint("bad ureg in noted or call to noted when not notified\n"); pexit("Suicide", 0); diff --git a/sys/src/9/port/sysproc.c b/sys/src/9/port/sysproc.c index 2a1b15b94..2b368e7ca 100644 --- a/sys/src/9/port/sysproc.c +++ b/sys/src/9/port/sysproc.c @@ -221,7 +221,7 @@ sysrfork(va_list list) procwired(p, wm->machno); ready(p); sched(); - return (uintptr)pid; + return pid; } static ulong @@ -579,7 +579,7 @@ syssleep(va_list list) uintptr sysalarm(va_list list) { - return (uintptr)procalarm(va_arg(list, ulong)); + return procalarm(va_arg(list, ulong)); } @@ -612,34 +612,32 @@ sysexits(va_list list) uintptr sys_wait(va_list list) { - int pid; + ulong pid; Waitmsg w; OWaitmsg *ow; ow = va_arg(list, OWaitmsg*); - if(ow == 0) + if(ow == nil) pid = pwait(nil); else { validaddr((uintptr)ow, sizeof(OWaitmsg), 1); evenaddr((uintptr)ow); pid = pwait(&w); - if(pid >= 0){ - readnum(0, ow->pid, NUMSIZE, w.pid, NUMSIZE); - readnum(0, ow->time+TUser*NUMSIZE, NUMSIZE, w.time[TUser], NUMSIZE); - readnum(0, ow->time+TSys*NUMSIZE, NUMSIZE, w.time[TSys], NUMSIZE); - readnum(0, ow->time+TReal*NUMSIZE, NUMSIZE, w.time[TReal], NUMSIZE); - strncpy(ow->msg, w.msg, sizeof(ow->msg)-1); - ow->msg[sizeof(ow->msg)-1] = '\0'; - } } - return (uintptr)pid; + if(ow != nil){ + readnum(0, ow->pid, NUMSIZE, w.pid, NUMSIZE); + readnum(0, ow->time+TUser*NUMSIZE, NUMSIZE, w.time[TUser], NUMSIZE); + readnum(0, ow->time+TSys*NUMSIZE, NUMSIZE, w.time[TSys], NUMSIZE); + readnum(0, ow->time+TReal*NUMSIZE, NUMSIZE, w.time[TReal], NUMSIZE); + strncpy(ow->msg, w.msg, sizeof(ow->msg)-1); + ow->msg[sizeof(ow->msg)-1] = '\0'; + } + return pid; } uintptr sysawait(va_list list) { - int i; - int pid; char *p; Waitmsg w; uint n; @@ -647,16 +645,11 @@ sysawait(va_list list) p = va_arg(list, char*); n = va_arg(list, uint); validaddr((uintptr)p, n, 1); - pid = pwait(&w); - if(pid < 0) - i = -1; - else { - i = snprint(p, n, "%d %lud %lud %lud %q", - w.pid, - w.time[TUser], w.time[TSys], w.time[TReal], - w.msg); - } - return (uintptr)i; + pwait(&w); + return (uintptr)snprint(p, n, "%d %lud %lud %lud %q", + w.pid, + w.time[TUser], w.time[TSys], w.time[TReal], + w.msg); } void diff --git a/sys/src/9/ppc/trap.c b/sys/src/9/ppc/trap.c index 5099b4d14..1dca77482 100644 --- a/sys/src/9/ppc/trap.c +++ b/sys/src/9/ppc/trap.c @@ -748,7 +748,7 @@ notify(Ureg* ur) sp = ur->usp & ~(BY2V-1); sp -= sizeof(Ureg); - if(!okaddr((ulong)up->notify, BY2WD, 0) || + if(!okaddr((uintptr)up->notify, BY2WD, 0) || !okaddr(sp-ERRMAX-4*BY2WD, sizeof(Ureg)+ERRMAX+4*BY2WD, 1)) { qunlock(&up->debug); pprint("suicide: bad address or sp in notify\n"); @@ -799,7 +799,7 @@ noted(Ureg* ureg, ulong arg0) /* sanity clause */ oureg = (ulong)nureg; - if(!okaddr((ulong)oureg-BY2WD, BY2WD+sizeof(Ureg), 0)){ + if(!okaddr(oureg-BY2WD, BY2WD+sizeof(Ureg), 0)){ qunlock(&up->debug); pprint("bad ureg in noted or call to noted when not notified\n"); pexit("Suicide", 0);