Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit aa8f0fd

Browse files
committedMar 23, 2025
Auto merge of #136929 - joboet:move_process_pal, r=Mark-Simulacrum
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.
2 parents 97fc1f6 + 89f85cb commit aa8f0fd

File tree

32 files changed

+90
-104
lines changed

32 files changed

+90
-104
lines changed
 

‎library/std/src/sys/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub mod io;
1717
pub mod net;
1818
pub mod os_str;
1919
pub mod path;
20+
pub mod process;
2021
pub mod random;
2122
pub mod stdio;
2223
pub mod sync;

‎library/std/src/sys/pal/hermit/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ pub mod futex;
2525
pub mod os;
2626
#[path = "../unsupported/pipe.rs"]
2727
pub mod pipe;
28-
#[path = "../unsupported/process.rs"]
29-
pub mod process;
3028
pub mod thread;
3129
pub mod time;
3230

‎library/std/src/sys/pal/sgx/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ mod libunwind_integration;
1616
pub mod os;
1717
#[path = "../unsupported/pipe.rs"]
1818
pub mod pipe;
19-
#[path = "../unsupported/process.rs"]
20-
pub mod process;
2119
pub mod thread;
2220
pub mod thread_parking;
2321
pub mod time;

‎library/std/src/sys/pal/solid/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ pub(crate) mod error;
2525
pub mod os;
2626
#[path = "../unsupported/pipe.rs"]
2727
pub mod pipe;
28-
#[path = "../unsupported/process.rs"]
29-
pub mod process;
3028
pub use self::itron::{thread, thread_parking};
3129
pub mod time;
3230

‎library/std/src/sys/pal/teeos/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ pub mod env;
1414
pub mod os;
1515
#[path = "../unsupported/pipe.rs"]
1616
pub mod pipe;
17-
#[path = "../unsupported/process.rs"]
18-
pub mod process;
1917
pub mod thread;
2018
#[allow(non_upper_case_globals)]
2119
#[path = "../unix/time.rs"]

‎library/std/src/sys/pal/uefi/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ pub mod helpers;
1919
pub mod os;
2020
#[path = "../unsupported/pipe.rs"]
2121
pub mod pipe;
22-
pub mod process;
2322
pub mod thread;
2423
pub mod time;
2524

‎library/std/src/sys/pal/unix/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ pub mod weak;
99
pub mod args;
1010
pub mod env;
1111
pub mod fd;
12+
#[cfg(target_os = "fuchsia")]
13+
pub mod fuchsia;
1214
pub mod futex;
1315
#[cfg(any(target_os = "linux", target_os = "android"))]
1416
pub mod kernel_copy;
1517
#[cfg(target_os = "linux")]
1618
pub mod linux;
1719
pub mod os;
1820
pub mod pipe;
19-
pub mod process;
2021
pub mod stack_overflow;
2122
pub mod sync;
2223
pub mod thread;
@@ -419,7 +420,7 @@ cfg_if::cfg_if! {
419420
}
420421

421422
#[cfg(any(target_os = "espidf", target_os = "horizon", target_os = "vita", target_os = "nuttx"))]
422-
mod unsupported {
423+
pub mod unsupported {
423424
use crate::io;
424425

425426
pub fn unsupported<T>() -> io::Result<T> {

‎library/std/src/sys/pal/unix/process/mod.rs

-27
This file was deleted.

‎library/std/src/sys/pal/unsupported/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ pub mod args;
44
pub mod env;
55
pub mod os;
66
pub mod pipe;
7-
pub mod process;
87
pub mod thread;
98
pub mod time;
109

‎library/std/src/sys/pal/wasi/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ pub mod futex;
2323
pub mod os;
2424
#[path = "../unsupported/pipe.rs"]
2525
pub mod pipe;
26-
#[path = "../unsupported/process.rs"]
27-
pub mod process;
2826
pub mod thread;
2927
pub mod time;
3028

‎library/std/src/sys/pal/wasip2/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ pub mod futex;
2020
pub mod os;
2121
#[path = "../unsupported/pipe.rs"]
2222
pub mod pipe;
23-
#[path = "../unsupported/process.rs"]
24-
pub mod process;
2523
#[path = "../wasi/thread.rs"]
2624
pub mod thread;
2725
#[path = "../wasi/time.rs"]

‎library/std/src/sys/pal/wasm/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ pub mod env;
2323
pub mod os;
2424
#[path = "../unsupported/pipe.rs"]
2525
pub mod pipe;
26-
#[path = "../unsupported/process.rs"]
27-
pub mod process;
2826
#[path = "../unsupported/time.rs"]
2927
pub mod time;
3028

‎library/std/src/sys/pal/windows/args.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
#[cfg(test)]
77
mod tests;
88

9+
use super::ensure_no_nuls;
910
use super::os::current_exe;
1011
use crate::ffi::{OsStr, OsString};
1112
use crate::num::NonZero;
1213
use crate::os::windows::prelude::*;
1314
use crate::path::{Path, PathBuf};
1415
use crate::sys::path::get_long_path;
15-
use crate::sys::process::ensure_no_nuls;
1616
use crate::sys::{c, to_u16s};
1717
use crate::sys_common::AsInner;
1818
use crate::sys_common::wstr::WStrUnits;

‎library/std/src/sys/pal/windows/mod.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ pub mod futex;
2222
pub mod handle;
2323
pub mod os;
2424
pub mod pipe;
25-
pub mod process;
2625
pub mod thread;
2726
pub mod time;
2827
cfg_if::cfg_if! {
@@ -287,6 +286,14 @@ pub fn truncate_utf16_at_nul(v: &[u16]) -> &[u16] {
287286
}
288287
}
289288

289+
pub fn ensure_no_nuls<T: AsRef<OsStr>>(s: T) -> crate::io::Result<T> {
290+
if s.as_ref().encode_wide().any(|b| b == 0) {
291+
Err(crate::io::const_error!(ErrorKind::InvalidInput, "nul byte found in provided data"))
292+
} else {
293+
Ok(s)
294+
}
295+
}
296+
290297
pub trait IsZero {
291298
fn is_zero(&self) -> bool;
292299
}

‎library/std/src/sys/pal/xous/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ pub mod env;
66
pub mod os;
77
#[path = "../unsupported/pipe.rs"]
88
pub mod pipe;
9-
#[path = "../unsupported/process.rs"]
10-
pub mod process;
119
pub mod thread;
1210
pub mod time;
1311

‎library/std/src/sys/pal/zkvm/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ pub mod env;
1717
pub mod os;
1818
#[path = "../unsupported/pipe.rs"]
1919
pub mod pipe;
20-
#[path = "../unsupported/process.rs"]
21-
pub mod process;
2220
#[path = "../unsupported/thread.rs"]
2321
pub mod thread;
2422
#[path = "../unsupported/time.rs"]

‎library/std/src/sys/process/mod.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
cfg_if::cfg_if! {
2+
if #[cfg(target_family = "unix")] {
3+
mod unix;
4+
use unix as imp;
5+
} else if #[cfg(target_os = "windows")] {
6+
mod windows;
7+
use windows as imp;
8+
} else if #[cfg(target_os = "uefi")] {
9+
mod uefi;
10+
use uefi as imp;
11+
} else {
12+
mod unsupported;
13+
use unsupported as imp;
14+
}
15+
}
16+
17+
pub use imp::{
18+
Command, CommandArgs, EnvKey, ExitCode, ExitStatus, ExitStatusError, Process, Stdio, StdioPipes,
19+
};

‎library/std/src/sys/pal/uefi/process.rs ‎library/std/src/sys/process/uefi.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
use r_efi::protocols::simple_text_output;
22

3-
use super::helpers;
43
use crate::collections::BTreeMap;
54
pub use crate::ffi::OsString as EnvKey;
65
use crate::ffi::{OsStr, OsString};
76
use crate::num::{NonZero, NonZeroI32};
87
use crate::path::Path;
98
use crate::sys::fs::File;
9+
use crate::sys::pal::helpers;
10+
use crate::sys::pal::os::error_string;
1011
use crate::sys::pipe::AnonPipe;
1112
use crate::sys::unsupported;
1213
use crate::sys_common::process::{CommandEnv, CommandEnvs};
@@ -225,7 +226,7 @@ impl ExitStatus {
225226

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

242243
impl fmt::Debug for ExitStatusError {
243244
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
244-
let err_str = super::os::error_string(self.0.as_usize());
245+
let err_str = error_string(self.0.as_usize());
245246
write!(f, "{}", err_str)
246247
}
247248
}
@@ -335,15 +336,14 @@ impl<'a> fmt::Debug for CommandArgs<'a> {
335336
mod uefi_command_internal {
336337
use r_efi::protocols::{loaded_image, simple_text_output};
337338

338-
use super::super::helpers;
339339
use crate::ffi::{OsStr, OsString};
340340
use crate::io::{self, const_error};
341341
use crate::mem::MaybeUninit;
342342
use crate::os::uefi::env::{boot_services, image_handle, system_table};
343343
use crate::os::uefi::ffi::{OsStrExt, OsStringExt};
344344
use crate::ptr::NonNull;
345345
use crate::slice;
346-
use crate::sys::pal::uefi::helpers::OwnedTable;
346+
use crate::sys::pal::helpers::{self, OwnedTable};
347347
use crate::sys_common::wstr::WStrUnits;
348348

349349
pub struct Image {

‎library/std/src/sys/pal/unix/process/process_common.rs ‎library/std/src/sys/process/unix/common.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ cfg_if::cfg_if! {
5454

5555
let bit = (signum - 1) as usize;
5656
if set.is_null() || bit >= (8 * size_of::<sigset_t>()) {
57-
crate::sys::pal::unix::os::set_errno(libc::EINVAL);
57+
crate::sys::pal::os::set_errno(libc::EINVAL);
5858
return -1;
5959
}
6060
let raw = slice::from_raw_parts_mut(

‎library/std/src/sys/pal/unix/process/process_fuchsia.rs ‎library/std/src/sys/process/unix/fuchsia.rs

+3-11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use libc::{c_int, size_t};
22

3+
use super::common::*;
34
use crate::num::NonZero;
4-
use crate::sys::process::process_common::*;
5-
use crate::sys::process::zircon::{Handle, zx_handle_t};
5+
use crate::sys::pal::fuchsia::*;
66
use crate::{fmt, io, mem, ptr};
77

88
////////////////////////////////////////////////////////////////////////////////
@@ -58,8 +58,6 @@ impl Command {
5858
stdio: ChildPipes,
5959
maybe_envp: Option<&CStringArray>,
6060
) -> io::Result<zx_handle_t> {
61-
use crate::sys::process::zircon::*;
62-
6361
let envp = match maybe_envp {
6462
// None means to clone the current environment, which is done in the
6563
// flags below.
@@ -152,8 +150,6 @@ impl Process {
152150
}
153151

154152
pub fn kill(&mut self) -> io::Result<()> {
155-
use crate::sys::process::zircon::*;
156-
157153
unsafe {
158154
zx_cvt(zx_task_kill(self.handle.raw()))?;
159155
}
@@ -162,8 +158,6 @@ impl Process {
162158
}
163159

164160
pub fn wait(&mut self) -> io::Result<ExitStatus> {
165-
use crate::sys::process::zircon::*;
166-
167161
let mut proc_info: zx_info_process_t = Default::default();
168162
let mut actual: size_t = 0;
169163
let mut avail: size_t = 0;
@@ -194,8 +188,6 @@ impl Process {
194188
}
195189

196190
pub fn try_wait(&mut self) -> io::Result<Option<ExitStatus>> {
197-
use crate::sys::process::zircon::*;
198-
199191
let mut proc_info: zx_info_process_t = Default::default();
200192
let mut actual: size_t = 0;
201193
let mut avail: size_t = 0;
@@ -251,7 +243,7 @@ impl ExitStatus {
251243
None
252244
}
253245

254-
// FIXME: The actually-Unix implementation in process_unix.rs uses WSTOPSIG, WCOREDUMP et al.
246+
// FIXME: The actually-Unix implementation in unix.rs uses WSTOPSIG, WCOREDUMP et al.
255247
// I infer from the implementation of `success`, `code` and `signal` above that these are not
256248
// available on Fuchsia.
257249
//
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#[cfg_attr(any(target_os = "espidf", target_os = "horizon", target_os = "nuttx"), allow(unused))]
2+
mod common;
3+
4+
cfg_if::cfg_if! {
5+
if #[cfg(target_os = "fuchsia")] {
6+
mod fuchsia;
7+
use fuchsia as imp;
8+
} else if #[cfg(target_os = "vxworks")] {
9+
mod vxworks;
10+
use vxworks as imp;
11+
} else if #[cfg(any(target_os = "espidf", target_os = "horizon", target_os = "vita", target_os = "nuttx"))] {
12+
mod unsupported;
13+
use unsupported as imp;
14+
} else {
15+
mod unix;
16+
use unix as imp;
17+
}
18+
}
19+
20+
pub use imp::{ExitStatus, ExitStatusError, Process};
21+
22+
pub use self::common::{Command, CommandArgs, ExitCode, Stdio, StdioPipes};
23+
pub use crate::ffi::OsString as EnvKey;
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Failed to load comments.