Update stack initialization to handle overflow by allocating a second page for argument pointers

This commit is contained in:
Themis Demetriades
2024-11-11 13:13:21 +00:00
parent 8b2fc86b51
commit b8d358ecb2

View File

@@ -88,6 +88,8 @@ process_execute (const char *cmd)
return tid; return tid;
} }
static bool install_page (void *upage, void *kpage, bool writable);
static bool process_init_stack (char *cmd_saveptr, void **esp, char *file_name); static bool process_init_stack (char *cmd_saveptr, void **esp, char *file_name);
static void *push_to_stack (void **esp, void *data, size_t data_size); static void *push_to_stack (void **esp, void *data, size_t data_size);
#define push_var_to_stack(esp, var) (push_to_stack (esp, &var, sizeof (var))) #define push_var_to_stack(esp, var) (push_to_stack (esp, &var, sizeof (var)))
@@ -186,10 +188,13 @@ process_init_stack (char *cmd_saveptr, void **esp, char *file_name)
+ return_addr_size; + return_addr_size;
/* If pushing the rest of the data required for the stack would cause /* If pushing the rest of the data required for the stack would cause
overflow, allocate an extra page. */ overflow, allocate an extra page that is contiguous within the
virtual address space (below the current address range). */
if (PHYS_BASE - *esp + remaining_size > PGSIZE) if (PHYS_BASE - *esp + remaining_size > PGSIZE)
{ {
/* TODO: Allocate an extra page for the rest of the process stack. */ uint8_t *kpage = palloc_get_page (PAL_USER | PAL_ZERO);
if (!install_page (((uint8_t *) PHYS_BASE) - PGSIZE * 2, kpage, true))
return false;
} }
/* Align stack pointer to word size before pushing argv elements for /* Align stack pointer to word size before pushing argv elements for
@@ -485,8 +490,6 @@ load (const char *file_name, void (**eip) (void), void **esp)
/* load() helpers. */ /* load() helpers. */
static bool install_page (void *upage, void *kpage, bool writable);
/* Checks whether PHDR describes a valid, loadable segment in /* Checks whether PHDR describes a valid, loadable segment in
FILE and returns true if so, false otherwise. */ FILE and returns true if so, false otherwise. */
static bool static bool