summaryrefslogtreecommitdiffstats
path: root/src/userprog/syscall.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/userprog/syscall.c')
-rw-r--r--src/userprog/syscall.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/userprog/syscall.c b/src/userprog/syscall.c
index 52526aa..a699784 100644
--- a/src/userprog/syscall.c
+++ b/src/userprog/syscall.c
@@ -9,9 +9,11 @@
#include "filesys/filesys.h"
#include "filesys/off_t.h"
#include "lib/pid_t.h"
+#include "userprog/pagedir.h"
#include "userprog/process.h"
#include "threads/init.h"
#include "threads/malloc.h"
+#include "threads/vaddr.h"
static void syscall_handler (struct intr_frame *);
@@ -162,13 +164,40 @@ exec (const char *file_name)
return process_execute (file_name);
}
+static bool
+ptr_is_valid (const void *ptr)
+{
+ // uintptr_t ptr = _ptr;
+ if (!is_user_vaddr (ptr))
+ return false;
+
+ struct thread *t = thread_current ();
+
+ if (pagedir_get_page (t->pagedir, ptr) == NULL)
+ return false;
+
+ return true;
+}
+
// cast to TYPE and deref argument N from f->esp
#define INTR_ESP(N, TYPE) *(TYPE *)(f->esp+(4*(N)))
+#define CHECK_ESP_AND_MAYBE_EXIT(N) \
+ do { \
+ if (!ptr_is_valid ((f->esp+(4*(N))))) { \
+ exit (-1); \
+ return; \
+ } \
+ } while (0)
+
+
static void
syscall_handler (struct intr_frame *f UNUSED)
{
+ // check esp
+ CHECK_ESP_AND_MAYBE_EXIT (0);
int syscall_number = INTR_ESP (0, int);
+
switch (syscall_number) {
case 0:
// halt