-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Add libstd support for Trusty targets #136842
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
Changes from 8 commits
87ca2db
7f6ee12
d633d8e
22fea97
5b94113
0b1a7ab
f5dd3d1
2b3b0bd
d3c55cd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,9 @@ | |
#[cfg(target_os = "hermit")] | ||
use hermit_abi as libc; | ||
|
||
#[cfg(not(target_os = "trusty"))] | ||
use crate::fs; | ||
use crate::io; | ||
#[cfg(target_os = "hermit")] | ||
use crate::os::hermit::io::OwnedFd; | ||
#[cfg(not(target_os = "hermit"))] | ||
|
@@ -15,8 +18,8 @@ use crate::os::unix::io::AsFd; | |
use crate::os::unix::io::OwnedFd; | ||
#[cfg(target_os = "wasi")] | ||
use crate::os::wasi::io::OwnedFd; | ||
#[cfg(not(target_os = "trusty"))] | ||
use crate::sys_common::{AsInner, IntoInner}; | ||
use crate::{fs, io}; | ||
|
||
/// Raw file descriptors. | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
|
@@ -161,20 +164,23 @@ impl FromRawFd for RawFd { | |
} | ||
|
||
#[stable(feature = "rust1", since = "1.0.0")] | ||
#[cfg(not(target_os = "trusty"))] | ||
impl AsRawFd for fs::File { | ||
#[inline] | ||
fn as_raw_fd(&self) -> RawFd { | ||
self.as_inner().as_raw_fd() | ||
} | ||
} | ||
#[stable(feature = "from_raw_os", since = "1.1.0")] | ||
#[cfg(not(target_os = "trusty"))] | ||
impl FromRawFd for fs::File { | ||
#[inline] | ||
unsafe fn from_raw_fd(fd: RawFd) -> fs::File { | ||
unsafe { fs::File::from(OwnedFd::from_raw_fd(fd)) } | ||
} | ||
} | ||
#[stable(feature = "into_raw_os", since = "1.4.0")] | ||
#[cfg(not(target_os = "trusty"))] | ||
impl IntoRawFd for fs::File { | ||
#[inline] | ||
fn into_raw_fd(self) -> RawFd { | ||
|
@@ -183,6 +189,7 @@ impl IntoRawFd for fs::File { | |
} | ||
|
||
#[stable(feature = "asraw_stdio", since = "1.21.0")] | ||
#[cfg(not(target_os = "trusty"))] | ||
impl AsRawFd for io::Stdin { | ||
#[inline] | ||
fn as_raw_fd(&self) -> RawFd { | ||
|
@@ -207,6 +214,7 @@ impl AsRawFd for io::Stderr { | |
} | ||
|
||
#[stable(feature = "asraw_stdio_locks", since = "1.35.0")] | ||
#[cfg(not(target_os = "trusty"))] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding a bunch of In general, we have avoided adding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a better approach to follow for disabling unsupported parts of std? Would it be better to instead stub out platform APIs with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is really no satisfactory answer, to be clear, which is why we have shifted towards being increasingly reluctant to allow targets to add only partial support for std. |
||
impl<'a> AsRawFd for io::StdinLock<'a> { | ||
#[inline] | ||
fn as_raw_fd(&self) -> RawFd { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -169,6 +169,8 @@ pub mod rtems; | |
pub mod solaris; | ||
#[cfg(target_os = "solid_asp3")] | ||
pub mod solid; | ||
#[cfg(target_os = "trusty")] | ||
pub mod trusty; | ||
#[cfg(target_os = "uefi")] | ||
pub mod uefi; | ||
#[cfg(target_os = "vita")] | ||
|
@@ -178,7 +180,7 @@ pub mod vxworks; | |
#[cfg(target_os = "xous")] | ||
pub mod xous; | ||
|
||
#[cfg(any(unix, target_os = "hermit", target_os = "wasi", doc))] | ||
#[cfg(any(unix, target_os = "hermit", target_os = "trusty", target_os = "wasi", doc))] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This whole module is about providing safe abstractions for file descriptors that maintain IO safety. But if I understand the documentation correctly, there is no way to open or close file descriptors on Trusty, meaning the whole concept of IO safety is unnecessary. Thus I don't think that this module should exist on Trusty. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do make heavy use of |
||
pub mod fd; | ||
|
||
#[cfg(any(target_os = "linux", target_os = "android", doc))] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#![stable(feature = "os_fd", since = "1.66.0")] | ||
|
||
#[stable(feature = "os_fd", since = "1.66.0")] | ||
pub use crate::os::fd::*; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#![stable(feature = "rust1", since = "1.0.0")] | ||
|
||
pub mod io; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
//! System bindings for the Trusty OS. | ||
|
||
#[path = "../unsupported/args.rs"] | ||
pub mod args; | ||
#[path = "../unsupported/common.rs"] | ||
#[deny(unsafe_op_in_unsafe_fn)] | ||
mod common; | ||
#[path = "../unsupported/env.rs"] | ||
pub mod env; | ||
#[path = "../unsupported/os.rs"] | ||
pub mod os; | ||
#[path = "../unsupported/pipe.rs"] | ||
pub mod pipe; | ||
#[path = "../unsupported/process.rs"] | ||
pub mod process; | ||
#[path = "../unsupported/thread.rs"] | ||
pub mod thread; | ||
#[path = "../unsupported/time.rs"] | ||
pub mod time; | ||
|
||
pub use common::*; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
extern "C" { | ||
fn trusty_rng_secure_rand(randomBuffer: *mut core::ffi::c_void, randomBufferLen: libc::size_t); | ||
} | ||
|
||
pub fn fill_bytes(bytes: &mut [u8]) { | ||
unsafe { trusty_rng_secure_rand(bytes.as_mut_ptr().cast(), bytes.len()) } | ||
} |
Uh oh!
There was an error while loading. Please reload this page.