diff --git a/sortix/elf.cpp b/sortix/elf.cpp index 875b2f05..6e0e02cc 100644 --- a/sortix/elf.cpp +++ b/sortix/elf.cpp @@ -35,15 +35,6 @@ namespace Sortix { namespace ELF { - // This works around an optimizer bug I ran into, where the memcpy below - // somehow gets executed prior to the memory was mapped. Somehow, when I - // tried to debug it, it suddenly worked. So here's some deep magic that - // somehow fixes my code. - void PreventHazardousCodeReordering() - { - Log::Print(""); - } - addr_t Construct32(Process* process, const void* file, size_t filelen) { if ( filelen < sizeof(Header32) ) { return 0; } @@ -70,6 +61,10 @@ namespace Sortix // Reset the current address space. process->ResetAddressSpace(); + // Flush the TLB such that no stale information from the last + // address space is used when creating the new one. + Memory::Flush(); + // Create all the segments in the final process. // TODO: Handle errors on bad/malicious input or out-of-mem! for ( uint16_t i = 0; i < numprogheaders; i++ ) @@ -94,7 +89,7 @@ namespace Sortix return 0; } - if ( !Memory::MapRangeUser(mapto, mapbytes) ) + if ( !Memory::MapRangeUser(mapto, mapbytes)) { return 0; } @@ -105,8 +100,6 @@ namespace Sortix segment->next = process->segments; process->segments = segment; - PreventHazardousCodeReordering(); - // Copy as much data as possible and memset the rest to 0. byte* memdest = (byte*) virtualaddr; byte* memsource = (byte*) ( ((addr_t)file) + pht->offset); diff --git a/sortix/x86-family/memorymanagement.cpp b/sortix/x86-family/memorymanagement.cpp index 62ceb826..04c2258e 100644 --- a/sortix/x86-family/memorymanagement.cpp +++ b/sortix/x86-family/memorymanagement.cpp @@ -66,7 +66,7 @@ namespace Sortix // Loop over every detected memory region. for ( - mmap_t mmap = (mmap_t) bootinfo->mmap_addr; + mmap_t mmap = (mmap_t) bootinfo->mmap_addr; (addr_t) mmap < bootinfo->mmap_addr + bootinfo->mmap_length; mmap = (mmap_t) ((addr_t) mmap + mmap->size + sizeof(mmap->size)) ) @@ -425,20 +425,10 @@ namespace Sortix while ( positionstack[TOPPMLLEVEL] < ENTRIES ) { - if ( level == 1 ) - { - //Log::PrintF("[%zu > %zu]", positionstack[2], positionstack[1]); - } - else - { - //Log::PrintF("[%zu]", positionstack[2]); - } - const size_t pos = positionstack[level]; if ( pos == ENTRIES ) { - //Log::PrintF(" done with level\n"); (positionstack[++level])++; pmloffset /= ENTRIES; continue; @@ -454,7 +444,6 @@ namespace Sortix if ( unlikely(phys == 0) ) { - //Log::PrintF(" out of memory!\n"); // Oh no. Out of memory! We'll have to undo everything // we just did. Argh! failure = true; @@ -472,8 +461,6 @@ namespace Sortix if ( level == 1 ) { - //Log::PrintF(" copy\n"); - // Determine the source page's address. const void* src = (const void*) (pmloffset * 4096UL); @@ -484,8 +471,6 @@ namespace Sortix } else { - //Log::PrintF(" recurse\n"); - // Fork the PML recursively! pmloffset = pmloffset * ENTRIES + pos; positionstack[--level] = 0; @@ -496,15 +481,12 @@ namespace Sortix // If this entry should be linked, link it. else { - //Log::PrintF(" link\n"); FORKPML[level].entry[pos] = entry; - } + } positionstack[level]++; } - //Log::PrintF("Fork: Loop Terminated\n"); - if ( !failure ) { // Now, the new top pml needs to have its fractal memory fixed. @@ -524,8 +506,6 @@ namespace Sortix childaddr = (FORKPML + i)->entry[ENTRIES-2] & PML_ADDRESS; } - //Log::PrintF("Fork: Done\n"); - return newtoppmladdr; }