From db4273ea2c2c867dfdd770760a188421e17c39ec Mon Sep 17 00:00:00 2001 From: Marcin Mielniczuk Date: Fri, 21 Jul 2017 10:12:06 +0200 Subject: [PATCH 1/4] Add offsets in user_regs_struct from sys/reg.h --- src/unix/notbsd/linux/other/b32/x86.rs | 19 +++++++++++++++ src/unix/notbsd/linux/other/b64/x86_64.rs | 29 +++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/src/unix/notbsd/linux/other/b32/x86.rs b/src/unix/notbsd/linux/other/b32/x86.rs index d13a8f58..16ffe282 100644 --- a/src/unix/notbsd/linux/other/b32/x86.rs +++ b/src/unix/notbsd/linux/other/b32/x86.rs @@ -695,6 +695,25 @@ pub const SYS_pkey_mprotect: ::c_int = 380; pub const SYS_pkey_alloc: ::c_int = 381; pub const SYS_pkey_free: ::c_int = 382; +// offsets in user_regs_structs, from sys/reg.h +pub const EBX: ::c_int = 0; +pub const ECX: ::c_int = 1; +pub const EDX: ::c_int = 2; +pub const ESI: ::c_int = 3; +pub const EDI: ::c_int = 4; +pub const EBP: ::c_int = 5; +pub const EAX: ::c_int = 6; +pub const DS: ::c_int = 7; +pub const ES: ::c_int = 8; +pub const FS: ::c_int = 9; +pub const GS: ::c_int = 10; +pub const ORIG_EAX: ::c_int = 11; +pub const EIP: ::c_int = 12; +pub const CS: ::c_int = 13; +pub const EFL: ::c_int = 14; +pub const UESP: ::c_int = 15; +pub const SS: ::c_int = 16; + extern { pub fn getcontext(ucp: *mut ucontext_t) -> ::c_int; pub fn setcontext(ucp: *const ucontext_t) -> ::c_int; diff --git a/src/unix/notbsd/linux/other/b64/x86_64.rs b/src/unix/notbsd/linux/other/b64/x86_64.rs index e3e701ac..72ea799c 100644 --- a/src/unix/notbsd/linux/other/b64/x86_64.rs +++ b/src/unix/notbsd/linux/other/b64/x86_64.rs @@ -907,6 +907,35 @@ pub const SYS_pkey_mprotect: ::c_int = 329; pub const SYS_pkey_alloc: ::c_int = 330; pub const SYS_pkey_free: ::c_int = 331; +// offsets in user_regs_structs, from sys/reg.h +pub const R15: ::c_int = 0; +pub const R14: ::c_int = 1; +pub const R13: ::c_int = 2; +pub const R12: ::c_int = 3; +pub const RBP: ::c_int = 4; +pub const RBX: ::c_int = 5; +pub const R11: ::c_int = 6; +pub const R10: ::c_int = 7; +pub const R9: ::c_int = 8; +pub const R8: ::c_int = 9; +pub const RAX: ::c_int = 10; +pub const RCX: ::c_int = 11; +pub const RDX: ::c_int = 12; +pub const RSI: ::c_int = 13; +pub const RDI: ::c_int = 14; +pub const ORIG_RAX: ::c_int = 15; +pub const RIP: ::c_int = 16; +pub const CS: ::c_int = 17; +pub const EFLAGS: ::c_int = 18; +pub const RSP: ::c_int = 19; +pub const SS: ::c_int = 20; +pub const FS_BASE: ::c_int = 21; +pub const GS_BASE: ::c_int = 22; +pub const DS: ::c_int = 23; +pub const ES: ::c_int = 24; +pub const FS: ::c_int = 25; +pub const GS: ::c_int = 26; + extern { pub fn getcontext(ucp: *mut ucontext_t) -> ::c_int; pub fn setcontext(ucp: *const ucontext_t) -> ::c_int; From 1535ee87036f7d20ecec94dfc43fb9f633be78d7 Mon Sep 17 00:00:00 2001 From: Marcin Mielniczuk Date: Fri, 21 Jul 2017 17:11:30 +0200 Subject: [PATCH 2/4] Include sys/user.h in the automatic test --- libc-test/build.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/libc-test/build.rs b/libc-test/build.rs index 0b905497..46ccbb6d 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -181,6 +181,7 @@ fn main() { cfg.header("sys/msg.h"); cfg.header("sys/shm.h"); cfg.header("sys/user.h"); + cfg.header("sys/reg.h"); cfg.header("sys/fsuid.h"); cfg.header("shadow.h"); cfg.header("linux/input.h"); From 37b4e73a1035940a228bc7b3241eb516cf362125 Mon Sep 17 00:00:00 2001 From: Marcin Mielniczuk Date: Fri, 21 Jul 2017 21:55:47 +0200 Subject: [PATCH 3/4] include sys/regs.h only on x86 and x86_64 --- libc-test/build.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index 46ccbb6d..0b47db6a 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -181,13 +181,15 @@ fn main() { cfg.header("sys/msg.h"); cfg.header("sys/shm.h"); cfg.header("sys/user.h"); - cfg.header("sys/reg.h"); cfg.header("sys/fsuid.h"); cfg.header("shadow.h"); cfg.header("linux/input.h"); if x86_64 { cfg.header("sys/io.h"); } + if x86 || x86_64 { + cfg.header("sys/reg.h"); + } } if linux || android { From 2a5976727f841970ba4efcf6ec775ee1197e8f37 Mon Sep 17 00:00:00 2001 From: Marcin Mielniczuk Date: Sat, 22 Jul 2017 09:37:22 +0200 Subject: [PATCH 4/4] Define i686 when TARGET=i686* --- libc-test/build.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index 0b47db6a..1db69079 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -7,6 +7,7 @@ use std::env; fn main() { let target = env::var("TARGET").unwrap(); let aarch64 = target.contains("aarch64"); + let i686 = target.contains("i686"); let x86_64 = target.contains("x86_64"); let windows = target.contains("windows"); let mingw = target.contains("windows-gnu"); @@ -187,7 +188,7 @@ fn main() { if x86_64 { cfg.header("sys/io.h"); } - if x86 || x86_64 { + if i686 || x86_64 { cfg.header("sys/reg.h"); } }