Skip to content

Commit 3fa2b56

Browse files
committed
Add ucontext_t and mcontext_t for RISC-V Linux
1 parent 9c7a326 commit 3fa2b56

File tree

6 files changed

+185
-0
lines changed

6 files changed

+185
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
s_no_extra_traits! {
2+
#[allow(missing_debug_implementations)]
3+
pub struct ucontext_t {
4+
pub __uc_flags: ::c_ulong,
5+
pub uc_link: *mut ucontext_t,
6+
pub uc_stack: ::stack_t,
7+
pub uc_sigmask: ::sigset_t,
8+
pub uc_mcontext: mcontext_t,
9+
}
10+
11+
#[allow(missing_debug_implementations)]
12+
#[repr(align(16))]
13+
pub struct mcontext_t {
14+
pub __gregs: [::c_ulong; 32],
15+
pub __fpregs: __riscv_mc_fp_state,
16+
}
17+
18+
#[allow(missing_debug_implementations)]
19+
pub union __riscv_mc_fp_state {
20+
pub __f: __riscv_mc_f_ext_state,
21+
pub __d: __riscv_mc_d_ext_state,
22+
pub __q: __riscv_mc_q_ext_state,
23+
}
24+
25+
#[allow(missing_debug_implementations)]
26+
pub struct __riscv_mc_f_ext_state {
27+
pub __f: [::c_uint; 32],
28+
pub __fcsr: ::c_uint,
29+
}
30+
31+
#[allow(missing_debug_implementations)]
32+
pub struct __riscv_mc_d_ext_state {
33+
pub __f: [::c_ulonglong; 32],
34+
pub __fcsr: ::c_uint,
35+
}
36+
37+
#[allow(missing_debug_implementations)]
38+
#[repr(align(16))]
39+
pub struct __riscv_mc_q_ext_state {
40+
pub __f: [::c_ulonglong; 64],
41+
pub __fcsr: ::c_uint,
42+
pub __glibc_reserved: [::c_uint; 3],
43+
}
44+
}

src/unix/linux_like/linux/gnu/b32/riscv32/mod.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,16 @@ pub const FLUSHO: ::tcflag_t = 4096;
457457
pub const EXTPROC: ::tcflag_t = 65536;
458458
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40;
459459
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56;
460+
pub const NGREG: usize = 32;
461+
pub const REG_PC: usize = 0;
462+
pub const REG_RA: usize = 1;
463+
pub const REG_SP: usize = 2;
464+
pub const REG_TP: usize = 4;
465+
pub const REG_S0: usize = 8;
466+
pub const REG_S1: usize = 9;
467+
pub const REG_A0: usize = 10;
468+
pub const REG_S2: usize = 18;
469+
pub const REG_NARGS: usize = 8;
460470

461471
pub const SYS_read: ::c_long = 63;
462472
pub const SYS_write: ::c_long = 64;
@@ -752,3 +762,10 @@ pub const SYS_faccessat2: ::c_long = 439;
752762
pub const SYS_process_madvise: ::c_long = 440;
753763
pub const SYS_epoll_pwait2: ::c_long = 441;
754764
pub const SYS_mount_setattr: ::c_long = 442;
765+
766+
cfg_if! {
767+
if #[cfg(libc_align)] {
768+
mod align;
769+
pub use self::align::*;
770+
}
771+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
s_no_extra_traits! {
2+
#[allow(missing_debug_implementations)]
3+
pub struct ucontext_t {
4+
pub __uc_flags: ::c_ulong,
5+
pub uc_link: *mut ucontext_t,
6+
pub uc_stack: ::stack_t,
7+
pub uc_sigmask: ::sigset_t,
8+
pub uc_mcontext: mcontext_t,
9+
}
10+
11+
#[allow(missing_debug_implementations)]
12+
#[repr(align(16))]
13+
pub struct mcontext_t {
14+
pub __gregs: [::c_ulong; 32],
15+
pub __fpregs: __riscv_mc_fp_state,
16+
}
17+
18+
#[allow(missing_debug_implementations)]
19+
pub union __riscv_mc_fp_state {
20+
pub __f: __riscv_mc_f_ext_state,
21+
pub __d: __riscv_mc_d_ext_state,
22+
pub __q: __riscv_mc_q_ext_state,
23+
}
24+
25+
#[allow(missing_debug_implementations)]
26+
pub struct __riscv_mc_f_ext_state {
27+
pub __f: [::c_uint; 32],
28+
pub __fcsr: ::c_uint,
29+
}
30+
31+
#[allow(missing_debug_implementations)]
32+
pub struct __riscv_mc_d_ext_state {
33+
pub __f: [::c_ulonglong; 32],
34+
pub __fcsr: ::c_uint,
35+
}
36+
37+
#[allow(missing_debug_implementations)]
38+
#[repr(align(16))]
39+
pub struct __riscv_mc_q_ext_state {
40+
pub __f: [::c_ulonglong; 64],
41+
pub __fcsr: ::c_uint,
42+
pub __glibc_reserved: [::c_uint; 3],
43+
}
44+
}

src/unix/linux_like/linux/gnu/b64/riscv64/mod.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,17 @@ pub const FLUSHO: ::tcflag_t = 4096;
496496
pub const EXTPROC: ::tcflag_t = 65536;
497497
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40;
498498
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56;
499+
pub const NGREG: usize = 32;
500+
pub const REG_PC: usize = 0;
501+
pub const REG_RA: usize = 1;
502+
pub const REG_SP: usize = 2;
503+
pub const REG_TP: usize = 4;
504+
pub const REG_S0: usize = 8;
505+
pub const REG_S1: usize = 9;
506+
pub const REG_A0: usize = 10;
507+
pub const REG_S2: usize = 18;
508+
pub const REG_NARGS: usize = 8;
509+
499510
pub const SYS_read: ::c_long = 63;
500511
pub const SYS_write: ::c_long = 64;
501512
pub const SYS_close: ::c_long = 57;
@@ -790,3 +801,10 @@ pub const SYS_faccessat2: ::c_long = 439;
790801
pub const SYS_process_madvise: ::c_long = 440;
791802
pub const SYS_epoll_pwait2: ::c_long = 441;
792803
pub const SYS_mount_setattr: ::c_long = 442;
804+
805+
cfg_if! {
806+
if #[cfg(libc_align)] {
807+
mod align;
808+
pub use self::align::*;
809+
}
810+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
s_no_extra_traits! {
2+
#[allow(missing_debug_implementations)]
3+
pub struct ucontext_t {
4+
pub __uc_flags: ::c_ulong,
5+
pub uc_link: *mut ucontext_t,
6+
pub uc_stack: ::stack_t,
7+
pub uc_sigmask: ::sigset_t,
8+
pub uc_mcontext: mcontext_t,
9+
}
10+
11+
#[allow(missing_debug_implementations)]
12+
#[repr(align(16))]
13+
pub struct mcontext_t {
14+
pub __gregs: [::c_ulong; 32],
15+
pub __fpregs: __riscv_mc_fp_state,
16+
}
17+
18+
#[allow(missing_debug_implementations)]
19+
pub union __riscv_mc_fp_state {
20+
pub __f: __riscv_mc_f_ext_state,
21+
pub __d: __riscv_mc_d_ext_state,
22+
pub __q: __riscv_mc_q_ext_state,
23+
}
24+
25+
#[allow(missing_debug_implementations)]
26+
pub struct __riscv_mc_f_ext_state {
27+
pub __f: [::c_uint; 32],
28+
pub __fcsr: ::c_uint,
29+
}
30+
31+
#[allow(missing_debug_implementations)]
32+
pub struct __riscv_mc_d_ext_state {
33+
pub __f: [::c_ulonglong; 32],
34+
pub __fcsr: ::c_uint,
35+
}
36+
37+
#[allow(missing_debug_implementations)]
38+
#[repr(align(16))]
39+
pub struct __riscv_mc_q_ext_state {
40+
pub __f: [::c_ulonglong; 64],
41+
pub __fcsr: ::c_uint,
42+
pub __glibc_reserved: [::c_uint; 3],
43+
}
44+
}

src/unix/linux_like/linux/musl/b64/riscv64/mod.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,3 +721,21 @@ pub const VMIN: usize = 6;
721721
pub const IEXTEN: ::tcflag_t = 0x00008000;
722722
pub const TOSTOP: ::tcflag_t = 0x00000100;
723723
pub const FLUSHO: ::tcflag_t = 0x00001000;
724+
725+
pub const NGREG: usize = 32;
726+
pub const REG_PC: usize = 0;
727+
pub const REG_RA: usize = 1;
728+
pub const REG_SP: usize = 2;
729+
pub const REG_TP: usize = 4;
730+
pub const REG_S0: usize = 8;
731+
pub const REG_S1: usize = 9;
732+
pub const REG_A0: usize = 10;
733+
pub const REG_S2: usize = 18;
734+
pub const REG_NARGS: usize = 8;
735+
736+
cfg_if! {
737+
if #[cfg(libc_align)] {
738+
mod align;
739+
pub use self::align::*;
740+
}
741+
}

0 commit comments

Comments
 (0)