Added protection against bad addrspace vars and bad Page::Put() calls.

This will offer protection against the bug fixed in the previous commit.
This commit is contained in:
Jonas 'Sortie' Termansen 2012-03-02 13:51:03 +01:00
parent 5e5991ce19
commit 6dd0e586ff
4 changed files with 17 additions and 1 deletions

View File

@ -143,6 +143,15 @@ namespace Sortix
nextthread->LoadRegisters(regs);
addr_t newaddrspace = nextthread->process->addrspace;
if ( unlikely(newaddrspace != Page::AlignDown(newaddrspace)) )
{
PanicF("Thread 0x%p, process %i (0x%p) (backup: %i), had bad "
"address space variable: 0x%zx: not page-aligned "
"(backup: 0x%zx)\n", nextthread,
nextthread->process->pid, nextthread->process,
nextthread->pidbackup, newaddrspace,
nextthread->addrspacebackup);
}
Memory::SwitchAddressSpace(newaddrspace);
currentthread = nextthread;

View File

@ -56,6 +56,7 @@ namespace Sortix
currentsignal = NULL;
sighandler = NULL;
pidbackup = -1;
addrspacebackup = 0UL;
terminated = false;
ResetCallbacks();
}
@ -80,6 +81,7 @@ namespace Sortix
scfunc = NULL;
sighandler = forkfrom->sighandler;
pidbackup = -1;
addrspacebackup = 0UL;
terminated = false;
ResetCallbacks();
}
@ -190,6 +192,7 @@ namespace Sortix
ready = true;
this->pidbackup = process->pid;
this->addrspacebackup = process->addrspace;
if ( Time::MicrosecondsSinceBoot() < sleepuntil )
{

View File

@ -61,6 +61,7 @@ namespace Sortix
size_t id;
Process* process;
pid_t pidbackup;
addr_t addrspacebackup;
bool terminated;
Thread* prevsibling;
Thread* nextsibling;

View File

@ -265,11 +265,14 @@ namespace Sortix
addr_t Get()
{
if ( unlikely(stackused == 0) ) { Error::Set(ENOMEM); return 0; }
return STACK[--stackused];
addr_t result = STACK[--stackused];
ASSERT(result == AlignDown(result));
return result;
}
void Put(addr_t page)
{
ASSERT(page == AlignDown(page));
ASSERT(stackused < MAXSTACKLENGTH);
STACK[stackused++] = page;
}