Compare commits
1 Commits
themis/use
...
rox-check-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
987a71ec40 |
@@ -212,7 +212,6 @@ donate_priority (struct thread *donee) {
|
||||
ASSERT (intr_get_level () == INTR_OFF);
|
||||
|
||||
struct thread *donor = thread_current ();
|
||||
list_remove (&donor->donor_elem);
|
||||
list_push_back (&donee->donors_list, &donor->donor_elem);
|
||||
|
||||
while (donee != NULL)
|
||||
@@ -261,7 +260,6 @@ lock_acquire (struct lock *lock)
|
||||
ASSERT (!lock_held_by_current_thread (lock));
|
||||
|
||||
struct thread *t = thread_current ();
|
||||
ASSERT (t->waiting_lock == NULL);
|
||||
|
||||
enum intr_level old_level = intr_disable ();
|
||||
if (lock->holder != NULL)
|
||||
@@ -343,6 +341,7 @@ lock_release (struct lock *lock)
|
||||
released, transfer the remaining orphaned donors to its donor list. */
|
||||
if (max_donor != NULL)
|
||||
{
|
||||
list_remove (&max_donor->donor_elem);
|
||||
while (!list_empty (&orphan_list))
|
||||
list_push_back (&max_donor->donors_list, list_pop_front (&orphan_list));
|
||||
}
|
||||
|
||||
@@ -373,9 +373,7 @@ thread_exit (void)
|
||||
and schedule another process. That process will destroy us
|
||||
when it calls thread_schedule_tail(). */
|
||||
intr_disable ();
|
||||
struct thread *t = thread_current ();
|
||||
list_remove (&t->allelem);
|
||||
list_remove (&t->donor_elem);
|
||||
list_remove (&thread_current()->allelem);
|
||||
thread_current ()->status = THREAD_DYING;
|
||||
schedule ();
|
||||
NOT_REACHED ();
|
||||
@@ -681,7 +679,6 @@ init_thread (struct thread *t, const char *name, int nice, int priority,
|
||||
t->base_priority
|
||||
= thread_mlfqs ? calculate_bsd_priority (recent_cpu, nice) : priority;
|
||||
list_init (&t->donors_list);
|
||||
list_push_back (&t->donors_list, &t->donor_elem);
|
||||
t->waiting_lock = NULL;
|
||||
|
||||
t->nice = nice;
|
||||
|
||||
@@ -47,9 +47,6 @@ 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. */
|
||||
struct semaphore load_sema;
|
||||
|
||||
bool success;
|
||||
};
|
||||
|
||||
static thread_func start_process NO_RETURN;
|
||||
@@ -65,7 +62,11 @@ process_execute (const char *cmd)
|
||||
char *cmd_copy;
|
||||
tid_t tid;
|
||||
|
||||
struct process_start_data data;
|
||||
struct process_start_data *data = malloc (sizeof (struct process_start_data));
|
||||
if (data == NULL)
|
||||
{
|
||||
return TID_ERROR;
|
||||
}
|
||||
|
||||
/* Make a copy of command.
|
||||
Otherwise there's a race between the caller and load(). */
|
||||
@@ -79,39 +80,21 @@ process_execute (const char *cmd)
|
||||
|
||||
/* Retrieve first argument of command, which is the file name
|
||||
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
|
||||
reopened here. Because load is an exported public function, this
|
||||
might be necessary. */
|
||||
lock_acquire (&filesys_lock);
|
||||
/* Validates that the current file to be executed is a valid file */
|
||||
bool valid_file = filesys_open (file_name) != NULL;
|
||||
lock_release (&filesys_lock);
|
||||
if (!valid_file)
|
||||
if (filesys_open (file_name) == NULL)
|
||||
return TID_ERROR;
|
||||
|
||||
/* Create a new thread to execute the command, by initializing
|
||||
it running the function 'start_process' with the appropriate
|
||||
arguments. For details of arguments, see 'start_process'. */
|
||||
data.cmd = cmd_copy;
|
||||
strlcpy (data.file_name, file_name, FNAME_MAX_LEN + 1);
|
||||
sema_init (&data.load_sema, 0);
|
||||
data.success = false;
|
||||
|
||||
tid = thread_create (file_name, PRI_DEFAULT, start_process, &data);
|
||||
data->cmd = cmd_copy;
|
||||
strlcpy (data->file_name, file_name, FNAME_MAX_LEN + 1);
|
||||
|
||||
tid = thread_create (file_name, PRI_DEFAULT, start_process, data);
|
||||
if (tid == TID_ERROR)
|
||||
{
|
||||
palloc_free_page (cmd_copy);
|
||||
}
|
||||
else
|
||||
{
|
||||
sema_down (&data.load_sema);
|
||||
if (!data.success)
|
||||
tid = TID_ERROR;
|
||||
}
|
||||
|
||||
palloc_free_page (cmd_copy);
|
||||
return tid;
|
||||
}
|
||||
|
||||
@@ -129,6 +112,7 @@ static void
|
||||
start_process (void *proc_start_data)
|
||||
{
|
||||
struct intr_frame if_;
|
||||
bool success;
|
||||
|
||||
struct process_start_data *data = proc_start_data;
|
||||
|
||||
@@ -137,38 +121,34 @@ start_process (void *proc_start_data)
|
||||
if_.gs = if_.fs = if_.es = if_.ds = if_.ss = SEL_UDSEG;
|
||||
if_.cs = SEL_UCSEG;
|
||||
if_.eflags = FLAG_IF | FLAG_MBS;
|
||||
|
||||
lock_acquire (&filesys_lock);
|
||||
|
||||
/* Prevent writing to the file being executed. */
|
||||
struct file *exec_file = filesys_open (data->file_name);
|
||||
thread_current ()->exec_file = exec_file;
|
||||
file_deny_write (exec_file);
|
||||
lock_release (&filesys_lock);
|
||||
success = load (data->file_name, &if_.eip, &if_.esp);
|
||||
|
||||
data->success = load (data->file_name, &if_.eip, &if_.esp);
|
||||
|
||||
/* If load failed, free process startup data and quit. */
|
||||
if (!data->success)
|
||||
/* If load failed, quit. */
|
||||
if (!success)
|
||||
{
|
||||
palloc_free_page (data->cmd);
|
||||
sema_up (&data->load_sema);
|
||||
thread_exit ();
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* Initialize user process stack and free page used to store the
|
||||
command that executed the process. */
|
||||
bool success = process_init_stack (data->cmd_saveptr, &if_.esp, data->file_name);
|
||||
success = process_init_stack (data->cmd_saveptr, &if_.esp, data->file_name);
|
||||
palloc_free_page (data->cmd);
|
||||
data->success = success;
|
||||
sema_up (&data->load_sema);
|
||||
|
||||
/* If stack initialization failed, free process resources and quit. */
|
||||
/* If stack initialization failed, free resources and quit. */
|
||||
if (!success)
|
||||
{
|
||||
thread_exit ();
|
||||
process_exit ();
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* NOTE: Currently, the file being executed is closed in load () and then
|
||||
reopened here. Because load is an exported public function, this
|
||||
might be necessary. */
|
||||
struct file *exec_file = filesys_open (data->file_name);
|
||||
thread_current ()->exec_file = exec_file;
|
||||
file_deny_write (exec_file);
|
||||
|
||||
/* 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
|
||||
@@ -177,6 +157,11 @@ start_process (void *proc_start_data)
|
||||
and jump to it. */
|
||||
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);
|
||||
thread_exit ();
|
||||
}
|
||||
|
||||
/* Helper function that initializes the stack of a newly created
|
||||
@@ -307,9 +292,7 @@ process_wait (tid_t child_tid UNUSED)
|
||||
break;
|
||||
}
|
||||
if (child_result == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return -1;
|
||||
/* Wait for child to die. */
|
||||
sema_down (&child_result->sema);
|
||||
/* We need lock release in process_exit, so we need to acquire (and possibly
|
||||
@@ -323,7 +306,6 @@ process_wait (tid_t child_tid UNUSED)
|
||||
int exit_status = child_result->exit_status;
|
||||
lock_release (&child_result->lock);
|
||||
free (child_result);
|
||||
|
||||
return exit_status;
|
||||
}
|
||||
|
||||
@@ -331,23 +313,11 @@ process_wait (tid_t child_tid UNUSED)
|
||||
void
|
||||
process_exit (void)
|
||||
{
|
||||
|
||||
|
||||
struct thread *cur = thread_current ();
|
||||
uint32_t *pd;
|
||||
|
||||
printf ("%s: exit(%d)\n", cur->name, cur->exit_status);
|
||||
|
||||
/* Clean up all open files */
|
||||
hash_destroy (&cur->open_files, fd_cleanup);
|
||||
|
||||
/* Close the executable file. */
|
||||
if (cur->exec_file != NULL)
|
||||
{
|
||||
lock_acquire (&filesys_lock);
|
||||
file_close (cur->exec_file);
|
||||
lock_release (&filesys_lock);
|
||||
}
|
||||
file_close (cur->exec_file);
|
||||
|
||||
/* Update process result. */
|
||||
if (cur->result != NULL)
|
||||
@@ -372,11 +342,10 @@ 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_end (&cur->child_results); e = list_next (e))
|
||||
{
|
||||
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))
|
||||
@@ -390,7 +359,6 @@ process_exit (void)
|
||||
sema_up (&result->sema);
|
||||
lock_release (&result->lock);
|
||||
}
|
||||
e = next;
|
||||
}
|
||||
|
||||
/* Destroy the current process's page directory and switch back
|
||||
@@ -509,7 +477,6 @@ load (const char *file_name, void (**eip) (void), void **esp)
|
||||
off_t file_ofs;
|
||||
bool success = false;
|
||||
int i;
|
||||
lock_acquire (&filesys_lock);
|
||||
|
||||
/* Allocate and activate page directory. */
|
||||
t->pagedir = pagedir_create ();
|
||||
@@ -609,7 +576,6 @@ load (const char *file_name, void (**eip) (void), void **esp)
|
||||
done:
|
||||
/* We arrive here whether the load is successful or not. */
|
||||
file_close (file);
|
||||
lock_release (&filesys_lock);
|
||||
return success;
|
||||
}
|
||||
|
||||
|
||||
@@ -378,20 +378,6 @@ fd_less (const struct hash_elem *a_, const struct hash_elem *b_,
|
||||
return a->fd < b->fd;
|
||||
}
|
||||
|
||||
/* Function to clean up an open file entry. Closes the file and frees the
|
||||
associated memory. */
|
||||
void
|
||||
fd_cleanup (struct hash_elem *e, void *aux UNUSED)
|
||||
{
|
||||
struct open_file *file_info = hash_entry (e, struct open_file, elem);
|
||||
|
||||
lock_acquire (&filesys_lock);
|
||||
file_close (file_info->file);
|
||||
lock_release (&filesys_lock);
|
||||
|
||||
free (file_info);
|
||||
}
|
||||
|
||||
/* Gets a file from its descriptor (FD number). If there is no file with the fd
|
||||
FD it returns NULL. */
|
||||
static struct open_file *
|
||||
|
||||
@@ -14,6 +14,5 @@ void syscall_init (void);
|
||||
|
||||
unsigned fd_hash (const struct hash_elem *element, void *aux);
|
||||
bool fd_less (const struct hash_elem *a, const struct hash_elem *b, void *aux);
|
||||
void fd_cleanup (struct hash_elem *e, void *aux);
|
||||
|
||||
#endif /* userprog/syscall.h */
|
||||
|
||||
Reference in New Issue
Block a user