From 4020a140d245e28905c051de94f2299c9b389233 Mon Sep 17 00:00:00 2001 From: Themis Demetriades Date: Wed, 6 Nov 2024 22:36:43 +0000 Subject: [PATCH 1/5] Fix removal of 'timer.h' include needed for calling timer_sleep in process module --- src/userprog/process.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/userprog/process.c b/src/userprog/process.c index 20e2677..4f72dc0 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. */ -- 2.49.1 From b2764cfa0c67b416355684c02bcce1b6de6e9c22 Mon Sep 17 00:00:00 2001 From: Themis Demetriades Date: Wed, 6 Nov 2024 22:46:11 +0000 Subject: [PATCH 2/5] Revert setup_stack pointer decrement 'hack' faking stack initialization --- src/userprog/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/userprog/process.c b/src/userprog/process.c index 4f72dc0..fd07a07 100644 --- a/src/userprog/process.c +++ b/src/userprog/process.c @@ -571,7 +571,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); } -- 2.49.1 From 1ca9d095128252a22a80301f1b92206f20ad94bf Mon Sep 17 00:00:00 2001 From: Themis Demetriades Date: Wed, 6 Nov 2024 23:01:10 +0000 Subject: [PATCH 3/5] Update exit () syscall to print correct termination message --- src/userprog/syscall.c | 1 + 1 file changed, 1 insertion(+) 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 (); } -- 2.49.1 From 26ae7ac02e9e2b569c6f7b6f40fba1ace80bac83 Mon Sep 17 00:00:00 2001 From: Themis Demetriades Date: Wed, 6 Nov 2024 23:57:48 +0000 Subject: [PATCH 4/5] Fix bug in stack creation which would count one extra argument for argc --- src/userprog/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/userprog/process.c b/src/userprog/process.c index fd07a07..d5f0621 100644 --- a/src/userprog/process.c +++ b/src/userprog/process.c @@ -102,7 +102,7 @@ start_process (void *file_name_) 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)); -- 2.49.1 From 273fb48b31f0829c35a8042d0a7fddb1fe9ccf01 Mon Sep 17 00:00:00 2001 From: Themis Demetriades Date: Thu, 7 Nov 2024 00:40:52 +0000 Subject: [PATCH 5/5] Fix stack initialization to pass stack addreses (rather than thread addresses) for the arguments and only pass name a single time --- src/userprog/process.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/userprog/process.c b/src/userprog/process.c index d5f0621..0e9fc75 100644 --- a/src/userprog/process.c +++ b/src/userprog/process.c @@ -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)); -- 2.49.1