diff --git a/src/userprog/process.c b/src/userprog/process.c index 20e2677..0e9fc75 100644 --- a/src/userprog/process.c +++ b/src/userprog/process.c @@ -20,6 +20,7 @@ #include "threads/thread.h" #include "threads/vaddr.h" #include "threads/synch.h" +#include "devices/timer.h" /* Keeps track of the position of pointers to user program arguments within a linked list. */ @@ -83,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; @@ -94,14 +99,10 @@ 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); - int arg_count = 1; + int arg_count = 0; while (arg != NULL) { push_to_stack (&if_.esp, arg, (strlen (arg) + 1) * sizeof (char)); @@ -116,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++; @@ -147,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); @@ -155,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)); @@ -570,7 +570,7 @@ setup_stack (void **esp) { success = install_page (((uint8_t *) PHYS_BASE) - PGSIZE, kpage, true); if (success) - *esp = PHYS_BASE - 12; + *esp = PHYS_BASE; else palloc_free_page (kpage); } diff --git a/src/userprog/syscall.c b/src/userprog/syscall.c index 1dbe73b..9991156 100644 --- a/src/userprog/syscall.c +++ b/src/userprog/syscall.c @@ -105,6 +105,7 @@ syscall_exit (int status) { /* Sets exit_status of the thread to status. thread_exit () will call process_exit () if user programs are allowed. */ + printf ("%s: exit(%d)\n", thread_current()->name, status); thread_current ()->exit_status = status; thread_exit (); }