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:
@@ -84,6 +84,10 @@ start_process (void *file_name_)
|
|||||||
char file_name[15];
|
char file_name[15];
|
||||||
strlcpy (file_name, arg, 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. */
|
/* Initialize interrupt frame and load executable. */
|
||||||
memset (&if_, 0, sizeof if_);
|
memset (&if_, 0, sizeof if_);
|
||||||
if_.gs = if_.fs = if_.es = if_.ds = if_.ss = SEL_UDSEG;
|
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
|
This can't cause overflow due to enforcing that the size of
|
||||||
command line input must fit in a page. Also keep track
|
command line input must fit in a page. Also keep track
|
||||||
of pointers to the argument data within a linked list. */
|
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;
|
struct list arg_list;
|
||||||
list_init (&arg_list);
|
list_init (&arg_list);
|
||||||
|
|
||||||
@@ -117,7 +117,7 @@ start_process (void *file_name_)
|
|||||||
thread_exit ();
|
thread_exit ();
|
||||||
}
|
}
|
||||||
|
|
||||||
arg_elem->arg = arg;
|
arg_elem->arg = if_.esp;
|
||||||
list_push_front (&arg_list, &arg_elem->elem);
|
list_push_front (&arg_list, &arg_elem->elem);
|
||||||
|
|
||||||
arg_count++;
|
arg_count++;
|
||||||
@@ -148,6 +148,9 @@ start_process (void *file_name_)
|
|||||||
/* Push a null pointer sentinel inside argv. */
|
/* Push a null pointer sentinel inside argv. */
|
||||||
if_.esp -= sizeof (char *);
|
if_.esp -= sizeof (char *);
|
||||||
*(char *) if_.esp = NULL;
|
*(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 */
|
/* Push pointers to process arguments from argument linked list */
|
||||||
struct list_elem *e = list_begin (&arg_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);
|
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);
|
e = list_next (e);
|
||||||
free (arg_elem);
|
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 pointer to the start of argv array. */
|
||||||
push_to_stack (&if_.esp, &argv, sizeof(argv));
|
push_to_stack (&if_.esp, &argv, sizeof(argv));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user