-
Notifications
You must be signed in to change notification settings - Fork 98
Description
jemallocator/jemalloc-sys/src/lib.rs
Line 53 in fd00e12
| type c_bool = c_int; |
This leads to a miscompilation when using API that involves c_bool, ie the extent hook API. For example, when my implementation of this Rust typedef wrote to the supposed c_bool pointers, it ended up smashing other variables in the caller's stack. I'm using the x86_64-unknown-linux-musl and x86_64-unknown-linux-gnu targets with gcc 11, gcc 12 and gcc 13.
jemalloc expects to be using C99 bool via the stdbool.h header, and the equivalent of that is Rust's bool, not c_int. jemalloc does have this header for Windows MSVC that defines it to win32's BOOL which is apparently an int. I'm not sure if even that is required, since web search seems to indicate MSVC also got stdbool.h in VS 2013, but I don't have Windows to check myself.
Workaround: Write the extent hook implementations with the correct signature (using Rust bool), then transmute then into the incorrect signatures that tikv-jemalloc-sys requires (using c_int) via std::mem::transmute.