Skip to content

Commit f414c33

Browse files
committed
Display error details when a mmap call fails
1 parent f5d8117 commit f414c33

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

library/std/src/sys/unix/stack_overflow.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ impl Drop for Handler {
3939
))]
4040
mod imp {
4141
use super::Handler;
42+
use crate::io;
4243
use crate::mem;
4344
use crate::ptr;
4445

@@ -149,11 +150,11 @@ mod imp {
149150
0,
150151
);
151152
if stackp == MAP_FAILED {
152-
panic!("failed to allocate an alternative stack");
153+
panic!("failed to allocate an alternative stack: {}", io::Error::last_os_error());
153154
}
154155
let guard_result = libc::mprotect(stackp, page_size(), PROT_NONE);
155156
if guard_result != 0 {
156-
panic!("failed to set up alternative stack guard page");
157+
panic!("failed to set up alternative stack guard page: {}", io::Error::last_os_error());
157158
}
158159
stackp.add(page_size())
159160
}

library/std/src/sys/unix/thread.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ pub mod guard {
231231
use libc::{mmap, mprotect};
232232
use libc::{MAP_ANON, MAP_FAILED, MAP_FIXED, MAP_PRIVATE, PROT_NONE, PROT_READ, PROT_WRITE};
233233

234+
use crate::io;
234235
use crate::ops::Range;
235236
use crate::sync::atomic::{AtomicUsize, Ordering};
236237
use crate::sys::os;
@@ -361,12 +362,12 @@ pub mod guard {
361362
0,
362363
);
363364
if result != stackaddr || result == MAP_FAILED {
364-
panic!("failed to allocate a guard page");
365+
panic!("failed to allocate a guard page: {}", io::Error::last_os_error());
365366
}
366367

367368
let result = mprotect(stackaddr, page_size, PROT_NONE);
368369
if result != 0 {
369-
panic!("failed to protect the guard page");
370+
panic!("failed to protect the guard page: {}", io::Error::last_os_error());
370371
}
371372

372373
let guardaddr = stackaddr as usize;

0 commit comments

Comments
 (0)