Create kernel stack with correct size and set up a guard page #335
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 last page of stack memory was not used before (see #294 ) because we initialized the stack pointer with the start address of the inclusive end page of the stack. This PR fixes this by initializing the stack pointer with the exact configured address, aligned to a 16-byte boundary. To verify that this works, I added a new
min_stack
test that tries booting with a kernel stack size of just 3000 bytes.We also claimed in the docs that we set up a guard page for the kernel stack, but never actually did this. This PR fixes that issue too by allocating an extra page when creating the virtual kernel stack mapping. We then leave the first page of that allocation unmapped so that a page fault will occur when the kernel overflows its stack.
To ensure that user-configured addresses have the correct alignment, I also added an alignment check to the
mapping_addr
function. There is also a new convenience function for allocating page-aligned virtual regions.Fixes #294