summaryrefslogtreecommitdiff
path: root/syscall.c
diff options
context:
space:
mode:
Diffstat (limited to 'syscall.c')
-rw-r--r--syscall.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/syscall.c b/syscall.c
index 9ae7536..ee85261 100644
--- a/syscall.c
+++ b/syscall.c
@@ -17,7 +17,9 @@
int
fetchint(uint addr, int *ip)
{
- if(addr >= proc->sz || addr+4 > proc->sz)
+ struct proc *curproc = myproc();
+
+ if(addr >= curproc->sz || addr+4 > curproc->sz)
return -1;
*ip = *(int*)(addr);
return 0;
@@ -30,14 +32,16 @@ int
fetchstr(uint addr, char **pp)
{
char *s, *ep;
+ struct proc *curproc = myproc();
- if(addr >= proc->sz)
+ if(addr >= curproc->sz)
return -1;
*pp = (char*)addr;
- ep = (char*)proc->sz;
- for(s = *pp; s < ep; s++)
+ ep = (char*)curproc->sz;
+ for(s = *pp; s < ep; s++){
if(*s == 0)
return s - *pp;
+ }
return -1;
}
@@ -45,7 +49,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
@@ -55,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 >= proc->sz || (uint)i+size > proc->sz)
+ if(size < 0 || (uint)i >= curproc->sz || (uint)i+size > curproc->sz)
return -1;
*pp = (char*)i;
return 0;
@@ -127,13 +132,14 @@ void
syscall(void)
{
int num;
+ struct proc *curproc = myproc();
- num = proc->tf->eax;
+ num = curproc->tf->eax;
if(num > 0 && num < NELEM(syscalls) && syscalls[num]) {
- proc->tf->eax = syscalls[num]();
+ curproc->tf->eax = syscalls[num]();
} else {
cprintf("%d %s: unknown sys call %d\n",
- proc->pid, proc->name, num);
- proc->tf->eax = -1;
+ curproc->pid, curproc->name, num);
+ curproc->tf->eax = -1;
}
}