Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename the public ptrace_* functions. #692

Merged
merged 43 commits into from
Jul 25, 2017
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
b4f1749
Rename the public ptrace_* functions.
marmistrz Jul 20, 2017
3192df4
Fix tests
marmistrz Jul 20, 2017
d5c4d0f
Tidy up imports in test_ptrace.rs
marmistrz Jul 20, 2017
18b2bc1
Get rid of the bulk imports
marmistrz Jul 21, 2017
8928a7d
Remove old workaround
Susurrus Jul 11, 2017
1b9a779
Re-add bad variant of ioctl!
Susurrus Jul 11, 2017
a5b01c0
Add a "bad none" variant to the ioctl macro
Susurrus Jul 11, 2017
2fe5c2b
Hide internal macros/types within ioctl
Susurrus Jul 11, 2017
233a678
Remove unnecessary path aliasing
Susurrus Jul 11, 2017
55a7d4b
Revise ioctl module documentation
Susurrus Jul 11, 2017
caaffb8
Remove ioc_* functions
Susurrus Jul 11, 2017
82e0139
Use the proper ioctl number type depending on target
Susurrus Jul 11, 2017
e4a1851
Remove c_int and c_void from root
Susurrus Jul 12, 2017
88dc19b
Remove unnecessary constants
Susurrus Jul 12, 2017
7b07847
Unify argument names to generated ioctl functions
Susurrus Jul 13, 2017
3cf4cc6
Split ioctl!(write ...) into write_ptr and write_int
Susurrus Jul 18, 2017
571386b
Add 'bad' prefixes for read, write_*, and readwrite ioctls
Susurrus Jul 13, 2017
d63c616
Refactor ioctl! for buffers
Susurrus Jul 13, 2017
93b2929
Update changelog
Susurrus Jul 17, 2017
085f47c
Fix thread safety issues in pty and termios tests
asomers Jul 20, 2017
1c9e0ca
fix some tests for Android
ndusart Jul 20, 2017
2a5b86d
Remove workaround for `pub extern crate`
jonas-schievink Jul 20, 2017
b6ad298
Remove `homepage` from Cargo.toml
jonas-schievink Jul 20, 2017
845453b
Add tests of actual ioctl usage
Susurrus Jul 20, 2017
903a52f
Add WaitStatus::PtraceSyscall for use with PTRACE_O_TRACESYSGOOD
geofft Mar 28, 2017
2288202
Document WaitStatus and its variants
geofft Jun 20, 2017
907bb98
use std::env::temp_dir() to retrieve the temp directory in test_mkstemp
ndusart Jul 20, 2017
a162ea2
Allow doc attributes in ioctl macro
roblabla Jul 8, 2017
745a4ab
Document invariants of fork and fix tests
jonas-schievink Jul 20, 2017
4cefd53
Remove unneeded local
jonas-schievink Jul 22, 2017
536787e
Replace remaining process::exit with libc::_exit
jonas-schievink Jul 22, 2017
283fb1c
Add CHANGELOG entry for PR #661
asomers Jul 24, 2017
f3167db
Release 0.9.0
asomers Jul 24, 2017
021e851
Bump version to 0.10.0-pre
asomers Jul 24, 2017
8beaea2
Move Tier 3s to Tier 2
Susurrus Jul 9, 2017
46191fd
Disable tests on s390x
Susurrus Jul 9, 2017
a717003
Disable failing tests on mips64
Susurrus Jul 9, 2017
ce60aa5
Disable testing because of musl #include issues
Susurrus Jul 9, 2017
1844378
Add a changelog entry
marmistrz Jul 25, 2017
6583fd1
Merge branch 'master' into ptrace-rename
marmistrz Jul 25, 2017
9cf8248
Fix the tests compiling
marmistrz Jul 25, 2017
6ce39a6
Merge branch 'ptrace-rename' of github.com:marmistrz/nix into ptrace-…
marmistrz Jul 25, 2017
bf93180
Remove the TODO comments, add unwrap() for ptrace.
marmistrz Jul 25, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Changed
- Renamed existing `ptrace` wrappers to encourage namespacing ([#692](https://github.com/nix-rust/nix/pull/692))

## [0.9.0] 2017-07-23

### Added
Expand Down
8 changes: 4 additions & 4 deletions src/sys/ptrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ fn ptrace_other(request: ptrace::PtraceRequest, pid: Pid, addr: *mut c_void, dat
}

/// Set options, as with `ptrace(PTRACE_SETOPTIONS,...)`.
pub fn ptrace_setoptions(pid: Pid, options: ptrace::PtraceOptions) -> Result<()> {
pub fn setoptions(pid: Pid, options: ptrace::PtraceOptions) -> Result<()> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no module-level documentation for the ptrace module, but it'd be good to add one showing an example usage that demonstrates the namespacing we recomment. We don't need it per-say, but it'd help users use this crate very easily. It'll also help us see where the imports aren't very ergonomic so we can improve them later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add the documentation when I'm done with all the ptrace changes, ok?

Besides, I really think about splitting up #666 into a couple smaller PRs because I'm starting to lose control of the tests.

use self::ptrace::*;
use std::ptr;

Expand All @@ -117,19 +117,19 @@ pub fn ptrace_setoptions(pid: Pid, options: ptrace::PtraceOptions) -> Result<()>
}

/// Gets a ptrace event as described by `ptrace(PTRACE_GETEVENTMSG,...)`
pub fn ptrace_getevent(pid: Pid) -> Result<c_long> {
pub fn getevent(pid: Pid) -> Result<c_long> {
use self::ptrace::*;
ptrace_get_data::<c_long>(PTRACE_GETEVENTMSG, pid)
}

/// Get siginfo as with `ptrace(PTRACE_GETSIGINFO,...)`
pub fn ptrace_getsiginfo(pid: Pid) -> Result<siginfo_t> {
pub fn getsiginfo(pid: Pid) -> Result<siginfo_t> {
use self::ptrace::*;
ptrace_get_data::<siginfo_t>(PTRACE_GETSIGINFO, pid)
}

/// Set siginfo as with `ptrace(PTRACE_SETSIGINFO,...)`
pub fn ptrace_setsiginfo(pid: Pid, sig: &siginfo_t) -> Result<()> {
pub fn setsiginfo(pid: Pid, sig: &siginfo_t) -> Result<()> {
use self::ptrace::*;
let ret = unsafe{
Errno::clear();
Expand Down
19 changes: 10 additions & 9 deletions test/sys/test_ptrace.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
use nix::Error;
use nix::errno::*;
use nix::unistd::*;
use nix::sys::ptrace::*;
use nix::sys::ptrace::ptrace::*;
use nix::errno::Errno;
use nix::unistd::getpid;
use nix::sys::ptrace;

use std::{mem, ptr};

#[test]
fn test_ptrace() {
use nix::sys::ptrace::ptrace::PTRACE_ATTACH;
// Just make sure ptrace can be called at all, for now.
// FIXME: qemu-user doesn't implement ptrace on all arches, so permit ENOSYS
let err = ptrace(PTRACE_ATTACH, getpid(), ptr::null_mut(), ptr::null_mut()).unwrap_err();
let err = ptrace::ptrace(PTRACE_ATTACH, getpid(), ptr::null_mut(), ptr::null_mut()).unwrap_err();
assert!(err == Error::Sys(Errno::EPERM) || err == Error::Sys(Errno::ENOSYS));
}

// Just make sure ptrace_setoptions can be called at all, for now.
#[test]
fn test_ptrace_setoptions() {
let err = ptrace_setoptions(getpid(), PTRACE_O_TRACESYSGOOD).unwrap_err();
use nix::sys::ptrace::ptrace::PTRACE_O_TRACESYSGOOD;
let err = ptrace::setoptions(getpid(), PTRACE_O_TRACESYSGOOD).unwrap_err();
assert!(err != Error::UnsupportedOperation);
}

// Just make sure ptrace_getevent can be called at all, for now.
#[test]
fn test_ptrace_getevent() {
let err = ptrace_getevent(getpid()).unwrap_err();
let err = ptrace::getevent(getpid()).unwrap_err();
assert!(err != Error::UnsupportedOperation);
}

// Just make sure ptrace_getsiginfo can be called at all, for now.
#[test]
fn test_ptrace_getsiginfo() {
match ptrace_getsiginfo(getpid()) {
match ptrace::getsiginfo(getpid()) {
Err(Error::UnsupportedOperation) => panic!("ptrace_getsiginfo returns Error::UnsupportedOperation!"),
_ => (),
}
Expand All @@ -41,7 +42,7 @@ fn test_ptrace_getsiginfo() {
#[test]
fn test_ptrace_setsiginfo() {
let siginfo = unsafe { mem::uninitialized() };
match ptrace_setsiginfo(getpid(), &siginfo) {
match ptrace::setsiginfo(getpid(), &siginfo) {
Err(Error::UnsupportedOperation) => panic!("ptrace_setsiginfo returns Error::UnsupportedOperation!"),
_ => (),
}
Expand Down
15 changes: 9 additions & 6 deletions test/sys/test_wait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn test_wait_exit() {
// FIXME: qemu-user doesn't implement ptrace on most arches
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
mod ptrace {
use nix::sys::ptrace::*;
use nix::sys::ptrace;
use nix::sys::ptrace::ptrace::*;
use nix::sys::signal::*;
use nix::sys::wait::*;
Expand All @@ -51,7 +51,8 @@ mod ptrace {
use libc::_exit;

fn ptrace_child() -> ! {
let _ = ptrace(PTRACE_TRACEME, Pid::from_raw(0), ptr::null_mut(), ptr::null_mut());
// TODO ptrace::traceme will be added in #666
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need for these comments.

let _ = ptrace::ptrace(PTRACE_TRACEME, Pid::from_raw(0), ptr::null_mut(), ptr::null_mut());
// As recommended by ptrace(2), raise SIGTRAP to pause the child
// until the parent is ready to continue
let _ = raise(SIGTRAP);
Expand All @@ -62,16 +63,18 @@ mod ptrace {
// Wait for the raised SIGTRAP
assert_eq!(waitpid(child, None), Ok(WaitStatus::Stopped(child, SIGTRAP)));
// We want to test a syscall stop and a PTRACE_EVENT stop
assert!(ptrace_setoptions(child, PTRACE_O_TRACESYSGOOD | PTRACE_O_TRACEEXIT).is_ok());
assert!(ptrace::setoptions(child, PTRACE_O_TRACESYSGOOD | PTRACE_O_TRACEEXIT).is_ok());

// First, stop on the next system call, which will be exit()
assert!(ptrace(PTRACE_SYSCALL, child, ptr::null_mut(), ptr::null_mut()).is_ok());
// TODO ptrace::syscall will be added in #666
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here.

assert!(ptrace::ptrace(PTRACE_SYSCALL, child, ptr::null_mut(), ptr::null_mut()).is_ok());
assert_eq!(waitpid(child, None), Ok(WaitStatus::PtraceSyscall(child)));
// Then get the ptrace event for the process exiting
assert!(ptrace(PTRACE_CONT, child, ptr::null_mut(), ptr::null_mut()).is_ok());
// TODO ptrace::cont will be added in #666
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

assert!(ptrace::ptrace(PTRACE_CONT, child, ptr::null_mut(), ptr::null_mut()).is_ok());
assert_eq!(waitpid(child, None), Ok(WaitStatus::PtraceEvent(child, SIGTRAP, PTRACE_EVENT_EXIT)));
// Finally get the normal wait() result, now that the process has exited
assert!(ptrace(PTRACE_CONT, child, ptr::null_mut(), ptr::null_mut()).is_ok());
assert!(ptrace::ptrace(PTRACE_CONT, child, ptr::null_mut(), ptr::null_mut()).is_ok());
assert_eq!(waitpid(child, None), Ok(WaitStatus::Exited(child, 0)));
}

Expand Down