diff --git a/src/lib/kernel/list.c b/src/lib/kernel/list.c index f8f7fbb..83dc95e 100644 --- a/src/lib/kernel/list.c +++ b/src/lib/kernel/list.c @@ -170,6 +170,7 @@ list_insert (struct list_elem *before, struct list_elem *elem) { ASSERT (is_interior (before) || is_tail (before)); ASSERT (elem != NULL); + // Sanity checks to prevent (some) loop lists ASSERT (before != elem); ASSERT (before->prev != elem); diff --git a/src/tests/filesys/base/syn-write.c b/src/tests/filesys/base/syn-write.c index 1439862..26733c6 100644 --- a/src/tests/filesys/base/syn-write.c +++ b/src/tests/filesys/base/syn-write.c @@ -20,7 +20,6 @@ test_main (void) int fd; CHECK (create (file_name, sizeof buf1), "create \"%s\"", file_name); - exec_children ("child-syn-wrt", children, CHILD_CNT); wait_children (children, CHILD_CNT); diff --git a/src/userprog/process.c b/src/userprog/process.c index 3d12bd1..cecedc1 100644 --- a/src/userprog/process.c +++ b/src/userprog/process.c @@ -8,6 +8,7 @@ #include #include "userprog/gdt.h" #include "userprog/pagedir.h" +#include "userprog/syscall.h" #include "userprog/tss.h" #include "filesys/directory.h" #include "filesys/file.h" @@ -81,6 +82,12 @@ process_execute (const char *cmd) of the process. */ 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. */ +struct file *exec_file = filesys_open (file_name); +file_deny_write (exec_file); + /* Validates that the current file to be executed is a valid file */ if (filesys_open (file_name) == NULL) return TID_ERROR; @@ -120,7 +127,10 @@ 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); success = load (data->file_name, &if_.eip, &if_.esp); + lock_release (&filesys_lock); /* If load failed, quit. */ if (!success) @@ -141,13 +151,6 @@ start_process (void *proc_start_data) 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 diff --git a/src/userprog/syscall.c b/src/userprog/syscall.c index ccb02f3..1192f46 100644 --- a/src/userprog/syscall.c +++ b/src/userprog/syscall.c @@ -13,7 +13,6 @@ #include #include -static struct lock filesys_lock; static unsigned fd_counter = MIN_USER_FD; struct open_file diff --git a/src/userprog/syscall.h b/src/userprog/syscall.h index 0f9288b..16af00c 100644 --- a/src/userprog/syscall.h +++ b/src/userprog/syscall.h @@ -2,11 +2,14 @@ #define USERPROG_SYSCALL_H #include +#include "threads/synch.h" #define MIN_USER_FD 2 typedef int pid_t; +struct lock filesys_lock; + void syscall_init (void); unsigned fd_hash (const struct hash_elem *element, void *aux);