From 6507da772d63d4dd0e365b976f2b400d64dcfccb Mon Sep 17 00:00:00 2001
From: Robert Morris <rtm@csail.mit.edu>
Date: Sun, 28 Jul 2019 06:29:37 -0400
Subject: argptr no longer needed, since copyin checks

---
 kernel/defs.h    |  1 -
 kernel/syscall.c | 28 +++++++---------------------
 kernel/sysfile.c |  8 ++++----
 3 files changed, 11 insertions(+), 26 deletions(-)

(limited to 'kernel')

diff --git a/kernel/defs.h b/kernel/defs.h
index 52fca8e..de4acfd 100644
--- a/kernel/defs.h
+++ b/kernel/defs.h
@@ -130,7 +130,6 @@ char*           strncpy(char*, const char*, int);
 
 // syscall.c
 int             argint(int, int*);
-int             argptr(int, uint64*, int);
 int             argstr(int, char*, int);
 int             argaddr(int, uint64 *);
 int             fetchstr(uint64, char*, int);
diff --git a/kernel/syscall.c b/kernel/syscall.c
index 117e78e..197bca1 100644
--- a/kernel/syscall.c
+++ b/kernel/syscall.c
@@ -33,7 +33,7 @@ fetchstr(uint64 addr, char *buf, int max)
 }
 
 static uint64
-fetcharg(int n)
+argraw(int n)
 {
   struct proc *p = myproc();
   switch (n) {
@@ -50,7 +50,7 @@ fetcharg(int n)
   case 5:
     return p->tf->a5;
   }
-  panic("fetcharg");
+  panic("argraw");
   return -1;
 }
 
@@ -58,31 +58,17 @@ fetcharg(int n)
 int
 argint(int n, int *ip)
 {
-  *ip = fetcharg(n);
+  *ip = argraw(n);
   return 0;
 }
 
+// Retrieve an argument as a pointer.
+// Doesn't check for legality, since
+// copyin/copyout will do that.
 int
 argaddr(int n, uint64 *ip)
 {
-  *ip = fetcharg(n);
-  return 0;
-}
-
-// Fetch the nth word-sized system call argument as a pointer
-// to a block of memory of size bytes.  Check that the pointer
-// lies within the process address space.
-int
-argptr(int n, uint64 *pp, int size)
-{
-  uint64 i;
-  struct proc *p = myproc();
- 
-  if(argaddr(n, &i) < 0)
-    return -1;
-  if(size < 0 || (uint)i >= p->sz || (uint)i+size > p->sz)
-    return -1;
-  *pp = i;
+  *ip = argraw(n);
   return 0;
 }
 
diff --git a/kernel/sysfile.c b/kernel/sysfile.c
index 2c787ec..292fa27 100644
--- a/kernel/sysfile.c
+++ b/kernel/sysfile.c
@@ -73,7 +73,7 @@ sys_read(void)
   int n;
   uint64 p;
 
-  if(argfd(0, 0, &f) < 0 || argint(2, &n) < 0 || argptr(1, &p, n) < 0)
+  if(argfd(0, 0, &f) < 0 || argint(2, &n) < 0 || argaddr(1, &p) < 0)
     return -1;
   return fileread(f, p, n);
 }
@@ -85,7 +85,7 @@ sys_write(void)
   int n;
   uint64 p;
 
-  if(argfd(0, 0, &f) < 0 || argint(2, &n) < 0 || argptr(1, &p, n) < 0)
+  if(argfd(0, 0, &f) < 0 || argint(2, &n) < 0 || argaddr(1, &p) < 0)
     return -1;
 
   return filewrite(f, p, n);
@@ -110,7 +110,7 @@ sys_fstat(void)
   struct file *f;
   uint64 st; // user pointer to struct stat
 
-  if(argfd(0, 0, &f) < 0 || argptr(1, &st, sizeof(struct stat)) < 0)
+  if(argfd(0, 0, &f) < 0 || argaddr(1, &st) < 0)
     return -1;
   return filestat(f, st);
 }
@@ -453,7 +453,7 @@ sys_pipe(void)
   int fd0, fd1;
   struct proc *p = myproc();
 
-  if(argptr(0, &fdarray, 2*sizeof(int)) < 0)
+  if(argaddr(0, &fdarray) < 0)
     return -1;
   if(pipealloc(&rf, &wf) < 0)
     return -1;
-- 
cgit v1.2.3