Page 1 of 1
Weird task switching bug
Posted: Mon Apr 20, 2026 6:03 am
by yucarp
When I load and change the cr3 register the stack pointer suddenly increases by 0x120. That eventually causes a memory spill and triple fault. Commenting the mov %r11, %cr3 makes it work fine but stack pointer goes to random places when I remove the comment. Any clues what causes this?
Re: Weird task switching bug
Posted: Thu Apr 30, 2026 12:58 pm
by yucarp
This bug has to do with the APIC timer, when setting the timer correct the bug was fixed
Re: Weird task switching bug
Posted: Thu Apr 30, 2026 2:16 pm
by savoita
Can you elaborate on what you mean by "setting the timer right" ? Might be useful for others in the future.
Re: Weird task switching bug
Posted: Thu Apr 30, 2026 2:27 pm
by yucarp
Ah, my bad... So I was measuring time with TSC but it was giving unaligned values (for example 13241). Instead I aligned the time (for example 13000) and it works perfectly.
Re: Weird task switching bug
Posted: Thu Apr 30, 2026 7:38 pm
by Octocontrabass
How did that change fix the bug? It sounds an awful lot like the bug is still there and you've only made it less likely to occur.