diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/userprog/build/fail | 9 | ||||
| -rw-r--r-- | src/userprog/process.c | 2 | ||||
| -rw-r--r-- | src/userprog/syscall.c | 57 |
3 files changed, 49 insertions, 19 deletions
diff --git a/src/userprog/build/fail b/src/userprog/build/fail index fc47d60..e69de29 100644 --- a/src/userprog/build/fail +++ b/src/userprog/build/fail @@ -1,9 +0,0 @@ -FAIL tests/userprog/sc-bad-arg -FAIL tests/userprog/create-null -FAIL tests/userprog/create-bad-ptr -FAIL tests/userprog/open-null -FAIL tests/userprog/open-bad-ptr -FAIL tests/userprog/read-bad-ptr -FAIL tests/userprog/write-bad-ptr -FAIL tests/userprog/exec-bad-ptr -FAIL tests/userprog/wait-twice diff --git a/src/userprog/process.c b/src/userprog/process.c index fbf2f50..6170b53 100644 --- a/src/userprog/process.c +++ b/src/userprog/process.c @@ -145,6 +145,8 @@ process_wait (tid_t child_tid) sema_down (&pc->exit_sema); int exit_status = pc->exit_status; pc->exit_status = -1; + sema_up (&pc->exit_sema); // a bit of a hack + // the child is killed so we can read again if we want to return exit_status; } } diff --git a/src/userprog/syscall.c b/src/userprog/syscall.c index 4d2ce7a..e845edb 100644 --- a/src/userprog/syscall.c +++ b/src/userprog/syscall.c @@ -159,9 +159,9 @@ close (int fd_i) } static pid_t -exec (const char *file_name) +exec (const char *filename) { - return process_execute (file_name); + return process_execute (filename); } static bool @@ -199,6 +199,13 @@ syscall_handler (struct intr_frame *f UNUSED) CHECK_PTR_AND_MAYBE_EXIT (syscall_number); + char **filename; + int *status, *fd_i; + off_t *initial_size; + tid_t *child_tid; + unsigned *size; + void **buf; + switch (*syscall_number) { case 0: // halt @@ -206,35 +213,65 @@ syscall_handler (struct intr_frame *f UNUSED) break; case 1: // exit - exit (*INTR_ESP (1, int)); + status = INTR_ESP (1, int); + CHECK_PTR_AND_MAYBE_EXIT (status); + exit (*status); break; case 2: // exec - f->eax = exec (*INTR_ESP (1, char *)); + filename = INTR_ESP (1, char *); + CHECK_PTR_AND_MAYBE_EXIT (filename); + CHECK_PTR_AND_MAYBE_EXIT (*filename); + f->eax = exec (*filename); break; case 3: // wait - f->eax = wait (*INTR_ESP (1, tid_t)); + child_tid = INTR_ESP (1, tid_t); + CHECK_PTR_AND_MAYBE_EXIT (child_tid); + f->eax = wait (*child_tid); break; case 4: // create - f->eax = create (*INTR_ESP (1, char *), *INTR_ESP (2, off_t)); + filename = INTR_ESP (1, char *); + initial_size = INTR_ESP (2, off_t); + CHECK_PTR_AND_MAYBE_EXIT (filename); + CHECK_PTR_AND_MAYBE_EXIT (*filename); + CHECK_PTR_AND_MAYBE_EXIT (initial_size); + f->eax = create (*filename, *initial_size); break; case 6: // open - f->eax = open (*INTR_ESP (1, char *)); + filename = INTR_ESP (1, char *); + CHECK_PTR_AND_MAYBE_EXIT (filename); + CHECK_PTR_AND_MAYBE_EXIT (*filename); + f->eax = open (*filename); break; case 8: // read - f->eax = read (*INTR_ESP (1, int), *INTR_ESP (2, void *), *INTR_ESP (3, unsigned)); + fd_i = INTR_ESP (1, int); + buf = INTR_ESP (2, void *); + size = INTR_ESP (3, unsigned); + CHECK_PTR_AND_MAYBE_EXIT (fd_i); + CHECK_PTR_AND_MAYBE_EXIT (buf); + CHECK_PTR_AND_MAYBE_EXIT (*buf); + CHECK_PTR_AND_MAYBE_EXIT (size); + f->eax = read (*fd_i, *buf, *size); break; case 9: // write - f->eax = write (*INTR_ESP (1, int), *INTR_ESP (2, const void *), *INTR_ESP (3, unsigned)); + fd_i = INTR_ESP (1, int); + buf = INTR_ESP (2, void *); + size = INTR_ESP (3, unsigned); + CHECK_PTR_AND_MAYBE_EXIT (fd_i); + CHECK_PTR_AND_MAYBE_EXIT (buf); + CHECK_PTR_AND_MAYBE_EXIT (*buf); + CHECK_PTR_AND_MAYBE_EXIT (size); + f->eax = write (*fd_i, *buf, *size); break; case 12: // close - close (*INTR_ESP (1, int)); + fd_i = INTR_ESP (1, int); + close (*fd_i); break; default: printf ("kernel: unknown syscall '%d'\n", *syscall_number); |
