From 5230d11ee8abdb05e3dc2bf7671258738143121c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Thu, 11 Feb 2021 11:47:09 +0100 Subject: implement exit --- src/userprog/syscall.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/userprog/syscall.c') 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 -- cgit v1.2.1