Skip to content

Commit 6ef5d9e

Browse files
authored
Update the polyfill to the latest I/O safety documentation. (#865)
Update the maybe_polyfill sources to the latest upstream changes. And fix a missing word in a comment.
1 parent f466001 commit 6ef5d9e

4 files changed

Lines changed: 30 additions & 12 deletions

File tree

src/fs/statx.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ mod compat {
7272

7373
use backend::fs::types::{Statx, StatxFlags};
7474

75-
// Linux kernel prior to 4.11 old versions of Docker don't support `statx`.
76-
// We store the availability in a global to avoid unnecessary syscalls.
75+
// Linux kernel prior to 4.11 and old versions of Docker don't support
76+
// `statx`. We store the availability in a global to avoid unnecessary
77+
// syscalls.
7778
//
7879
// 0: Unknown
7980
// 1: Not available

src/maybe_polyfill/no_std/os/fd/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
//! All code in this file is licensed MIT or Apache 2.0 at your option.
66
//!
77
//! Owned and borrowed Unix-like file descriptors.
8+
//!
9+
//! This module is supported on Unix platforms and WASI, which both use a
10+
//! similar file descriptor system for referencing OS resources.
811
9-
#![cfg_attr(staged_api, unstable(feature = "io_safety", issue = "87074"))]
12+
#![cfg_attr(staged_api, stable(feature = "os_fd", since = "1.66.0"))]
1013
#![deny(unsafe_op_in_unsafe_fn)]
1114

1215
// `RawFd`, `AsRawFd`, etc.
@@ -15,5 +18,8 @@ mod raw;
1518
// `OwnedFd`, `AsFd`, etc.
1619
mod owned;
1720

21+
// Export the types and traits for the public API.
22+
#[cfg_attr(staged_api, stable(feature = "os_fd", since = "1.66.0"))]
1823
pub use owned::*;
24+
#[cfg_attr(staged_api, stable(feature = "os_fd", since = "1.66.0"))]
1925
pub use raw::*;

src/maybe_polyfill/no_std/os/fd/owned.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! The following is derived from Rust's
22
//! library/std/src/os/fd/owned.rs at revision
3-
//! fa68e73e9947be8ffc5b3b46d899e4953a44e7e9.
3+
//! 334a54cd83191f38ad8046ed94c45de735c86c65.
44
//!
55
//! All code in this file is licensed MIT or Apache 2.0 at your option.
66
//!
@@ -18,8 +18,9 @@ use core::mem::forget;
1818

1919
/// A borrowed file descriptor.
2020
///
21-
/// This has a lifetime parameter to tie it to the lifetime of something that
22-
/// owns the file descriptor.
21+
/// This has a lifetime parameter to tie it to the lifetime of something that owns the file
22+
/// descriptor. For the duration of that lifetime, it is guaranteed that nobody will close the file
23+
/// descriptor.
2324
///
2425
/// This uses `repr(transparent)` and has the representation of a host file
2526
/// descriptor, so it can be used in FFI in places where a file descriptor is
@@ -36,16 +37,17 @@ use core::mem::forget;
3637
// 32-bit c_int. Below is -2, in two's complement, but that only works out
3738
// because c_int is 32 bits.
3839
#[cfg_attr(rustc_attrs, rustc_layout_scalar_valid_range_end(0xFF_FF_FF_FE))]
39-
#[cfg_attr(staged_api, unstable(feature = "io_safety", issue = "87074"))]
4040
#[cfg_attr(rustc_attrs, rustc_nonnull_optimization_guaranteed)]
41+
#[cfg_attr(staged_api, stable(feature = "io_safety", since = "1.63.0"))]
4142
pub struct BorrowedFd<'fd> {
4243
fd: RawFd,
4344
_phantom: PhantomData<&'fd OwnedFd>,
4445
}
4546

4647
/// An owned file descriptor.
4748
///
48-
/// This closes the file descriptor on drop.
49+
/// This closes the file descriptor on drop. It is guaranteed that nobody else will close the file
50+
/// descriptor.
4951
///
5052
/// This uses `repr(transparent)` and has the representation of a host file
5153
/// descriptor, so it can be used in FFI in places where a file descriptor is
@@ -71,7 +73,11 @@ impl BorrowedFd<'_> {
7173
/// The resource pointed to by `fd` must remain open for the duration of
7274
/// the returned `BorrowedFd`, and it must not have the value `-1`.
7375
#[inline]
74-
#[cfg_attr(staged_api, unstable(feature = "io_safety", issue = "87074"))]
76+
#[cfg_attr(
77+
staged_api,
78+
rustc_const_stable(feature = "io_safety", since = "1.63.0")
79+
)]
80+
#[cfg_attr(staged_api, stable(feature = "io_safety", since = "1.63.0"))]
7581
pub const unsafe fn borrow_raw(fd: RawFd) -> Self {
7682
assert!(fd != u32::MAX as RawFd);
7783
// SAFETY: we just asserted that the value is in the valid range and isn't `-1` (the only value bigger than `0xFF_FF_FF_FE` unsigned)
@@ -184,7 +190,9 @@ impl FromRawFd for OwnedFd {
184190
/// # Safety
185191
///
186192
/// The resource pointed to by `fd` must be open and suitable for assuming
187-
/// ownership. The resource must not require any cleanup other than `close`.
193+
/// [ownership][io-safety]. The resource must not require any cleanup other than `close`.
194+
///
195+
/// [io-safety]: io#io-safety
188196
#[inline]
189197
unsafe fn from_raw_fd(fd: RawFd) -> Self {
190198
assert_ne!(fd, u32::MAX as RawFd);

src/maybe_polyfill/no_std/os/fd/raw.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! The following is derived from Rust's
22
//! library/std/src/os/fd/raw.rs at revision
3-
//! fa68e73e9947be8ffc5b3b46d899e4953a44e7e9.
3+
//! 334a54cd83191f38ad8046ed94c45de735c86c65.
44
//!
55
//! All code in this file is licensed MIT or Apache 2.0 at your option.
66
//!
@@ -71,7 +71,10 @@ pub trait FromRawFd {
7171
///
7272
/// # Safety
7373
///
74-
/// The `fd` passed in must be a valid an open file descriptor.
74+
/// The `fd` passed in must be an [owned file descriptor][io-safety];
75+
/// in particular, it must be open.
76+
///
77+
/// [io-safety]: io#io-safety
7578
///
7679
/// # Example
7780
///

0 commit comments

Comments
 (0)