diff --git a/userprog/process.c b/userprog/process.c index 1f6f72a73c1c984ecdca3ed54da0f8bca28e4a27..5cf724a3d6398386a858e009fe6d39a0ac44ef05 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 688cd2a37fd2c1bd7fdcb417f834026a25fa4945..ad49fecdbd9c79a0019f7a9bc102e0ad8e018240 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);