Skip to content
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

Display error details when a mmap call fails #83223

Merged
merged 1 commit into from
Mar 18, 2021
Merged
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions library/std/src/sys/unix/stack_overflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ impl Drop for Handler {
))]
mod imp {
use super::Handler;
use crate::io;
use crate::mem;
use crate::ptr;

Expand Down Expand Up @@ -149,11 +150,11 @@ mod imp {
0,
);
if stackp == MAP_FAILED {
panic!("failed to allocate an alternative stack");
panic!("failed to allocate an alternative stack: {}", io::Error::last_os_error());
}
let guard_result = libc::mprotect(stackp, page_size(), PROT_NONE);
if guard_result != 0 {
panic!("failed to set up alternative stack guard page");
panic!("failed to set up alternative stack guard page: {}", io::Error::last_os_error());
}
stackp.add(page_size())
}
Expand Down
5 changes: 3 additions & 2 deletions library/std/src/sys/unix/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ pub mod guard {
use libc::{mmap, mprotect};
use libc::{MAP_ANON, MAP_FAILED, MAP_FIXED, MAP_PRIVATE, PROT_NONE, PROT_READ, PROT_WRITE};

use crate::io;
use crate::ops::Range;
use crate::sync::atomic::{AtomicUsize, Ordering};
use crate::sys::os;
Expand Down Expand Up @@ -361,12 +362,12 @@ pub mod guard {
0,
);
if result != stackaddr || result == MAP_FAILED {
panic!("failed to allocate a guard page");
panic!("failed to allocate a guard page: {}", io::Error::last_os_error());
}

let result = mprotect(stackaddr, page_size, PROT_NONE);
if result != 0 {
panic!("failed to protect the guard page");
panic!("failed to protect the guard page: {}", io::Error::last_os_error());
}

let guardaddr = stackaddr as usize;
Expand Down