[shm] fork() and execve() don't wreak havoc on shm

This commit is contained in:
Markus Schober 2012-02-08 16:00:51 -06:00
parent aa73f6fc6e
commit 27d0deed5b
4 changed files with 26 additions and 3 deletions

View File

@ -246,8 +246,7 @@ int shm_release (char * path) {
page_t * page = get_page(mapping->vaddrs[i], 0, proc->thread.page_directory);
assert(page && "Shared memory mapping was invalid!");
// memset(page, 0, sizeof(page_t));
page->frame = 0x0;
memset(page, 0, sizeof(page_t));
}
/* Clean up */

View File

@ -175,7 +175,7 @@ process_t * spawn_init() {
/* Process is not finished */
init->finished = 0;
init->wait_queue = list_create();
init->shm_mappings = NULL;
init->shm_mappings = list_create();
init->signal_queue = list_create();
/* What the hey, let's also set the description on this one */

View File

@ -174,6 +174,8 @@ static int execve(const char * filename, char *const argv[], char *const envp[])
argv_[j] = malloc((strlen(argv[j]) + 1) * sizeof(char));
memcpy(argv_[j], argv[j], strlen(argv[j]) + 1);
}
shm_release_all((process_t *)current_process);
/* Discard envp */
exec((char *)filename, i, (char **)argv_);
return -1;

View File

@ -7,6 +7,7 @@
#include <process.h>
#include <logging.h>
#include <shm.h>
#include <mem.h>
#define TASK_MAGIC 0xDEADBEEF
@ -197,6 +198,27 @@ fork() {
/* Set the new process instruction pointer (to the return from read_eip) */
new_proc->thread.eip = eip;
/* Clear page table tie-ins for shared memory mappings */
assert((new_proc->shm_mappings->length == 0) && "Spawned process had shared memory mappings!");
foreach (n, current_process->shm_mappings) {
shm_mapping_t * mapping = (shm_mapping_t *)n->value;
for (uint32_t i = 0; i < mapping->num_vaddrs; i++) {
/* Get the vpage address (it's the same for the cloned directory)... */
uintptr_t vpage = mapping->vaddrs[i];
assert(!(vpage & 0xFFF) && "shm_mapping_t contained a ptr to the middle of a page (bad)");
/* ...and from that, the cloned dir's page entry... */
page_t * page = get_page(vpage, 0, new_proc->thread.page_directory);
assert(test_frame(page->frame * 0x1000) && "ptr wasn't mapped in?");
/* ...which refers to a bogus frame that we don't want. */
clear_frame(page->frame * 0x1000);
memset(page, 0, sizeof(page_t));
}
}
/* Add the new process to the ready queue */
make_process_ready(new_proc);