Skip to content

Commit 05e0d74

Browse files
authored
Rollup merge of #40139 - tedsta:fuchsia_std_process_fix, r=alexcrichton
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
2 parents c883f4f + 2123d6a commit 05e0d74

File tree

2 files changed

+31
-27
lines changed

2 files changed

+31
-27
lines changed

src/libstd/sys/unix/process/magenta.rs

+16-6
Original file line numberDiff line numberDiff line change
@@ -156,18 +156,18 @@ extern {
156156
pub fn launchpad_create(job: mx_handle_t, name: *const c_char,
157157
lp: *mut *mut launchpad_t) -> mx_status_t;
158158

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

161163
pub fn launchpad_destroy(lp: *mut launchpad_t);
162164

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

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

168-
pub fn launchpad_clone_mxio_root(lp: *mut launchpad_t) -> mx_status_t;
169-
170-
pub fn launchpad_clone_mxio_cwd(lp: *mut launchpad_t) -> mx_status_t;
170+
pub fn launchpad_clone(lp: *mut launchpad_t, what: u32) -> mx_status_t;
171171

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

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

185+
// Launchpad clone constants
186+
187+
pub const LP_CLONE_MXIO_ROOT: u32 = 0x0001;
188+
pub const LP_CLONE_MXIO_CWD: u32 = 0x0002;
189+
// LP_CLONE_MXIO_STDIO = 0x0004
190+
// LP_CLONE_MXIO_ALL = 0x00FF
191+
// LP_CLONE_ENVIRON = 0x0100
192+
// LP_CLONE_DEFAULT_JOB = 0x0200
193+
// LP_CLONE_ALL = 0xFFFF
194+
185195
// Errors
186196

187197
#[allow(unused)] pub const ERR_INTERNAL: mx_status_t = -1;

src/libstd/sys/unix/process/process_fuchsia.rs

+15-21
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use libc;
1313
use mem;
1414
use ptr;
1515

16-
use sys::process::magenta::{Handle, launchpad_t, mx_handle_t};
16+
use sys::process::magenta::{Handle, mx_handle_t};
1717
use sys::process::process_common::*;
1818

1919
////////////////////////////////////////////////////////////////////////////////
@@ -30,9 +30,9 @@ impl Command {
3030

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

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

35-
Ok((Process { launchpad: launchpad, handle: Handle::new(process_handle) }, ours))
35+
Ok((Process { handle: Handle::new(process_handle) }, ours))
3636
}
3737

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

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

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

7777
// Set the process argv
78-
mx_cvt(launchpad_arguments(launchpad, self.get_argv().len() as i32 - 1,
79-
self.get_argv().as_ptr()))?;
78+
mx_cvt(launchpad_set_args(launchpad, self.get_argv().len() as i32 - 1,
79+
self.get_argv().as_ptr()))?;
8080
// Setup the environment vars
81-
mx_cvt(launchpad_environ(launchpad, envp))?;
81+
mx_cvt(launchpad_set_environ(launchpad, envp))?;
8282
mx_cvt(launchpad_add_vdso_vmo(launchpad))?;
83-
mx_cvt(launchpad_clone_mxio_root(launchpad))?;
8483
// Load the executable
8584
mx_cvt(launchpad_elf_load(launchpad, launchpad_vmo_from_file(self.get_argv()[0])))?;
8685
mx_cvt(launchpad_load_vdso(launchpad, MX_HANDLE_INVALID))?;
87-
mx_cvt(launchpad_clone_mxio_cwd(launchpad))?;
86+
mx_cvt(launchpad_clone(launchpad, LP_CLONE_MXIO_ROOT | LP_CLONE_MXIO_CWD))?;
8887

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

114-
let process_handle = mx_cvt(launchpad_start(launchpad))?;
115-
116-
// Successfully started the launchpad
113+
// `launchpad_go` destroys the launchpad, so we must not
117114
mem::forget(launchpad_destructor);
118115

119-
Ok((launchpad, process_handle))
116+
let mut process_handle: mx_handle_t = 0;
117+
let mut err_msg: *const libc::c_char = ptr::null();
118+
mx_cvt(launchpad_go(launchpad, &mut process_handle, &mut err_msg))?;
119+
// FIXME: See if we want to do something with that err_msg
120+
121+
Ok(process_handle)
120122
}
121123
}
122124

@@ -125,7 +127,6 @@ impl Command {
125127
////////////////////////////////////////////////////////////////////////////////
126128

127129
pub struct Process {
128-
launchpad: *mut launchpad_t,
129130
handle: Handle,
130131
}
131132

@@ -195,10 +196,3 @@ impl Process {
195196
Ok(Some(ExitStatus::new(proc_info.rec.return_code)))
196197
}
197198
}
198-
199-
impl Drop for Process {
200-
fn drop(&mut self) {
201-
use sys::process::magenta::launchpad_destroy;
202-
unsafe { launchpad_destroy(self.launchpad); }
203-
}
204-
}

0 commit comments

Comments
 (0)