Compare commits

...

7 Commits

Author SHA1 Message Date
149b0a9d87 Remove filesys CI for gitlab 2024-11-14 03:25:33 +00:00
Saleh Bubshait
79b3b8fda7 Merge branch 'userprog-oom' into 'master'
Fix multi-oom

See merge request lab2425_autumn/pintos_22!39
2024-11-13 22:09:11 +00:00
f5e498e0a9 explicit thread_exit () when process_start () fails 2024-11-13 21:58:41 +00:00
d02b956221 Merge branch 'system-calls' into 'userprog-oom'
Add Fixes to Memory Leaks, Memory Access Validation, Synchronised Processes and Refactoring

See merge request lab2425_autumn/pintos_22!38
2024-11-13 19:20:19 +00:00
Saleh Bubshait
927c376d02 Merge branch 'task2/system-calls/saleh' into 'system-calls'
Fix Memory Leaks, Synchronisation in Processes, and Refactoring

See merge request lab2425_autumn/pintos_22!37
2024-11-13 18:51:51 +00:00
e7cb16b301 Fix child_results loop accessing next after free() 2024-11-13 18:29:05 +00:00
005791edd2 Synchronise process_execute return with child process load 2024-11-13 11:05:09 +00:00
2 changed files with 27 additions and 12 deletions

View File

@@ -23,11 +23,6 @@ test_devices:
variables:
DIR: devices
test_filesys:
extends: .pintos_tests
variables:
DIR: filesys
test_threads:
extends: .pintos_tests
variables:

View File

@@ -47,6 +47,9 @@ struct process_start_data
tokens while maintaining state. */
char file_name[FNAME_MAX_LEN + 1]; /* Name of the file of the process to
be started. */
bool success; /* Indicates whether the process was successfully loaded. */
struct semaphore loaded; /* Semaphore used to signal that the process has
been loaded. */
};
static thread_func start_process NO_RETURN;
@@ -67,6 +70,8 @@ process_execute (const char *cmd)
{
return TID_ERROR;
}
sema_init (&data->loaded, 0);
data->success = false;
/* Make a copy of command.
Otherwise there's a race between the caller and load(). */
@@ -100,7 +105,14 @@ process_execute (const char *cmd)
tid = thread_create (file_name, PRI_DEFAULT, start_process, data);
if (tid == TID_ERROR)
palloc_free_page (cmd_copy);
palloc_free_page (cmd_copy);
else
{
sema_down (&data->loaded);
if (!data->success)
tid = TID_ERROR;
}
free (data);
return tid;
}
@@ -132,6 +144,11 @@ start_process (void *proc_start_data)
/* Prevent writing to the file being executed. */
struct file *exec_file = filesys_open (data->file_name);
if (exec_file == NULL)
{
lock_release (&filesys_lock);
goto fail;
}
thread_current ()->exec_file = exec_file;
file_deny_write (exec_file);
lock_release (&filesys_lock);
@@ -153,10 +170,11 @@ start_process (void *proc_start_data)
/* If stack initialization failed, free resources and quit. */
if (!success)
{
process_exit ();
goto fail;
}
data->success = true;
sema_up (&data->loaded);
/* 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
@@ -166,9 +184,10 @@ start_process (void *proc_start_data)
asm volatile ("movl %0, %%esp; jmp intr_exit" : : "g" (&if_) : "memory");
NOT_REACHED ();
/* If starting the process failed, free its common resources and exit. */
fail:
free (data);
/* If starting the process failed, exit. */
fail:
data->success = false;
sema_up (&data->loaded);
thread_exit ();
}
@@ -333,7 +352,6 @@ process_exit (void)
if (cur->exec_file != NULL)
{
lock_acquire (&filesys_lock);
file_allow_write (cur->exec_file);
file_close (cur->exec_file);
lock_release (&filesys_lock);
}
@@ -361,10 +379,11 @@ process_exit (void)
/* Free child process results or signal parent's death. */
struct list_elem *e;
for (e = list_begin (&cur->child_results);
e != list_end (&cur->child_results); e = list_next (e))
e != list_end (&cur->child_results);)
{
struct process_result *result
= list_entry (e, struct process_result, elem);
struct list_elem *next = list_next (e);
lock_acquire (&result->lock);
/* Child has died (and was not waited for). Free the result. */
if (sema_try_down (&result->sema))
@@ -378,6 +397,7 @@ process_exit (void)
sema_up (&result->sema);
lock_release (&result->lock);
}
e = next;
}
/* Destroy the current process's page directory and switch back