Fix stack initialization to correctness of passing argument tests #28
@@ -20,6 +20,7 @@
|
|||||||
#include "threads/thread.h"
|
#include "threads/thread.h"
|
||||||
#include "threads/vaddr.h"
|
#include "threads/vaddr.h"
|
||||||
#include "threads/synch.h"
|
#include "threads/synch.h"
|
||||||
|
#include "devices/timer.h"
|
||||||
|
|
||||||
/* Keeps track of the position of pointers to user program arguments
|
/* Keeps track of the position of pointers to user program arguments
|
||||||
within a linked list. */
|
within a linked list. */
|
||||||
@@ -83,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;
|
||||||
@@ -94,14 +99,10 @@ 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);
|
||||||
|
|
||||||
int arg_count = 1;
|
int arg_count = 0;
|
||||||
while (arg != NULL)
|
while (arg != NULL)
|
||||||
{
|
{
|
||||||
push_to_stack (&if_.esp, arg, (strlen (arg) + 1) * sizeof (char));
|
push_to_stack (&if_.esp, arg, (strlen (arg) + 1) * sizeof (char));
|
||||||
@@ -116,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++;
|
||||||
@@ -147,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);
|
||||||
@@ -155,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));
|
||||||
|
|
||||||
@@ -570,7 +570,7 @@ setup_stack (void **esp)
|
|||||||
{
|
{
|
||||||
success = install_page (((uint8_t *) PHYS_BASE) - PGSIZE, kpage, true);
|
success = install_page (((uint8_t *) PHYS_BASE) - PGSIZE, kpage, true);
|
||||||
if (success)
|
if (success)
|
||||||
*esp = PHYS_BASE - 12;
|
*esp = PHYS_BASE;
|
||||||
else
|
else
|
||||||
palloc_free_page (kpage);
|
palloc_free_page (kpage);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,6 +105,7 @@ syscall_exit (int status)
|
|||||||
{
|
{
|
||||||
/* Sets exit_status of the thread to status. thread_exit () will call
|
/* Sets exit_status of the thread to status. thread_exit () will call
|
||||||
process_exit () if user programs are allowed. */
|
process_exit () if user programs are allowed. */
|
||||||
|
printf ("%s: exit(%d)\n", thread_current()->name, status);
|
||||||
thread_current ()->exit_status = status;
|
thread_current ()->exit_status = status;
|
||||||
thread_exit ();
|
thread_exit ();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user