Skip to content

Commit

Permalink
SetThreadStackGuarantee can also error on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
lovasoa committed Feb 19, 2025
1 parent 0c4110e commit 53918d0
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/backends/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pub fn _grow(stack_size: usize, callback: &mut dyn FnMut()) {
}

#[inline(always)]
fn get_thread_stack_guarantee() -> usize {
fn get_thread_stack_guarantee() -> Option<usize> {
let min_guarantee = if cfg!(target_pointer_width = "32") {
0x1000
} else {
Expand All @@ -114,9 +114,12 @@ fn get_thread_stack_guarantee() -> usize {
// some further logic to calculate the real stack
// guarantee. This logic is what is used on x86-32 and
// x86-64 Windows 10. Other versions and platforms may differ
SetThreadStackGuarantee(&mut stack_guarantee)
let ret = SetThreadStackGuarantee(&mut stack_guarantee);
if ret == 0 {
return None;
}
};
std::cmp::max(stack_guarantee, min_guarantee) as usize + 0x1000
Some(std::cmp::max(stack_guarantee, min_guarantee) as usize + 0x1000)
}

#[inline(always)]
Expand All @@ -135,5 +138,5 @@ pub unsafe fn guess_os_stack_limit() -> Option<usize> {
if res == 0 {
return None;
}
Some(mi.assume_init().AllocationBase as usize + get_thread_stack_guarantee() + 0x1000)
Some(mi.assume_init().AllocationBase as usize + get_thread_stack_guarantee()? + 0x1000)
}

0 comments on commit 53918d0

Please sign in to comment.