From 8005136813bb1c0610da32d39c5b14dc0f01187a Mon Sep 17 00:00:00 2001 From: Havard Eidnes Date: Fri, 19 Dec 2025 17:07:45 +0000 Subject: [PATCH] netbsd/riscv64.rs: make changes so that this builds again. * Use the same type names as used by the native libc, to allow more self-tests to succeed * Remove un-needed imports, uncovered by libc's "cargo test" * Compute _ALIGNBYTES the same way gcc does. Verified by * Running (and passing) the libc self-tests "natively" on an emulated NetBSD/riscv64 system. * Cross-built rust 1.92.0 with this file in place for riscv64 in the vendored libc-0.2.17{5,6,7} versions, targeting NetBSD/riscv64. [ extracted this commit from the two in the PR - Trevor ] --- src/unix/bsd/netbsdlike/netbsd/riscv64.rs | 35 +++++++++++++---------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/src/unix/bsd/netbsdlike/netbsd/riscv64.rs b/src/unix/bsd/netbsdlike/netbsd/riscv64.rs index 8cacb7250eddc..05c0cd55cb80d 100644 --- a/src/unix/bsd/netbsdlike/netbsd/riscv64.rs +++ b/src/unix/bsd/netbsdlike/netbsd/riscv64.rs @@ -2,17 +2,9 @@ use crate::prelude::*; use crate::PT_FIRSTMACH; pub type __greg_t = u64; -pub type __cpu_simple_lock_nv_t = c_int; -pub type __gregset = [__greg_t; _NGREG]; -pub type __fregset = [__fpreg; _NFREG]; - -s! { - pub struct mcontext_t { - pub __gregs: __gregset, - pub __fregs: __fregset, - __spare: [crate::__greg_t; 7], - } -} +pub type __cpu_simple_lock_nv_t = c_uint; +pub type __gregset_t = [__greg_t; _NGREG]; +pub type __fregset_t = [__fpreg; _NFREG]; s_no_extra_traits! { pub union __fpreg { @@ -21,23 +13,36 @@ s_no_extra_traits! { } } +s! { + pub struct mcontext_t { + pub __gregs: __gregset_t, + pub __fregs: __fregset_t, + __spare: [crate::__greg_t; 7], + } +} + cfg_if! { if #[cfg(feature = "extra_traits")] { impl PartialEq for __fpreg { - fn eq(&self, other: &Self) -> bool { - unsafe { self.u_u64 == other.u_u64 } + fn eq(&self, other: &__fpreg) -> bool { + unsafe { self.u_u64 == other.u_u64 || self.u_d == other.u_d } } } impl Eq for __fpreg {} impl hash::Hash for __fpreg { fn hash(&self, state: &mut H) { - unsafe { self.u_u64.hash(state) }; + unsafe { + self.u_u64.hash(state); + } } } } } -pub(crate) const _ALIGNBYTES: usize = size_of::() - 1; +// gcc for riscv64 defines `BIGGEST_ALIGNMENT`, but it's mesured in bits. +pub(crate) const __BIGGEST_ALIGNMENT_IN_BITS__: usize = 128; +// `_ALIGNBYTES` is measured in, well, bytes. +pub(crate) const _ALIGNBYTES: usize = (__BIGGEST_ALIGNMENT_IN_BITS__ / 8) - 1; pub const PT_GETREGS: c_int = PT_FIRSTMACH + 0; pub const PT_SETREGS: c_int = PT_FIRSTMACH + 1;