Skip to content

Commit

Permalink
fix error handling on windows
Browse files Browse the repository at this point in the history
VirtualQuery is a faillible function that was treated as infaillible
https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-virtualquery
  • Loading branch information
lovasoa committed Feb 19, 2025
1 parent 5837340 commit 0c4110e
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/backends/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,13 @@ pub unsafe fn guess_os_stack_limit() -> Option<usize> {
// FIXME: we could read stack base from the TIB, specifically the 3rd element of it.
type QueryT = windows_sys::Win32::System::Memory::MEMORY_BASIC_INFORMATION;
let mut mi = std::mem::MaybeUninit::<QueryT>::uninit();
VirtualQuery(
let res = VirtualQuery(
psm::stack_pointer() as *const _,
mi.as_mut_ptr(),
std::mem::size_of::<QueryT>() as usize,
);
if res == 0 {
return None;
}
Some(mi.assume_init().AllocationBase as usize + get_thread_stack_guarantee() + 0x1000)
}

0 comments on commit 0c4110e

Please sign in to comment.