Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions library/std/src/sys/pal/unix/stack_overflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,11 @@ mod imp {

#[forbid(unsafe_op_in_unsafe_fn)]
unsafe fn install_main_guard_linux(page_size: usize) -> Option<Range<usize>> {
// See the corresponding conditional in init().
// Avoid stack_start_aligned, which makes slow syscalls to read /proc/self/maps
if cfg!(panic = "immediate-abort") {
return None;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also be done for other targets where the OS already provides guard pages for the stack, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added to install_main_guard_bsds

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The FreeBSD code can also be skipped.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added to install_main_guard_freebsd

// Linux doesn't allocate the whole stack right away, and
// the kernel has its own stack-guard mechanism to fault
// when growing too close to an existing mapping. If we map
Expand Down Expand Up @@ -456,6 +461,10 @@ mod imp {
#[forbid(unsafe_op_in_unsafe_fn)]
#[cfg(target_os = "freebsd")]
unsafe fn install_main_guard_freebsd(page_size: usize) -> Option<Range<usize>> {
// See the corresponding conditional in install_main_guard_linux().
if cfg!(panic = "immediate-abort") {
return None;
}
// FreeBSD's stack autogrows, and optionally includes a guard page
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asomers do you have context on what this "optionally" here is referring to? Not really related to this PR but since we intend to guarantee stack guards, I'm wondering if we should be branching on something and defining our own if FreeBSD didn't?

// at the bottom. If we try to remap the bottom of the stack
// ourselves, FreeBSD's guard page moves upwards. So we'll just use
Expand Down Expand Up @@ -489,6 +498,10 @@ mod imp {

#[forbid(unsafe_op_in_unsafe_fn)]
unsafe fn install_main_guard_bsds(page_size: usize) -> Option<Range<usize>> {
// See the corresponding conditional in install_main_guard_linux().
if cfg!(panic = "immediate-abort") {
return None;
}
// OpenBSD stack already includes a guard page, and stack is
// immutable.
// NetBSD stack includes the guard page.
Expand Down
Loading