A crate to spawn a child process on OS X and get the child's Mach task port. Many useful OS X kernel APIs require access to the task port, and in recent releases of OS X the security around task_for_pid
has been tightened such that it no longer works reliably even as root. However, for processes that you are spawning it is possible to have the child cooperate and send its task port to the parent. This crate uses CommandExt::before_exec
and a handful of Mach APIs to have the child process do just that.
Much of this code is written using information from Michael Weber's Some Fun with Mach Ports blog post, and other bits were gleaned from Chromium's machportbroker.mm.
This crate was written so I could use it to write tests for the read-process-memory crate. You may find this crate useful in conjunction with that one!
```rust,norun extern crate spawntask_port;
use std::io; use std::process::Command; use spawntaskport::CommandSpawnWithTask;
// Spawn exe
with args
as a child process and do interesting
// things to it.
fn dosomework(exe: &str, args: &[&str]) -> io::Result<()> {
let (mut child, taskport) = Command::new(&)
.args(args)
.spawngettaskport()?
// Now you can call mach APIs that require a mach_port_t
using task_port
,
// like vm_read
.
child.wait()?;
Ok(())
}
```