unix: unsafe-wrap install_main_guard_default
This commit is contained in:
parent
6ed563d491
commit
d47cb26ddd
@ -419,6 +419,7 @@ mod imp {
|
|||||||
Some(stackaddr - page_size..stackaddr)
|
Some(stackaddr - page_size..stackaddr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[forbid(unsafe_op_in_unsafe_fn)]
|
||||||
unsafe fn install_main_guard_default(page_size: usize) -> Option<Range<usize>> {
|
unsafe fn install_main_guard_default(page_size: usize) -> Option<Range<usize>> {
|
||||||
// Reallocate the last page of the stack.
|
// Reallocate the last page of the stack.
|
||||||
// This ensures SIGBUS will be raised on
|
// This ensures SIGBUS will be raised on
|
||||||
@ -429,19 +430,21 @@ mod imp {
|
|||||||
// read/write permissions and only then mprotect() it to
|
// read/write permissions and only then mprotect() it to
|
||||||
// no permissions at all. See issue #50313.
|
// no permissions at all. See issue #50313.
|
||||||
let stackptr = stack_start_aligned(page_size)?;
|
let stackptr = stack_start_aligned(page_size)?;
|
||||||
let result = mmap64(
|
let result = unsafe {
|
||||||
stackptr,
|
mmap64(
|
||||||
page_size,
|
stackptr,
|
||||||
PROT_READ | PROT_WRITE,
|
page_size,
|
||||||
MAP_PRIVATE | MAP_ANON | MAP_FIXED,
|
PROT_READ | PROT_WRITE,
|
||||||
-1,
|
MAP_PRIVATE | MAP_ANON | MAP_FIXED,
|
||||||
0,
|
-1,
|
||||||
);
|
0,
|
||||||
|
)
|
||||||
|
};
|
||||||
if result != stackptr || result == MAP_FAILED {
|
if result != stackptr || result == MAP_FAILED {
|
||||||
panic!("failed to allocate a guard page: {}", io::Error::last_os_error());
|
panic!("failed to allocate a guard page: {}", io::Error::last_os_error());
|
||||||
}
|
}
|
||||||
|
|
||||||
let result = mprotect(stackptr, page_size, PROT_NONE);
|
let result = unsafe { mprotect(stackptr, page_size, PROT_NONE) };
|
||||||
if result != 0 {
|
if result != 0 {
|
||||||
panic!("failed to protect the guard page: {}", io::Error::last_os_error());
|
panic!("failed to protect the guard page: {}", io::Error::last_os_error());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user