Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: nix-rust/nix
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: c25b9f616a4ced5cb7b25e0b8c9ec1009558d0b7
Choose a base ref
..
head repository: nix-rust/nix
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 509da5112c2ba9c4c8b7bbb1c02b0f31332fc845
Choose a head ref
Showing with 13 additions and 17 deletions.
  1. +13 −17 src/sys/ptrace.rs
30 changes: 13 additions & 17 deletions src/sys/ptrace.rs
Original file line number Diff line number Diff line change
@@ -6,18 +6,14 @@ use ::unistd::Pid;
pub mod ptrace {
use libc::c_int;

/// The datatype used for the `request` argument to `ptrace`
#[cfg(any(all(target_os = "linux", arch = "s390x"),
all(target_os = "linux", target_env = "gnu")))]
#[doc(hidden)]
pub type ptrace_request_type = ::libc::c_uint;

#[cfg(not(any(all(target_os = "linux", arch = "s390x"),
all(target_os = "linux", target_env = "gnu"))))]
#[doc(hidden)]
pub type ptrace_request_type = ::libc::c_int;

pub type PtraceRequest = ptrace_request_type;
cfg_if! {
if #[cfg(any(all(target_os = "linux", arch = "s390x"),
all(target_os = "linux", target_env = "gnu")))] {
pub type PtraceRequest = ::libc::c_uint;
} else {
pub type PtraceRequest = c_int;
}
}

pub const PTRACE_TRACEME: PtraceRequest = 0;
pub const PTRACE_PEEKTEXT: PtraceRequest = 1;
@@ -86,7 +82,7 @@ pub fn ptrace(request: ptrace::PtraceRequest, pid: Pid, addr: *mut c_void, data:
fn ptrace_peek(request: ptrace::PtraceRequest, pid: Pid, addr: *mut c_void, data: *mut c_void) -> Result<c_long> {
let ret = unsafe {
Errno::clear();
libc::ptrace(request, Into::<libc::pid_t>::into(pid), addr, data)
libc::ptrace(request, libc::pid_t::from(pid), addr, data)
};
match Errno::result(ret) {
Ok(..) | Err(Error::Sys(Errno::UnknownErrno)) => Ok(ret),
@@ -101,21 +97,21 @@ fn ptrace_peek(request: ptrace::PtraceRequest, pid: Pid, addr: *mut c_void, data
fn ptrace_get_data<T>(request: ptrace::PtraceRequest, pid: Pid) -> Result<T> {
// Creates an uninitialized pointer to store result in
let data: T = unsafe { mem::uninitialized() };
let res = unsafe { libc::ptrace(request, Into::<libc::pid_t>::into(pid), ptr::null_mut::<T>(), &data as *const _ as *const c_void) };
let res = unsafe { libc::ptrace(request, libc::pid_t::from(pid), ptr::null_mut::<T>(), &data as *const _ as *const c_void) };
Errno::result(res)?;
Ok(data)
}

fn ptrace_other(request: ptrace::PtraceRequest, pid: Pid, addr: *mut c_void, data: *mut c_void) -> Result<c_long> {
Errno::result(unsafe { libc::ptrace(request, Into::<libc::pid_t>::into(pid), addr, data) }).map(|_| 0)
Errno::result(unsafe { libc::ptrace(request, libc::pid_t::from(pid), addr, data) }).map(|_| 0)
}

/// Set options, as with `ptrace(PTRACE_SETOPTIONS,...)`.
pub fn setoptions(pid: Pid, options: ptrace::PtraceOptions) -> Result<()> {
use self::ptrace::*;
use std::ptr;

let res = unsafe { libc::ptrace(PTRACE_SETOPTIONS, Into::<libc::pid_t>::into(pid), ptr::null_mut::<libc::c_void>(), options as *mut c_void) };
let res = unsafe { libc::ptrace(PTRACE_SETOPTIONS, libc::pid_t::from(pid), ptr::null_mut::<libc::c_void>(), options as *mut c_void) };
Errno::result(res).map(|_| ())
}

@@ -136,7 +132,7 @@ pub fn setsiginfo(pid: Pid, sig: &siginfo_t) -> Result<()> {
use self::ptrace::*;
let ret = unsafe{
Errno::clear();
libc::ptrace(PTRACE_SETSIGINFO, Into::<libc::pid_t>::into(pid), ptr::null_mut::<libc::c_void>(), sig as *const _ as *const c_void)
libc::ptrace(PTRACE_SETSIGINFO, libc::pid_t::from(pid), ptr::null_mut::<libc::c_void>(), sig as *const _ as *const c_void)
};
match Errno::result(ret) {
Ok(_) => Ok(()),