syscall issueshttps://gitlab.redox-os.org/redox-os/syscall/-/issues2023-06-08T10:08:00Zhttps://gitlab.redox-os.org/redox-os/syscall/-/issues/32Use a safe transmute crate2023-06-08T10:08:00ZJacob Lorentzon4ldo2@protonmail.comUse a safe transmute crateCurrently, many of the redox_syscall structs are repr(C) although using Deref impls to be convertible to regular slices. This has a few downsides, such as requiring explicit unsafe when casting *slices* of structs, as well as unsafe boil...Currently, many of the redox_syscall structs are repr(C) although using Deref impls to be convertible to regular slices. This has a few downsides, such as requiring explicit unsafe when casting *slices* of structs, as well as unsafe boilerplate. Reading padding bytes from a struct is UB, and `Stat` (on x86_64 at least) does contain implicit padding, making its Deref impl unsound (cf. https://gitlab.redox-os.org/redox-os/syscall/-/issues/29).
Some Redox drivers use `plain`, which would be a great improvement, although requiring manual `unsafe impl Plain for Struct`, and only allowing `slice_from_bytes` (as opposed to `slice_to_bytes`, which is impossible since plain does not forbid padding bytes). A better alternative might be `bytemuck`, which uses a derive-macro to safely implement traits, with the addition of being able to safely convert contiguous enums to/from ints (zerocopy would also work, but might not be ideal due to licensing).