From 87126237ad7ac56cac1062982d05b13c4179690f Mon Sep 17 00:00:00 2001 From: EDiasAlberto Date: Sun, 3 Nov 2024 23:20:42 +0000 Subject: [PATCH] Implement function to validate user memory pointers w/ S. --- src/userprog/syscall.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/userprog/syscall.c b/src/userprog/syscall.c index 6e7fb17..9164142 100644 --- a/src/userprog/syscall.c +++ b/src/userprog/syscall.c @@ -1,5 +1,6 @@ #include "userprog/syscall.h" #include "devices/shutdown.h" +#include "threads/vaddr.h" #include #include #include "threads/interrupt.h" @@ -51,4 +52,15 @@ static void exit (int status) { //TODO +} + +/* A function to validate if a block of memory starting at PTR and of + size SIZE bytes is fully contained within user virtual memory. */ +static void * +validate_user_pointer (void *ptr, size_t size) +{ + if (ptr == NULL || !is_user_vaddr (ptr) || !is_user_vaddr (ptr + size - 1)) + thread_exit (); + + return ptr; } \ No newline at end of file