-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Description
This function is the problem:
rust/library/std/src/sys/windows/compat.rs
Lines 17 to 28 in f5230fb
pub fn lookup(module: &str, symbol: &str) -> Option<usize> { | |
let mut module: Vec<u16> = module.encode_utf16().collect(); | |
module.push(0); | |
let symbol = CString::new(symbol).unwrap(); | |
unsafe { | |
let handle = c::GetModuleHandleW(module.as_ptr()); | |
match c::GetProcAddress(handle, symbol.as_ptr()) as usize { | |
0 => None, | |
n => Some(n), | |
} | |
} | |
} |
AcquireSRWLockExclusive
is one of the functions utilizing this compatibility layer. However, most custom allocators indirectly rely on this function.
This means that allocators must be re-entrant, which is essentially impossible since re-entrancy detection requires thread-local storage, which in turn calls AcquireSRWLockExclusive
.
For some reason I haven't been able to fathom, this does not always result in a crash, so many custom allocators which rely on TLS appear to work. However, seemingly inconsequential changes (such as changing the size of a struct) result in the program crashing with an access violation or stack overflow.
The fix is to remove this allocation and encode these strings at compile-time.