Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions library/std/src/os/wasi/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,116 +6,121 @@
#![allow(dead_code, unused)]

use crate::os::wasi::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
use crate::process;
use crate::sys::{AsInner, FromInner, IntoInner};
use crate::{process, sys};

#[stable(feature = "process_extensions", since = "1.2.0")]
impl FromRawFd for process::Stdio {
#[inline]
unsafe fn from_raw_fd(fd: RawFd) -> process::Stdio {
unimplemented!()
let fd = unsafe { sys::fd::FileDesc::from_raw_fd(fd) };
let io = sys::process::Stdio::Fd(fd);
process::Stdio::from_inner(io)
}
}

#[stable(feature = "io_safety", since = "1.63.0")]
impl From<OwnedFd> for process::Stdio {
#[inline]
fn from(fd: OwnedFd) -> process::Stdio {
unimplemented!()
let fd = sys::fd::FileDesc::from_inner(fd);
let io = sys::process::Stdio::Fd(fd);
process::Stdio::from_inner(io)
}
}

#[stable(feature = "process_extensions", since = "1.2.0")]
impl AsRawFd for process::ChildStdin {
#[inline]
fn as_raw_fd(&self) -> RawFd {
unimplemented!()
self.as_inner().as_raw_fd()
}
}

#[stable(feature = "process_extensions", since = "1.2.0")]
impl AsRawFd for process::ChildStdout {
#[inline]
fn as_raw_fd(&self) -> RawFd {
unimplemented!()
self.as_inner().as_raw_fd()
}
}

#[stable(feature = "process_extensions", since = "1.2.0")]
impl AsRawFd for process::ChildStderr {
#[inline]
fn as_raw_fd(&self) -> RawFd {
unimplemented!()
self.as_inner().as_raw_fd()
}
}

#[stable(feature = "into_raw_os", since = "1.4.0")]
impl IntoRawFd for process::ChildStdin {
#[inline]
fn into_raw_fd(self) -> RawFd {
unimplemented!()
self.into_inner().into_raw_fd()
}
}

#[stable(feature = "into_raw_os", since = "1.4.0")]
impl IntoRawFd for process::ChildStdout {
#[inline]
fn into_raw_fd(self) -> RawFd {
unimplemented!()
self.into_inner().into_raw_fd()
}
}

#[stable(feature = "into_raw_os", since = "1.4.0")]
impl IntoRawFd for process::ChildStderr {
#[inline]
fn into_raw_fd(self) -> RawFd {
unimplemented!()
self.into_inner().into_raw_fd()
}
}

#[stable(feature = "io_safety", since = "1.63.0")]
impl AsFd for crate::process::ChildStdin {
#[inline]
fn as_fd(&self) -> BorrowedFd<'_> {
unimplemented!()
self.as_inner().as_fd()
}
}

#[stable(feature = "io_safety", since = "1.63.0")]
impl From<crate::process::ChildStdin> for OwnedFd {
#[inline]
fn from(child_stdin: crate::process::ChildStdin) -> OwnedFd {
unimplemented!()
child_stdin.into_inner().into_inner()
}
}

#[stable(feature = "io_safety", since = "1.63.0")]
impl AsFd for crate::process::ChildStdout {
#[inline]
fn as_fd(&self) -> BorrowedFd<'_> {
unimplemented!()
self.as_inner().as_fd()
}
}

#[stable(feature = "io_safety", since = "1.63.0")]
impl From<crate::process::ChildStdout> for OwnedFd {
#[inline]
fn from(child_stdout: crate::process::ChildStdout) -> OwnedFd {
unimplemented!()
child_stdout.into_inner().into_inner()
}
}

#[stable(feature = "io_safety", since = "1.63.0")]
impl AsFd for crate::process::ChildStderr {
#[inline]
fn as_fd(&self) -> BorrowedFd<'_> {
unimplemented!()
self.as_inner().as_fd()
}
}

#[stable(feature = "io_safety", since = "1.63.0")]
impl From<crate::process::ChildStderr> for OwnedFd {
#[inline]
fn from(child_stderr: crate::process::ChildStderr) -> OwnedFd {
unimplemented!()
child_stderr.into_inner().into_inner()
}
}
50 changes: 50 additions & 0 deletions library/std/tests/wasix_process_fds.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#![cfg(all(target_os = "wasi", target_vendor = "wasmer"))]

use std::env;
use std::os::wasi::io::{AsFd, AsRawFd, FromRawFd, IntoRawFd, OwnedFd};
use std::process::{Command, Stdio};

fn assert_borrowed_fd<T: AsFd + AsRawFd>(stream: &T) {
assert_eq!(stream.as_raw_fd(), stream.as_fd().as_raw_fd());
}

fn stdio_through_raw_fd<T: IntoRawFd>(stream: T) -> Stdio {
let fd = stream.into_raw_fd();
unsafe { Stdio::from_raw_fd(fd) }
}

fn stdio_through_owned_fd<T: Into<OwnedFd>>(stream: T) -> Stdio {
Stdio::from(stream.into())
}

#[test]
fn child_stream_fd_conversions_transfer_ownership() {
const CHILD: &str = "RUST_STD_WASIX_PROCESS_FD_CHILD";
if env::var_os(CHILD).is_some() {
return;
}

let mut child = Command::new(env::current_exe().unwrap())
.arg("--exact")
.arg("child_stream_fd_conversions_transfer_ownership")
.env(CHILD, "1")
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()
.unwrap();

let stdin = child.stdin.take().unwrap();
assert_borrowed_fd(&stdin);
drop(stdio_through_raw_fd(stdin));

let stdout = child.stdout.take().unwrap();
assert_borrowed_fd(&stdout);
drop(stdio_through_owned_fd(stdout));

let stderr = child.stderr.take().unwrap();
assert_borrowed_fd(&stderr);
drop(stdio_through_owned_fd(stderr));

assert!(child.wait().unwrap().success());
}
Loading