From 692f4b8eadbc463795fb2c88d27b0965321ece7e Mon Sep 17 00:00:00 2001 From: Joshua Saxby <joshua.a.saxby@gmail.com> Date: Fri, 29 Nov 2019 14:36:34 +0000 Subject: [PATCH] Modify parameter name file_name in process_execute() Let's clarify this because variables should be named what they are: The argument passed to `process_execute()` is NOT a filename --it is the entire command string used for executing the program, which includes the file name AND any of its arguments, thus this variable is renamed to reflect this. Also added comment block clarifying this within process_execute() --- userprog/process.c | 23 +++++++++++++++-------- userprog/process.h | 2 +- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/userprog/process.c b/userprog/process.c index 1f6f72a..5cf724a 100644 --- a/userprog/process.c +++ b/userprog/process.c @@ -21,25 +21,32 @@ static thread_func start_process NO_RETURN; static bool load (const char *cmdline, void (**eip) (void), void **esp); -/* Starts a new thread running a user program loaded from - FILENAME. The new thread may be scheduled (and may even exit) +/* Starts a new thread running a user program loaded by parsing + COMMAND. The new thread may be scheduled (and may even exit) before process_execute() returns. Returns the new process's thread id, or TID_ERROR if the thread cannot be created. */ tid_t -process_execute (const char *file_name) +process_execute (const char *command) { char *fn_copy; tid_t tid; - /* Make a copy of FILE_NAME. + /* Make a copy of COMMAND. Otherwise there's a race between the caller and load(). */ fn_copy = palloc_get_page (0); if (fn_copy == NULL) return TID_ERROR; - strlcpy (fn_copy, file_name, PGSIZE); - - /* Create a new thread to execute FILE_NAME. */ - tid = thread_create (file_name, PRI_DEFAULT, start_process, fn_copy); + strlcpy (fn_copy, command, PGSIZE); + + /* Create a new thread to execute COMMAND. */ + /* + * FIXME: right now, COMMAND is assumed to be just the filename on its own + * + * If this is not the case (if the user passed a program name with arguments), + * then loading will fail. + * NOTE: remove this comment block when argument parsing is implemented. + */ + tid = thread_create (command, PRI_DEFAULT, start_process, fn_copy); if (tid == TID_ERROR) palloc_free_page (fn_copy); diff --git a/userprog/process.h b/userprog/process.h index 688cd2a..ad49fec 100644 --- a/userprog/process.h +++ b/userprog/process.h @@ -3,7 +3,7 @@ #include "threads/thread.h" -tid_t process_execute (const char *file_name); +tid_t process_execute (const char *command); int process_wait (tid_t); void process_exit (void); void process_activate (void); -- GitLab