add file_deny_write and file_allow_write to process creation and exiting to make executable read-only
This commit is contained in:
@@ -127,6 +127,7 @@ struct thread
|
|||||||
struct process_result *result; /* Result of the process. */
|
struct process_result *result; /* Result of the process. */
|
||||||
struct list child_results; /* List of children's of this thread
|
struct list child_results; /* List of children's of this thread
|
||||||
process results. */
|
process results. */
|
||||||
|
struct file *exec_file; /* Thread's currently running file */
|
||||||
|
|
||||||
/* Shared between thread.c and synch.c. */
|
/* Shared between thread.c and synch.c. */
|
||||||
struct list_elem elem; /* List element. */
|
struct list_elem elem; /* List element. */
|
||||||
|
|||||||
@@ -181,6 +181,10 @@ start_process (void *file_name_)
|
|||||||
if (!success)
|
if (!success)
|
||||||
thread_exit ();
|
thread_exit ();
|
||||||
|
|
||||||
|
struct file *exec_file = filesys_open (file_name);
|
||||||
|
thread_current ()->exec_file = exec_file;
|
||||||
|
file_deny_write (exec_file);
|
||||||
|
|
||||||
/* Start the user process by simulating a return from an
|
/* Start the user process by simulating a return from an
|
||||||
interrupt, implemented by intr_exit (in
|
interrupt, implemented by intr_exit (in
|
||||||
threads/intr-stubs.S). Because intr_exit takes all of its
|
threads/intr-stubs.S). Because intr_exit takes all of its
|
||||||
@@ -246,6 +250,7 @@ process_exit (void)
|
|||||||
uint32_t *pd;
|
uint32_t *pd;
|
||||||
|
|
||||||
printf ("%s: exit(%d)\n", cur->name, cur->exit_status);
|
printf ("%s: exit(%d)\n", cur->name, cur->exit_status);
|
||||||
|
file_close (cur->exec_file);
|
||||||
|
|
||||||
/* Update process result. */
|
/* Update process result. */
|
||||||
if (cur->result != NULL)
|
if (cur->result != NULL)
|
||||||
|
|||||||
Reference in New Issue
Block a user