From 7daf4fb079a89e8292de4f7891de19da5c8c173e Mon Sep 17 00:00:00 2001 From: sBubshait Date: Fri, 15 Nov 2024 15:35:07 +0000 Subject: [PATCH] Refactor process_exit to add more comments for readability --- src/userprog/process.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/userprog/process.c b/src/userprog/process.c index 1e7b227..e712e22 100644 --- a/src/userprog/process.c +++ b/src/userprog/process.c @@ -209,7 +209,7 @@ process_init_stack (char *cmd_saveptr, void **esp, char *file_name) /* filename has already been validated to be a safe-to-access string, so we can safely use strlen here. Filename has already been split from the command line arguments. */ - push_to_stack (esp, arg, strlen (arg) + 1); + push_to_stack (esp, arg, (strlen (arg) + 1) * sizeof (char)); /* Try to allocate memory for the argument pointer. */ struct arg_elem *arg_elem = malloc (sizeof (struct arg_elem)); @@ -376,9 +376,10 @@ process_exit (void) /* Clean up all open files */ hash_destroy (&cur->open_files, fd_cleanup); - /* Close the executable file. */ + /* Close the executable file, implicitly allowing it to be written to. */ if (cur->exec_file != NULL) { + /* Acquire the file system lock to prevent race conditions. */ lock_acquire (&filesys_lock); file_close (cur->exec_file); lock_release (&filesys_lock);