Update start_process to acquire filesys lock when loading user process file

This commit is contained in:
Themis Demetriades
2024-11-12 14:21:33 +00:00
parent 7d9900c6d8
commit a69b9c808e
5 changed files with 14 additions and 9 deletions

View File

@@ -8,6 +8,7 @@
#include <string.h>
#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