Refactor process.c for comments, clarity and readability
This commit is contained in:
@@ -84,9 +84,9 @@ process_execute (const char *cmd)
|
||||
|
||||
/* Validates that the current file to be executed can be opened/exists. */
|
||||
lock_acquire (&filesys_lock);
|
||||
bool valid_file = filesys_open (file_name) != NULL;
|
||||
struct file *file = filesys_open (file_name);
|
||||
lock_release (&filesys_lock);
|
||||
if (!valid_file)
|
||||
if (file == NULL)
|
||||
return TID_ERROR;
|
||||
|
||||
/* Create a new thread to execute the command, by initializing
|
||||
@@ -128,7 +128,6 @@ static void
|
||||
start_process (void *proc_start_data)
|
||||
{
|
||||
struct intr_frame if_;
|
||||
|
||||
struct process_start_data *data = proc_start_data;
|
||||
|
||||
/* Initialize interrupt frame and load executable. */
|
||||
@@ -137,40 +136,45 @@ start_process (void *proc_start_data)
|
||||
if_.cs = SEL_UCSEG;
|
||||
if_.eflags = FLAG_IF | FLAG_MBS;
|
||||
|
||||
/* Acquire the file system lock to prevent race conditions. */
|
||||
lock_acquire (&filesys_lock);
|
||||
|
||||
/* Prevent writing to the file being executed. */
|
||||
struct file *exec_file = filesys_open (data->file_name);
|
||||
if (exec_file == NULL)
|
||||
{
|
||||
/* If the executable file cannot be opened, free resources and quit. */
|
||||
lock_release (&filesys_lock);
|
||||
sema_up (&data->loaded);
|
||||
thread_exit ();
|
||||
}
|
||||
|
||||
/* Deny write to the executable file to prevent writing to it and release the
|
||||
file system lock. */
|
||||
file_deny_write (exec_file);
|
||||
lock_release (&filesys_lock);
|
||||
|
||||
thread_current ()->exec_file = exec_file;
|
||||
|
||||
/* Load the ELF executable file, and store the success of the operation in
|
||||
the 'success' variable in data. */
|
||||
data->success = load (data->file_name, &if_.eip, &if_.esp);
|
||||
|
||||
/* If load failed, quit. */
|
||||
if (!data->success)
|
||||
/* If load was sucessful, initialize user process stack and free page used
|
||||
to store the command that executed the process. */
|
||||
if (data->success)
|
||||
{
|
||||
sema_up (&data->loaded);
|
||||
thread_exit ();
|
||||
data->success =
|
||||
process_init_stack (data->cmd_saveptr, &if_.esp, data->file_name);
|
||||
}
|
||||
|
||||
/* Initialize user process stack and free page used to store the
|
||||
command that executed the process. */
|
||||
data->success = process_init_stack (data->cmd_saveptr, &if_.esp, data->file_name);
|
||||
/* Signal that the process has finished attempting to load. */
|
||||
bool success = data->success;
|
||||
sema_up (&data->loaded);
|
||||
|
||||
/* If stack initialization failed, free resources and quit. */
|
||||
/* If the load was unsuccessful or if it was but the stack initialization
|
||||
failed, exit the thread. */
|
||||
if (!success)
|
||||
{
|
||||
thread_exit ();
|
||||
}
|
||||
|
||||
/* Start the user process by simulating a return from an
|
||||
interrupt, implemented by intr_exit (in
|
||||
|
||||
Reference in New Issue
Block a user