1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00

Fixes to memory management that helps me sleep at night.

This commit is contained in:
Jonas 'Sortie' Termansen 2011-10-10 17:22:03 +02:00
parent c16bdd2604
commit 1b7dc2d817
2 changed files with 7 additions and 34 deletions

View file

@ -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);

View file

@ -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;
}