Skip to content

Commit 6110a67

Browse files
committed
Refactor documentation a little
1 parent 7ac8aba commit 6110a67

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/sys/ptrace.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ use {Errno, Error, Result};
33
use libc::{c_void, c_long, siginfo_t};
44
use ::unistd::Pid;
55

6-
//------------------ First part: a low-level wrapper for ptrace -----------------//
7-
86
#[cfg(all(target_os = "linux",
97
any(target_arch = "x86",
108
target_arch = "x86_64",
@@ -79,6 +77,7 @@ mod ffi {
7977
/// Performs a `ptrace` request. If the request in question is provided by a specialised function
8078
/// this function will return an unsupported operation error.
8179
///
80+
/// # Safety
8281
/// When used incorrectly, this function may crash the tracer or the tracee, thus is marked `unsafe`.
8382
pub unsafe fn ptrace(request: ptrace::PtraceRequest, pid: Pid, addr: *mut c_void, data: *mut c_void) -> Result<c_long> {
8483
use self::ptrace::*;
@@ -151,11 +150,8 @@ pub fn ptrace_setsiginfo(pid: Pid, sig: &siginfo_t) -> Result<()> {
151150
}
152151
}
153152

154-
//-------------------------- Second part: a high-level wrapper for ptrace ----------------------//
155-
156153
#[cfg(target_arch = "x86_64")]
157154
// We're going to export it anyway
158-
#[allow(dead_code)]
159155
#[allow(non_camel_case_types)]
160156
pub enum Register {
161157
R15 = 0 * 8,
@@ -202,10 +198,11 @@ pub fn peekuser(pid: Pid, reg: Register) -> Result<Word> {
202198
unsafe {
203199
ptrace(ptrace::PTRACE_PEEKUSER, pid, reg_arg, ptr::null_mut()).map(|r| r as Word)
204200
}
205-
}
201+
}
206202

207203
/// Makes the `PTRACE_POKEUSER` request to ptrace
208-
///
204+
///
205+
/// # Safety
209206
/// When incorrectly used, may change the registers to bad values,
210207
/// causing e.g. memory being corrupted by a syscall, thus is marked unsafe
211208
pub unsafe fn pokeuser(pid: Pid, reg: Register, val: Word) -> Result<()> {
@@ -226,17 +223,19 @@ pub fn traceme() -> Result<()> {
226223
}
227224

228225
/// Makes the `PTRACE_PEEKDATA` request to ptrace
229-
///
226+
///
227+
/// # Safety
230228
/// This function allows to access arbitrary data in the traced process
231229
/// and may crash the inferior if used incorrectly and is thus marked `unsafe`.
232230
pub unsafe fn peekdata(pid: Pid, addr: usize) -> Result<Word> {
233231
ptrace(ptrace::PTRACE_PEEKDATA, pid, addr as *mut c_void, ptr::null_mut()).map(|r| r as Word)
234232
}
235233

236-
/// Makes the `PTRACE_PEEKDATA` request to ptrace
234+
/// Makes the `PTRACE_POKEDATA` request to ptrace
237235
///
236+
/// # Safety
238237
/// This function allows to access arbitrary data in the traced process
239-
/// and may crash the inferior or introduce race conditions if used
238+
/// and may crash the inferior or introduce race conditions if used
240239
/// incorrectly and is thus marked `unsafe`.
241240
pub unsafe fn pokedata(pid: Pid, addr: usize, val: Word) -> Result<()> {
242241
ptrace(

0 commit comments

Comments
 (0)