twizzler-operating-system / twizzler

The Twizzler Operating System
BSD 3-Clause "New" or "Revised" License
62 stars 13 forks source link

Fix aarch64 thread stack initialization #184

Closed PandaZ3D closed 3 weeks ago

PandaZ3D commented 3 weeks ago

This PR fixes a stack corruption bug caused by bad thread stack initialization. I discovered that the synchronization bug I was chasing was a stack corruption bug. Essentially the aarch64 thread stack initialization code simply sets the stack pointer to the end of the stack instead of the base. This is a problem since on aarch64 the stack is full descending and grows towards lower addresses. This did not cause any immediate issues when the system ran with a few threads.

However, when running the kernel tests ,the synchronization tests (mutex/condvar) failed. This is because those tests create many threads which cause execution of code to overwrite the stack of other threads. Now that the threads stacks are initialized correctly, the tests test_condvar and test_mutex pass. According to those test, there are no synchronization bugs ;)

There are still a few tests that the aarch64 version of the kernel does not pass. Those bugs will be fixed in future PRs.