summaryrefslogtreecommitdiff
path: root/sys/src/9/port/sysproc.c
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@gmx.de>2013-09-24 01:52:20 +0200
committercinap_lenrek <cinap_lenrek@gmx.de>2013-09-24 01:52:20 +0200
commit62b3eea2715a9e67cdb0873faa0d802344bf7683 (patch)
tree4b6449a693ab7f6a14bf819c81917d2eb10d40e3 /sys/src/9/port/sysproc.c
parent365fd745d62e9fdc43b22a0a1916c595749eb575 (diff)
syssem*: eleminate redundant validaddr() checks
validaddr looks up the segments for an address range and checks the flags and if the address range lies within bounds on the segments. as we'r going to lookup the segment in the syssem* syscalls anyway, we can do the checks ourselfs avoiding the double segment array lookups. the implication of this tho is that now a semaphore cannot span multiple segments. but this would be highly unusual given that segments are page aligned.
Diffstat (limited to 'sys/src/9/port/sysproc.c')
-rw-r--r--sys/src/9/port/sysproc.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/sys/src/9/port/sysproc.c b/sys/src/9/port/sysproc.c
index 9f670a5a0..fbad6942f 100644
--- a/sys/src/9/port/sysproc.c
+++ b/sys/src/9/port/sysproc.c
@@ -1109,13 +1109,15 @@ syssemacquire(ulong *arg)
long *addr;
Segment *s;
- validaddr(arg[0], sizeof(long), 1);
evenaddr(arg[0]);
addr = (long*)arg[0];
block = arg[1];
-
- if((s = seg(up, (ulong)addr, 0)) == nil)
+
+ s = seg(up, (ulong)addr, 0);
+ if(s == nil || (s->type&SG_RONLY) != 0 || (ulong)addr+sizeof(long) > s->top){
+ validaddr((ulong)addr, sizeof(long), 1);
error(Ebadarg);
+ }
if(*addr < 0)
error(Ebadarg);
return semacquire(s, addr, block);
@@ -1128,13 +1130,15 @@ systsemacquire(ulong *arg)
ulong ms;
Segment *s;
- validaddr(arg[0], sizeof(long), 1);
evenaddr(arg[0]);
addr = (long*)arg[0];
ms = arg[1];
- if((s = seg(up, (ulong)addr, 0)) == nil)
+ s = seg(up, (ulong)addr, 0);
+ if(s == nil || (s->type&SG_RONLY) != 0 || (ulong)addr+sizeof(long) > s->top){
+ validaddr((ulong)addr, sizeof(long), 1);
error(Ebadarg);
+ }
if(*addr < 0)
error(Ebadarg);
return tsemacquire(s, addr, ms);
@@ -1146,13 +1150,15 @@ syssemrelease(ulong *arg)
long *addr, delta;
Segment *s;
- validaddr(arg[0], sizeof(long), 1);
evenaddr(arg[0]);
addr = (long*)arg[0];
delta = arg[1];
- if((s = seg(up, (ulong)addr, 0)) == nil)
+ s = seg(up, (ulong)addr, 0);
+ if(s == nil || (s->type&SG_RONLY) != 0 || (ulong)addr+sizeof(long) > s->top){
+ validaddr((ulong)addr, sizeof(long), 1);
error(Ebadarg);
+ }
/* delta == 0 is a no-op, not a release */
if(delta < 0 || *addr < 0)
error(Ebadarg);