Merge basic system calls with stack set-up infrastructure #27

Merged
td1223 merged 31 commits from user-programs into user-programs-stdout 2024-11-06 22:21:28 +00:00
2 changed files with 82 additions and 125 deletions
Showing only changes of commit 3a258cf064 - Show all commits

View File

@@ -80,11 +80,15 @@ exit (int status UNUSED)
} }
/* Validates if a block of memory starting at PTR and of size SIZE bytes is /* Validates if a block of memory starting at PTR and of size SIZE bytes is
fully contained within user virtual memory. */ fully contained within user virtual memory. Kills the thread (by calling
thread_exit) if the memory is invalid. Otherwise, returns the PTR given.
If the size is 0, the function does no checks and returns PTR.*/
static void * static void *
validate_user_pointer (void *ptr, size_t size) validate_user_pointer (void *ptr, size_t size)
{ {
if (ptr == NULL || !is_user_vaddr (ptr) || !is_user_vaddr (ptr + size - 1)) if (size > 0 && (ptr == NULL ||
!is_user_vaddr (ptr) ||
!is_user_vaddr (ptr + size - 1)))
thread_exit (); thread_exit ();
return ptr; return ptr;