From 52441c28b1daa6f9febf1bc6588b625b167bd2c3 Mon Sep 17 00:00:00 2001 From: jD91mZM2 Date: Wed, 24 Jul 2019 21:41:57 +0200 Subject: [PATCH] First step for ptrace overhaul --- src/data.rs | 47 +++++++++++++++++++++++------------------------ src/flag.rs | 27 +++++++++++++++------------ 2 files changed, 38 insertions(+), 36 deletions(-) diff --git a/src/data.rs b/src/data.rs index 6ad8d8b683..3b40727d35 100644 --- a/src/data.rs +++ b/src/data.rs @@ -1,5 +1,5 @@ use core::ops::{Deref, DerefMut}; -use core::{fmt, mem, slice}; +use core::{mem, slice}; #[derive(Copy, Clone, Debug, Default)] #[repr(C)] @@ -303,32 +303,16 @@ impl DerefMut for FloatRegisters { } } -#[derive(Clone, Copy)] -#[repr(C)] -pub union PtraceEventData { - pub clone: usize, - pub signal: usize -} - -impl Default for PtraceEventData { - fn default() -> Self { - Self { - clone: 0, - } - } -} - -impl fmt::Debug for PtraceEventData { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "PtraceEventData(...)") - } -} - #[derive(Clone, Copy, Debug, Default)] #[repr(C)] pub struct PtraceEvent { - pub tag: u16, - pub data: PtraceEventData, + pub cause: u64, + pub a: usize, + pub b: usize, + pub c: usize, + pub d: usize, + pub e: usize, + pub f: usize } impl Deref for PtraceEvent { @@ -347,3 +331,18 @@ impl DerefMut for PtraceEvent { } } } + +#[macro_export] +macro_rules! ptrace_event { + ($cause:expr $(, $a:expr $(, $b:expr $(, $c:expr)?)?)?) => { + PtraceEvent { + cause: $cause, + $(a: $a, + $(b: $b, + $(c: $c,)? + )? + )? + ..Default::default() + } + } +} diff --git a/src/flag.rs b/src/flag.rs index 9c928b4caf..ad66d69b29 100644 --- a/src/flag.rs +++ b/src/flag.rs @@ -60,23 +60,26 @@ pub const PHYSMAP_WRITE: usize = 0x0000_0001; pub const PHYSMAP_WRITE_COMBINE: usize = 0x0000_0002; pub const PHYSMAP_NO_CACHE: usize = 0x0000_0004; +// The top 32 bits of PTRACE_* are reserved, for now + +pub const PTRACE_STOP_PRE_SYSCALL: u64 = 0x0000_0001; +pub const PTRACE_STOP_POST_SYSCALL: u64 = 0x0000_0002; +pub const PTRACE_STOP_SINGLESTEP: u64 = 0x0000_0004; +pub const PTRACE_STOP_SIGNAL: u64 = 0x0000_0008; +pub const PTRACE_STOP_MASK: u64 = 0x0000_00FF; + +pub const PTRACE_EVENT_CLONE: u64 = 0x0000_0100; +pub const PTRACE_EVENT_MASK: u64 = 0x0000_0F00; + +pub const PTRACE_FLAG_SYSEMU: u64 = 0x0000_1000; +pub const PTRACE_FLAG_WAIT: u64 = 0x0000_2000; +pub const PTRACE_FLAG_MASK: u64 = 0x0000_F000; + pub const PROT_NONE: usize = 0x0000_0000; pub const PROT_EXEC: usize = 0x0001_0000; pub const PROT_WRITE: usize = 0x0002_0000; pub const PROT_READ: usize = 0x0004_0000; -pub const PTRACE_CONT: u8 = 0b0000_0001; -pub const PTRACE_SINGLESTEP: u8 = 0b0000_0010; -pub const PTRACE_SYSCALL: u8 = 0b0000_0011; -pub const PTRACE_WAIT: u8 = 0b0000_0100; -pub const PTRACE_SIGNAL: u8 = 0b0000_0101; - -pub const PTRACE_OPERATIONMASK: u8 = 0b0000_1111; -pub const PTRACE_SYSEMU: u8 = 0b0001_0000; - -pub const PTRACE_EVENT_CLONE: u16 = 0; -pub const PTRACE_EVENT_SIGNAL: u16 = 1; - pub const SEEK_SET: usize = 0; pub const SEEK_CUR: usize = 1; pub const SEEK_END: usize = 2;