Skip to content

Commit

Permalink
Merge branch 'ptrace' of github.com:marmistrz/nix into ptrace
Browse files Browse the repository at this point in the history
  • Loading branch information
marmistrz committed Jul 19, 2017
2 parents 8a85c39 + 067f937 commit dd80b55
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/sys/ptrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ use ::unistd::Pid;

//------------------ First part: a low-level wrapper for ptrace -----------------//

<<<<<<< HEAD
#[cfg(all(target_os = "linux",
any(target_arch = "x86",
target_arch = "x86_64",
target_arch = "arm")),
)]
=======
>>>>>>> 067f937f087c4fe00b7281d9829f33a3dae4a9bd
pub mod ptrace {
use libc::c_int;

Expand Down Expand Up @@ -151,7 +154,11 @@ pub fn ptrace_setsiginfo(pid: Pid, sig: &siginfo_t) -> Result<()> {
}
}

<<<<<<< HEAD
//-------------------------- Second part: a high-level wrapper for ptrace ----------------------//
=======
//-------------------------- Second part: a low-level wrapper for ptrace ----------------------//
>>>>>>> 067f937f087c4fe00b7281d9829f33a3dae4a9bd

#[cfg(target_arch = "x86_64")]
// We're going to export it anyway
Expand Down Expand Up @@ -187,15 +194,22 @@ pub enum Register {
GS = 26 * 8,
}

<<<<<<< HEAD
type Word = usize;

=======
>>>>>>> 067f937f087c4fe00b7281d9829f33a3dae4a9bd
/// Makes the `PTRACE_SYSCALL` request to ptrace
pub fn syscall(pid: Pid) -> Result<()> {
ptrace(ptrace::PTRACE_SYSCALL, pid, ptr::null_mut(), ptr::null_mut()).map(|_| ()) // ignore the useless return value
}

/// Makes the `PTRACE_PEEKUSER` request to ptrace
<<<<<<< HEAD
pub fn peekuser(pid: Pid, reg: Register) -> Result<Word> {
=======
pub fn peekuser(pid: Pid, reg: Register) -> Result<c_long> {
>>>>>>> 067f937f087c4fe00b7281d9829f33a3dae4a9bd
let reg_arg = (reg as i32) as *mut c_void;
ptrace(ptrace::PTRACE_PEEKUSER, pid, reg_arg, ptr::null_mut())
}
Expand All @@ -214,7 +228,11 @@ pub fn traceme() -> Result<()> {
///
/// This function allows to access arbitrary data in the traced process
/// and may crash the inferior if used incorrectly and is thus marked `unsafe`.
<<<<<<< HEAD
pub unsafe fn peekdata(pid: Pid, addr: usize) -> Result<Word> {
=======
pub unsafe fn peekdata(pid: Pid, addr: c_long) -> Result<c_long> {
>>>>>>> 067f937f087c4fe00b7281d9829f33a3dae4a9bd
ptrace(ptrace::PTRACE_PEEKDATA, pid, addr as *mut c_void, ptr::null_mut())
}

Expand All @@ -223,13 +241,18 @@ pub unsafe fn peekdata(pid: Pid, addr: usize) -> Result<Word> {
/// This function allows to access arbitrary data in the traced process
/// and may crash the inferior or introduce race conditions if used
/// incorrectly and is thus marked `unsafe`.
<<<<<<< HEAD
pub unsafe fn pokedata(pid: Pid, addr: usize, val: Word) -> Result<()> {
=======
pub unsafe fn pokedata(pid: Pid, addr: c_long, val: c_long) -> Result<()> {
>>>>>>> 067f937f087c4fe00b7281d9829f33a3dae4a9bd
ptrace(
ptrace::PTRACE_POKEDATA,
pid,
addr as *mut c_void,
val as *mut c_void,
).map(|_| ()) // ignore the useless return value
<<<<<<< HEAD
}


Expand All @@ -255,3 +278,6 @@ mod tests {
assert_eq!(len, 0);
}
}
=======
}
>>>>>>> 067f937f087c4fe00b7281d9829f33a3dae4a9bd

0 comments on commit dd80b55

Please sign in to comment.