Skip to content
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

std: move process implementations to sys #136929

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
1 change: 1 addition & 0 deletions library/std/src/sys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub mod io;
pub mod net;
pub mod os_str;
pub mod path;
pub mod process;
pub mod random;
pub mod stdio;
pub mod sync;
Expand Down
2 changes: 0 additions & 2 deletions library/std/src/sys/pal/hermit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ pub mod futex;
pub mod os;
#[path = "../unsupported/pipe.rs"]
pub mod pipe;
#[path = "../unsupported/process.rs"]
pub mod process;
pub mod thread;
pub mod time;

Expand Down
2 changes: 0 additions & 2 deletions library/std/src/sys/pal/sgx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ mod libunwind_integration;
pub mod os;
#[path = "../unsupported/pipe.rs"]
pub mod pipe;
#[path = "../unsupported/process.rs"]
pub mod process;
pub mod thread;
pub mod thread_parking;
pub mod time;
Expand Down
2 changes: 0 additions & 2 deletions library/std/src/sys/pal/solid/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ pub(crate) mod error;
pub mod os;
#[path = "../unsupported/pipe.rs"]
pub mod pipe;
#[path = "../unsupported/process.rs"]
pub mod process;
pub use self::itron::{thread, thread_parking};
pub mod time;

Expand Down
2 changes: 0 additions & 2 deletions library/std/src/sys/pal/teeos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ pub mod env;
pub mod os;
#[path = "../unsupported/pipe.rs"]
pub mod pipe;
#[path = "../unsupported/process.rs"]
pub mod process;
pub mod thread;
#[allow(non_upper_case_globals)]
#[path = "../unix/time.rs"]
Expand Down
1 change: 0 additions & 1 deletion library/std/src/sys/pal/uefi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ pub mod helpers;
pub mod os;
#[path = "../unsupported/pipe.rs"]
pub mod pipe;
pub mod process;
pub mod thread;
pub mod time;

Expand Down
5 changes: 3 additions & 2 deletions library/std/src/sys/pal/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ pub mod weak;
pub mod args;
pub mod env;
pub mod fd;
#[cfg(target_os = "fuchsia")]
pub mod fuchsia;
pub mod futex;
#[cfg(any(target_os = "linux", target_os = "android"))]
pub mod kernel_copy;
#[cfg(target_os = "linux")]
pub mod linux;
pub mod os;
pub mod pipe;
pub mod process;
pub mod stack_overflow;
pub mod sync;
pub mod thread;
Expand Down Expand Up @@ -419,7 +420,7 @@ cfg_if::cfg_if! {
}

#[cfg(any(target_os = "espidf", target_os = "horizon", target_os = "vita", target_os = "nuttx"))]
mod unsupported {
pub mod unsupported {
use crate::io;

pub fn unsupported<T>() -> io::Result<T> {
Expand Down
27 changes: 0 additions & 27 deletions library/std/src/sys/pal/unix/process/mod.rs

This file was deleted.

1 change: 0 additions & 1 deletion library/std/src/sys/pal/unsupported/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pub mod args;
pub mod env;
pub mod os;
pub mod pipe;
pub mod process;
pub mod thread;
pub mod time;

Expand Down
2 changes: 0 additions & 2 deletions library/std/src/sys/pal/wasi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ pub mod futex;
pub mod os;
#[path = "../unsupported/pipe.rs"]
pub mod pipe;
#[path = "../unsupported/process.rs"]
pub mod process;
pub mod thread;
pub mod time;

Expand Down
2 changes: 0 additions & 2 deletions library/std/src/sys/pal/wasip2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ pub mod futex;
pub mod os;
#[path = "../unsupported/pipe.rs"]
pub mod pipe;
#[path = "../unsupported/process.rs"]
pub mod process;
#[path = "../wasi/thread.rs"]
pub mod thread;
#[path = "../wasi/time.rs"]
Expand Down
2 changes: 0 additions & 2 deletions library/std/src/sys/pal/wasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ pub mod env;
pub mod os;
#[path = "../unsupported/pipe.rs"]
pub mod pipe;
#[path = "../unsupported/process.rs"]
pub mod process;
#[path = "../unsupported/time.rs"]
pub mod time;

Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys/pal/windows/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
#[cfg(test)]
mod tests;

use super::ensure_no_nuls;
use super::os::current_exe;
use crate::ffi::{OsStr, OsString};
use crate::num::NonZero;
use crate::os::windows::prelude::*;
use crate::path::{Path, PathBuf};
use crate::sys::path::get_long_path;
use crate::sys::process::ensure_no_nuls;
use crate::sys::{c, to_u16s};
use crate::sys_common::AsInner;
use crate::sys_common::wstr::WStrUnits;
Expand Down
9 changes: 8 additions & 1 deletion library/std/src/sys/pal/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ pub mod futex;
pub mod handle;
pub mod os;
pub mod pipe;
pub mod process;
pub mod thread;
pub mod time;
cfg_if::cfg_if! {
Expand Down Expand Up @@ -287,6 +286,14 @@ pub fn truncate_utf16_at_nul(v: &[u16]) -> &[u16] {
}
}

pub fn ensure_no_nuls<T: AsRef<OsStr>>(s: T) -> crate::io::Result<T> {
if s.as_ref().encode_wide().any(|b| b == 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, are we using this for soundness anywhere? The AsRef<OsStr> conversion could e.g. return different results spuriously which would be a problem if we are.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Luckily that's not the case, we only use this with trusted types. But I agree that this isn't great, I'll try to find a better solution in another PR.

Err(crate::io::const_error!(ErrorKind::InvalidInput, "nul byte found in provided data"))
} else {
Ok(s)
}
}

pub trait IsZero {
fn is_zero(&self) -> bool;
}
Expand Down
2 changes: 0 additions & 2 deletions library/std/src/sys/pal/xous/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ pub mod env;
pub mod os;
#[path = "../unsupported/pipe.rs"]
pub mod pipe;
#[path = "../unsupported/process.rs"]
pub mod process;
pub mod thread;
pub mod time;

Expand Down
2 changes: 0 additions & 2 deletions library/std/src/sys/pal/zkvm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ pub mod env;
pub mod os;
#[path = "../unsupported/pipe.rs"]
pub mod pipe;
#[path = "../unsupported/process.rs"]
pub mod process;
#[path = "../unsupported/thread.rs"]
pub mod thread;
#[path = "../unsupported/time.rs"]
Expand Down
19 changes: 19 additions & 0 deletions library/std/src/sys/process/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
cfg_if::cfg_if! {
if #[cfg(target_family = "unix")] {
mod unix;
use unix as imp;
} else if #[cfg(target_os = "windows")] {
mod windows;
use windows as imp;
} else if #[cfg(target_os = "uefi")] {
mod uefi;
use uefi as imp;
} else {
mod unsupported;
use unsupported as imp;
}
}

pub use imp::{
Command, CommandArgs, EnvKey, ExitCode, ExitStatus, ExitStatusError, Process, Stdio, StdioPipes,
};
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use r_efi::protocols::simple_text_output;

use super::helpers;
use crate::collections::BTreeMap;
pub use crate::ffi::OsString as EnvKey;
use crate::ffi::{OsStr, OsString};
use crate::num::{NonZero, NonZeroI32};
use crate::path::Path;
use crate::sys::fs::File;
use crate::sys::pal::helpers;
use crate::sys::pal::os::error_string;
use crate::sys::pipe::AnonPipe;
use crate::sys::unsupported;
use crate::sys_common::process::{CommandEnv, CommandEnvs};
Expand Down Expand Up @@ -225,7 +226,7 @@ impl ExitStatus {

impl fmt::Display for ExitStatus {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let err_str = super::os::error_string(self.0.as_usize());
let err_str = error_string(self.0.as_usize());
write!(f, "{}", err_str)
}
}
Expand All @@ -241,7 +242,7 @@ pub struct ExitStatusError(r_efi::efi::Status);

impl fmt::Debug for ExitStatusError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let err_str = super::os::error_string(self.0.as_usize());
let err_str = error_string(self.0.as_usize());
write!(f, "{}", err_str)
}
}
Expand Down Expand Up @@ -335,15 +336,14 @@ impl<'a> fmt::Debug for CommandArgs<'a> {
mod uefi_command_internal {
use r_efi::protocols::{loaded_image, simple_text_output};

use super::super::helpers;
use crate::ffi::{OsStr, OsString};
use crate::io::{self, const_error};
use crate::mem::MaybeUninit;
use crate::os::uefi::env::{boot_services, image_handle, system_table};
use crate::os::uefi::ffi::{OsStrExt, OsStringExt};
use crate::ptr::NonNull;
use crate::slice;
use crate::sys::pal::uefi::helpers::OwnedTable;
use crate::sys::pal::helpers::{self, OwnedTable};
use crate::sys_common::wstr::WStrUnits;

pub struct Image {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ cfg_if::cfg_if! {

let bit = (signum - 1) as usize;
if set.is_null() || bit >= (8 * size_of::<sigset_t>()) {
crate::sys::pal::unix::os::set_errno(libc::EINVAL);
crate::sys::pal::os::set_errno(libc::EINVAL);
return -1;
}
let raw = slice::from_raw_parts_mut(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use libc::{c_int, size_t};

use super::common::*;
use crate::num::NonZero;
use crate::sys::process::process_common::*;
use crate::sys::process::zircon::{Handle, zx_handle_t};
use crate::sys::pal::fuchsia::*;
use crate::{fmt, io, mem, ptr};

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -58,8 +58,6 @@ impl Command {
stdio: ChildPipes,
maybe_envp: Option<&CStringArray>,
) -> io::Result<zx_handle_t> {
use crate::sys::process::zircon::*;

let envp = match maybe_envp {
// None means to clone the current environment, which is done in the
// flags below.
Expand Down Expand Up @@ -152,8 +150,6 @@ impl Process {
}

pub fn kill(&mut self) -> io::Result<()> {
use crate::sys::process::zircon::*;

unsafe {
zx_cvt(zx_task_kill(self.handle.raw()))?;
}
Expand All @@ -162,8 +158,6 @@ impl Process {
}

pub fn wait(&mut self) -> io::Result<ExitStatus> {
use crate::sys::process::zircon::*;

let mut proc_info: zx_info_process_t = Default::default();
let mut actual: size_t = 0;
let mut avail: size_t = 0;
Expand Down Expand Up @@ -194,8 +188,6 @@ impl Process {
}

pub fn try_wait(&mut self) -> io::Result<Option<ExitStatus>> {
use crate::sys::process::zircon::*;

let mut proc_info: zx_info_process_t = Default::default();
let mut actual: size_t = 0;
let mut avail: size_t = 0;
Expand Down Expand Up @@ -251,7 +243,7 @@ impl ExitStatus {
None
}

// FIXME: The actually-Unix implementation in process_unix.rs uses WSTOPSIG, WCOREDUMP et al.
// FIXME: The actually-Unix implementation in unix.rs uses WSTOPSIG, WCOREDUMP et al.
// I infer from the implementation of `success`, `code` and `signal` above that these are not
// available on Fuchsia.
//
Expand Down
23 changes: 23 additions & 0 deletions library/std/src/sys/process/unix/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#[cfg_attr(any(target_os = "espidf", target_os = "horizon", target_os = "nuttx"), allow(unused))]
mod common;

cfg_if::cfg_if! {
if #[cfg(target_os = "fuchsia")] {
mod fuchsia;
use fuchsia as imp;
} else if #[cfg(target_os = "vxworks")] {
mod vxworks;
use vxworks as imp;
} else if #[cfg(any(target_os = "espidf", target_os = "horizon", target_os = "vita", target_os = "nuttx"))] {
mod unsupported;
use unsupported as imp;
} else {
mod unix;
use unix as imp;
}
}

pub use imp::{ExitStatus, ExitStatusError, Process};

pub use self::common::{Command, CommandArgs, ExitCode, Stdio, StdioPipes};
pub use crate::ffi::OsString as EnvKey;
Loading
Loading