threads: set stack pointer correctly for x86-64#120
Merged
Conversation
The tutorial was setting the stack pointer on x86-64 such that it was not aligned to 16 bytes. gcc 14.2 emits SSE instructions that require 16 byte alignment and fault when the stack is not correctly aligned. The misaligned stems from the fact that x86-64 expects a return address on the stack when the function is entered, but we were passing the top of the stack instead. The Arm ABI has the return address in the link register instead. Explain this difference in the tutorial and adjust the code accordingly. The later helper function `sel4utils_arch_init_local_context` already did this directly. Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
midnightveil
approved these changes
Jun 1, 2026
midnightveil
left a comment
There was a problem hiding this comment.
Is that TODO for you or the tutorial user? (the latter seems a bit weird?).
Member
Author
It's for the tutorial user, the tutorials all use TODO tags to mark the bits in the template that should be filled in. This one is indeed a bit weird, but it was worse before, because the text, the template, and the solution all said different things about whether or not to use |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The tutorial was setting the stack pointer on x86-64 such that it was not aligned to 16 bytes. gcc 14.2 emits SSE instructions that require 16 byte alignment and fault when the stack is not correctly aligned.
The misalignment stems from the fact that x86-64 expects a return address on the stack when the function is entered, but we were passing the top of the stack instead. The Arm ABI has the return address in the link register instead.
Explain this difference in the tutorial and adjust the code accordingly. The later helper function
sel4utils_arch_init_local_contextalready did this directly.