Skip to content

Commit

Permalink
Rollup merge of rust-lang#40139 - tedsta:fuchsia_std_process_fix, r=a…
Browse files Browse the repository at this point in the history
…lexcrichton

std::process for fuchsia: updated to latest liblaunchpad

Our liblaunchpad changed a bit and so fuchsia's std::process impl needs to change a bit.

@raphlinus
  • Loading branch information
frewsxcv authored Mar 2, 2017
2 parents 618cad5 + 2123d6a commit cedc0d2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 27 deletions.
22 changes: 16 additions & 6 deletions src/libstd/sys/unix/process/magenta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,18 @@ extern {
pub fn launchpad_create(job: mx_handle_t, name: *const c_char,
lp: *mut *mut launchpad_t) -> mx_status_t;

pub fn launchpad_start(lp: *mut launchpad_t) -> mx_status_t;
pub fn launchpad_go(lp: *mut launchpad_t,
proc_handle: *mut mx_handle_t,
err_msg: *mut *const c_char) -> mx_status_t;

pub fn launchpad_destroy(lp: *mut launchpad_t);

pub fn launchpad_arguments(lp: *mut launchpad_t, argc: c_int,
pub fn launchpad_set_args(lp: *mut launchpad_t, argc: c_int,
argv: *const *const c_char) -> mx_status_t;

pub fn launchpad_environ(lp: *mut launchpad_t, envp: *const *const c_char) -> mx_status_t;
pub fn launchpad_set_environ(lp: *mut launchpad_t, envp: *const *const c_char) -> mx_status_t;

pub fn launchpad_clone_mxio_root(lp: *mut launchpad_t) -> mx_status_t;

pub fn launchpad_clone_mxio_cwd(lp: *mut launchpad_t) -> mx_status_t;
pub fn launchpad_clone(lp: *mut launchpad_t, what: u32) -> mx_status_t;

pub fn launchpad_clone_fd(lp: *mut launchpad_t, fd: c_int, target_fd: c_int) -> mx_status_t;

Expand All @@ -182,6 +182,16 @@ extern {
pub fn launchpad_vmo_from_file(filename: *const c_char) -> mx_handle_t;
}

// Launchpad clone constants

pub const LP_CLONE_MXIO_ROOT: u32 = 0x0001;
pub const LP_CLONE_MXIO_CWD: u32 = 0x0002;
// LP_CLONE_MXIO_STDIO = 0x0004
// LP_CLONE_MXIO_ALL = 0x00FF
// LP_CLONE_ENVIRON = 0x0100
// LP_CLONE_DEFAULT_JOB = 0x0200
// LP_CLONE_ALL = 0xFFFF

// Errors

#[allow(unused)] pub const ERR_INTERNAL: mx_status_t = -1;
Expand Down
36 changes: 15 additions & 21 deletions src/libstd/sys/unix/process/process_fuchsia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use libc;
use mem;
use ptr;

use sys::process::magenta::{Handle, launchpad_t, mx_handle_t};
use sys::process::magenta::{Handle, mx_handle_t};
use sys::process::process_common::*;

////////////////////////////////////////////////////////////////////////////////
Expand All @@ -30,9 +30,9 @@ impl Command {

let (ours, theirs) = self.setup_io(default, needs_stdin)?;

let (launchpad, process_handle) = unsafe { self.do_exec(theirs)? };
let process_handle = unsafe { self.do_exec(theirs)? };

Ok((Process { launchpad: launchpad, handle: Handle::new(process_handle) }, ours))
Ok((Process { handle: Handle::new(process_handle) }, ours))
}

pub fn exec(&mut self, default: Stdio) -> io::Error {
Expand All @@ -51,7 +51,7 @@ impl Command {
}

unsafe fn do_exec(&mut self, stdio: ChildPipes)
-> io::Result<(*mut launchpad_t, mx_handle_t)> {
-> io::Result<mx_handle_t> {
use sys::process::magenta::*;

let job_handle = mx_job_default();
Expand All @@ -75,16 +75,15 @@ impl Command {
let launchpad_destructor = LaunchpadDestructor(launchpad);

// Set the process argv
mx_cvt(launchpad_arguments(launchpad, self.get_argv().len() as i32 - 1,
self.get_argv().as_ptr()))?;
mx_cvt(launchpad_set_args(launchpad, self.get_argv().len() as i32 - 1,
self.get_argv().as_ptr()))?;
// Setup the environment vars
mx_cvt(launchpad_environ(launchpad, envp))?;
mx_cvt(launchpad_set_environ(launchpad, envp))?;
mx_cvt(launchpad_add_vdso_vmo(launchpad))?;
mx_cvt(launchpad_clone_mxio_root(launchpad))?;
// Load the executable
mx_cvt(launchpad_elf_load(launchpad, launchpad_vmo_from_file(self.get_argv()[0])))?;
mx_cvt(launchpad_load_vdso(launchpad, MX_HANDLE_INVALID))?;
mx_cvt(launchpad_clone_mxio_cwd(launchpad))?;
mx_cvt(launchpad_clone(launchpad, LP_CLONE_MXIO_ROOT | LP_CLONE_MXIO_CWD))?;

// Clone stdin, stdout, and stderr
if let Some(fd) = stdio.stdin.fd() {
Expand All @@ -111,12 +110,15 @@ impl Command {
callback()?;
}

let process_handle = mx_cvt(launchpad_start(launchpad))?;

// Successfully started the launchpad
// `launchpad_go` destroys the launchpad, so we must not
mem::forget(launchpad_destructor);

Ok((launchpad, process_handle))
let mut process_handle: mx_handle_t = 0;
let mut err_msg: *const libc::c_char = ptr::null();
mx_cvt(launchpad_go(launchpad, &mut process_handle, &mut err_msg))?;
// FIXME: See if we want to do something with that err_msg

Ok(process_handle)
}
}

Expand All @@ -125,7 +127,6 @@ impl Command {
////////////////////////////////////////////////////////////////////////////////

pub struct Process {
launchpad: *mut launchpad_t,
handle: Handle,
}

Expand Down Expand Up @@ -195,10 +196,3 @@ impl Process {
Ok(Some(ExitStatus::new(proc_info.rec.return_code)))
}
}

impl Drop for Process {
fn drop(&mut self) {
use sys::process::magenta::launchpad_destroy;
unsafe { launchpad_destroy(self.launchpad); }
}
}

0 comments on commit cedc0d2

Please sign in to comment.