Update syscall.c to use syscall_exit on failure instead of calling thread_exit directly
This commit is contained in:
@@ -81,7 +81,6 @@ static const syscall_arguments syscall_lookup[] =
|
|||||||
static const int LOOKUP_SIZE
|
static const int LOOKUP_SIZE
|
||||||
= sizeof (syscall_lookup) / sizeof (syscall_arguments);
|
= sizeof (syscall_lookup) / sizeof (syscall_arguments);
|
||||||
|
|
||||||
|
|
||||||
/* Initialises the syscall handling system, as well as a global lock to
|
/* Initialises the syscall handling system, as well as a global lock to
|
||||||
synchronise all file access between processes. */
|
synchronise all file access between processes. */
|
||||||
void
|
void
|
||||||
@@ -103,13 +102,14 @@ syscall_handler (struct intr_frame *f)
|
|||||||
|
|
||||||
/* Ensures the number corresponds to a system call that can be handled. */
|
/* Ensures the number corresponds to a system call that can be handled. */
|
||||||
if (syscall_number >= LOOKUP_SIZE)
|
if (syscall_number >= LOOKUP_SIZE)
|
||||||
thread_exit ();
|
syscall_exit (EXIT_FAILURE);
|
||||||
|
|
||||||
syscall_arguments syscall = syscall_lookup[syscall_number];
|
syscall_arguments syscall = syscall_lookup[syscall_number];
|
||||||
|
|
||||||
/* Next, read and copy the arguments from the stack pointer. */
|
/* Next, read and copy the arguments from the stack pointer. */
|
||||||
validate_user_pointer (f->esp + sizeof (uintptr_t),
|
validate_user_pointer (f->esp + sizeof (uintptr_t),
|
||||||
syscall.arity * sizeof (uintptr_t));
|
syscall.arity * sizeof (uintptr_t));
|
||||||
|
|
||||||
uintptr_t args[MAX_SYSCALL_ARGS] = {0};
|
uintptr_t args[MAX_SYSCALL_ARGS] = {0};
|
||||||
for (int i = 0; i < syscall.arity && i < MAX_SYSCALL_ARGS; i++)
|
for (int i = 0; i < syscall.arity && i < MAX_SYSCALL_ARGS; i++)
|
||||||
args[i] = *(uintptr_t *) (f->esp + sizeof (uintptr_t) * (i + 1));
|
args[i] = *(uintptr_t *) (f->esp + sizeof (uintptr_t) * (i + 1));
|
||||||
@@ -427,13 +427,13 @@ validate_user_pointer (const void *start, size_t size)
|
|||||||
const void *end = start + size - 1;
|
const void *end = start + size - 1;
|
||||||
|
|
||||||
if (start == NULL || !is_user_vaddr (start) || !is_user_vaddr (end))
|
if (start == NULL || !is_user_vaddr (start) || !is_user_vaddr (end))
|
||||||
thread_exit ();
|
syscall_exit (EXIT_FAILURE);
|
||||||
|
|
||||||
/* We now need to check if the entire memory block is mapped to physical
|
/* We now need to check if the entire memory block is mapped to physical
|
||||||
memory by the page table. */
|
memory by the page table. */
|
||||||
for (const void *ptr = start; ptr <= end; ptr += PGSIZE)
|
for (const void *ptr = start; ptr <= end; ptr += PGSIZE)
|
||||||
if (pagedir_get_page (thread_current ()->pagedir, ptr) == NULL)
|
if (pagedir_get_page (thread_current ()->pagedir, ptr) == NULL)
|
||||||
thread_exit ();
|
syscall_exit (EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Validates if a string is fully contained within user virtual memory. Kills
|
/* Validates if a string is fully contained within user virtual memory. Kills
|
||||||
@@ -443,7 +443,7 @@ static void
|
|||||||
validate_user_string (const char *str)
|
validate_user_string (const char *str)
|
||||||
{
|
{
|
||||||
if (str == NULL || !is_user_vaddr (str))
|
if (str == NULL || !is_user_vaddr (str))
|
||||||
thread_exit ();
|
syscall_exit (EXIT_FAILURE);
|
||||||
|
|
||||||
size_t length = 0;
|
size_t length = 0;
|
||||||
size_t offset = (uintptr_t) str % PGSIZE;
|
size_t offset = (uintptr_t) str % PGSIZE;
|
||||||
@@ -455,7 +455,7 @@ validate_user_string (const char *str)
|
|||||||
|
|
||||||
if (!is_user_vaddr(page) ||
|
if (!is_user_vaddr(page) ||
|
||||||
pagedir_get_page (thread_current ()->pagedir, page) == NULL)
|
pagedir_get_page (thread_current ()->pagedir, page) == NULL)
|
||||||
thread_exit ();
|
syscall_exit (EXIT_FAILURE);
|
||||||
|
|
||||||
while (offset < PGSIZE)
|
while (offset < PGSIZE)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user