-
Notifications
You must be signed in to change notification settings - Fork 70
stacker - stack_area() returns incorrect size
#133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d216a8f
7b4a4be
26691f9
0f8b7c9
aadcb10
3fc137e
b4e6894
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -82,7 +82,7 @@ impl StackRestoreGuard { | |
| unsafe { | ||
| ( | ||
| self.mapping.add(self.page_size), | ||
| self.size_with_guard - self.page_size, | ||
| self.size_with_guard - 2 * self.page_size, | ||
| ) | ||
| } | ||
| } | ||
|
|
@@ -103,3 +103,27 @@ fn page_size() -> usize { | |
| // FIXME: consider caching the page size. | ||
| unsafe { libc::sysconf(libc::_SC_PAGE_SIZE) as usize } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn test_stack_area() { | ||
| for stack_size_kb in 1..64 { | ||
| let size = stack_size_kb * 1024; | ||
| let stack = StackRestoreGuard::new(size); | ||
| let (mut ptr, actual_size) = stack.stack_area(); | ||
| for _ in 0..actual_size { | ||
| unsafe { | ||
| core::ptr::write_volatile(ptr, 0b10101011); | ||
| ptr = ptr.add(1) | ||
| } | ||
| } | ||
| assert_eq!( | ||
| actual_size, | ||
| size.div_ceil(page_size()) * page_size() | ||
| ) | ||
|
Comment on lines
123
to
126
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would you mind adjusting the test to also attempt a write to every byte of the allocated stack mapping?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure! Good idea. I will also simplify that test to use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I updated the test, but:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, I confirmed segfaults occur when using |
||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
allocated_stack_sizecould result in a segfault if the actual size is smaller than is reported bystack_area(), and if the stack overflows into these guard pages.