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

Use upstream libc ptrace FFI #728

Merged
merged 1 commit into from
Aug 11, 2017
Merged

Use upstream libc ptrace FFI #728

merged 1 commit into from
Aug 11, 2017

Conversation

Susurrus
Copy link
Contributor

This might fail on Mac because of how libc defines ptrace on that platform, but we'll see!

@Susurrus
Copy link
Contributor Author

Susurrus commented Aug 11, 2017

We don't expose this on mac, which is good because that API is considerably different. So this should be good to merge.

@Susurrus
Copy link
Contributor Author

@marmistrz Wanna give this a quick look-over since it pertains to the ptrace work you've been doing?

#[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;
Copy link
Contributor

Choose a reason for hiding this comment

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

__ptrace_request is an enum in C. Won't we be cafe with an int?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Enums are c_int by default in C. But I'm following the argument type dictated by libc's definition of ptrace() across all supported platforms.

@@ -83,7 +86,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();
ffi::ptrace(request, pid.into(), addr, data)
libc::ptrace(request, Into::<libc::pid_t>::into(pid), addr, data)
Copy link
Contributor

Choose a reason for hiding this comment

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

libc::pid_t::from(pid) would be cleaner. same in several other places.

#[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;
Copy link
Contributor

Choose a reason for hiding this comment

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

You're importing libc::self, so the leading :: is not needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually libc::self is not imported into this module, so the leading :: is necessary here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, indeed, it's a submodule.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, we'll remove it when we refactor all these constants as part of #724.

@Susurrus
Copy link
Contributor Author

Susurrus commented Aug 11, 2017

@marmistrz Thanks for the review. This should clean things up a bit nicer.

@Susurrus
Copy link
Contributor Author

bors r+ marmistrz

@bors
Copy link
Contributor

bors bot commented Aug 11, 2017

Merge conflict

@Susurrus
Copy link
Contributor Author

bors r+ marmistrz

bors bot added a commit that referenced this pull request Aug 11, 2017
728: Use upstream libc ptrace FFI r=Susurrus

This might fail on Mac because of how libc defines ptrace on that platform, but we'll see!

731: Use upstream libc definitions in mman module r=asomers
@bors
Copy link
Contributor

bors bot commented Aug 11, 2017

@bors bors bot merged commit 0e0de31 into nix-rust:master Aug 11, 2017
@Susurrus Susurrus deleted the ptrace_ffi branch August 12, 2017 18:06
Susurrus pushed a commit to Susurrus/nix that referenced this pull request Aug 27, 2017
Used the libc_enum! macro to create enums for the ptrace event, request, and libc_bitflags for options constants defined in libc.
Also, replicated functionality to move from c_int to PtraceEvent enum in PR nix-rust#728 as it appears to be abandoned.

Added utility function for detaching from tracee. Updated names and removed ptrace::ptrace namespace
asomers pushed a commit to asomers/nix that referenced this pull request Sep 3, 2017
Used the libc_enum! macro to create enums for the ptrace event, request, and libc_bitflags for options constants defined in libc.
Also, replicated functionality to move from c_int to PtraceEvent enum in PR nix-rust#728 as it appears to be abandoned.

Added utility function for detaching from tracee. Updated names and removed ptrace::ptrace namespace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants