Update user proc stack initialization comments to be more helpful

This commit is contained in:
Themis Demetriades
2024-11-14 15:54:34 +00:00
parent 8821851459
commit 3a46e0f73a

View File

@@ -49,7 +49,7 @@ struct process_start_data
be started. */ be started. */
bool success; /* Indicates whether the process was successfully loaded. */ bool success; /* Indicates whether the process was successfully loaded. */
struct semaphore loaded; /* Semaphore used to signal that the process has struct semaphore loaded; /* Semaphore used to signal that the process has
been loaded. */ finished attempting to load. */
}; };
static thread_func start_process NO_RETURN; static thread_func start_process NO_RETURN;
@@ -64,7 +64,6 @@ process_execute (const char *cmd)
{ {
char *cmd_copy; char *cmd_copy;
tid_t tid; tid_t tid;
struct process_start_data data; struct process_start_data data;
/* Make a copy of command. /* Make a copy of command.
@@ -81,11 +80,8 @@ process_execute (const char *cmd)
of the process. */ of the process. */
char *file_name = strtok_r (cmd_copy, " ", &data.cmd_saveptr); char *file_name = strtok_r (cmd_copy, " ", &data.cmd_saveptr);
/* NOTE: Currently, the file being executed is closed in load () and then /* Validates that the current file to be executed can be opened/exists. */
reopened here. Because load is an exported public function, this
might be necessary. */
lock_acquire (&filesys_lock); lock_acquire (&filesys_lock);
/* Validates that the current file to be executed is a valid file */
bool valid_file = filesys_open (file_name) != NULL; bool valid_file = filesys_open (file_name) != NULL;
lock_release (&filesys_lock); lock_release (&filesys_lock);
if (!valid_file) if (!valid_file)
@@ -100,14 +96,20 @@ process_execute (const char *cmd)
data.success = false; data.success = false;
tid = thread_create (file_name, PRI_DEFAULT, start_process, &data); tid = thread_create (file_name, PRI_DEFAULT, start_process, &data);
/* Return TID_ERROR and free resources if starting execution went wrong. */
if (tid == TID_ERROR) if (tid == TID_ERROR)
palloc_free_page (cmd_copy); palloc_free_page (cmd_copy);
else else
{ {
/* Wait until process file has finished attempting to load via the child
thread before reporting success of starting execution. */
sema_down (&data.loaded); sema_down (&data.loaded);
if (!data.success) if (!data.success)
tid = TID_ERROR; tid = TID_ERROR;
} }
return tid; return tid;
} }
@@ -119,8 +121,11 @@ static void *push_to_stack (void **esp, void *data, size_t data_size);
/* Make the current thread execute 'cmd', passing in a copy of the /* Make the current thread execute 'cmd', passing in a copy of the
command string used for processing, the saveptr used by strtok_r command string used for processing, the saveptr used by strtok_r
(in order to further tokenize the same command and retrieve its (in order to further tokenize the same command and retrieve its
arguments), as well as the name of the file being executed. This arguments), the name of the file being executed, and a semaphore that
involves loading the specified file and starting it running. */ calls sema_up to indicate that the 'success' variable passed to it
has been updated to indicate whether the process file loading succeeded.
This involves loading the specified file and calling its main () function
with the specified command arguments. */
static void static void
start_process (void *proc_start_data) start_process (void *proc_start_data)
{ {