From fbb4c0944422f860484142010bb9f366f3e87bf8 Mon Sep 17 00:00:00 2001 From: Frans Kaashoek Date: Tue, 31 Jan 2017 20:21:14 -0500 Subject: Read curproc from cpu structure, but be careful because after a schedule event myproc() points to a different thread. myproc(); sched(); myproc(); // this proc maybe different than the one before sched Thus, in a function that operates on one thread better to retrieve the current process once at the start of the function. --- syscall.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'syscall.c') diff --git a/syscall.c b/syscall.c index 2d6769e..ee85261 100644 --- a/syscall.c +++ b/syscall.c @@ -17,7 +17,9 @@ int fetchint(uint addr, int *ip) { - if(addr >= myproc()->sz || addr+4 > myproc()->sz) + struct proc *curproc = myproc(); + + if(addr >= curproc->sz || addr+4 > curproc->sz) return -1; *ip = *(int*)(addr); return 0; @@ -30,11 +32,12 @@ int fetchstr(uint addr, char **pp) { char *s, *ep; + struct proc *curproc = myproc(); - if(addr >= myproc()->sz) + if(addr >= curproc->sz) return -1; *pp = (char*)addr; - ep = (char*)myproc()->sz; + ep = (char*)curproc->sz; for(s = *pp; s < ep; s++){ if(*s == 0) return s - *pp; @@ -56,10 +59,11 @@ int argptr(int n, char **pp, int size) { int i; - + struct proc *curproc = myproc(); + if(argint(n, &i) < 0) return -1; - if(size < 0 || (uint)i >= myproc()->sz || (uint)i+size > myproc()->sz) + if(size < 0 || (uint)i >= curproc->sz || (uint)i+size > curproc->sz) return -1; *pp = (char*)i; return 0; @@ -128,13 +132,14 @@ void syscall(void) { int num; + struct proc *curproc = myproc(); - num = myproc()->tf->eax; + num = curproc->tf->eax; if(num > 0 && num < NELEM(syscalls) && syscalls[num]) { - myproc()->tf->eax = syscalls[num](); + curproc->tf->eax = syscalls[num](); } else { cprintf("%d %s: unknown sys call %d\n", - myproc()->pid, myproc()->name, num); - myproc()->tf->eax = -1; + curproc->pid, curproc->name, num); + curproc->tf->eax = -1; } } -- cgit v1.2.3