Skip to content

Commit 0587977

Browse files
committed
Deprecate ptrace.
1 parent ebcedb3 commit 0587977

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/sys/ptrace.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ mod ffi {
7373

7474
/// Performs a ptrace request. If the request in question is provided by a specialised function
7575
/// this function will return an unsupported operation error.
76+
#[deprecated(
77+
since="0.10.0",
78+
note="usages of `ptrace()` should be replaced with the specialized helper functions instead"
79+
)]
7680
pub unsafe fn ptrace(request: ptrace::PtraceRequest, pid: Pid, addr: *mut c_void, data: *mut c_void) -> Result<c_long> {
7781
use self::ptrace::*;
7882

@@ -106,8 +110,9 @@ fn ptrace_get_data<T>(request: ptrace::PtraceRequest, pid: Pid) -> Result<T> {
106110
Ok(data)
107111
}
108112

109-
fn ptrace_other(request: ptrace::PtraceRequest, pid: Pid, addr: *mut c_void, data: *mut c_void) -> Result<c_long> {
110-
Errno::result(unsafe { ffi::ptrace(request, pid.into(), addr, data) }).map(|_| 0)
113+
/// Performs a general ptrace request.
114+
unsafe fn ptrace_other(request: ptrace::PtraceRequest, pid: Pid, addr: *mut c_void, data: *mut c_void) -> Result<c_long> {
115+
Errno::result(ffi::ptrace(request, pid.into(), addr, data)).map(|_| 0)
111116
}
112117

113118
/// Set options, as with `ptrace(PTRACE_SETOPTIONS,...)`.
@@ -150,7 +155,7 @@ pub fn setsiginfo(pid: Pid, sig: &siginfo_t) -> Result<()> {
150155
/// This is the only ptrace request to be issued by the tracee.
151156
pub fn traceme() -> Result<()> {
152157
unsafe {
153-
ptrace(
158+
ptrace_other(
154159
ptrace::PTRACE_TRACEME,
155160
Pid::from_raw(0),
156161
ptr::null_mut(),
@@ -164,7 +169,7 @@ pub fn traceme() -> Result<()> {
164169
/// Arranges for the tracee to be stopped at the next entry to or exit from a system call.
165170
pub fn syscall(pid: Pid) -> Result<()> {
166171
unsafe {
167-
ptrace(
172+
ptrace_other(
168173
ptrace::PTRACE_SYSCALL,
169174
pid,
170175
ptr::null_mut(),
@@ -178,7 +183,7 @@ pub fn syscall(pid: Pid) -> Result<()> {
178183
/// Attaches to the process specified in pid, making it a tracee of the calling process.
179184
pub fn attach(pid: Pid) -> Result<()> {
180185
unsafe {
181-
ptrace(
186+
ptrace_other(
182187
ptrace::PTRACE_ATTACH,
183188
pid,
184189
ptr::null_mut(),
@@ -197,7 +202,7 @@ pub fn cont<T: Into<Option<Signal>>>(pid: Pid, sig: T) -> Result<()> {
197202
None => ptr::null_mut(),
198203
};
199204
unsafe {
200-
ptrace(ptrace::PTRACE_CONT, pid, ptr::null_mut(), data).map(|_| ()) // ignore the useless return value
205+
ptrace_other(ptrace::PTRACE_CONT, pid, ptr::null_mut(), data).map(|_| ()) // ignore the useless return value
201206
}
202207
}
203208

0 commit comments

Comments
 (0)