Very interesting, and I look forward to seeing the larger project you alluded to. Was the use of libc::write in the generated code just to avoid bringing in Rust’s formatting and panic machinery, or was there another reason behind that?
I would assume that bit only gets called when std::mem::transmute returns null for some reason, so at that point the whole Rust runtime is not to be trusted. Not sure what would cause transmute to return null though.
Was the use of libc::write in the generated code just to avoid bringing in Rust’s formatting and panic machinery, or was there another reason behind that?
Yep, exactly – if we somehow end up in a wrapper without an underlying handle to call via dlsym, then there’s a good chance either (1) the runtime is broken or (2) the user hooked something so intrinsic to the Rust runtime that their hook ran in “life before main.” In both cases we can’t rely on the panic or formatting machinery, so we have to abort directly.
Should
real_read
bereal_rand
?Yes, thanks. Fixing it now!
Very interesting, and I look forward to seeing the larger project you alluded to. Was the use of
libc::write
in the generated code just to avoid bringing in Rust’s formatting and panic machinery, or was there another reason behind that?I would assume that bit only gets called when
std::mem::transmute
returns null for some reason, so at that point the whole Rust runtime is not to be trusted. Not sure what would causetransmute
to return null though.By definition
transmute
can’t change the value. It’s not a conversion function, it’s a type-system cheating function.Also, there’s
cast()
on pointers that you could use to remove all transmutes and casts except the one for thefn()
type.Yep, exactly – if we somehow end up in a wrapper without an underlying handle to call via
dlsym
, then there’s a good chance either (1) the runtime is broken or (2) the user hooked something so intrinsic to the Rust runtime that their hook ran in “life before main.” In both cases we can’t rely on the panic or formatting machinery, so we have to abort directly.