From 69dafab7a17d600826ce10e36526bbb807a09a4d Mon Sep 17 00:00:00 2001
From: Joshua Saxby <joshua.a.saxby@gmail.com>
Date: Tue, 3 Dec 2019 09:04:21 +0000
Subject: [PATCH] Add skeleton of new write system call

---
 Makefile.build           |  1 +
 userprog/syscall.c       |  4 +++-
 userprog/syscall_write.c | 12 ++++++++++++
 userprog/system_calls.h  |  7 +++++++
 4 files changed, 23 insertions(+), 1 deletion(-)
 create mode 100644 userprog/syscall_write.c

diff --git a/Makefile.build b/Makefile.build
index 30d709b..2fb7073 100644
--- a/Makefile.build
+++ b/Makefile.build
@@ -67,6 +67,7 @@ userprog_SRC += userprog/syscall_exit.c
 userprog_SRC += userprog/syscall_halt.c
 userprog_SRC += userprog/syscall_wait.c
 userprog_SRC += userprog/syscall_create.c
+userprog_SRC += userprog/syscall_write.c
 
 # No virtual memory code yet.
 #vm_SRC = vm/file.c			# Some file.
diff --git a/userprog/syscall.c b/userprog/syscall.c
index c78175f..24a2654 100644
--- a/userprog/syscall.c
+++ b/userprog/syscall.c
@@ -70,9 +70,11 @@ syscall_handler (struct intr_frame *f UNUSED)
   case SYSCALL_CREATE:
     syscall_create(f);
     break;
+  case SYSCALL_WRITE:
+    syscall_write(f);
+    break;
   default:
     printf ("WARNING: Invalid Syscall (%d)\n", syscall_number);
     thread_exit ();
   }
-  // TODO: remove this call to exit as we don't want all syscalls to make the thread exit
 }
diff --git a/userprog/syscall_write.c b/userprog/syscall_write.c
new file mode 100644
index 0000000..cf476a7
--- /dev/null
+++ b/userprog/syscall_write.c
@@ -0,0 +1,12 @@
+/*
+ * The Write System Call
+ *
+ * Authored by Joshua Saxby
+ */
+#include "system_calls.h"
+#include "threads/interrupt.h"
+
+void syscall_write(struct intr_frame *f) {
+    // TODO: implement me!
+    (void*)0;
+}
diff --git a/userprog/system_calls.h b/userprog/system_calls.h
index 6fadcd1..be83270 100644
--- a/userprog/system_calls.h
+++ b/userprog/system_calls.h
@@ -35,6 +35,13 @@ void syscall_wait(struct intr_frame *f);
  */
 void syscall_create(struct intr_frame *f);
 
+/*
+ * Writes size bytes from buffer to the open file fd.
+ * Returns the number of bytes actually written, which may be less than size if
+ * some bytes could not be written.
+ */
+void syscall_write(struct intr_frame *f);
+
 /*
  * NOTE: There are more system calls implemented by Pintos but we are not
  * implementing them because the assignment brief does not ask of it.
-- 
GitLab