From b988f5406cfc303615d7dfa4cd83a6de446f0d2e Mon Sep 17 00:00:00 2001
From: Alex <alexander3.stratford@live.uwe.ac.uk>
Date: Tue, 3 Dec 2019 18:10:02 +0000
Subject: [PATCH] Adding files from other branch

---
 examples/exit.c         | 14 ++++++++++++++
 userprog/syscall_exit.c | 14 +++++++++-----
 2 files changed, 23 insertions(+), 5 deletions(-)
 create mode 100644 examples/exit.c

diff --git a/examples/exit.c b/examples/exit.c
new file mode 100644
index 0000000..2a45b77
--- /dev/null
+++ b/examples/exit.c
@@ -0,0 +1,14 @@
+/* halt.c
+
+   Simple program to test whether running a user program works.
+ 	
+   Just invokes a system call that shuts down the OS. */
+
+#include <syscall.h>
+
+int
+main (void)
+{
+  exit (5);
+  /* not reached */
+}
diff --git a/userprog/syscall_exit.c b/userprog/syscall_exit.c
index 4441a27..51b2208 100644
--- a/userprog/syscall_exit.c
+++ b/userprog/syscall_exit.c
@@ -1,11 +1,15 @@
 #include "system_calls.h"
-#include "threads/thread.h"
+#include "threads/interrupt.h" // Dependency for intr_frame struct
+#include "threads/thread.h" // Dependency for thread struct
 
-void syscall_exit(struct intr_frame *status) {
+void syscall_exit(struct intr_frame *f) {
 	struct thread *current_thread;	// creates thread struct from thread.h
 	current_thread = thread_current(); // Sets current thread
 
-	current_thread->status = status; // Returning status to kernel
+	// pop off first int argument from interrupt frame
+	int exit_code = *((int*)f->esp + 1);
+	current_thread->exit_code = exit_code; // Returns exit code to kernel
+
 	thread_exit(); // Exiting current thread
-	return -1; // Returning -1 for success
-}
+	f->eax = -1; // Returning -1 for success
+}
\ No newline at end of file
-- 
GitLab