about summary refs log tree commit diff
path: root/library/std/src/sys
diff options
context:
space:
mode:
authorjoboet <jonasboettiger@icloud.com>2025-02-12 16:26:34 +0100
committerjoboet <jonasboettiger@icloud.com>2025-03-22 12:42:34 +0100
commit89f85cbfa7e508e55f2f05c00356b6d430c55c4e (patch)
tree5bc245e760b7f82273237ae0c5285fc1d09db1a6 /library/std/src/sys
parentdb687889a5833381b8b02738a1af93a09a97ba16 (diff)
downloadrust-89f85cbfa7e508e55f2f05c00356b6d430c55c4e.tar.gz
rust-89f85cbfa7e508e55f2f05c00356b6d430c55c4e.zip
std: move process implementations to `sys`
As per #117276, this moves the implementations of `Process` and friends out of the `pal` module and into the `sys` module, removing quite a lot of error-prone `#[path]` imports in the process (hah, get it ;-)). I've also made the `zircon` module a dedicated submodule of `pal::unix`, hopefully we can move some other definitions there as well (they are currently quite a lot of duplications in `sys`). Also, the `ensure_no_nuls` function on Windows now lives in `sys::pal::windows` – it's not specific to processes and shared by the argument implementation.
Diffstat (limited to 'library/std/src/sys')
-rw-r--r--library/std/src/sys/mod.rs1
-rw-r--r--library/std/src/sys/pal/hermit/mod.rs2
-rw-r--r--library/std/src/sys/pal/sgx/mod.rs2
-rw-r--r--library/std/src/sys/pal/solid/mod.rs2
-rw-r--r--library/std/src/sys/pal/teeos/mod.rs2
-rw-r--r--library/std/src/sys/pal/uefi/mod.rs1
-rw-r--r--library/std/src/sys/pal/unix/fuchsia.rs (renamed from library/std/src/sys/pal/unix/process/zircon.rs)0
-rw-r--r--library/std/src/sys/pal/unix/mod.rs5
-rw-r--r--library/std/src/sys/pal/unix/process/mod.rs27
-rw-r--r--library/std/src/sys/pal/unsupported/mod.rs1
-rw-r--r--library/std/src/sys/pal/wasi/mod.rs2
-rw-r--r--library/std/src/sys/pal/wasip2/mod.rs2
-rw-r--r--library/std/src/sys/pal/wasm/mod.rs2
-rw-r--r--library/std/src/sys/pal/windows/args.rs2
-rw-r--r--library/std/src/sys/pal/windows/mod.rs9
-rw-r--r--library/std/src/sys/pal/xous/mod.rs2
-rw-r--r--library/std/src/sys/pal/zkvm/mod.rs2
-rw-r--r--library/std/src/sys/process/mod.rs19
-rw-r--r--library/std/src/sys/process/uefi.rs (renamed from library/std/src/sys/pal/uefi/process.rs)10
-rw-r--r--library/std/src/sys/process/unix/common.rs (renamed from library/std/src/sys/pal/unix/process/process_common.rs)2
-rw-r--r--library/std/src/sys/process/unix/common/tests.rs (renamed from library/std/src/sys/pal/unix/process/process_common/tests.rs)0
-rw-r--r--library/std/src/sys/process/unix/fuchsia.rs (renamed from library/std/src/sys/pal/unix/process/process_fuchsia.rs)14
-rw-r--r--library/std/src/sys/process/unix/mod.rs23
-rw-r--r--library/std/src/sys/process/unix/unix.rs (renamed from library/std/src/sys/pal/unix/process/process_unix.rs)18
-rw-r--r--library/std/src/sys/process/unix/unix/tests.rs (renamed from library/std/src/sys/pal/unix/process/process_unix/tests.rs)0
-rw-r--r--library/std/src/sys/process/unix/unsupported.rs (renamed from library/std/src/sys/pal/unix/process/process_unsupported.rs)4
-rw-r--r--library/std/src/sys/process/unix/unsupported/wait_status.rs (renamed from library/std/src/sys/pal/unix/process/process_unsupported/wait_status.rs)7
-rw-r--r--library/std/src/sys/process/unix/unsupported/wait_status/tests.rs (renamed from library/std/src/sys/pal/unix/process/process_unsupported/wait_status/tests.rs)2
-rw-r--r--library/std/src/sys/process/unix/vxworks.rs (renamed from library/std/src/sys/pal/unix/process/process_vxworks.rs)6
-rw-r--r--library/std/src/sys/process/unsupported.rs (renamed from library/std/src/sys/pal/unsupported/process.rs)0
-rw-r--r--library/std/src/sys/process/windows.rs (renamed from library/std/src/sys/pal/windows/process.rs)25
-rw-r--r--library/std/src/sys/process/windows/tests.rs (renamed from library/std/src/sys/pal/windows/process/tests.rs)0
32 files changed, 90 insertions, 104 deletions
diff --git a/library/std/src/sys/mod.rs b/library/std/src/sys/mod.rs
index 09677b9d642..f0cfb9b2773 100644
--- a/library/std/src/sys/mod.rs
+++ b/library/std/src/sys/mod.rs
@@ -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;
diff --git a/library/std/src/sys/pal/hermit/mod.rs b/library/std/src/sys/pal/hermit/mod.rs
index 608245bd430..67eab96fa40 100644
--- a/library/std/src/sys/pal/hermit/mod.rs
+++ b/library/std/src/sys/pal/hermit/mod.rs
@@ -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;
 
diff --git a/library/std/src/sys/pal/sgx/mod.rs b/library/std/src/sys/pal/sgx/mod.rs
index bb419c2530e..fe43cfd2caf 100644
--- a/library/std/src/sys/pal/sgx/mod.rs
+++ b/library/std/src/sys/pal/sgx/mod.rs
@@ -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;
diff --git a/library/std/src/sys/pal/solid/mod.rs b/library/std/src/sys/pal/solid/mod.rs
index e4a61fdcfe3..22052a168fd 100644
--- a/library/std/src/sys/pal/solid/mod.rs
+++ b/library/std/src/sys/pal/solid/mod.rs
@@ -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;
 
diff --git a/library/std/src/sys/pal/teeos/mod.rs b/library/std/src/sys/pal/teeos/mod.rs
index 41b25121592..c1921a2f40d 100644
--- a/library/std/src/sys/pal/teeos/mod.rs
+++ b/library/std/src/sys/pal/teeos/mod.rs
@@ -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"]
diff --git a/library/std/src/sys/pal/uefi/mod.rs b/library/std/src/sys/pal/uefi/mod.rs
index 714dc392688..fc12ec63b5c 100644
--- a/library/std/src/sys/pal/uefi/mod.rs
+++ b/library/std/src/sys/pal/uefi/mod.rs
@@ -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;
 
diff --git a/library/std/src/sys/pal/unix/process/zircon.rs b/library/std/src/sys/pal/unix/fuchsia.rs
index 7932bd26d76..7932bd26d76 100644
--- a/library/std/src/sys/pal/unix/process/zircon.rs
+++ b/library/std/src/sys/pal/unix/fuchsia.rs
diff --git a/library/std/src/sys/pal/unix/mod.rs b/library/std/src/sys/pal/unix/mod.rs
index e2e537b7bd3..413fda1d8d8 100644
--- a/library/std/src/sys/pal/unix/mod.rs
+++ b/library/std/src/sys/pal/unix/mod.rs
@@ -9,6 +9,8 @@ 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;
@@ -16,7 +18,6 @@ pub mod kernel_copy;
 pub mod linux;
 pub mod os;
 pub mod pipe;
-pub mod process;
 pub mod stack_overflow;
 pub mod sync;
 pub mod thread;
@@ -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> {
diff --git a/library/std/src/sys/pal/unix/process/mod.rs b/library/std/src/sys/pal/unix/process/mod.rs
deleted file mode 100644
index 2751d51c44d..00000000000
--- a/library/std/src/sys/pal/unix/process/mod.rs
+++ /dev/null
@@ -1,27 +0,0 @@
-pub use self::process_common::{Command, CommandArgs, ExitCode, Stdio, StdioPipes};
-pub use self::process_inner::{ExitStatus, ExitStatusError, Process};
-pub use crate::ffi::OsString as EnvKey;
-
-#[cfg_attr(any(target_os = "espidf", target_os = "horizon", target_os = "nuttx"), allow(unused))]
-mod process_common;
-
-#[cfg(any(target_os = "espidf", target_os = "horizon", target_os = "vita", target_os = "nuttx"))]
-mod process_unsupported;
-
-cfg_if::cfg_if! {
-    if #[cfg(target_os = "fuchsia")] {
-        #[path = "process_fuchsia.rs"]
-        mod process_inner;
-        mod zircon;
-    } else if #[cfg(target_os = "vxworks")] {
-        #[path = "process_vxworks.rs"]
-        mod process_inner;
-    } else if #[cfg(any(target_os = "espidf", target_os = "horizon", target_os = "vita", target_os = "nuttx"))] {
-        mod process_inner {
-            pub use super::process_unsupported::*;
-        }
-    } else {
-        #[path = "process_unix.rs"]
-        mod process_inner;
-    }
-}
diff --git a/library/std/src/sys/pal/unsupported/mod.rs b/library/std/src/sys/pal/unsupported/mod.rs
index bcea699f3b2..38838b915b5 100644
--- a/library/std/src/sys/pal/unsupported/mod.rs
+++ b/library/std/src/sys/pal/unsupported/mod.rs
@@ -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;
 
diff --git a/library/std/src/sys/pal/wasi/mod.rs b/library/std/src/sys/pal/wasi/mod.rs
index c89832857dd..cdd613f76b6 100644
--- a/library/std/src/sys/pal/wasi/mod.rs
+++ b/library/std/src/sys/pal/wasi/mod.rs
@@ -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;
 
diff --git a/library/std/src/sys/pal/wasip2/mod.rs b/library/std/src/sys/pal/wasip2/mod.rs
index 3008ba88753..6ac28f1bf4f 100644
--- a/library/std/src/sys/pal/wasip2/mod.rs
+++ b/library/std/src/sys/pal/wasip2/mod.rs
@@ -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"]
diff --git a/library/std/src/sys/pal/wasm/mod.rs b/library/std/src/sys/pal/wasm/mod.rs
index 175fe75357f..8d39b70d039 100644
--- a/library/std/src/sys/pal/wasm/mod.rs
+++ b/library/std/src/sys/pal/wasm/mod.rs
@@ -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;
 
diff --git a/library/std/src/sys/pal/windows/args.rs b/library/std/src/sys/pal/windows/args.rs
index 3447a0157e4..d973743639a 100644
--- a/library/std/src/sys/pal/windows/args.rs
+++ b/library/std/src/sys/pal/windows/args.rs
@@ -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;
diff --git a/library/std/src/sys/pal/windows/mod.rs b/library/std/src/sys/pal/windows/mod.rs
index 6eb68f3a3bc..bdf0cc2c59c 100644
--- a/library/std/src/sys/pal/windows/mod.rs
+++ b/library/std/src/sys/pal/windows/mod.rs
@@ -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! {
@@ -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) {
+        Err(crate::io::const_error!(ErrorKind::InvalidInput, "nul byte found in provided data"))
+    } else {
+        Ok(s)
+    }
+}
+
 pub trait IsZero {
     fn is_zero(&self) -> bool;
 }
diff --git a/library/std/src/sys/pal/xous/mod.rs b/library/std/src/sys/pal/xous/mod.rs
index 7d823012ad1..58926e2beb1 100644
--- a/library/std/src/sys/pal/xous/mod.rs
+++ b/library/std/src/sys/pal/xous/mod.rs
@@ -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;
 
diff --git a/library/std/src/sys/pal/zkvm/mod.rs b/library/std/src/sys/pal/zkvm/mod.rs
index 499e2787201..4659dad16e8 100644
--- a/library/std/src/sys/pal/zkvm/mod.rs
+++ b/library/std/src/sys/pal/zkvm/mod.rs
@@ -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"]
diff --git a/library/std/src/sys/process/mod.rs b/library/std/src/sys/process/mod.rs
new file mode 100644
index 00000000000..92cfac7f47c
--- /dev/null
+++ b/library/std/src/sys/process/mod.rs
@@ -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,
+};
diff --git a/library/std/src/sys/pal/uefi/process.rs b/library/std/src/sys/process/uefi.rs
index 1203d51e531..b46418ae9bb 100644
--- a/library/std/src/sys/pal/uefi/process.rs
+++ b/library/std/src/sys/process/uefi.rs
@@ -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};
@@ -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)
     }
 }
@@ -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)
     }
 }
@@ -335,7 +336,6 @@ 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;
@@ -343,7 +343,7 @@ mod uefi_command_internal {
     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 {
diff --git a/library/std/src/sys/pal/unix/process/process_common.rs b/library/std/src/sys/process/unix/common.rs
index a1c747c8df4..8bc17f31491 100644
--- a/library/std/src/sys/pal/unix/process/process_common.rs
+++ b/library/std/src/sys/process/unix/common.rs
@@ -54,7 +54,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(
diff --git a/library/std/src/sys/pal/unix/process/process_common/tests.rs b/library/std/src/sys/process/unix/common/tests.rs
index e5c8dd6e341..e5c8dd6e341 100644
--- a/library/std/src/sys/pal/unix/process/process_common/tests.rs
+++ b/library/std/src/sys/process/unix/common/tests.rs
diff --git a/library/std/src/sys/pal/unix/process/process_fuchsia.rs b/library/std/src/sys/process/unix/fuchsia.rs
index 05c9ace470e..0de32ecffd4 100644
--- a/library/std/src/sys/pal/unix/process/process_fuchsia.rs
+++ b/library/std/src/sys/process/unix/fuchsia.rs
@@ -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};
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -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.
@@ -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()))?;
         }
@@ -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;
@@ -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;
@@ -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.
     //
diff --git a/library/std/src/sys/process/unix/mod.rs b/library/std/src/sys/process/unix/mod.rs
new file mode 100644
index 00000000000..2e8b38f7de1
--- /dev/null
+++ b/library/std/src/sys/process/unix/mod.rs
@@ -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;
diff --git a/library/std/src/sys/pal/unix/process/process_unix.rs b/library/std/src/sys/process/unix/unix.rs
index f19512233d8..42542f81b65 100644
--- a/library/std/src/sys/pal/unix/process/process_unix.rs
+++ b/library/std/src/sys/process/unix/unix.rs
@@ -10,12 +10,12 @@ use libc::{c_int, pid_t};
 )))]
 use libc::{gid_t, uid_t};
 
+use super::common::*;
 use crate::io::{self, Error, ErrorKind};
 use crate::num::NonZero;
 use crate::sys::cvt;
 #[cfg(target_os = "linux")]
-use crate::sys::pal::unix::linux::pidfd::PidFd;
-use crate::sys::process::process_common::*;
+use crate::sys::pal::linux::pidfd::PidFd;
 use crate::{fmt, mem, sys};
 
 cfg_if::cfg_if! {
@@ -1051,7 +1051,7 @@ impl ExitStatus {
         // true on all actual versions of Unix, is widely assumed, and is specified in SuS
         // https://pubs.opengroup.org/onlinepubs/9699919799/functions/wait.html. If it is not
         // true for a platform pretending to be Unix, the tests (our doctests, and also
-        // process_unix/tests.rs) will spot it. `ExitStatusError::code` assumes this too.
+        // unix/tests.rs) will spot it. `ExitStatusError::code` assumes this too.
         match NonZero::try_from(self.0) {
             /* was nonzero */ Ok(failure) => Err(ExitStatusError(failure)),
             /* was zero, couldn't convert */ Err(_) => Ok(()),
@@ -1232,10 +1232,9 @@ impl ExitStatusError {
 
 #[cfg(target_os = "linux")]
 mod linux_child_ext {
-
+    use crate::io::ErrorKind;
     use crate::os::linux::process as os;
-    use crate::sys::pal::unix::ErrorKind;
-    use crate::sys::pal::unix::linux::pidfd as imp;
+    use crate::sys::pal::linux::pidfd as imp;
     use crate::sys_common::FromInner;
     use crate::{io, mem};
 
@@ -1261,10 +1260,9 @@ mod linux_child_ext {
 }
 
 #[cfg(test)]
-#[path = "process_unix/tests.rs"]
 mod tests;
 
-// See [`process_unsupported_wait_status::compare_with_linux`];
+// See [`unsupported_wait_status::compare_with_linux`];
 #[cfg(all(test, target_os = "linux"))]
-#[path = "process_unsupported/wait_status.rs"]
-mod process_unsupported_wait_status;
+#[path = "unsupported/wait_status.rs"]
+mod unsupported_wait_status;
diff --git a/library/std/src/sys/pal/unix/process/process_unix/tests.rs b/library/std/src/sys/process/unix/unix/tests.rs
index f4d6ac6b4e3..f4d6ac6b4e3 100644
--- a/library/std/src/sys/pal/unix/process/process_unix/tests.rs
+++ b/library/std/src/sys/process/unix/unix/tests.rs
diff --git a/library/std/src/sys/pal/unix/process/process_unsupported.rs b/library/std/src/sys/process/unix/unsupported.rs
index c58548835ff..78d270923cf 100644
--- a/library/std/src/sys/pal/unix/process/process_unsupported.rs
+++ b/library/std/src/sys/process/unix/unsupported.rs
@@ -1,9 +1,9 @@
 use libc::{c_int, pid_t};
 
+use super::common::*;
 use crate::io;
 use crate::num::NonZero;
-use crate::sys::pal::unix::unsupported::*;
-use crate::sys::process::process_common::*;
+use crate::sys::pal::unsupported::*;
 
 ////////////////////////////////////////////////////////////////////////////////
 // Command
diff --git a/library/std/src/sys/pal/unix/process/process_unsupported/wait_status.rs b/library/std/src/sys/process/unix/unsupported/wait_status.rs
index f04036bde49..f348d557e4b 100644
--- a/library/std/src/sys/pal/unix/process/process_unsupported/wait_status.rs
+++ b/library/std/src/sys/process/unix/unsupported/wait_status.rs
@@ -7,7 +7,7 @@ use crate::ffi::c_int;
 use crate::fmt;
 use crate::num::NonZero;
 
-/// Emulated wait status for use by `process_unsupported.rs`
+/// Emulated wait status for use by `unsupported.rs`
 ///
 /// Uses the "traditional unix" encoding.  For use on platfors which are `#[cfg(unix)]`
 /// but do not actually support subprocesses at all.
@@ -48,7 +48,7 @@ impl ExitStatus {
         // true on all actual versions of Unix, is widely assumed, and is specified in SuS
         // https://pubs.opengroup.org/onlinepubs/9699919799/functions/wait.html. If it is not
         // true for a platform pretending to be Unix, the tests (our doctests, and also
-        // process_unix/tests.rs) will spot it. `ExitStatusError::code` assumes this too.
+        // unix/tests.rs) will spot it. `ExitStatusError::code` assumes this too.
         match NonZero::try_from(self.wait_status) {
             /* was nonzero */ Ok(failure) => Err(ExitStatusError(failure)),
             /* was zero, couldn't convert */ Err(_) => Ok(()),
@@ -79,5 +79,6 @@ impl ExitStatus {
 }
 
 #[cfg(test)]
-#[path = "wait_status/tests.rs"] // needed because of strange layout of process_unsupported
+#[path = "wait_status/tests.rs"]
+// needed because this module is also imported through #[path] for testing purposes
 mod tests;
diff --git a/library/std/src/sys/pal/unix/process/process_unsupported/wait_status/tests.rs b/library/std/src/sys/process/unix/unsupported/wait_status/tests.rs
index 5132eab10a1..0d9232fac5e 100644
--- a/library/std/src/sys/pal/unix/process/process_unsupported/wait_status/tests.rs
+++ b/library/std/src/sys/process/unix/unsupported/wait_status/tests.rs
@@ -1,4 +1,4 @@
-// Note that tests in this file are run on Linux as well as on platforms using process_unsupported
+// Note that tests in this file are run on Linux as well as on platforms using unsupported
 
 // Test that our emulation exactly matches Linux
 //
diff --git a/library/std/src/sys/pal/unix/process/process_vxworks.rs b/library/std/src/sys/process/unix/vxworks.rs
index e2c1b6a0326..5f1727789a1 100644
--- a/library/std/src/sys/pal/unix/process/process_vxworks.rs
+++ b/library/std/src/sys/process/unix/vxworks.rs
@@ -1,11 +1,11 @@
 #![forbid(unsafe_op_in_unsafe_fn)]
 use libc::{self, RTP_ID, c_char, c_int};
 
+use super::common::*;
 use crate::io::{self, ErrorKind};
 use crate::num::NonZero;
 use crate::sys::cvt;
-use crate::sys::pal::unix::thread;
-use crate::sys::process::process_common::*;
+use crate::sys::pal::thread;
 use crate::{fmt, sys};
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -200,7 +200,7 @@ impl ExitStatus {
         // true on all actual versions of Unix, is widely assumed, and is specified in SuS
         // https://pubs.opengroup.org/onlinepubs/9699919799/functions/wait.html. If it is not
         // true for a platform pretending to be Unix, the tests (our doctests, and also
-        // process_unix/tests.rs) will spot it. `ExitStatusError::code` assumes this too.
+        // unix/tests.rs) will spot it. `ExitStatusError::code` assumes this too.
         match NonZero::try_from(self.0) {
             Ok(failure) => Err(ExitStatusError(failure)),
             Err(_) => Ok(()),
diff --git a/library/std/src/sys/pal/unsupported/process.rs b/library/std/src/sys/process/unsupported.rs
index fee81744f09..fee81744f09 100644
--- a/library/std/src/sys/pal/unsupported/process.rs
+++ b/library/std/src/sys/process/unsupported.rs
diff --git a/library/std/src/sys/pal/windows/process.rs b/library/std/src/sys/process/windows.rs
index 50e4baba607..06c15e08f3f 100644
--- a/library/std/src/sys/pal/windows/process.rs
+++ b/library/std/src/sys/process/windows.rs
@@ -5,11 +5,10 @@ mod tests;
 
 use core::ffi::c_void;
 
-use super::api::{self, WinError};
 use crate::collections::BTreeMap;
 use crate::env::consts::{EXE_EXTENSION, EXE_SUFFIX};
 use crate::ffi::{OsStr, OsString};
-use crate::io::{self, Error, ErrorKind};
+use crate::io::{self, Error};
 use crate::num::NonZero;
 use crate::os::windows::ffi::{OsStrExt, OsStringExt};
 use crate::os::windows::io::{AsHandle, AsRawHandle, BorrowedHandle, FromRawHandle, IntoRawHandle};
@@ -20,6 +19,8 @@ use crate::sys::args::{self, Arg};
 use crate::sys::c::{self, EXIT_FAILURE, EXIT_SUCCESS};
 use crate::sys::fs::{File, OpenOptions};
 use crate::sys::handle::Handle;
+use crate::sys::pal::api::{self, WinError};
+use crate::sys::pal::{ensure_no_nuls, fill_utf16_buf};
 use crate::sys::pipe::{self, AnonPipe};
 use crate::sys::{cvt, path, stdio};
 use crate::sys_common::IntoInner;
@@ -142,14 +143,6 @@ impl AsRef<OsStr> for EnvKey {
     }
 }
 
-pub(crate) fn ensure_no_nuls<T: AsRef<OsStr>>(s: T) -> io::Result<T> {
-    if s.as_ref().encode_wide().any(|b| b == 0) {
-        Err(io::const_error!(ErrorKind::InvalidInput, "nul byte found in provided data"))
-    } else {
-        Ok(s)
-    }
-}
-
 pub struct Command {
     program: OsString,
     args: Vec<Arg>,
@@ -279,7 +272,7 @@ impl Command {
         let is_batch_file = if path::is_verbatim(&program) {
             has_bat_extension(&program[..program.len() - 1])
         } else {
-            super::fill_utf16_buf(
+            fill_utf16_buf(
                 |buffer, size| unsafe {
                     // resolve the path so we can test the final file name.
                     c::GetFullPathNameW(program.as_ptr(), size, buffer, ptr::null_mut())
@@ -521,7 +514,7 @@ where
     // 3 & 4. System paths
     // SAFETY: This uses `fill_utf16_buf` to safely call the OS functions.
     unsafe {
-        if let Ok(Some(path)) = super::fill_utf16_buf(
+        if let Ok(Some(path)) = fill_utf16_buf(
             |buf, size| c::GetSystemDirectoryW(buf, size),
             |buf| exists(PathBuf::from(OsString::from_wide(buf))),
         ) {
@@ -529,7 +522,7 @@ where
         }
         #[cfg(not(target_vendor = "uwp"))]
         {
-            if let Ok(Some(path)) = super::fill_utf16_buf(
+            if let Ok(Some(path)) = fill_utf16_buf(
                 |buf, size| c::GetWindowsDirectoryW(buf, size),
                 |buf| exists(PathBuf::from(OsString::from_wide(buf))),
             ) {
@@ -851,10 +844,8 @@ fn make_command_line(argv0: &OsStr, args: &[Arg], force_quotes: bool) -> io::Res
 
 // Get `cmd.exe` for use with bat scripts, encoded as a UTF-16 string.
 fn command_prompt() -> io::Result<Vec<u16>> {
-    let mut system: Vec<u16> = super::fill_utf16_buf(
-        |buf, size| unsafe { c::GetSystemDirectoryW(buf, size) },
-        |buf| buf.into(),
-    )?;
+    let mut system: Vec<u16> =
+        fill_utf16_buf(|buf, size| unsafe { c::GetSystemDirectoryW(buf, size) }, |buf| buf.into())?;
     system.extend("\\cmd.exe".encode_utf16().chain([0]));
     Ok(system)
 }
diff --git a/library/std/src/sys/pal/windows/process/tests.rs b/library/std/src/sys/process/windows/tests.rs
index 1377e12162f..1377e12162f 100644
--- a/library/std/src/sys/pal/windows/process/tests.rs
+++ b/library/std/src/sys/process/windows/tests.rs