]> Devi Nivas Git - cs3210-lab0.git/commitdiff
Make fetchint and fetchstr use proc instead of taking a struct proc
authorAustin Clements <amdragon@mit.edu>
Sat, 18 Feb 2012 04:20:13 +0000 (23:20 -0500)
committerAustin Clements <amdragon@mit.edu>
Sat, 18 Feb 2012 04:20:13 +0000 (23:20 -0500)
Previously, these were inconsistent: they used their struct proc
argument for bounds checking, but always copied the argument from the
current address space (and hence the current process).  Drop the
struct proc argument and always use the current proc.

Suggested by Carmi Merimovich.

defs.h
syscall.c
sysfile.c

diff --git a/defs.h b/defs.h
index efbbe3d63d5544b2a9c3d7388052dd7493564d9c..7f1e88d34f5f3aacfb0e55cac8985fbb8beb00bb 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -142,8 +142,8 @@ char*           strncpy(char*, const char*, int);
 int             argint(int, int*);
 int             argptr(int, char**, int);
 int             argstr(int, char**);
-int             fetchint(struct proc*, uint, int*);
-int             fetchstr(struct proc*, uint, char**);
+int             fetchint(uint, int*);
+int             fetchstr(uint, char**);
 void            syscall(void);
 
 // timer.c
index 0918da7131988eb24cbf830fb93286198701aefa..45f758e54540a9220e529489a2ec241112d5aa37 100644 (file)
--- a/syscall.c
+++ b/syscall.c
 // library system call function. The saved user %esp points
 // to a saved program counter, and then the first argument.
 
-// Fetch the int at addr from process p.
+// Fetch the int at addr from the current process.
 int
-fetchint(struct proc *p, uint addr, int *ip)
+fetchint(uint addr, int *ip)
 {
-  if(addr >= p->sz || addr+4 > p->sz)
+  if(addr >= proc->sz || addr+4 > proc->sz)
     return -1;
   *ip = *(int*)(addr);
   return 0;
 }
 
-// Fetch the nul-terminated string at addr from process p.
+// Fetch the nul-terminated string at addr from the current process.
 // Doesn't actually copy the string - just sets *pp to point at it.
 // Returns length of string, not including nul.
 int
-fetchstr(struct proc *p, uint addr, char **pp)
+fetchstr(uint addr, char **pp)
 {
   char *s, *ep;
 
-  if(addr >= p->sz)
+  if(addr >= proc->sz)
     return -1;
   *pp = (char*)addr;
-  ep = (char*)p->sz;
+  ep = (char*)proc->sz;
   for(s = *pp; s < ep; s++)
     if(*s == 0)
       return s - *pp;
@@ -45,7 +45,7 @@ fetchstr(struct proc *p, uint addr, char **pp)
 int
 argint(int n, int *ip)
 {
-  return fetchint(proc, proc->tf->esp + 4 + 4*n, ip);
+  return fetchint(proc->tf->esp + 4 + 4*n, ip);
 }
 
 // Fetch the nth word-sized system call argument as a pointer
@@ -74,7 +74,7 @@ argstr(int n, char **pp)
   int addr;
   if(argint(n, &addr) < 0)
     return -1;
-  return fetchstr(proc, addr, pp);
+  return fetchstr(addr, pp);
 }
 
 extern int sys_chdir(void);
index e6d08e842d2f6a5d199ae952ead41aec61882dfd..64f2b331490c27bf747cdba1fb39ea75577f2270 100644 (file)
--- a/sysfile.c
+++ b/sysfile.c
@@ -388,13 +388,13 @@ sys_exec(void)
   for(i=0;; i++){
     if(i >= NELEM(argv))
       return -1;
-    if(fetchint(proc, uargv+4*i, (int*)&uarg) < 0)
+    if(fetchint(uargv+4*i, (int*)&uarg) < 0)
       return -1;
     if(uarg == 0){
       argv[i] = 0;
       break;
     }
-    if(fetchstr(proc, uarg, &argv[i]) < 0)
+    if(fetchstr(uarg, &argv[i]) < 0)
       return -1;
   }
   return exec(path, argv);