Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
149b0a9d87
|
|||
| 79b3b8fda7 | |||
|
f5e498e0a9
|
|||
| d02b956221 | |||
| 927c376d02 | |||
|
e7cb16b301
|
|||
|
005791edd2
|
@@ -23,11 +23,6 @@ test_devices:
|
||||
variables:
|
||||
DIR: devices
|
||||
|
||||
test_filesys:
|
||||
extends: .pintos_tests
|
||||
variables:
|
||||
DIR: filesys
|
||||
|
||||
test_threads:
|
||||
extends: .pintos_tests
|
||||
variables:
|
||||
|
||||
+27
-7
@@ -47,6 +47,9 @@ struct process_start_data
|
||||
tokens while maintaining state. */
|
||||
char file_name[FNAME_MAX_LEN + 1]; /* Name of the file of the process to
|
||||
be started. */
|
||||
bool success; /* Indicates whether the process was successfully loaded. */
|
||||
struct semaphore loaded; /* Semaphore used to signal that the process has
|
||||
been loaded. */
|
||||
};
|
||||
|
||||
static thread_func start_process NO_RETURN;
|
||||
@@ -67,6 +70,8 @@ process_execute (const char *cmd)
|
||||
{
|
||||
return TID_ERROR;
|
||||
}
|
||||
sema_init (&data->loaded, 0);
|
||||
data->success = false;
|
||||
|
||||
/* Make a copy of command.
|
||||
Otherwise there's a race between the caller and load(). */
|
||||
@@ -100,7 +105,14 @@ process_execute (const char *cmd)
|
||||
|
||||
tid = thread_create (file_name, PRI_DEFAULT, start_process, data);
|
||||
if (tid == TID_ERROR)
|
||||
palloc_free_page (cmd_copy);
|
||||
palloc_free_page (cmd_copy);
|
||||
else
|
||||
{
|
||||
sema_down (&data->loaded);
|
||||
if (!data->success)
|
||||
tid = TID_ERROR;
|
||||
}
|
||||
free (data);
|
||||
return tid;
|
||||
}
|
||||
|
||||
@@ -132,6 +144,11 @@ start_process (void *proc_start_data)
|
||||
|
||||
/* Prevent writing to the file being executed. */
|
||||
struct file *exec_file = filesys_open (data->file_name);
|
||||
if (exec_file == NULL)
|
||||
{
|
||||
lock_release (&filesys_lock);
|
||||
goto fail;
|
||||
}
|
||||
thread_current ()->exec_file = exec_file;
|
||||
file_deny_write (exec_file);
|
||||
lock_release (&filesys_lock);
|
||||
@@ -153,10 +170,11 @@ start_process (void *proc_start_data)
|
||||
/* If stack initialization failed, free resources and quit. */
|
||||
if (!success)
|
||||
{
|
||||
process_exit ();
|
||||
goto fail;
|
||||
}
|
||||
|
||||
data->success = true;
|
||||
sema_up (&data->loaded);
|
||||
/* Start the user process by simulating a return from an
|
||||
interrupt, implemented by intr_exit (in
|
||||
threads/intr-stubs.S). Because intr_exit takes all of its
|
||||
@@ -166,9 +184,10 @@ start_process (void *proc_start_data)
|
||||
asm volatile ("movl %0, %%esp; jmp intr_exit" : : "g" (&if_) : "memory");
|
||||
NOT_REACHED ();
|
||||
|
||||
/* If starting the process failed, free its common resources and exit. */
|
||||
fail:
|
||||
free (data);
|
||||
/* If starting the process failed, exit. */
|
||||
fail:
|
||||
data->success = false;
|
||||
sema_up (&data->loaded);
|
||||
thread_exit ();
|
||||
}
|
||||
|
||||
@@ -333,7 +352,6 @@ process_exit (void)
|
||||
if (cur->exec_file != NULL)
|
||||
{
|
||||
lock_acquire (&filesys_lock);
|
||||
file_allow_write (cur->exec_file);
|
||||
file_close (cur->exec_file);
|
||||
lock_release (&filesys_lock);
|
||||
}
|
||||
@@ -361,10 +379,11 @@ process_exit (void)
|
||||
/* Free child process results or signal parent's death. */
|
||||
struct list_elem *e;
|
||||
for (e = list_begin (&cur->child_results);
|
||||
e != list_end (&cur->child_results); e = list_next (e))
|
||||
e != list_end (&cur->child_results);)
|
||||
{
|
||||
struct process_result *result
|
||||
= list_entry (e, struct process_result, elem);
|
||||
struct list_elem *next = list_next (e);
|
||||
lock_acquire (&result->lock);
|
||||
/* Child has died (and was not waited for). Free the result. */
|
||||
if (sema_try_down (&result->sema))
|
||||
@@ -378,6 +397,7 @@ process_exit (void)
|
||||
sema_up (&result->sema);
|
||||
lock_release (&result->lock);
|
||||
}
|
||||
e = next;
|
||||
}
|
||||
|
||||
/* Destroy the current process's page directory and switch back
|
||||
|
||||
Reference in New Issue
Block a user