Reimplement memcpy() using slices, fix unaligned read/write, add test
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 since this relied on unaligned access (there is no alignment requirement for u64
-based copying from the old implementation,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.
Edit: Now also includes addition of a C test, and copying in chunks of the largest possible Rust primitive type that is well-aligned for the middle part of the given input slices.