Skip to content

Commit

Permalink
Auto merge of #117285 - joboet:move_platforms_to_pal, r=ChrisDenton
Browse files Browse the repository at this point in the history
Move platform modules into `sys::pal`

This is the initial step of #117276. `sys` just re-exports everything from the current `sys` for now, I'll move the implementations for the individual features one-by-one after this PR merges.
  • Loading branch information
bors committed Jan 13, 2024
2 parents 284cb71 + 0cfc995 commit 1d8d7b1
Show file tree
Hide file tree
Showing 280 changed files with 215 additions and 209 deletions.
2 changes: 1 addition & 1 deletion .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Copyright: 2019 The Crossbeam Project Developers
The Rust Project Developers (see https://thanks.rust-lang.org)
License: MIT OR Apache-2.0

Files: library/std/src/sys/unix/locks/fuchsia_mutex.rs
Files: library/std/src/sys/pal/unix/locks/fuchsia_mutex.rs
Copyright: 2016 The Fuchsia Authors
The Rust Project Developers (see https://thanks.rust-lang.org)
License: BSD-2-Clause AND (MIT OR Apache-2.0)
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_session/src/config/sigpipe.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! NOTE: Keep these constants in sync with `library/std/src/sys/unix/mod.rs`!
//! NOTE: Keep these constants in sync with `library/std/src/sys/pal/unix/mod.rs`!

/// The default value if `#[unix_sigpipe]` is not specified. This resolves
/// to `SIG_IGN` in `library/std/src/sys/unix/mod.rs`.
/// to `SIG_IGN` in `library/std/src/sys/pal/unix/mod.rs`.
///
/// Note that `SIG_IGN` has been the Rust default since 2014. See
/// <https://github.com/rust-lang/rust/issues/62569>.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/base/illumos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub fn opts() -> TargetOptions {
// While we support ELF TLS, rust requires a way to register
// cleanup handlers (in C, this would be something along the lines of:
// void register_callback(void (*fn)(void *), void *arg);
// (see src/libstd/sys/unix/fast_thread_local.rs) that is currently
// (see src/libstd/sys/pal/unix/fast_thread_local.rs) that is currently
// missing in illumos. For now at least, we must fallback to using
// pthread_{get,set}specific.
//has_thread_local: true,
Expand Down
132 changes: 8 additions & 124 deletions library/std/src/sys/mod.rs
Original file line number Diff line number Diff line change
@@ -1,124 +1,8 @@
//! Platform-dependent platform abstraction.
//!
//! The `std::sys` module is the abstracted interface through which
//! `std` talks to the underlying operating system. It has different
//! implementations for different operating system families, today
//! just Unix and Windows, and initial support for Redox.
//!
//! The centralization of platform-specific code in this module is
//! enforced by the "platform abstraction layer" tidy script in
//! `tools/tidy/src/pal.rs`.
//!
//! This module is closely related to the platform-independent system
//! integration code in `std::sys_common`. See that module's
//! documentation for details.
//!
//! In the future it would be desirable for the independent
//! implementations of this module to be extracted to their own crates
//! that `std` can link to, thus enabling their implementation
//! out-of-tree via crate replacement. Though due to the complex
//! inter-dependencies within `std` that will be a challenging goal to
//! achieve.

#![allow(missing_debug_implementations)]

pub mod common;
mod personality;

cfg_if::cfg_if! {
if #[cfg(unix)] {
mod unix;
pub use self::unix::*;
} else if #[cfg(windows)] {
mod windows;
pub use self::windows::*;
} else if #[cfg(target_os = "solid_asp3")] {
mod solid;
pub use self::solid::*;
} else if #[cfg(target_os = "hermit")] {
mod hermit;
pub use self::hermit::*;
} else if #[cfg(target_os = "wasi")] {
mod wasi;
pub use self::wasi::*;
} else if #[cfg(target_family = "wasm")] {
mod wasm;
pub use self::wasm::*;
} else if #[cfg(target_os = "xous")] {
mod xous;
pub use self::xous::*;
} else if #[cfg(target_os = "uefi")] {
mod uefi;
pub use self::uefi::*;
} else if #[cfg(all(target_vendor = "fortanix", target_env = "sgx"))] {
mod sgx;
pub use self::sgx::*;
} else if #[cfg(target_os = "teeos")] {
mod teeos;
pub use self::teeos::*;
} else {
mod unsupported;
pub use self::unsupported::*;
}
}

cfg_if::cfg_if! {
// Fuchsia components default to full backtrace.
if #[cfg(target_os = "fuchsia")] {
pub const FULL_BACKTRACE_DEFAULT: bool = true;
} else {
pub const FULL_BACKTRACE_DEFAULT: bool = false;
}
}

#[cfg(not(test))]
cfg_if::cfg_if! {
if #[cfg(target_os = "android")] {
pub use self::android::log2f32;
pub use self::android::log2f64;
} else {
#[inline]
pub fn log2f32(n: f32) -> f32 {
unsafe { crate::intrinsics::log2f32(n) }
}

#[inline]
pub fn log2f64(n: f64) -> f64 {
unsafe { crate::intrinsics::log2f64(n) }
}
}
}

// Solaris/Illumos requires a wrapper around log, log2, and log10 functions
// because of their non-standard behavior (e.g., log(-n) returns -Inf instead
// of expected NaN).
#[cfg(not(test))]
#[cfg(any(target_os = "solaris", target_os = "illumos"))]
#[inline]
pub fn log_wrapper<F: Fn(f64) -> f64>(n: f64, log_fn: F) -> f64 {
if n.is_finite() {
if n > 0.0 {
log_fn(n)
} else if n == 0.0 {
f64::NEG_INFINITY // log(0) = -Inf
} else {
f64::NAN // log(-n) = NaN
}
} else if n.is_nan() {
n // log(NaN) = NaN
} else if n > 0.0 {
n // log(Inf) = Inf
} else {
f64::NAN // log(-Inf) = NaN
}
}

#[cfg(not(test))]
#[cfg(not(any(target_os = "solaris", target_os = "illumos")))]
#[inline]
pub fn log_wrapper<F: Fn(f64) -> f64>(n: f64, log_fn: F) -> f64 {
log_fn(n)
}

#[cfg(not(target_os = "uefi"))]
pub type RawOsError = i32;
/// The PAL (platform abstraction layer) contains platform-specific abstractions
/// for implementing the features in the other submodules, e.g. UNIX file
/// descriptors.
mod pal;

// FIXME(117276): remove this, move feature implementations into individual
// submodules.
pub use pal::*;
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::abi;
use crate::alloc::{GlobalAlloc, Layout, System};
use crate::ptr;
use crate::sys::hermit::abi;

#[stable(feature = "alloc_system_type", since = "1.28.0")]
unsafe impl GlobalAlloc for System {
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#![unstable(reason = "not public", issue = "none", feature = "fd")]

use super::abi;
use crate::io::{self, Read};
use crate::os::hermit::io::{FromRawFd, OwnedFd, RawFd};
use crate::sys::cvt;
use crate::sys::hermit::abi;
use crate::sys::unsupported;
use crate::sys_common::{AsInner, FromInner, IntoInner};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use super::abi::{self, O_APPEND, O_CREAT, O_EXCL, O_RDONLY, O_RDWR, O_TRUNC, O_WRONLY};
use super::fd::FileDesc;
use crate::ffi::{CStr, OsString};
use crate::fmt;
use crate::hash::{Hash, Hasher};
Expand All @@ -7,10 +9,6 @@ use crate::os::hermit::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, Raw
use crate::path::{Path, PathBuf};
use crate::sys::common::small_c_string::run_path_with_cstr;
use crate::sys::cvt;
use crate::sys::hermit::abi::{
self, O_APPEND, O_CREAT, O_EXCL, O_RDONLY, O_RDWR, O_TRUNC, O_WRONLY,
};
use crate::sys::hermit::fd::FileDesc;
use crate::sys::time::SystemTime;
use crate::sys::unsupported;
use crate::sys_common::{AsInner, AsInnerMut, FromInner, IntoInner};
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ pub unsafe extern "C" fn runtime_entry(
argv: *const *const c_char,
env: *const *const c_char,
) -> ! {
use crate::sys::hermit::thread_local_dtor::run_dtors;
use thread_local_dtor::run_dtors;
extern "C" {
fn main(argc: isize, argv: *const *const c_char) -> i32;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#![allow(dead_code)]

use super::fd::FileDesc;
use crate::cmp;
use crate::io::{self, BorrowedBuf, BorrowedCursor, IoSlice, IoSliceMut};
use crate::mem;
use crate::net::{Shutdown, SocketAddr};
use crate::os::hermit::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, RawFd};
use crate::sys::hermit::fd::FileDesc;
use crate::sys::time::Instant;
use crate::sys_common::net::{getsockopt, setsockopt, sockaddr_to_addr};
use crate::sys_common::{AsInner, FromInner, IntoInner};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use super::abi;
use crate::collections::HashMap;
use crate::error::Error as StdError;
use crate::ffi::{CStr, OsStr, OsString};
Expand All @@ -8,7 +9,6 @@ use crate::os::hermit::ffi::OsStringExt;
use crate::path::{self, PathBuf};
use crate::str;
use crate::sync::Mutex;
use crate::sys::hermit::abi;
use crate::sys::memchr;
use crate::sys::unsupported;
use crate::vec;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::abi;
use crate::io;
use crate::io::{IoSlice, IoSliceMut};
use crate::sys::hermit::abi;

pub struct Stdin;
pub struct Stdout;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#![allow(dead_code)]

use super::abi;
use super::thread_local_dtor::run_dtors;
use crate::ffi::CStr;
use crate::io;
use crate::mem;
use crate::num::NonZeroUsize;
use crate::ptr;
use crate::sys::hermit::abi;
use crate::sys::hermit::thread_local_dtor::run_dtors;
use crate::time::Duration;

pub type Tid = abi::Tid;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#![allow(dead_code)]

use super::abi;
use super::abi::timespec;
use super::abi::{CLOCK_MONOTONIC, CLOCK_REALTIME, NSEC_PER_SEC};
use crate::cmp::Ordering;
use crate::ops::{Add, AddAssign, Sub, SubAssign};
use crate::sys::hermit::abi;
use crate::sys::hermit::abi::timespec;
use crate::sys::hermit::abi::{CLOCK_MONOTONIC, CLOCK_REALTIME, NSEC_PER_SEC};
use crate::time::Duration;
use core::hash::{Hash, Hasher};

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
124 changes: 124 additions & 0 deletions library/std/src/sys/pal/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
//! Platform-dependent platform abstraction.
//!
//! The `std::sys` module is the abstracted interface through which
//! `std` talks to the underlying operating system. It has different
//! implementations for different operating system families, today
//! just Unix and Windows, and initial support for Redox.
//!
//! The centralization of platform-specific code in this module is
//! enforced by the "platform abstraction layer" tidy script in
//! `tools/tidy/src/pal.rs`.
//!
//! This module is closely related to the platform-independent system
//! integration code in `std::sys_common`. See that module's
//! documentation for details.
//!
//! In the future it would be desirable for the independent
//! implementations of this module to be extracted to their own crates
//! that `std` can link to, thus enabling their implementation
//! out-of-tree via crate replacement. Though due to the complex
//! inter-dependencies within `std` that will be a challenging goal to
//! achieve.

#![allow(missing_debug_implementations)]

pub mod common;
mod personality;

cfg_if::cfg_if! {
if #[cfg(unix)] {
mod unix;
pub use self::unix::*;
} else if #[cfg(windows)] {
mod windows;
pub use self::windows::*;
} else if #[cfg(target_os = "solid_asp3")] {
mod solid;
pub use self::solid::*;
} else if #[cfg(target_os = "hermit")] {
mod hermit;
pub use self::hermit::*;
} else if #[cfg(target_os = "wasi")] {
mod wasi;
pub use self::wasi::*;
} else if #[cfg(target_family = "wasm")] {
mod wasm;
pub use self::wasm::*;
} else if #[cfg(target_os = "xous")] {
mod xous;
pub use self::xous::*;
} else if #[cfg(target_os = "uefi")] {
mod uefi;
pub use self::uefi::*;
} else if #[cfg(all(target_vendor = "fortanix", target_env = "sgx"))] {
mod sgx;
pub use self::sgx::*;
} else if #[cfg(target_os = "teeos")] {
mod teeos;
pub use self::teeos::*;
} else {
mod unsupported;
pub use self::unsupported::*;
}
}

cfg_if::cfg_if! {
// Fuchsia components default to full backtrace.
if #[cfg(target_os = "fuchsia")] {
pub const FULL_BACKTRACE_DEFAULT: bool = true;
} else {
pub const FULL_BACKTRACE_DEFAULT: bool = false;
}
}

#[cfg(not(test))]
cfg_if::cfg_if! {
if #[cfg(target_os = "android")] {
pub use self::android::log2f32;
pub use self::android::log2f64;
} else {
#[inline]
pub fn log2f32(n: f32) -> f32 {
unsafe { crate::intrinsics::log2f32(n) }
}

#[inline]
pub fn log2f64(n: f64) -> f64 {
unsafe { crate::intrinsics::log2f64(n) }
}
}
}

// Solaris/Illumos requires a wrapper around log, log2, and log10 functions
// because of their non-standard behavior (e.g., log(-n) returns -Inf instead
// of expected NaN).
#[cfg(not(test))]
#[cfg(any(target_os = "solaris", target_os = "illumos"))]
#[inline]
pub fn log_wrapper<F: Fn(f64) -> f64>(n: f64, log_fn: F) -> f64 {
if n.is_finite() {
if n > 0.0 {
log_fn(n)
} else if n == 0.0 {
f64::NEG_INFINITY // log(0) = -Inf
} else {
f64::NAN // log(-n) = NaN
}
} else if n.is_nan() {
n // log(NaN) = NaN
} else if n > 0.0 {
n // log(Inf) = Inf
} else {
f64::NAN // log(-Inf) = NaN
}
}

#[cfg(not(test))]
#[cfg(not(any(target_os = "solaris", target_os = "illumos")))]
#[inline]
pub fn log_wrapper<F: Fn(f64) -> f64>(n: f64, log_fn: F) -> f64 {
log_fn(n)
}

#[cfg(not(target_os = "uefi"))]
pub type RawOsError = i32;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 1d8d7b1

Please sign in to comment.