Apply rustc-0054-Add-std-os-fd-support-for-Trusty.patch

This commit is contained in:
Nicole LeGare 2025-02-04 22:00:20 +00:00 committed by Nicole L
parent 87ca2dbb00
commit 7f6ee12526
7 changed files with 43 additions and 6 deletions

View File

@ -13,6 +13,7 @@ mod raw;
mod owned;
// Implementations for `AsRawFd` etc. for network types.
#[cfg(not(target_os = "trusty"))]
mod net;
#[cfg(test)]

View File

@ -6,10 +6,13 @@
use super::raw::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
use crate::marker::PhantomData;
use crate::mem::ManuallyDrop;
#[cfg(not(any(target_arch = "wasm32", target_env = "sgx", target_os = "hermit")))]
#[cfg(not(any(target_arch = "wasm32", target_env = "sgx", target_os = "hermit", target_os = "trusty")))]
use crate::sys::cvt;
#[cfg(not(target_os = "trusty"))]
use crate::sys_common::{AsInner, FromInner, IntoInner};
use crate::{fmt, fs, io};
use crate::{fmt, io};
#[cfg(not(target_os = "trusty"))]
use crate::fs;
type ValidRawFd = core::num::niche_types::NotAllOnes<RawFd>;
@ -87,7 +90,7 @@ impl OwnedFd {
impl BorrowedFd<'_> {
/// Creates a new `OwnedFd` instance that shares the same underlying file
/// description as the existing `BorrowedFd` instance.
#[cfg(not(any(target_arch = "wasm32", target_os = "hermit")))]
#[cfg(not(any(target_arch = "wasm32", target_os = "hermit", target_os = "trusty")))]
#[stable(feature = "io_safety", since = "1.63.0")]
pub fn try_clone_to_owned(&self) -> crate::io::Result<OwnedFd> {
// We want to atomically duplicate this file descriptor and set the
@ -110,7 +113,7 @@ impl BorrowedFd<'_> {
/// Creates a new `OwnedFd` instance that shares the same underlying file
/// description as the existing `BorrowedFd` instance.
#[cfg(any(target_arch = "wasm32", target_os = "hermit"))]
#[cfg(any(target_arch = "wasm32", target_os = "hermit", target_os = "trusty"))]
#[stable(feature = "io_safety", since = "1.63.0")]
pub fn try_clone_to_owned(&self) -> crate::io::Result<OwnedFd> {
Err(crate::io::Error::UNSUPPORTED_PLATFORM)
@ -280,6 +283,7 @@ impl AsFd for OwnedFd {
}
#[stable(feature = "io_safety", since = "1.63.0")]
#[cfg(not(target_os = "trusty"))]
impl AsFd for fs::File {
#[inline]
fn as_fd(&self) -> BorrowedFd<'_> {
@ -288,6 +292,7 @@ impl AsFd for fs::File {
}
#[stable(feature = "io_safety", since = "1.63.0")]
#[cfg(not(target_os = "trusty"))]
impl From<fs::File> for OwnedFd {
/// Takes ownership of a [`File`](fs::File)'s underlying file descriptor.
#[inline]
@ -297,6 +302,7 @@ impl From<fs::File> for OwnedFd {
}
#[stable(feature = "io_safety", since = "1.63.0")]
#[cfg(not(target_os = "trusty"))]
impl From<OwnedFd> for fs::File {
/// Returns a [`File`](fs::File) that takes ownership of the given
/// file descriptor.
@ -307,6 +313,7 @@ impl From<OwnedFd> for fs::File {
}
#[stable(feature = "io_safety", since = "1.63.0")]
#[cfg(not(target_os = "trusty"))]
impl AsFd for crate::net::TcpStream {
#[inline]
fn as_fd(&self) -> BorrowedFd<'_> {
@ -315,6 +322,7 @@ impl AsFd for crate::net::TcpStream {
}
#[stable(feature = "io_safety", since = "1.63.0")]
#[cfg(not(target_os = "trusty"))]
impl From<crate::net::TcpStream> for OwnedFd {
/// Takes ownership of a [`TcpStream`](crate::net::TcpStream)'s socket file descriptor.
#[inline]
@ -324,6 +332,7 @@ impl From<crate::net::TcpStream> for OwnedFd {
}
#[stable(feature = "io_safety", since = "1.63.0")]
#[cfg(not(target_os = "trusty"))]
impl From<OwnedFd> for crate::net::TcpStream {
#[inline]
fn from(owned_fd: OwnedFd) -> Self {
@ -334,6 +343,7 @@ impl From<OwnedFd> for crate::net::TcpStream {
}
#[stable(feature = "io_safety", since = "1.63.0")]
#[cfg(not(target_os = "trusty"))]
impl AsFd for crate::net::TcpListener {
#[inline]
fn as_fd(&self) -> BorrowedFd<'_> {
@ -342,6 +352,7 @@ impl AsFd for crate::net::TcpListener {
}
#[stable(feature = "io_safety", since = "1.63.0")]
#[cfg(not(target_os = "trusty"))]
impl From<crate::net::TcpListener> for OwnedFd {
/// Takes ownership of a [`TcpListener`](crate::net::TcpListener)'s socket file descriptor.
#[inline]
@ -351,6 +362,7 @@ impl From<crate::net::TcpListener> for OwnedFd {
}
#[stable(feature = "io_safety", since = "1.63.0")]
#[cfg(not(target_os = "trusty"))]
impl From<OwnedFd> for crate::net::TcpListener {
#[inline]
fn from(owned_fd: OwnedFd) -> Self {
@ -361,6 +373,7 @@ impl From<OwnedFd> for crate::net::TcpListener {
}
#[stable(feature = "io_safety", since = "1.63.0")]
#[cfg(not(target_os = "trusty"))]
impl AsFd for crate::net::UdpSocket {
#[inline]
fn as_fd(&self) -> BorrowedFd<'_> {
@ -369,6 +382,7 @@ impl AsFd for crate::net::UdpSocket {
}
#[stable(feature = "io_safety", since = "1.63.0")]
#[cfg(not(target_os = "trusty"))]
impl From<crate::net::UdpSocket> for OwnedFd {
/// Takes ownership of a [`UdpSocket`](crate::net::UdpSocket)'s file descriptor.
#[inline]
@ -378,6 +392,7 @@ impl From<crate::net::UdpSocket> for OwnedFd {
}
#[stable(feature = "io_safety", since = "1.63.0")]
#[cfg(not(target_os = "trusty"))]
impl From<OwnedFd> for crate::net::UdpSocket {
#[inline]
fn from(owned_fd: OwnedFd) -> Self {

View File

@ -15,8 +15,11 @@ 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};
#[cfg(not(target_os = "trusty"))]
use crate::fs;
use crate::io;
/// Raw file descriptors.
#[stable(feature = "rust1", since = "1.0.0")]
@ -161,6 +164,7 @@ 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 {
@ -168,6 +172,7 @@ impl AsRawFd for fs::File {
}
}
#[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 {
@ -175,6 +180,7 @@ impl FromRawFd for fs::File {
}
}
#[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"))]
impl<'a> AsRawFd for io::StdinLock<'a> {
#[inline]
fn as_raw_fd(&self) -> RawFd {

View File

@ -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))]
pub mod fd;
#[cfg(any(target_os = "linux", target_os = "android", doc))]

View File

@ -0,0 +1,4 @@
//! Owned and borrowed file descriptors.
#![stable(feature = "os_fd", since = "1.66.0")]
pub use crate::os::fd::owned::*;

View File

@ -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::*;

View File

@ -0,0 +1,3 @@
#![stable(feature = "rust1", since = "1.0.0")]
pub mod io;