1

enable number validity checking and ptr::invalid checking by default by RalfJung...

 1 year ago
source link: https://github.com/rust-lang/miri/pull/2151
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Member

RalfJung commented 10 days ago

edited

This removes the -Zmiri-check-number-validity flag, enabling its effects by default. (We don't error when the flag is passed, for backwards compatibility.) We also enable by default that transmuting an integer to a pointer now creates a pointer with None provenance, which is invalid to dereference (and, in the case of a function pointer, invalid to call). I did this together since it is all related to ptr2int/int2ptr transmutation.

Two new flags are added to optionally take back these stricter checks:

  • -Zmiri-allow-uninit-numbers makes Miri accept uninit data in integers and floats
  • -Zmiri-allow-ptr-int-transmute makes Miri accept pointers (provenance data) in integers and floats, and makes Miri treat int2ptr transmutes as equivalent to a cast.

The flag names make sense IMO, but they are somewhat inconsistent with our existing flags since we usually call things -Zmiri-disable-$CHECK rather than -Zmiri-allow-$THING. But -Zmiri-disable-uninit-number-check sounds silly?

(Whenever I say "transmute" this includes union and pointer based type punning.)
Cc @saethlin I hope this won't break everything?^^ I think the most risky part is the int2ptr transmute aspect, in particular around function pointers where no as casts are possible. The correct pattern is to first cast to a raw ptr and then transmute that to a fn ptr. We should probably document this better, in the transmute documentation and maybe in the documentation for the fn() type. I should run this PR against the std test suite before we land it.
r? @oli-obk

  • Ensure stdlib docs recommend "usize -> raw ptr -> fn ptr" for int-to-fnptr casts: rust-lang/rust#97321
  • Run the stdlib test suite

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK