diff --git a/syscall.c b/syscall.c index 6ac739f..decf393 100644 --- a/syscall.c +++ b/syscall.c @@ -30,7 +30,18 @@ fetchint(struct proc *p, unsigned addr, int *ip) if(addr > p->sz - 4) return -1; - memmove(ip, p->mem + addr, 4); + *ip = *(int*)(p->mem + addr); + return 0; +} + +// Fetch byte from a user-supplied pointer. +// Returns 0 on success, -1 if pointer is illegal. +int +fetchbyte(struct proc *p, unsigned addr, char* c) +{ + if(addr >= p->sz) + return -1; + *c = *(p->mem + addr); return 0; } @@ -174,7 +185,8 @@ sys_kill(void) { int pid; - fetcharg(0, &pid); + if(fetcharg(0, &pid) < 0) + return -1; return proc_kill(pid); } @@ -182,9 +194,31 @@ int sys_cons_putc(void) { int c; + char buf[2]; - fetcharg(0, &c); - cons_putc(c & 0xff); + if(fetcharg(0, &c) < 0) + return -1; + buf[0] = c; + buf[1] = 0; + cprintf("%s", buf); + return 0; +} + +int +sys_cons_puts(void) +{ + char buf[256]; + int i; + unsigned addr; + struct proc *cp = curproc[cpu()]; + + if(fetcharg(0, &addr) < 0) + return -1; + for(i=0; i= 0; i++) + if(buf[i] == 0) + break; + buf[i] = 0; + cprintf("%s", buf); return 0; } @@ -219,7 +253,8 @@ sys_panic(void) struct proc *p = curproc[cpu()]; unsigned int addr; - fetcharg(0, &addr); + if(fetcharg(0, &addr) < 0) + return -1; panic(p->mem + addr); return 0; } diff --git a/syscall.h b/syscall.h index 52e2301..9ca3bd4 100644 --- a/syscall.h +++ b/syscall.h @@ -9,3 +9,4 @@ #define SYS_block 9 #define SYS_kill 10 #define SYS_panic 11 +#define SYS_cons_puts 12