From 3f6dd37ee0c9f21a7af811db9cbf7f2cb4b8ee21 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sat, 9 Dec 2023 13:15:26 +0000 Subject: [PATCH 1/5] netbsd adding mcontext related data for riscv64 ref: https://github.com/NetBSD/src/blob/0465e5c825effb130eca95499f5ac6454fe0d5ab/sys/arch/riscv/include/mcontext.h#L44 (backport ) (cherry picked from commit fb52c7a4b74f224366062b1c454cb51730fd9f3d) --- src/unix/bsd/netbsdlike/netbsd/riscv64.rs | 66 +++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/src/unix/bsd/netbsdlike/netbsd/riscv64.rs b/src/unix/bsd/netbsdlike/netbsd/riscv64.rs index 643940d03de85..14b1be38041c7 100644 --- a/src/unix/bsd/netbsdlike/netbsd/riscv64.rs +++ b/src/unix/bsd/netbsdlike/netbsd/riscv64.rs @@ -3,7 +3,26 @@ use PT_FIRSTMACH; pub type c_long = i64; pub type c_ulong = u64; pub type c_char = u8; +pub type __greg_t = u64; pub type __cpu_simple_lock_nv_t = ::c_int; +pub type __gregset = [__greg_t; _NGREG]; +pub type __fregset = [__freg; _NFREG]; + +s! { + pub struct mcontext_t { + pub __gregs: __gregset, + pub __fregs: __fpregset, + __spare: [::__greg_t; 7], + } +} + +s_no_extra_traits! { + #[cfg_attr(feature = "extra_traits", allow(missing_debug_implementations))] + pub union __fpreg { + pub u_u64: u64, + pub u_d: ::c_double, + } +} pub(crate) const _ALIGNBYTES: usize = ::mem::size_of::<::c_long>() - 1; @@ -11,3 +30,50 @@ pub const PT_GETREGS: ::c_int = PT_FIRSTMACH + 0; pub const PT_SETREGS: ::c_int = PT_FIRSTMACH + 1; pub const PT_GETFPREGS: ::c_int = PT_FIRSTMACH + 2; pub const PT_SETFPREGS: ::c_int = PT_FIRSTMACH + 3; + +pub const _NGREG: usize = 32; +pub const _NFREG: usize = 33; + +pub const _REG_X1: ::c_int = 0; +pub const _REG_X2: ::c_int = 1; +pub const _REG_X3: ::c_int = 2; +pub const _REG_X4: ::c_int = 3; +pub const _REG_X5: ::c_int = 4; +pub const _REG_X6: ::c_int = 5; +pub const _REG_X7: ::c_int = 6; +pub const _REG_X8: ::c_int = 7; +pub const _REG_X9: ::c_int = 8; +pub const _REG_X10: ::c_int = 9; +pub const _REG_X11: ::c_int = 10; +pub const _REG_X12: ::c_int = 11; +pub const _REG_X13: ::c_int = 12; +pub const _REG_X14: ::c_int = 13; +pub const _REG_X15: ::c_int = 14; +pub const _REG_X16: ::c_int = 15; +pub const _REG_X17: ::c_int = 16; +pub const _REG_X18: ::c_int = 17; +pub const _REG_X19: ::c_int = 18; +pub const _REG_X20: ::c_int = 19; +pub const _REG_X21: ::c_int = 20; +pub const _REG_X22: ::c_int = 21; +pub const _REG_X23: ::c_int = 22; +pub const _REG_X24: ::c_int = 23; +pub const _REG_X25: ::c_int = 24; +pub const _REG_X26: ::c_int = 25; +pub const _REG_X27: ::c_int = 26; +pub const _REG_X28: ::c_int = 27; +pub const _REG_X29: ::c_int = 28; +pub const _REG_X30: ::c_int = 29; +pub const _REG_X31: ::c_int = 30; +pub const _REG_PC: ::c_int = 31; + +pub const _REG_RA: ::c_int = _REG_X1; +pub const _REG_SP: ::c_int = _REG_X2; +pub const _REG_GP: ::c_int = _REG_X3; +pub const _REG_TP: ::c_int = _REG_X4; +pub const _REG_S0: ::c_int = _REG_X8; +pub const _REG_RV: ::c_int = _REG_X10; +pub const _REG_A0: ::c_int = _REG_X10; + +pub const _REG_F0: ::c_int = 0; +pub const _REG_FPCSR: ::c_int = 32; From e49123ee0e273d0cf469222e322d4794763aaf89 Mon Sep 17 00:00:00 2001 From: Xiaobo Liu Date: Wed, 19 Apr 2023 11:53:14 +0800 Subject: [PATCH 2/5] uclibc/mips: fixed SA_* mismatched types Signed-off-by: Xiaobo Liu (backport ) (cherry picked from commit e8f54bbda52cc67eb2721c32400b19b776fd2cf0) --- src/unix/linux_like/linux/uclibc/mips/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/unix/linux_like/linux/uclibc/mips/mod.rs b/src/unix/linux_like/linux/uclibc/mips/mod.rs index 56bfcc5d355a7..d51d73f2944fe 100644 --- a/src/unix/linux_like/linux/uclibc/mips/mod.rs +++ b/src/unix/linux_like/linux/uclibc/mips/mod.rs @@ -23,10 +23,10 @@ pub const ECOMM: ::c_int = 70; pub const EPROTO: ::c_int = 71; pub const EDOTDOT: ::c_int = 73; -pub const SA_NODEFER: ::c_int = 0x40000000; -pub const SA_RESETHAND: ::c_int = 0x80000000; -pub const SA_RESTART: ::c_int = 0x10000000; -pub const SA_NOCLDSTOP: ::c_int = 0x00000001; +pub const SA_NODEFER: ::c_uint = 0x40000000; +pub const SA_RESETHAND: ::c_uint = 0x80000000; +pub const SA_RESTART: ::c_uint = 0x10000000; +pub const SA_NOCLDSTOP: ::c_uint = 0x00000001; pub const EPOLL_CLOEXEC: ::c_int = 0x80000; From 34fdd5b1d79c78def991f32d8f1ac495af8da2b3 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Wed, 20 Nov 2024 20:18:41 +0100 Subject: [PATCH 3/5] hurd: Fix MAP_HASSEMAPHORE name According to upstream fix https://sourceware.org/git/?p=glibc.git;a=commit;h=c0365d3791666c67ad410007efb52fc9b16d4287 (backport ) (cherry picked from commit 0fd366704968f11b03ec5c5e7a185ab3fb7eeb5e) --- src/unix/hurd/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/unix/hurd/mod.rs b/src/unix/hurd/mod.rs index 72e5bf76087b4..9d35805ca4204 100644 --- a/src/unix/hurd/mod.rs +++ b/src/unix/hurd/mod.rs @@ -2732,7 +2732,7 @@ pub const MAP_SHARED: ::c_int = 16; pub const MAP_PRIVATE: ::c_int = 0; pub const MAP_FIXED: ::c_int = 256; pub const MAP_NOEXTEND: ::c_int = 512; -pub const MAP_HASSEMPHORE: ::c_int = 1024; +pub const MAP_HASSEMAPHORE: ::c_int = 1024; pub const MAP_INHERIT: ::c_int = 2048; pub const MAP_FAILED: *mut ::c_void = !0 as *mut ::c_void; pub const MADV_NORMAL: ::c_int = 0; From b3f0be092989e714e5f4d333fe5840404b962cf7 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Wed, 20 Nov 2024 20:19:16 +0100 Subject: [PATCH 4/5] hurd: Add MAP_32BIT and MAP_EXCL As defined in glibc https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/mach/hurd/bits/mman_ext.h (backport ) (cherry picked from commit d07804831eb4f6f29ac73011b26832cbd67d61f3) --- src/unix/hurd/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/unix/hurd/mod.rs b/src/unix/hurd/mod.rs index 9d35805ca4204..f9410317a8bfa 100644 --- a/src/unix/hurd/mod.rs +++ b/src/unix/hurd/mod.rs @@ -2734,6 +2734,8 @@ pub const MAP_FIXED: ::c_int = 256; pub const MAP_NOEXTEND: ::c_int = 512; pub const MAP_HASSEMAPHORE: ::c_int = 1024; pub const MAP_INHERIT: ::c_int = 2048; +pub const MAP_32BIT: ::c_int = 4096; +pub const MAP_EXCL: ::c_int = 16384; pub const MAP_FAILED: *mut ::c_void = !0 as *mut ::c_void; pub const MADV_NORMAL: ::c_int = 0; pub const MADV_RANDOM: ::c_int = 1; From 24358295c9f53b2acf5630060ad93989d7b4fc50 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Wed, 20 Nov 2024 12:25:47 -0700 Subject: [PATCH 5/5] Fix the tests on riscv64gc-unknown-freebsd The fpregs was defined with two fields having the wrong sign, and one field having the wrong name. (backport ) (cherry picked from commit 730bf7330f33b7438f4536562ae8da920eb64938) --- src/unix/bsd/freebsdlike/freebsd/riscv64.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/unix/bsd/freebsdlike/freebsd/riscv64.rs b/src/unix/bsd/freebsdlike/freebsd/riscv64.rs index 143393e5c56ae..85afef02975bf 100644 --- a/src/unix/bsd/freebsdlike/freebsd/riscv64.rs +++ b/src/unix/bsd/freebsdlike/freebsd/riscv64.rs @@ -21,10 +21,10 @@ s_no_extra_traits! { } pub struct fpregs { - pub fp_x: [[::register_t; 2]; 32], - pub fp_fcsr: ::register_t, + pub fp_x: [[u64; 2]; 32], + pub fp_fcsr: u64, pub fp_flags: ::c_int, - pub fp_pad: ::c_int, + pub pad: ::c_int, } pub struct mcontext_t { @@ -85,7 +85,7 @@ cfg_if! { self.fp_x == other.fp_x && self.fp_fcsr == other.fp_fcsr && self.fp_flags == other.fp_flags - && self.fp_pad == other.fp_pad + && self.pad == other.pad } } impl Eq for fpregs {} @@ -95,7 +95,7 @@ cfg_if! { .field("fp_x", &self.fp_x) .field("fp_fcsr", &self.fp_fcsr) .field("fp_flags", &self.fp_flags) - .field("fp_pad", &self.fp_pad) + .field("pad", &self.pad) .finish() } } @@ -104,7 +104,7 @@ cfg_if! { self.fp_x.hash(state); self.fp_fcsr.hash(state); self.fp_flags.hash(state); - self.fp_pad.hash(state); + self.pad.hash(state); } } impl PartialEq for mcontext_t {