Skip to content

Commit d033b45

Browse files
committed
Auto merge of #1488 - loganwendholt:user-regs, r=gnzlbg
Copy structs from bits/user.h for musl x86_64 While statically compiling a binary with `musl`, I ran into the following error regarding a missing struct: ``` error[E0412]: cannot find type `user_regs_struct` in crate `libc` --> src/debug.rs:37:32 | 37 | fn show_user_regs(regs: &libc::user_regs_struct) -> String { | ^^^^^^^^^^^^^^^^ not found in `libc` ``` This struct was previously added for `glibc` in #599, but was never added to `musl`, despite the data format being the same in both. This fix simply copies `user_regs_struct` into the proper location within the `musl` files.
2 parents 9af04ce + 9883697 commit d033b45

File tree

1 file changed

+120
-0
lines changed

1 file changed

+120
-0
lines changed

src/unix/linux_like/linux/musl/b64/x86_64.rs

+120
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,58 @@ s! {
4747
__reserved: [::c_long; 3],
4848
}
4949

50+
pub struct user_regs_struct {
51+
pub r15: ::c_ulong,
52+
pub r14: ::c_ulong,
53+
pub r13: ::c_ulong,
54+
pub r12: ::c_ulong,
55+
pub rbp: ::c_ulong,
56+
pub rbx: ::c_ulong,
57+
pub r11: ::c_ulong,
58+
pub r10: ::c_ulong,
59+
pub r9: ::c_ulong,
60+
pub r8: ::c_ulong,
61+
pub rax: ::c_ulong,
62+
pub rcx: ::c_ulong,
63+
pub rdx: ::c_ulong,
64+
pub rsi: ::c_ulong,
65+
pub rdi: ::c_ulong,
66+
pub orig_rax: ::c_ulong,
67+
pub rip: ::c_ulong,
68+
pub cs: ::c_ulong,
69+
pub eflags: ::c_ulong,
70+
pub rsp: ::c_ulong,
71+
pub ss: ::c_ulong,
72+
pub fs_base: ::c_ulong,
73+
pub gs_base: ::c_ulong,
74+
pub ds: ::c_ulong,
75+
pub es: ::c_ulong,
76+
pub fs: ::c_ulong,
77+
pub gs: ::c_ulong,
78+
}
79+
80+
pub struct user {
81+
pub regs: user_regs_struct,
82+
pub u_fpvalid: ::c_int,
83+
pub i387: user_fpregs_struct,
84+
pub u_tsize: ::c_ulong,
85+
pub u_dsize: ::c_ulong,
86+
pub u_ssize: ::c_ulong,
87+
pub start_code: ::c_ulong,
88+
pub start_stack: ::c_ulong,
89+
pub signal: ::c_long,
90+
__reserved: ::c_int,
91+
#[cfg(target_pointer_width = "32")]
92+
__pad1: u32,
93+
pub u_ar0: *mut user_regs_struct,
94+
#[cfg(target_pointer_width = "32")]
95+
__pad2: u32,
96+
pub u_fpstate: *mut user_fpregs_struct,
97+
pub magic: ::c_ulong,
98+
pub u_comm: [::c_char; 32],
99+
pub u_debugreg: [::c_ulong; 8],
100+
}
101+
50102
pub struct mcontext_t {
51103
__private: [u64; 32],
52104
}
@@ -65,6 +117,20 @@ s! {
65117
}
66118

67119
s_no_extra_traits!{
120+
pub struct user_fpregs_struct {
121+
pub cwd: ::c_ushort,
122+
pub swd: ::c_ushort,
123+
pub ftw: ::c_ushort,
124+
pub fop: ::c_ushort,
125+
pub rip: ::c_ulong,
126+
pub rdp: ::c_ulong,
127+
pub mxcsr: ::c_uint,
128+
pub mxcr_mask: ::c_uint,
129+
pub st_space: [::c_uint; 32],
130+
pub xmm_space: [::c_uint; 64],
131+
padding: [::c_uint; 24],
132+
}
133+
68134
pub struct ucontext_t {
69135
pub uc_flags: ::c_ulong,
70136
pub uc_link: *mut ucontext_t,
@@ -77,6 +143,60 @@ s_no_extra_traits!{
77143

78144
cfg_if! {
79145
if #[cfg(feature = "extra_traits")] {
146+
impl PartialEq for user_fpregs_struct {
147+
fn eq(&self, other: &user_fpregs_struct) -> bool {
148+
self.cwd == other.cwd
149+
&& self.swd == other.swd
150+
&& self.ftw == other.ftw
151+
&& self.fop == other.fop
152+
&& self.rip == other.rip
153+
&& self.rdp == other.rdp
154+
&& self.mxcsr == other.mxcsr
155+
&& self.mxcr_mask == other.mxcr_mask
156+
&& self.st_space == other.st_space
157+
&& self
158+
.xmm_space
159+
.iter()
160+
.zip(other.xmm_space.iter())
161+
.all(|(a,b)| a == b)
162+
// Ignore padding field
163+
}
164+
}
165+
166+
impl Eq for user_fpregs_struct {}
167+
168+
impl ::fmt::Debug for user_fpregs_struct {
169+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
170+
f.debug_struct("user_fpregs_struct")
171+
.field("cwd", &self.cwd)
172+
.field("ftw", &self.ftw)
173+
.field("fop", &self.fop)
174+
.field("rip", &self.rip)
175+
.field("rdp", &self.rdp)
176+
.field("mxcsr", &self.mxcsr)
177+
.field("mxcr_mask", &self.mxcr_mask)
178+
.field("st_space", &self.st_space)
179+
// FIXME: .field("xmm_space", &self.xmm_space)
180+
// Ignore padding field
181+
.finish()
182+
}
183+
}
184+
185+
impl ::hash::Hash for user_fpregs_struct {
186+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
187+
self.cwd.hash(state);
188+
self.ftw.hash(state);
189+
self.fop.hash(state);
190+
self.rip.hash(state);
191+
self.rdp.hash(state);
192+
self.mxcsr.hash(state);
193+
self.mxcr_mask.hash(state);
194+
self.st_space.hash(state);
195+
self.xmm_space.hash(state);
196+
// Ignore padding field
197+
}
198+
}
199+
80200
impl PartialEq for ucontext_t {
81201
fn eq(&self, other: &ucontext_t) -> bool {
82202
self.uc_flags == other.uc_flags

0 commit comments

Comments
 (0)