-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Fuchsia support for std::process via liblaunchpad. #37936
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
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @aturon (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
cc @brson @alexcrichton, have one of you been looking at Fuchsia-related PRs? |
Yep, I'll take this one unless @brson gets to it first. |
The linter complained about my fuchsia-specific stuff in |
Awesome, thanks for the PR! I wonder, how close to Unix (like Linux Unix) is Fuchsia? If it's relatively far off then it may be worthwhile just creating a whole new |
(hnd_type & 0xFFFF) | ((arg & 0xFFFF) << 16) | ||
} | ||
|
||
#[link(name="mxio")] |
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.
It's ok to nix these #[link]
annotations as they get added via the build script above
-> io::Result<(*mut launchpad_t, mx_handle_t)> { | ||
use sys::magenta::*; | ||
|
||
macro_rules! tlp { |
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.
Perhaps this could be done instead with a small value on the stack that has a destructor?
I agree there should be a They say eventually there will be fork emulation, but that we don't want to use it for Rust's libstd. So I wonder if we want to be using the musl's pipe stuff when we could just directly use |
I'll try to dig in to the code soon. Quick comments: +1 to In general, musl (and mxio as an overlay) provide a whole bunch of posix emulation, and that's a good way to get things working, but as a long term trend I think we'd like to migrate to things running directly in terms of lower-level system functionality. |
…d refactored out some now-duplicated code into a 'process_common.rs'
Made some changes to address @alexcrichton's comments. I don't like the getters I had to add to |
Oh yeah we definitely prefer to bind to the "true nature" of a platform where possible. For example we don't use file descriptors on Windows but rather use |
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.
Looking good, thanks!
I think I'm convinced though that we may want to start out with src/libstd/sys/fuchsia
rather than continue to bolt onto the existing #[cfg(unix)]
category. With functionality like exec
not existing and file descriptors being a shim it makes me think that we may wish to stick to a separate body of code. I'd imagine that over time if we continue to add to sys/unix
that it'll tangle up the existing code quite a bit and not end up sharing much in the long run?
cc @brson, do you have thoughts?
} else { | ||
unsafe { | ||
mx_cvt(mx_handle_close(self.handle))?; | ||
launchpad_destroy(self.launchpad); |
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.
If this is a "proper handle" as opposed to a pid, it may be best to do this in a Drop
implementation (like Windows) perhaps?
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.
Right, good idea
mx_cvt(mx_object_get_info(self.handle, MX_INFO_PROCESS, | ||
&mut proc_info as *mut _ as *mut libc::c_void, | ||
mem::size_of::<mx_info_process_t>(), &mut actual, | ||
&mut avail))?; |
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.
We can likely remove the Option<ExitStatus>
in this Process
by deferring destruction until Drop
? (similar to Windows)
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.
It took me a while to grok this statement. I'll play around with it and see where I get.
Generally looks good to me (I scanned through the code but didn't go through it with a fine-toothed comb). I agree that it would probably be cleaner to separate out the fuchia stuff from the generic Unix mechanisms. |
Alright, I'll make a |
This plan sounds good to me! |
@tedsta yeah that's fine by me, let's go ahead and land the process changes with the organization you've got in this PR, and then we can in follow up PRs move everything to |
…y launchpads and close handles in Drop impls rather than manually
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.
Just a few minor comments, but otherwise looks good to me!
#[cfg(not(target_os="fuchsia"))] | ||
pub fn get_gid(&self) -> Option<gid_t> { | ||
self.gid | ||
} |
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.
These are #[cfg]'d out for lints I think, right? In that case could these just be tagged with #[allow(dead_code)]
?
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.
Right. Done.
@@ -164,6 +171,19 @@ pub fn cvt_r<T, F>(mut f: F) -> io::Result<T> | |||
} | |||
} | |||
|
|||
#[cfg(target_os = "fuchsia")] | |||
pub fn mx_cvt<T>(t: T) -> io::Result<T> where T: TryInto<mx_status_t>+Copy { |
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.
I think this is only used in the fuchsia process module, right? If so could this be moved into there for now? When we extract to sys/fuchsia
we can put in src/fuchsia/mod.rs
likely.
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.
Right. Done.
&mut job_copy as *mut mx_handle_t))?; | ||
// Create a launchpad | ||
mx_cvt(launchpad_create(job_copy, self.get_argv()[0], | ||
&mut launchpad as *mut *mut launchpad_t))?; |
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.
&mut launchpad.0
I think here could avoid the as
cast
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.
launchpad
is actually a regular *mut launchpad_t
. It get's Copy
ed as LaunchpadDestructor.0
. Should "move" it into the LaunchpadDestructor
and s/LaunchpadDestructor/Launchpad
instead?
// Duplicate the job handle | ||
let mut job_copy: mx_handle_t = MX_HANDLE_INVALID; | ||
mx_cvt(mx_handle_duplicate(job_handle, MX_RIGHT_SAME_RIGHTS, | ||
&mut job_copy as *mut mx_handle_t))?; |
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.
I think the as
cast here is fine to elide
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.
Done
@bors: r+ |
📌 Commit e1b752b has been approved by |
Fuchsia support for std::process via liblaunchpad. Now we can launch processes on Fuchsia via the Rust standard library! ... Mostly. Right now, ~5% of the time, reading the stdout/stderr off the pipes will fail. Some Magenta kernel people think it's probably a bug in Magenta's pipes. I wrote a unit test that demonstrates the issue in C, which I was told will expedite a fix. https://fuchsia-review.googlesource.com/#/c/15628/ Hopefully this can get merged once the issue is fixed :) @raphlinus
Now we can launch processes on Fuchsia via the Rust standard library! ... Mostly.
Right now, ~5% of the time, reading the stdout/stderr off the pipes will fail. Some Magenta kernel people think it's probably a bug in Magenta's pipes. I wrote a unit test that demonstrates the issue in C, which I was told will expedite a fix. https://fuchsia-review.googlesource.com/#/c/15628/
Hopefully this can get merged once the issue is fixed :)
@raphlinus