Skip to content

Commit d3f21b6

Browse files
committed
Move args into std::sys
1 parent d1d4180 commit d3f21b6

File tree

26 files changed

+53
-41
lines changed

26 files changed

+53
-41
lines changed
File renamed without changes.

Diff for: std/src/sys/args/mod.rs

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//! Platform-dependent command line arguments abstraction.
2+
3+
#![forbid(unsafe_op_in_unsafe_fn)]
4+
5+
cfg_if::cfg_if! {
6+
if #[cfg(target_family = "unix")] {
7+
mod unix;
8+
pub use unix::*;
9+
} else if #[cfg(target_family = "windows")] {
10+
mod windows;
11+
pub use windows::*;
12+
} else if #[cfg(target_os = "hermit")] {
13+
mod hermit;
14+
pub use hermit::*;
15+
} else if #[cfg(all(target_vendor = "fortanix", target_env = "sgx"))] {
16+
mod sgx;
17+
pub use sgx::*;
18+
} else if #[cfg(target_os = "uefi")] {
19+
mod uefi;
20+
pub use uefi::*;
21+
} else if #[cfg(target_os = "wasi")] {
22+
mod wasi;
23+
pub use wasi::*;
24+
} else if #[cfg(target_os = "xous")] {
25+
mod xous;
26+
pub use xous::*;
27+
} else if #[cfg(target_os = "zkvm")] {
28+
mod zkvm;
29+
pub use zkvm::*;
30+
} else {
31+
mod unsupported;
32+
pub use unsupported::*;
33+
}
34+
}

Diff for: std/src/sys/pal/sgx/args.rs renamed to std/src/sys/args/sgx.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
use super::abi::usercalls::alloc;
2-
use super::abi::usercalls::raw::ByteBuffer;
1+
#![allow(fuzzy_provenance_casts)] // FIXME: this module systematically confuses pointers and integers
2+
33
use crate::ffi::OsString;
44
use crate::sync::atomic::{AtomicUsize, Ordering};
55
use crate::sys::os_str::Buf;
6+
use crate::sys::pal::abi::usercalls::alloc;
7+
use crate::sys::pal::abi::usercalls::raw::ByteBuffer;
68
use crate::sys_common::FromInner;
79
use crate::{fmt, slice};
810

Diff for: std/src/sys/pal/uefi/args.rs renamed to std/src/sys/args/uefi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use r_efi::protocols::loaded_image;
22

3-
use super::helpers;
43
use crate::env::current_exe;
54
use crate::ffi::OsString;
65
use crate::iter::Iterator;
6+
use crate::sys::pal::helpers;
77
use crate::{fmt, vec};
88

99
pub struct Args {

Diff for: std/src/sys/pal/unix/args.rs renamed to std/src/sys/args/unix.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::{fmt, vec};
1111

1212
/// One-time global initialization.
1313
pub unsafe fn init(argc: isize, argv: *const *const u8) {
14-
imp::init(argc, argv)
14+
unsafe { imp::init(argc, argv) }
1515
}
1616

1717
/// Returns the command line arguments
@@ -141,7 +141,7 @@ mod imp {
141141
pub unsafe fn init(argc: isize, argv: *const *const u8) {
142142
// on GNU/Linux if we are main then we will init argv and argc twice, it "duplicates work"
143143
// BUT edge-cases are real: only using .init_array can break most emulators, dlopen, etc.
144-
really_init(argc, argv);
144+
unsafe { really_init(argc, argv) };
145145
}
146146

147147
/// glibc passes argc, argv, and envp to functions in .init_array, as a non-standard extension.
@@ -159,9 +159,7 @@ mod imp {
159159
argv: *const *const u8,
160160
_envp: *const *const u8,
161161
) {
162-
unsafe {
163-
really_init(argc as isize, argv);
164-
}
162+
unsafe { really_init(argc as isize, argv) };
165163
}
166164
init_wrapper
167165
};
File renamed without changes.
File renamed without changes.

Diff for: std/src/sys/pal/windows/args.rs renamed to std/src/sys/args/windows.rs

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

9-
use super::ensure_no_nuls;
10-
use super::os::current_exe;
119
use crate::ffi::{OsStr, OsString};
1210
use crate::num::NonZero;
1311
use crate::os::windows::prelude::*;
1412
use crate::path::{Path, PathBuf};
13+
use crate::sys::pal::os::current_exe;
14+
use crate::sys::pal::{ensure_no_nuls, fill_utf16_buf};
1515
use crate::sys::path::get_long_path;
1616
use crate::sys::{c, to_u16s};
1717
use crate::sys_common::AsInner;
1818
use crate::sys_common::wstr::WStrUnits;
19-
use crate::{fmt, io, iter, vec};
19+
use crate::{fmt, io, iter, ptr, vec};
2020

2121
pub fn args() -> Args {
2222
// SAFETY: `GetCommandLineW` returns a pointer to a null terminated UTF-16
@@ -384,9 +384,6 @@ pub(crate) fn to_user_path(path: &Path) -> io::Result<Vec<u16>> {
384384
from_wide_to_user_path(to_u16s(path)?)
385385
}
386386
pub(crate) fn from_wide_to_user_path(mut path: Vec<u16>) -> io::Result<Vec<u16>> {
387-
use super::fill_utf16_buf;
388-
use crate::ptr;
389-
390387
// UTF-16 encoded code points, used in parsing and building UTF-16 paths.
391388
// All of these are in the ASCII range so they can be cast directly to `u16`.
392389
const SEP: u16 = b'\\' as _;
File renamed without changes.

Diff for: std/src/sys/pal/xous/args.rs renamed to std/src/sys/args/xous.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::ffi::OsString;
2-
use crate::sys::pal::xous::os::get_application_parameters;
3-
use crate::sys::pal::xous::os::params::ArgumentList;
2+
use crate::sys::pal::os::get_application_parameters;
3+
use crate::sys::pal::os::params::ArgumentList;
44
use crate::{fmt, vec};
55

66
pub struct Args {

Diff for: std/src/sys/pal/zkvm/args.rs renamed to std/src/sys/args/zkvm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use super::{WORD_SIZE, abi};
21
use crate::ffi::OsString;
32
use crate::fmt;
43
use crate::sys::os_str;
4+
use crate::sys::pal::{WORD_SIZE, abi};
55
use crate::sys_common::FromInner;
66

77
pub struct Args {

Diff for: std/src/sys/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ mod alloc;
99
mod personality;
1010

1111
pub mod anonymous_pipe;
12+
pub mod args;
1213
pub mod backtrace;
1314
pub mod cmath;
1415
pub mod exit_guard;

Diff for: std/src/sys/pal/hermit/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
use crate::os::raw::c_char;
2020

21-
pub mod args;
2221
pub mod env;
2322
pub mod futex;
2423
pub mod os;
@@ -58,7 +57,7 @@ pub extern "C" fn __rust_abort() {
5857
// NOTE: this is not guaranteed to run, for example when Rust code is called externally.
5958
pub unsafe fn init(argc: isize, argv: *const *const u8, _sigpipe: u8) {
6059
unsafe {
61-
args::init(argc, argv);
60+
crate::sys::args::init(argc, argv);
6261
}
6362
}
6463

Diff for: std/src/sys/pal/sgx/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use crate::io::ErrorKind;
99
use crate::sync::atomic::{AtomicBool, Ordering};
1010

1111
pub mod abi;
12-
pub mod args;
1312
pub mod env;
1413
mod libunwind_integration;
1514
pub mod os;
@@ -24,7 +23,7 @@ pub mod waitqueue;
2423
// NOTE: this is not guaranteed to run, for example when Rust code is called externally.
2524
pub unsafe fn init(argc: isize, argv: *const *const u8, _sigpipe: u8) {
2625
unsafe {
27-
args::init(argc, argv);
26+
crate::sys::args::init(argc, argv);
2827
}
2928
}
3029

Diff for: std/src/sys/pal/solid/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ pub mod itron {
1616
use super::unsupported;
1717
}
1818

19-
#[path = "../unsupported/args.rs"]
20-
pub mod args;
2119
pub mod env;
2220
// `error` is `pub(crate)` so that it can be accessed by `itron/error.rs` as
2321
// `crate::sys::error`

Diff for: std/src/sys/pal/teeos/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
#![allow(unused_variables)]
77
#![allow(dead_code)]
88

9-
#[path = "../unsupported/args.rs"]
10-
pub mod args;
119
#[path = "../unsupported/env.rs"]
1210
pub mod env;
1311
//pub mod fd;

Diff for: std/src/sys/pal/trusty/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//! System bindings for the Trusty OS.
22
3-
#[path = "../unsupported/args.rs"]
4-
pub mod args;
53
#[path = "../unsupported/common.rs"]
64
#[deny(unsafe_op_in_unsafe_fn)]
75
mod common;

Diff for: std/src/sys/pal/uefi/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
//! [`OsString`]: crate::ffi::OsString
1414
#![forbid(unsafe_op_in_unsafe_fn)]
1515

16-
pub mod args;
1716
pub mod env;
1817
pub mod helpers;
1918
pub mod os;

Diff for: std/src/sys/pal/unix/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use crate::io::ErrorKind;
66
#[macro_use]
77
pub mod weak;
88

9-
pub mod args;
109
pub mod env;
1110
#[cfg(target_os = "fuchsia")]
1211
pub mod fuchsia;
@@ -47,7 +46,7 @@ pub unsafe fn init(argc: isize, argv: *const *const u8, sigpipe: u8) {
4746
reset_sigpipe(sigpipe);
4847

4948
stack_overflow::init();
50-
args::init(argc, argv);
49+
crate::sys::args::init(argc, argv);
5150

5251
// Normally, `thread::spawn` will call `Thread::set_name` but since this thread
5352
// already exists, we have to call it ourselves. We only do this on Apple targets

Diff for: std/src/sys/pal/unsupported/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#![deny(unsafe_op_in_unsafe_fn)]
22

3-
pub mod args;
43
pub mod env;
54
pub mod os;
65
pub mod pipe;

Diff for: std/src/sys/pal/wasi/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
//! compiling for wasm. That way it's a compile time error for something that's
1414
//! guaranteed to be a runtime error!
1515
16-
pub mod args;
1716
pub mod env;
1817
#[allow(unused)]
1918
#[path = "../wasm/atomics/futex.rs"]

Diff for: std/src/sys/pal/wasip2/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
//! To begin with, this target mirrors the wasi target 1 to 1, but over
77
//! time this will change significantly.
88
9-
#[path = "../wasi/args.rs"]
10-
pub mod args;
119
#[path = "../wasi/env.rs"]
1210
pub mod env;
1311
#[allow(unused)]

Diff for: std/src/sys/pal/wasm/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
1717
#![deny(unsafe_op_in_unsafe_fn)]
1818

19-
#[path = "../unsupported/args.rs"]
20-
pub mod args;
2119
pub mod env;
2220
#[path = "../unsupported/os.rs"]
2321
pub mod os;

Diff for: std/src/sys/pal/windows/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ pub mod compat;
1414

1515
pub mod api;
1616

17-
pub mod args;
1817
pub mod c;
1918
pub mod env;
2019
#[cfg(not(target_vendor = "win7"))]

Diff for: std/src/sys/pal/xous/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#![forbid(unsafe_op_in_unsafe_fn)]
22

3-
pub mod args;
43
#[path = "../unsupported/env.rs"]
54
pub mod env;
65
pub mod os;

Diff for: std/src/sys/pal/zkvm/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88
//! will likely change over time.
99
#![forbid(unsafe_op_in_unsafe_fn)]
1010

11-
const WORD_SIZE: usize = size_of::<u32>();
11+
pub const WORD_SIZE: usize = size_of::<u32>();
1212

1313
pub mod abi;
14-
#[path = "../zkvm/args.rs"]
15-
pub mod args;
1614
pub mod env;
1715
pub mod os;
1816
#[path = "../unsupported/pipe.rs"]

0 commit comments

Comments
 (0)