Skip to content

Commit 0c4110e

Browse files
committed
fix error handling on windows
VirtualQuery is a faillible function that was treated as infaillible https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-virtualquery
1 parent 5837340 commit 0c4110e

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/backends/windows.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,13 @@ pub unsafe fn guess_os_stack_limit() -> Option<usize> {
127127
// FIXME: we could read stack base from the TIB, specifically the 3rd element of it.
128128
type QueryT = windows_sys::Win32::System::Memory::MEMORY_BASIC_INFORMATION;
129129
let mut mi = std::mem::MaybeUninit::<QueryT>::uninit();
130-
VirtualQuery(
130+
let res = VirtualQuery(
131131
psm::stack_pointer() as *const _,
132132
mi.as_mut_ptr(),
133133
std::mem::size_of::<QueryT>() as usize,
134134
);
135+
if res == 0 {
136+
return None;
137+
}
135138
Some(mi.assume_init().AllocationBase as usize + get_thread_stack_guarantee() + 0x1000)
136139
}

0 commit comments

Comments
 (0)