Refactor process_init_stack to add asserts and comments

This commit is contained in:
sBubshait
2024-11-15 14:52:21 +00:00
parent f4c900e56c
commit 0f1bce2e88

View File

@@ -191,6 +191,10 @@ start_process (void *proc_start_data)
static bool
process_init_stack (char *cmd_saveptr, void **esp, char *file_name)
{
ASSERT (cmd_saveptr != NULL);
ASSERT (esp != NULL);
ASSERT (file_name != NULL);
/* Load command line argument *data* to user process stack.
This can't cause overflow due to enforcing that the size of
command line input must fit in a page. Also keep track
@@ -202,7 +206,10 @@ process_init_stack (char *cmd_saveptr, void **esp, char *file_name)
int arg_count = 0;
while (arg != NULL)
{
push_to_stack (esp, arg, (strlen (arg) + 1) * sizeof (char));
/* filename has already been validated to be a safe-to-access string,
so we can safely use strlen here. Filename has already been
split from the command line arguments. */
push_to_stack (esp, arg, strlen (arg) + 1);
struct arg_elem *arg_elem = malloc (sizeof (struct arg_elem));
if (arg_elem == NULL)