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

@@ -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);

View File

@@ -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);

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

View File

@@ -13,7 +13,6 @@
#include <stdio.h>
#include <syscall-nr.h>
static struct lock filesys_lock;
static unsigned fd_counter = MIN_USER_FD;
struct open_file

View File

@@ -2,11 +2,14 @@
#define USERPROG_SYSCALL_H
#include <hash.h>
#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);