Implement initial fork syscall

This commit is contained in:
Justin C. Miller
2019-03-09 12:18:21 -08:00
parent 241e1dacb0
commit 97ac3c09fa
12 changed files with 143 additions and 25 deletions

View File

@@ -92,12 +92,19 @@ page_table *
page_manager::copy_table(page_table *from, page_table::level lvl)
{
page_table *to = get_table_page();
log::debug(logs::memory, "Page manager copying level %d table at %016lx to %016lx.", lvl, from, to);
if (lvl == page_table::level::pml4) {
to->entries[510] = m_kernel_pml4->entries[510];
to->entries[511] = m_kernel_pml4->entries[511];
}
const int max =
lvl == page_table::level::pml4 ?
510 :
512;
unsigned pages_copied = 0;
for (int i = 0; i < max; ++i) {
if (!from->is_present(i)) {
to->entries[i] = 0;
@@ -112,6 +119,7 @@ page_manager::copy_table(page_table *from, page_table::level lvl)
uint16_t flags = from->entries[i] & 0xfffull;
uintptr_t orig = from->entries[i] & ~0xfffull;
to->entries[i] = copy_page(orig) | flags;
pages_copied++;
} else {
uint16_t flags = 0;
page_table *next_from = from->get(i, &flags);
@@ -120,6 +128,9 @@ page_manager::copy_table(page_table *from, page_table::level lvl)
}
}
if (pages_copied)
log::debug(logs::memory, " copied %3u pages", pages_copied);
return to;
}