Undefined behavior in custom `memcpy`/`memset`/etc... implementations
It looks like the implementation in !11 (merged) relies on undefined behavior in the following line:
*((dest as usize + i) as *mut u64) = *((src as usize + i) as *const u64);
This is only correct if dest
and src
are word aligned, which is not guaranteed for memcpy. Note that this is UB even on x86. While the architecture allows for unaligned loads, LLVM does not. It is free to assume that any usize
loads/stores are word-aligned.
If redox only cares about running on new-ish x86 hardware, implementing these as assembly (calling rep movsb
and rep stosb
) might be the best bet.
I found this from https://github.com/rust-lang/compiler-builtins/issues/339