Skip to content

Commit 454fb0e

Browse files
committed
Auto merge of #2748 - s1341:add_android_x86_64_user_struct, r=Amanieu
Add android x86_64 user struct This PR adds the `user`, `user_regs_struct` and `user_fpregs_struct` structures to android x86_64
2 parents c3e4df1 + b484a8d commit 454fb0e

File tree

3 files changed

+125
-2
lines changed

3 files changed

+125
-2
lines changed

src/unix/linux_like/android/b32/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,6 @@ pub const RTLD_DEFAULT: *mut ::c_void = -1isize as *mut ::c_void;
203203

204204
pub const PTRACE_GETFPREGS: ::c_int = 14;
205205
pub const PTRACE_SETFPREGS: ::c_int = 15;
206-
pub const PTRACE_GETREGS: ::c_int = 12;
207-
pub const PTRACE_SETREGS: ::c_int = 13;
208206

209207
pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { value: 0 };
210208
pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t { value: 0 };

src/unix/linux_like/android/b64/x86_64/mod.rs

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,61 @@ s! {
4747
pub struct _libc_xmmreg {
4848
pub element: [u32; 4],
4949
}
50+
51+
pub struct user_regs_struct {
52+
pub r15: ::c_ulong,
53+
pub r14: ::c_ulong,
54+
pub r13: ::c_ulong,
55+
pub r12: ::c_ulong,
56+
pub rbp: ::c_ulong,
57+
pub rbx: ::c_ulong,
58+
pub r11: ::c_ulong,
59+
pub r10: ::c_ulong,
60+
pub r9: ::c_ulong,
61+
pub r8: ::c_ulong,
62+
pub rax: ::c_ulong,
63+
pub rcx: ::c_ulong,
64+
pub rdx: ::c_ulong,
65+
pub rsi: ::c_ulong,
66+
pub rdi: ::c_ulong,
67+
pub orig_rax: ::c_ulong,
68+
pub rip: ::c_ulong,
69+
pub cs: ::c_ulong,
70+
pub eflags: ::c_ulong,
71+
pub rsp: ::c_ulong,
72+
pub ss: ::c_ulong,
73+
pub fs_base: ::c_ulong,
74+
pub gs_base: ::c_ulong,
75+
pub ds: ::c_ulong,
76+
pub es: ::c_ulong,
77+
pub fs: ::c_ulong,
78+
pub gs: ::c_ulong,
79+
}
80+
81+
pub struct user {
82+
pub regs: user_regs_struct,
83+
pub u_fpvalid: ::c_int,
84+
pub i387: user_fpregs_struct,
85+
pub u_tsize: ::c_ulong,
86+
pub u_dsize: ::c_ulong,
87+
pub u_ssize: ::c_ulong,
88+
pub start_code: ::c_ulong,
89+
pub start_stack: ::c_ulong,
90+
pub signal: ::c_long,
91+
__reserved: ::c_int,
92+
#[cfg(target_pointer_width = "32")]
93+
__pad1: u32,
94+
pub u_ar0: *mut user_regs_struct,
95+
#[cfg(target_pointer_width = "32")]
96+
__pad2: u32,
97+
pub u_fpstate: *mut user_fpregs_struct,
98+
pub magic: ::c_ulong,
99+
pub u_comm: [::c_char; 32],
100+
pub u_debugreg: [::c_ulong; 8],
101+
pub error_code: ::c_ulong,
102+
pub fault_address: ::c_ulong,
103+
}
104+
50105
}
51106

52107
cfg_if! {
@@ -118,6 +173,20 @@ s_no_extra_traits! {
118173
pub uc_sigmask64: __c_anonymous_uc_sigmask,
119174
__fpregs_mem: _libc_fpstate,
120175
}
176+
177+
pub struct user_fpregs_struct {
178+
pub cwd: ::c_ushort,
179+
pub swd: ::c_ushort,
180+
pub ftw: ::c_ushort,
181+
pub fop: ::c_ushort,
182+
pub rip: ::c_ulong,
183+
pub rdp: ::c_ulong,
184+
pub mxcsr: ::c_uint,
185+
pub mxcr_mask: ::c_uint,
186+
pub st_space: [::c_uint; 32],
187+
pub xmm_space: [::c_uint; 64],
188+
padding: [::c_uint; 24],
189+
}
121190
}
122191

123192
cfg_if! {
@@ -254,6 +323,60 @@ cfg_if! {
254323
// Ignore padding field
255324
}
256325
}
326+
327+
impl PartialEq for user_fpregs_struct {
328+
fn eq(&self, other: &user_fpregs_struct) -> bool {
329+
self.cwd == other.cwd
330+
&& self.swd == other.swd
331+
&& self.ftw == other.ftw
332+
&& self.fop == other.fop
333+
&& self.rip == other.rip
334+
&& self.rdp == other.rdp
335+
&& self.mxcsr == other.mxcsr
336+
&& self.mxcr_mask == other.mxcr_mask
337+
&& self.st_space == other.st_space
338+
&& self
339+
.xmm_space
340+
.iter()
341+
.zip(other.xmm_space.iter())
342+
.all(|(a,b)| a == b)
343+
// Ignore padding field
344+
}
345+
}
346+
347+
impl Eq for user_fpregs_struct {}
348+
349+
impl ::fmt::Debug for user_fpregs_struct {
350+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
351+
f.debug_struct("user_fpregs_struct")
352+
.field("cwd", &self.cwd)
353+
.field("ftw", &self.ftw)
354+
.field("fop", &self.fop)
355+
.field("rip", &self.rip)
356+
.field("rdp", &self.rdp)
357+
.field("mxcsr", &self.mxcsr)
358+
.field("mxcr_mask", &self.mxcr_mask)
359+
.field("st_space", &self.st_space)
360+
// FIXME: .field("xmm_space", &self.xmm_space)
361+
// Ignore padding field
362+
.finish()
363+
}
364+
}
365+
366+
impl ::hash::Hash for user_fpregs_struct {
367+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
368+
self.cwd.hash(state);
369+
self.ftw.hash(state);
370+
self.fop.hash(state);
371+
self.rip.hash(state);
372+
self.rdp.hash(state);
373+
self.mxcsr.hash(state);
374+
self.mxcr_mask.hash(state);
375+
self.st_space.hash(state);
376+
self.xmm_space.hash(state);
377+
// Ignore padding field
378+
}
379+
}
257380
}
258381
}
259382

src/unix/linux_like/android/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,6 +1281,8 @@ pub const PTRACE_POKEUSER: ::c_int = 6;
12811281
pub const PTRACE_CONT: ::c_int = 7;
12821282
pub const PTRACE_KILL: ::c_int = 8;
12831283
pub const PTRACE_SINGLESTEP: ::c_int = 9;
1284+
pub const PTRACE_GETREGS: ::c_int = 12;
1285+
pub const PTRACE_SETREGS: ::c_int = 13;
12841286
pub const PTRACE_ATTACH: ::c_int = 16;
12851287
pub const PTRACE_DETACH: ::c_int = 17;
12861288
pub const PTRACE_SYSCALL: ::c_int = 24;

0 commit comments

Comments
 (0)