Skip to content

Commit

Permalink
Make argint() and argaddr() of type void (thanks Harry Porter)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaashoek committed Aug 22, 2022
1 parent 7086197 commit 2a391eb
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 30 deletions.
4 changes: 2 additions & 2 deletions kernel/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ int strncmp(const char*, const char*, uint);
char* strncpy(char*, const char*, int);

// syscall.c
int argint(int, int*);
void argint(int, int*);
int argstr(int, char*, int);
int argaddr(int, uint64 *);
void argaddr(int, uint64 *);
int fetchstr(uint64, char*, int);
int fetchaddr(uint64, uint64*);
void syscall();
Expand Down
9 changes: 3 additions & 6 deletions kernel/syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,19 @@ argraw(int n)
}

// Fetch the nth 32-bit system call argument.
int
void
argint(int n, int *ip)
{
*ip = argraw(n);
return 0;
}

// Retrieve an argument as a pointer.
// Doesn't check for legality, since
// copyin/copyout will do that.
int
void
argaddr(int n, uint64 *ip)
{
*ip = argraw(n);
return 0;
}

// Fetch the nth word-sized system call argument as a null-terminated string.
Expand All @@ -77,8 +75,7 @@ int
argstr(int n, char *buf, int max)
{
uint64 addr;
if(argaddr(n, &addr) < 0)
return -1;
argaddr(n, &addr);
return fetchstr(addr, buf, max);
}

Expand Down
29 changes: 17 additions & 12 deletions kernel/sysfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ argfd(int n, int *pfd, struct file **pf)
int fd;
struct file *f;

if(argint(n, &fd) < 0)
return -1;
argint(n, &fd);
if(fd < 0 || fd >= NOFILE || (f=myproc()->ofile[fd]) == 0)
return -1;
if(pfd)
Expand Down Expand Up @@ -73,7 +72,9 @@ sys_read(void)
int n;
uint64 p;

if(argfd(0, 0, &f) < 0 || argint(2, &n) < 0 || argaddr(1, &p) < 0)
argaddr(1, &p);
argint(2, &n);
if(argfd(0, 0, &f) < 0)
return -1;
return fileread(f, p, n);
}
Expand All @@ -84,8 +85,10 @@ sys_write(void)
struct file *f;
int n;
uint64 p;

if(argfd(0, 0, &f) < 0 || argint(2, &n) < 0 || argaddr(1, &p) < 0)

argaddr(1, &p);
argint(2, &n);
if(argfd(0, 0, &f) < 0)
return -1;

return filewrite(f, p, n);
Expand All @@ -110,7 +113,8 @@ sys_fstat(void)
struct file *f;
uint64 st; // user pointer to struct stat

if(argfd(0, 0, &f) < 0 || argaddr(1, &st) < 0)
argaddr(1, &st);
if(argfd(0, 0, &f) < 0)
return -1;
return filestat(f, st);
}
Expand Down Expand Up @@ -292,7 +296,8 @@ sys_open(void)
struct inode *ip;
int n;

if((n = argstr(0, path, MAXPATH)) < 0 || argint(1, &omode) < 0)
argint(1, &omode);
if((n = argstr(0, path, MAXPATH)) < 0)
return -1;

begin_op();
Expand Down Expand Up @@ -375,9 +380,9 @@ sys_mknod(void)
int major, minor;

begin_op();
argint(1, &major);
argint(2, &minor);
if((argstr(0, path, MAXPATH)) < 0 ||
argint(1, &major) < 0 ||
argint(2, &minor) < 0 ||
(ip = create(path, T_DEVICE, major, minor)) == 0){
end_op();
return -1;
Expand Down Expand Up @@ -419,7 +424,8 @@ sys_exec(void)
int i;
uint64 uargv, uarg;

if(argstr(0, path, MAXPATH) < 0 || argaddr(1, &uargv) < 0){
argaddr(1, &uargv);
if(argstr(0, path, MAXPATH) < 0) {
return -1;
}
memset(argv, 0, sizeof(argv));
Expand Down Expand Up @@ -462,8 +468,7 @@ sys_pipe(void)
int fd0, fd1;
struct proc *p = myproc();

if(argaddr(0, &fdarray) < 0)
return -1;
argaddr(0, &fdarray);
if(pipealloc(&rf, &wf) < 0)
return -1;
fd0 = -1;
Expand Down
15 changes: 5 additions & 10 deletions kernel/sysproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ uint64
sys_exit(void)
{
int n;
if(argint(0, &n) < 0)
return -1;
argint(0, &n);
exit(n);
return 0; // not reached
}
Expand All @@ -32,8 +31,7 @@ uint64
sys_wait(void)
{
uint64 p;
if(argaddr(0, &p) < 0)
return -1;
argaddr(0, &p);
return wait(p);
}

Expand All @@ -43,8 +41,7 @@ sys_sbrk(void)
uint64 addr;
int n;

if(argint(0, &n) < 0)
return -1;
argint(0, &n);
addr = myproc()->sz;
if(growproc(n) < 0)
return -1;
Expand All @@ -57,8 +54,7 @@ sys_sleep(void)
int n;
uint ticks0;

if(argint(0, &n) < 0)
return -1;
argint(0, &n);
acquire(&tickslock);
ticks0 = ticks;
while(ticks - ticks0 < n){
Expand All @@ -77,8 +73,7 @@ sys_kill(void)
{
int pid;

if(argint(0, &pid) < 0)
return -1;
argint(0, &pid);
return kill(pid);
}

Expand Down

0 comments on commit 2a391eb

Please sign in to comment.