Fix stack initialization to pass stack addreses (rather than thread addresses) for the arguments and only pass name a single time

This commit is contained in:
Themis Demetriades
2024-11-07 00:40:52 +00:00
parent 26ae7ac02e
commit 273fb48b31

View File

@@ -84,6 +84,10 @@ start_process (void *file_name_)
char file_name[15];
strlcpy (file_name, arg, 15);
/* TODO: Move naming of thread to process_execute, so start
tokenizing there. */
strlcpy (thread_current ()->name, file_name, 15);
/* Initialize interrupt frame and load executable. */
memset (&if_, 0, sizeof if_);
if_.gs = if_.fs = if_.es = if_.ds = if_.ss = SEL_UDSEG;
@@ -95,10 +99,6 @@ start_process (void *file_name_)
This can't cause overflow due to enforcing that the size of
command line input must fit in a page. Also keep track
of pointers to the argument data within a linked list. */
char *file_name_ptr = push_to_stack (&if_.esp, file_name,
(strlen (file_name) + 1)
* sizeof (char));
struct list arg_list;
list_init (&arg_list);
@@ -117,7 +117,7 @@ start_process (void *file_name_)
thread_exit ();
}
arg_elem->arg = arg;
arg_elem->arg = if_.esp;
list_push_front (&arg_list, &arg_elem->elem);
arg_count++;
@@ -148,6 +148,9 @@ start_process (void *file_name_)
/* Push a null pointer sentinel inside argv. */
if_.esp -= sizeof (char *);
*(char *) if_.esp = NULL;
/* Push pointer to the process file name to the stack. */
char **argv;
/* Push pointers to process arguments from argument linked list */
struct list_elem *e = list_begin (&arg_list);
@@ -156,16 +159,12 @@ start_process (void *file_name_)
{
struct arg_elem *arg_elem = list_entry (e, struct arg_elem, elem);
push_to_stack (&if_.esp, &arg_elem->arg, sizeof (arg_elem->arg));
argv = push_to_stack (&if_.esp, &arg_elem->arg, sizeof (arg_elem->arg));
e = list_next (e);
free (arg_elem);
}
/* Push pointer to the process file name to the stack. */
char **argv = push_to_stack (&if_.esp, &file_name_ptr,
sizeof (file_name_ptr));
/* Push pointer to the start of argv array. */
push_to_stack (&if_.esp, &argv, sizeof(argv));