-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Add SOLID targets #86191
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
19
compiler/rustc_target/src/spec/armv7a_kmc_solid_asp3_eabi.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
19
compiler/rustc_target/src/spec/armv7a_kmc_solid_asp3_eabihf.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
//! SOLID-specific extensions to general I/O primitives | ||
|
||
#![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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
andOwnedFd
and related traits, which are missing here.)There was a problem hiding this comment.
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 bylibc::close
. This doesn't hold in this platform.