diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2021-02-11 11:47:09 +0100 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2021-02-11 11:53:35 +0100 |
| commit | 5230d11ee8abdb05e3dc2bf7671258738143121c (patch) | |
| tree | 989b565f230d24b5aa0994dd9737df8852de73f8 /src/userprog | |
| parent | d996bc9b9bc2f06c99d09071f53ac4870f91cc78 (diff) | |
| download | pintos-5230d11ee8abdb05e3dc2bf7671258738143121c.tar.gz | |
implement exit
Diffstat (limited to 'src/userprog')
| -rw-r--r-- | src/userprog/syscall.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/userprog/syscall.c b/src/userprog/syscall.c index 2116e5c..cce7574 100644 --- a/src/userprog/syscall.c +++ b/src/userprog/syscall.c @@ -83,6 +83,23 @@ get_file (struct thread *thread, int fd_i) return fd->file; } +static void +exit (int status) +{ + struct thread *thread = thread_current (); + + if (thread->fds) { + for (int i = 0; i < MAX_FDS; i++) { + struct fd *fd = thread->fds + i; + if (fd && fd->active) { + file_close (fd->file); + fd->active = false; + } + } + free(thread->fds); + } +} + static int read (int fd_i, void *buf, unsigned size) { @@ -168,6 +185,7 @@ syscall_handler (struct intr_frame *f UNUSED) break; case 1: // exit + exit (INTR_ESP (1, int)); break; case 4: // create |
