Skip to content

Commit

Permalink
Ensure fibers get guard pages on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoxc committed Dec 10, 2017
1 parent ea31e2c commit ec906c4
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion rayon-core/src/fiber/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,9 @@ impl WinFiber {

fn new(stack_size: usize) -> Option<Self> {
unsafe {
let fiber = kernel32::CreateFiber(stack_size as _,
let fiber = kernel32::CreateFiberEx(0x1000,
stack_size as _,
0,
Some(fiber_proc),
0i32 as _);
if fiber == 0i32 as _ {
Expand All @@ -510,6 +512,14 @@ impl Drop for WinFiber {

#[cfg(windows)]
unsafe extern "system" fn fiber_proc(_: winapi::LPVOID) {
#[cfg(debug_assertions)] {
let mut stack_low = 0;
let mut stack_high = 0;
kernel32::GetCurrentThreadStackLimits(&mut stack_low, &mut stack_high);
let mut mbi = mem::zeroed();
assert!(kernel32::VirtualQuery(stack_low as _, &mut mbi, 0x1000) == 0);
}

let worker = &*WorkerThread::current();
loop {
let data = NEW_FIBER_DATA.with(|fiber_data| fiber_data.take());
Expand Down

0 comments on commit ec906c4

Please sign in to comment.