From abf847a083888bbed4260ecacf849ea19f23e810 Mon Sep 17 00:00:00 2001 From: Frans Kaashoek Date: Tue, 31 Jan 2017 17:47:16 -0500 Subject: Start of an experiment to remove the use of gs for cpu local variables. --- syscall.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'syscall.c') diff --git a/syscall.c b/syscall.c index 9ae7536..2d6769e 100644 --- a/syscall.c +++ b/syscall.c @@ -17,7 +17,7 @@ int fetchint(uint addr, int *ip) { - if(addr >= proc->sz || addr+4 > proc->sz) + if(addr >= myproc()->sz || addr+4 > myproc()->sz) return -1; *ip = *(int*)(addr); return 0; @@ -31,13 +31,14 @@ fetchstr(uint addr, char **pp) { char *s, *ep; - if(addr >= proc->sz) + if(addr >= myproc()->sz) return -1; *pp = (char*)addr; - ep = (char*)proc->sz; - for(s = *pp; s < ep; s++) + ep = (char*)myproc()->sz; + for(s = *pp; s < ep; s++){ if(*s == 0) return s - *pp; + } return -1; } @@ -45,7 +46,7 @@ fetchstr(uint addr, char **pp) int argint(int n, int *ip) { - return fetchint(proc->tf->esp + 4 + 4*n, ip); + return fetchint((myproc()->tf->esp) + 4 + 4*n, ip); } // Fetch the nth word-sized system call argument as a pointer @@ -58,7 +59,7 @@ argptr(int n, char **pp, int size) if(argint(n, &i) < 0) return -1; - if(size < 0 || (uint)i >= proc->sz || (uint)i+size > proc->sz) + if(size < 0 || (uint)i >= myproc()->sz || (uint)i+size > myproc()->sz) return -1; *pp = (char*)i; return 0; @@ -128,12 +129,12 @@ syscall(void) { int num; - num = proc->tf->eax; + num = myproc()->tf->eax; if(num > 0 && num < NELEM(syscalls) && syscalls[num]) { - proc->tf->eax = syscalls[num](); + myproc()->tf->eax = syscalls[num](); } else { cprintf("%d %s: unknown sys call %d\n", - proc->pid, proc->name, num); - proc->tf->eax = -1; + myproc()->pid, myproc()->name, num); + myproc()->tf->eax = -1; } } -- cgit v1.2.3 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