Refactor System Calls and Process for Readability; Change FD to local counter and use it as hash #47

Merged
sb3923 merged 9 commits from task2/refactoring/saleh into master 2024-11-15 16:41:13 +00:00
3 changed files with 116 additions and 36 deletions
Showing only changes of commit 7daf4fb079 - Show all commits

View File

@@ -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, /* filename has already been validated to be a safe-to-access string,
so we can safely use strlen here. Filename has already been so we can safely use strlen here. Filename has already been
split from the command line arguments. */ 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. */ /* Try to allocate memory for the argument pointer. */
struct arg_elem *arg_elem = malloc (sizeof (struct arg_elem)); struct arg_elem *arg_elem = malloc (sizeof (struct arg_elem));
@@ -376,9 +376,10 @@ process_exit (void)
/* Clean up all open files */ /* Clean up all open files */
hash_destroy (&cur->open_files, fd_cleanup); 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) if (cur->exec_file != NULL)
{ {
/* Acquire the file system lock to prevent race conditions. */
lock_acquire (&filesys_lock); lock_acquire (&filesys_lock);
file_close (cur->exec_file); file_close (cur->exec_file);
lock_release (&filesys_lock); lock_release (&filesys_lock);