Stable versions of volatile copy and set functions

The standard library has the stable functions core::ptr::write_volatile and core::ptr::read_volatile (also in std) and the equivalent methods for *mut T and *const T (the latter for reads only, of course). However there is no equivalent to do a volatile read or write of an entire slice (though you could certainly do so in a loop). Although the methods (but not the functions in core::ptr) are implemented where T: ?Sized, they can't actually be used on slices since that would involve directly passing or returning a slice (rather than a reference or pointer to a slice).

There are however, unstable intrinsics which are meant for volatile reads and writes of slices: volatile_copy_memory, volatile_set_memory, etc. There was a pre-RFC proposed by Dan Cross to stabilize these (with functions in the ptr module) back in 2019, but it appears that the neither he nor anyone else took any further action.

I would like to add these proposed functions to core::ptr (and by extension std::ptr) as suggested in Dan Cross' pre-RFC and possibly also implement equivalent methods for *mut T and *const T, for example, (*mut T)::copy_to_volatile, (*const|mut T)::copy_from_volatile, (*mut T)::copy_to_nonoverlapping_volatile, etc. What are people's thoughts on this?


1 Like