-
Notifications
You must be signed in to change notification settings - Fork 675
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
Add PTRACE_INTERRUPT call as ptrace::interrupt(pid)
#1422
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,6 +114,48 @@ fn test_ptrace_cont() { | |
} | ||
} | ||
|
||
#[cfg(target_os = "linux")] | ||
#[test] | ||
fn test_ptrace_interrupt() { | ||
use nix::sys::ptrace; | ||
use nix::sys::signal::Signal; | ||
use nix::sys::wait::{waitpid, WaitPidFlag, WaitStatus}; | ||
use nix::unistd::fork; | ||
use nix::unistd::ForkResult::*; | ||
use std::thread::sleep; | ||
use std::time::Duration; | ||
|
||
require_capability!(CAP_SYS_PTRACE); | ||
|
||
let _m = crate::FORK_MTX.lock().expect("Mutex got poisoned by another test"); | ||
|
||
match unsafe{fork()}.expect("Error: Fork Failed") { | ||
Child => { | ||
loop { | ||
sleep(Duration::from_millis(1000)); | ||
} | ||
|
||
}, | ||
Parent { child } => { | ||
ptrace::seize(child, ptrace::Options::PTRACE_O_TRACESYSGOOD).unwrap(); | ||
ptrace::interrupt(child).unwrap(); | ||
assert_eq!(waitpid(child, None), Ok(WaitStatus::PtraceEvent(child, Signal::SIGTRAP, 128))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This I verified, interrupt will fire the PtraceEvent. Not sure about the third parameter 128, is it same over all systems? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good question. Where did you copy the 128 parameter from? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I took it from the
|
||
ptrace::syscall(child, None).unwrap(); | ||
assert_eq!(waitpid(child, None), Ok(WaitStatus::PtraceSyscall(child))); | ||
blaind marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ptrace::detach(child, Some(Signal::SIGKILL)).unwrap(); | ||
match waitpid(child, None) { | ||
Ok(WaitStatus::Signaled(pid, Signal::SIGKILL, _)) if pid == child => { | ||
let _ = waitpid(child, Some(WaitPidFlag::WNOHANG)); | ||
while ptrace::cont(child, Some(Signal::SIGKILL)).is_ok() { | ||
let _ = waitpid(child, Some(WaitPidFlag::WNOHANG)); | ||
} | ||
} | ||
_ => panic!("The process should have been killed"), | ||
} | ||
}, | ||
} | ||
} | ||
|
||
// ptrace::{setoptions, getregs} are only available in these platforms | ||
#[cfg(all(target_os = "linux", | ||
any(target_arch = "x86_64", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shoot. I just noticed that your CHANGELOG entry got moved into the wrong part of the file when you rebased. You'll have to move it up to the top.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, I forgot to stop bors when I found the CHANGELOG. problem. Don't worry; I'll take care of it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, sorry about that. Did not notice when rebasing with master. Thanks for fixing!