1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:07:45 +00:00

Kernel: Fix accidental restore of bogus FPU state after fork

Cloned threads (basically, forked processes) inherit the complete FPU
state of their origin thread. There was a bug in the lazy FPU state
save/restore mechanism where a cloned thread would believe it had a
buffer full of valid FPU state (because the inherited flag said so)
but the origin thread had never actually copied any FPU state into it.

This patch fixes that by forcing out an FPU state save after doing
the initial FPU initialization (FNINIT) in a thread. :^)
This commit is contained in:
Andreas Kling 2019-10-13 14:39:04 +02:00
parent 40beb4c5c0
commit 44fb71261a

View file

@ -221,6 +221,8 @@ void exception_7_handler(RegisterDump& regs)
asm volatile("fxrstor %0" ::"m"(current->fpu_state()));
} else {
asm volatile("fninit");
asm volatile("fxsave %0"
: "=m"(g_last_fpu_thread->fpu_state()));
current->set_has_used_fpu(true);
}