mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:48:11 +00:00
Kernel: Fix intermittent assertion failure in sys$exec()
While setting up the main thread stack for a new process, we'd incur some zero-fill page faults. This was to be expected, since we allocate a huge stack but lazily populate it with physical pages. The problem is that page fault handlers may enable interrupts in order to grab a VMObject lock (or to page in from an inode.) During exec(), a process is reorganizing itself and will be in a very unrunnable state if the scheduler should interrupt it and then later ask it to run again. Which is exactly what happens if the process gets pre-empted while the new stack's zero-fill page fault grabs the lock. This patch fixes the issue by creating new main thread stacks before disabling interrupts and going into the critical part of exec().
This commit is contained in:
parent
1d4d6f16b2
commit
3012b224f0
3 changed files with 26 additions and 8 deletions
|
@ -616,12 +616,18 @@ int Process::do_exec(String path, Vector<String> arguments, Vector<String> envir
|
|||
}
|
||||
}
|
||||
|
||||
// NOTE: We create the new stack before disabling interrupts since it will zero-fault
|
||||
// and we don't want to deal with faults after this point.
|
||||
u32 new_userspace_esp = main_thread().make_userspace_stack_for_main_thread(move(arguments), move(environment));
|
||||
|
||||
// We cli() manually here because we don't want to get interrupted between do_exec() and Schedule::yield().
|
||||
// The reason is that the task redirection we've set up above will be clobbered by the timer IRQ.
|
||||
// If we used an InterruptDisabler that sti()'d on exit, we might timer tick'd too soon in exec().
|
||||
if (¤t->process() == this)
|
||||
cli();
|
||||
|
||||
// NOTE: Be careful to not trigger any page faults below!
|
||||
|
||||
Scheduler::prepare_to_modify_tss(main_thread());
|
||||
|
||||
m_name = parts.take_last();
|
||||
|
@ -645,7 +651,7 @@ int Process::do_exec(String path, Vector<String> arguments, Vector<String> envir
|
|||
main_thread().m_tss.gs = thread_specific_selector() | 3;
|
||||
main_thread().m_tss.ss = 0x23;
|
||||
main_thread().m_tss.cr3 = page_directory().cr3();
|
||||
main_thread().make_userspace_stack_for_main_thread(move(arguments), move(environment));
|
||||
main_thread().m_tss.esp = new_userspace_esp;
|
||||
main_thread().m_tss.ss0 = 0x10;
|
||||
main_thread().m_tss.esp0 = old_esp0;
|
||||
main_thread().m_tss.ss2 = m_pid;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue