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

Add SOLID targets #86191

Merged
merged 1 commit into from
Sep 28, 2021
Merged
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
19 changes: 19 additions & 0 deletions compiler/rustc_target/src/spec/aarch64_kmc_solid_asp3.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use super::{RelocModel, Target, TargetOptions};

pub fn target() -> Target {
let base = super::solid_base::opts("asp3");
Target {
llvm_target: "aarch64-unknown-none".to_string(),
pointer_width: 64,
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(),
arch: "aarch64".to_string(),
options: TargetOptions {
linker: Some("aarch64-kmc-elf-gcc".to_owned()),
features: "+neon,+fp-armv8".to_string(),
relocation_model: RelocModel::Static,
disable_redzone: true,
max_atomic_width: Some(128),
..base
},
}
}
19 changes: 19 additions & 0 deletions compiler/rustc_target/src/spec/armv7a_kmc_solid_asp3_eabi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use super::{RelocModel, Target, TargetOptions};

pub fn target() -> Target {
let base = super::solid_base::opts("asp3");
Target {
llvm_target: "armv7a-none-eabi".to_string(),
pointer_width: 32,
data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(),
arch: "arm".to_string(),
options: TargetOptions {
linker: Some("arm-kmc-eabi-gcc".to_owned()),
features: "+v7,+soft-float,+thumb2,-neon".to_string(),
relocation_model: RelocModel::Static,
disable_redzone: true,
max_atomic_width: Some(64),
..base
},
}
}
19 changes: 19 additions & 0 deletions compiler/rustc_target/src/spec/armv7a_kmc_solid_asp3_eabihf.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use super::{RelocModel, Target, TargetOptions};

pub fn target() -> Target {
let base = super::solid_base::opts("asp3");
Target {
llvm_target: "armv7a-none-eabihf".to_string(),
pointer_width: 32,
data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(),
arch: "arm".to_string(),
options: TargetOptions {
linker: Some("arm-kmc-eabi-gcc".to_owned()),
features: "+v7,+vfp3,-d32,+thumb2,-neon".to_string(),
relocation_model: RelocModel::Static,
disable_redzone: true,
max_atomic_width: Some(64),
..base
},
}
}
5 changes: 5 additions & 0 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ mod netbsd_base;
mod openbsd_base;
mod redox_base;
mod solaris_base;
mod solid_base;
mod thumb_base;
mod uefi_msvc_base;
mod vxworks_base;
Expand Down Expand Up @@ -932,6 +933,10 @@ supported_targets! {
("powerpc-wrs-vxworks-spe", powerpc_wrs_vxworks_spe),
("powerpc64-wrs-vxworks", powerpc64_wrs_vxworks),

("aarch64-kmc-solid_asp3", aarch64_kmc_solid_asp3),
("armv7a-kmc-solid_asp3-eabi", armv7a_kmc_solid_asp3_eabi),
("armv7a-kmc-solid_asp3-eabihf", armv7a_kmc_solid_asp3_eabihf),

("mipsel-sony-psp", mipsel_sony_psp),
("mipsel-unknown-none", mipsel_unknown_none),
("thumbv4t-none-eabi", thumbv4t_none_eabi),
Expand Down
12 changes: 12 additions & 0 deletions compiler/rustc_target/src/spec/solid_base.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use super::FramePointer;
use crate::spec::TargetOptions;

pub fn opts(kernel: &str) -> TargetOptions {
TargetOptions {
os: format!("solid_{}", kernel),
vendor: "kmc".to_string(),
frame_pointer: FramePointer::NonLeaf,
has_elf_tls: true,
..Default::default()
}
}
1 change: 1 addition & 0 deletions library/panic_abort/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub unsafe extern "C-unwind" fn __rust_start_panic(_payload: *mut &mut dyn BoxMe
libc::abort();
}
} else if #[cfg(any(target_os = "hermit",
target_os = "solid_asp3",
all(target_vendor = "fortanix", target_env = "sgx")
))] {
unsafe fn abort() -> ! {
Expand Down
1 change: 1 addition & 0 deletions library/panic_unwind/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ cfg_if::cfg_if! {
} else if #[cfg(any(
all(target_family = "windows", target_env = "gnu"),
target_os = "psp",
target_os = "solid_asp3",
all(target_family = "unix", not(target_os = "espidf")),
all(target_vendor = "fortanix", target_env = "sgx"),
))] {
Expand Down
1 change: 1 addition & 0 deletions library/std/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ fn main() {
|| target.contains("wasm32")
|| target.contains("asmjs")
|| target.contains("espidf")
|| target.contains("solid")
{
// These platforms don't have any special requirements.
} else {
Expand Down
2 changes: 2 additions & 0 deletions library/std/src/os/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ pub mod redox;
#[cfg(target_os = "solaris")]
pub mod solaris;

#[cfg(target_os = "solid_asp3")]
pub mod solid;
#[cfg(target_os = "vxworks")]
pub mod vxworks;

Expand Down
41 changes: 41 additions & 0 deletions library/std/src/os/solid/ffi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//! SOLID-specific extension to the primitives in the `std::ffi` module
//!
//! # Examples
//!
//! ```
//! use std::ffi::OsString;
//! use std::os::solid::ffi::OsStringExt;
//!
//! let bytes = b"foo".to_vec();
//!
//! // OsStringExt::from_vec
//! let os_string = OsString::from_vec(bytes);
//! assert_eq!(os_string.to_str(), Some("foo"));
//!
//! // OsStringExt::into_vec
//! let bytes = os_string.into_vec();
//! assert_eq!(bytes, b"foo");
//! ```
//!
//! ```
//! use std::ffi::OsStr;
//! use std::os::solid::ffi::OsStrExt;
//!
//! let bytes = b"foo";
//!
//! // OsStrExt::from_bytes
//! let os_str = OsStr::from_bytes(bytes);
//! assert_eq!(os_str.to_str(), Some("foo"));
//!
//! // OsStrExt::as_bytes
//! let bytes = os_str.as_bytes();
//! assert_eq!(bytes, b"foo");
//! ```

#![stable(feature = "rust1", since = "1.0.0")]

#[path = "../unix/ffi/os_str.rs"]
mod os_str;

#[stable(feature = "rust1", since = "1.0.0")]
pub use self::os_str::{OsStrExt, OsStringExt};
113 changes: 113 additions & 0 deletions library/std/src/os/solid/io.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
//! SOLID-specific extensions to general I/O primitives
Copy link
Member

Choose a reason for hiding this comment

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

The raw fd types and traits are now available under library/std/src/os/fd/mod.rs, so no need to repeat them here.

(And that also includes the new BorrowedFd and OwnedFd and related traits, which are missing here.)

Copy link
Contributor Author

@kawadakk kawadakk Sep 3, 2021

Choose a reason for hiding this comment

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

It seems that the raw FD types under library/std/src/os/fd/mod.rs assume POSIX-like FDs, i.e., there's a unified namespace for both normal files and sockets, and both can be closed by libc::close. This doesn't hold in this platform.


#![deny(unsafe_op_in_unsafe_fn)]
#![unstable(feature = "solid_ext", issue = "none")]

use crate::net;
use crate::sys;
use crate::sys_common::{self, AsInner, FromInner, IntoInner};

/// Raw file descriptors.
pub type RawFd = i32;

/// A trait to extract the raw SOLID Sockets file descriptor from an underlying
/// object.
pub trait AsRawFd {
/// Extracts the raw file descriptor.
///
/// This method does **not** pass ownership of the raw file descriptor
/// to the caller. The descriptor is only guaranteed to be valid while
/// the original object has not yet been destroyed.
fn as_raw_fd(&self) -> RawFd;
}

/// A trait to express the ability to construct an object from a raw file
/// descriptor.
pub trait FromRawFd {
/// Constructs a new instance of `Self` from the given raw file
/// descriptor.
///
/// This function **consumes ownership** of the specified file
/// descriptor. The returned object will take responsibility for closing
/// it when the object goes out of scope.
///
/// This function is also unsafe as the primitives currently returned
/// have the contract that they are the sole owner of the file
/// descriptor they are wrapping. Usage of this function could
/// accidentally allow violating this contract which can cause memory
/// unsafety in code that relies on it being true.
unsafe fn from_raw_fd(fd: RawFd) -> Self;
}

/// A trait to express the ability to consume an object and acquire ownership of
/// its raw file descriptor.
pub trait IntoRawFd {
/// Consumes this object, returning the raw underlying file descriptor.
///
/// This function **transfers ownership** of the underlying file descriptor
/// to the caller. Callers are then the unique owners of the file descriptor
/// and must close the descriptor once it's no longer needed.
fn into_raw_fd(self) -> RawFd;
}

#[stable(feature = "raw_fd_reflexive_traits", since = "1.48.0")]
impl AsRawFd for RawFd {
#[inline]
fn as_raw_fd(&self) -> RawFd {
*self
}
}
#[stable(feature = "raw_fd_reflexive_traits", since = "1.48.0")]
impl IntoRawFd for RawFd {
#[inline]
fn into_raw_fd(self) -> RawFd {
self
}
}
#[stable(feature = "raw_fd_reflexive_traits", since = "1.48.0")]
impl FromRawFd for RawFd {
#[inline]
unsafe fn from_raw_fd(fd: RawFd) -> RawFd {
fd
}
}

macro_rules! impl_as_raw_fd {
($($t:ident)*) => {$(
#[stable(feature = "rust1", since = "1.0.0")]
impl AsRawFd for net::$t {
#[inline]
fn as_raw_fd(&self) -> RawFd {
*self.as_inner().socket().as_inner()
}
}
)*};
}
impl_as_raw_fd! { TcpStream TcpListener UdpSocket }

macro_rules! impl_from_raw_fd {
($($t:ident)*) => {$(
#[stable(feature = "from_raw_os", since = "1.1.0")]
impl FromRawFd for net::$t {
#[inline]
unsafe fn from_raw_fd(fd: RawFd) -> net::$t {
let socket = sys::net::Socket::from_inner(fd);
net::$t::from_inner(sys_common::net::$t::from_inner(socket))
}
}
)*};
}
impl_from_raw_fd! { TcpStream TcpListener UdpSocket }

macro_rules! impl_into_raw_fd {
($($t:ident)*) => {$(
#[stable(feature = "into_raw_os", since = "1.4.0")]
impl IntoRawFd for net::$t {
#[inline]
fn into_raw_fd(self) -> RawFd {
self.into_inner().into_socket().into_inner()
}
}
)*};
}
impl_into_raw_fd! { TcpStream TcpListener UdpSocket }
17 changes: 17 additions & 0 deletions library/std/src/os/solid/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#![stable(feature = "rust1", since = "1.0.0")]

pub mod ffi;
pub mod io;

/// A prelude for conveniently writing platform-specific code.
///
/// Includes all extension traits, and some important type definitions.
#[stable(feature = "rust1", since = "1.0.0")]
pub mod prelude {
#[doc(no_inline)]
#[stable(feature = "rust1", since = "1.0.0")]
pub use super::ffi::{OsStrExt, OsStringExt};
#[doc(no_inline)]
#[stable(feature = "rust1", since = "1.0.0")]
pub use super::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
}
Loading