summaryrefslogtreecommitdiffstats
path: root/src/userprog
diff options
context:
space:
mode:
Diffstat (limited to 'src/userprog')
-rw-r--r--src/userprog/syscall.c18
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