mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:18:11 +00:00
Turn the syscall interrupt into a trap (by switching the gate type.)
This leaves interrupts enabled while we're in the kernel, which is precisely what we want. This uncovered a horrendous problem with kernel tasks silently overflowing their stacks. For now I've simply increased the stack size but I need a more MMU-y solution for this eventually.
This commit is contained in:
parent
2d1d01661b
commit
46ff281695
6 changed files with 116 additions and 25 deletions
|
@ -162,13 +162,14 @@ Task::Task(void (*e)(), const char* n, IPC::Handle h, RingLevel ring)
|
|||
|
||||
kprintf("basically ready\n");
|
||||
|
||||
// NOTE: Each task gets 4KB of stack.
|
||||
static const DWORD defaultStackSize = 4096;
|
||||
// NOTE: Each task gets 16KB of stack.
|
||||
static const DWORD defaultStackSize = 16384;
|
||||
|
||||
if (isRing0()) {
|
||||
// FIXME: This memory is leaked.
|
||||
// But uh, there's also no kernel task termination, so I guess it's not technically leaked...
|
||||
m_stackTop = ((DWORD)kmalloc(defaultStackSize) + defaultStackSize) & 0xffffff8;
|
||||
dword stackBottom = (dword)kmalloc(defaultStackSize);
|
||||
m_stackTop = (stackBottom + defaultStackSize) & 0xffffff8;
|
||||
m_tss.esp = m_stackTop;
|
||||
} else {
|
||||
auto* region = allocateRegion(defaultStackSize, "stack");
|
||||
|
@ -235,8 +236,8 @@ void Task::dumpRegions()
|
|||
|
||||
void Task::taskDidCrash(Task* crashedTask)
|
||||
{
|
||||
// NOTE: This is called from an excepton handler, so interrupts are disabled.
|
||||
crashedTask->setState(Crashing);
|
||||
|
||||
crashedTask->dumpRegions();
|
||||
|
||||
s_tasks->remove(crashedTask);
|
||||
|
@ -260,8 +261,11 @@ void yield()
|
|||
|
||||
//kprintf("%s<%u> yield()\n", current->name().characters(), current->pid());
|
||||
|
||||
if (!scheduleNewTask())
|
||||
cli();
|
||||
if (!scheduleNewTask()) {
|
||||
sti();
|
||||
return;
|
||||
}
|
||||
|
||||
//kprintf("yield() jumping to new task: %x (%s)\n", current->farPtr().selector, current->name().characters());
|
||||
switchNow();
|
||||
|
@ -272,7 +276,7 @@ void switchNow()
|
|||
Descriptor& descriptor = getGDTEntry(current->selector());
|
||||
descriptor.type = 9;
|
||||
flushGDT();
|
||||
asm(
|
||||
asm("sti\n"
|
||||
"ljmp *(%%eax)\n"
|
||||
::"a"(¤t->farPtr())
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue