Skip to content

Reimplement memcpy() using slices, fix unaligned read/write

Peter Limkilde Svendsen requested to merge plimkilde/relibc:memcpy-slices into master

This reimplements memcpy() to use MaybeUninit slices rather than raw pointers. This should help reason about safety and correctness.

I have tried to document the safety requirements and various caveats for this particular function.

I have also ditched the u64-based copying from the old implementation, since this relied on unaligned access (there is no alignment requirement for memcpy's input arguments). Attempting to copy using larger types is complicated by the fact that the s1 and s2 slices may decompose differently into (prefix, middle, suffix) with respect to the larger type. As an example, musl's implementation is quite convoluted. A possible alternative could be the compiler-builtins crate.

Merge request reports