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 some comments and minor cleanups #132

Merged
merged 22 commits into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
5 changes: 5 additions & 0 deletions src/imp/libc/fs/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -741,15 +741,20 @@ pub type FsWord = u32;
#[cfg(not(target_os = "redox"))]
pub use c::{UTIME_NOW, UTIME_OMIT};

/// `PROC_SUPER_MAGIC`—The magic number for the procfs filesystem.
#[cfg(all(
any(target_os = "android", target_os = "linux"),
not(target_env = "musl")
))]
pub const PROC_SUPER_MAGIC: FsWord = c::PROC_SUPER_MAGIC as FsWord;

/// `PROC_SUPER_MAGIC`—The magic number for the procfs filesystem.
#[cfg(all(any(target_os = "android", target_os = "linux"), target_env = "musl"))]
pub const PROC_SUPER_MAGIC: FsWord = 0x0000_9fa0;

/// `copyfile_state_t`—State for use with [`fcopyfile`].
///
/// [`fcopyfile`]: crate::fs::fcopyfile
#[cfg(any(target_os = "ios", target_os = "macos"))]
#[allow(non_camel_case_types)]
#[repr(transparent)]
Expand Down
2 changes: 2 additions & 0 deletions src/imp/libc/io/epoll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
//! # }
//! ```

#![allow(missing_docs)] // TODO: Write more docs.

use super::super::c;
use super::super::conv::{ret, ret_owned_fd, ret_u32};
use super::super::fd::{AsFd, AsRawFd, BorrowedFd, RawFd};
Expand Down
2 changes: 2 additions & 0 deletions src/imp/libc/io/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
//! This type holds an OS error code, which conceptually corresponds to an
//! `errno` value.

#![allow(missing_docs)]

use super::super::c;
use errno::errno;

Expand Down
9 changes: 7 additions & 2 deletions src/imp/libc/io/poll_fd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use bitflags::bitflags;
use core::marker::PhantomData;

bitflags! {
/// `POLL*`
/// `POLL*` flags for use with [`poll`].
///
/// [`poll`]: rustix::io::poll
pub struct PollFlags: c::c_short {
/// `POLLIN`
const IN = c::POLLIN;
Expand Down Expand Up @@ -41,7 +43,10 @@ bitflags! {
}
}

/// `struct pollfd`
/// `struct pollfd`—File descriptor and flags for use with [`poll`].
///
/// [`poll`]: rustix::io::poll
#[doc(alias = "pollfd")]
#[derive(Clone, Debug)]
#[repr(transparent)]
pub struct PollFd<'fd> {
Expand Down
14 changes: 9 additions & 5 deletions src/imp/libc/io/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ bitflags! {
/// [`preadv2`]: crate::io::preadv2
/// [`pwritev2`]: crate::io::pwritev
pub struct ReadWriteFlags: c::c_int {
/// `RWF_DSYNC`
/// `RWF_DSYNC` (since Linux 4.7)
#[cfg(all(target_os = "linux", target_env = "gnu"))]
const DSYNC = c::RWF_DSYNC;
/// `RWF_HIPRI`
/// `RWF_HIPRI` (since Linux 4.6)
#[cfg(all(target_os = "linux", target_env = "gnu"))]
const HIPRI = c::RWF_HIPRI;
/// `RWF_SYNC`
/// `RWF_SYNC` (since Linux 4.7)
#[cfg(all(target_os = "linux", target_env = "gnu"))]
const SYNC = c::RWF_SYNC;
/// `RWF_NOWAIT`
/// `RWF_NOWAIT` (since Linux 4.14)
#[cfg(all(target_os = "linux", target_env = "gnu"))]
const NOWAIT = c::RWF_NOWAIT;
/// `RWF_APPEND`
/// `RWF_APPEND` (since Linux 4.16)
#[cfg(all(target_os = "linux", target_env = "gnu"))]
const APPEND = c::RWF_APPEND;
}
Expand Down Expand Up @@ -429,11 +429,15 @@ pub type Termios = c::termios;
#[cfg(not(target_os = "wasi"))]
pub type Winsize = c::winsize;

/// `tcflag_t`—A type for the flags fields of [`Termios`].
#[cfg(not(target_os = "wasi"))]
pub type Tcflag = c::tcflag_t;

/// `ICANON`—A flag for the `c_lflag` field of [`Termios`] indicating
/// canonical mode.
#[cfg(not(target_os = "wasi"))]
pub const ICANON: Tcflag = c::ICANON;

/// `PIPE_BUF`—The maximum size of a write to a pipe guaranteed to be atomic.
#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
pub const PIPE_BUF: usize = c::PIPE_BUF;
33 changes: 33 additions & 0 deletions src/imp/libc/io_lifetimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ pub(crate) use io_lifetimes::OwnedSocket as OwnedFd;
pub use std::os::windows::io::RawSocket as RawFd;
pub(crate) use winapi::um::winsock2::SOCKET as LibcFd;

/// A version of [`AsRawFd`] for use with Winsock APIs.
///
/// [`AsRawFd`]: https://doc.rust-lang.org/stable/std/os/unix/io/trait.AsRawFd.html
pub trait AsRawFd {
/// A version of [`as_raw_fd`] for use with Winsock APIs.
///
/// [`as_raw_fd`]: https://doc.rust-lang.org/stable/std/os/unix/io/trait.FromRawFd.html#tymethod.as_raw_fd
fn as_raw_fd(&self) -> RawFd;
}
#[cfg(feature = "std")]
Expand All @@ -20,7 +26,13 @@ impl<T: std::os::windows::io::AsRawSocket> AsRawFd for T {
}
}

/// A version of [`IntoRawFd`] for use with Winsock APIs.
///
/// [`IntoRawFd`]: https://doc.rust-lang.org/stable/std/os/unix/io/trait.IntoRawFd.html
pub trait IntoRawFd {
/// A version of [`into_raw_fd`] for use with Winsock APIs.
///
/// [`into_raw_fd`]: https://doc.rust-lang.org/stable/std/os/unix/io/trait.FromRawFd.html#tymethod.into_raw_fd
fn into_raw_fd(self) -> RawFd;
}
#[cfg(feature = "std")]
Expand All @@ -31,7 +43,13 @@ impl<T: std::os::windows::io::IntoRawSocket> IntoRawFd for T {
}
}

/// A version of [`FromRawFd`] for use with Winsock APIs.
///
/// [`FromRawFd`]: https://doc.rust-lang.org/stable/std/os/unix/io/trait.FromRawFd.html
pub trait FromRawFd {
/// A version of [`from_raw_fd`] for use with Winsock APIs.
///
/// [`from_raw_fd`]: https://doc.rust-lang.org/stable/std/os/unix/io/trait.FromRawFd.html#tymethod.from_raw_fd
unsafe fn from_raw_fd(raw_fd: RawFd) -> Self;
}
#[cfg(feature = "std")]
Expand All @@ -42,6 +60,9 @@ impl<T: std::os::windows::io::FromRawSocket> FromRawFd for T {
}
}

/// A version of [`AsFd`] for use with Winsock APIs.
///
/// [`AsFd`]: https://doc.rust-lang.org/stable/std/os/unix/io/trait.AsFd.html
pub use io_lifetimes::AsSocket as AsFd;

/// We define `AsFd` as an alias for `AsSocket`, but that doesn't provide
Expand All @@ -57,7 +78,13 @@ impl<T: io_lifetimes::AsSocket> AsSocketAsFd for T {
}
}

/// A version of [`IntoFd`] for use with Winsock APIs.
///
/// [`IntoFd`]: https://docs.rs/io-lifetimes/latest/io_lifetimes/trait.IntoFd.html
pub trait IntoFd {
/// A version of [`into_fd`] for use with Winsock APIs.
///
/// [`into_fd`]: https://docs.rs/io-lifetimes/latest/io_lifetimes/trait.IntoFd.html#tymethod.into_fd
fn into_fd(self) -> OwnedFd;
}
impl<T: io_lifetimes::IntoSocket> IntoFd for T {
Expand All @@ -67,7 +94,13 @@ impl<T: io_lifetimes::IntoSocket> IntoFd for T {
}
}

/// A version of [`FromFd`] for use with Winsock APIs.
///
/// [`FromFd`]: https://docs.rs/io-lifetimes/latest/io_lifetimes/trait.FromFd.html
pub trait FromFd {
/// A version of [`from_fd`] for use with Winsock APIs.
///
/// [`from_fd`]: https://docs.rs/io-lifetimes/latest/io_lifetimes/trait.FromFd.html#tymethod.from_fd
fn from_fd(fd: OwnedFd) -> Self;
}
impl<T: io_lifetimes::FromSocket> FromFd for T {
Expand Down
14 changes: 7 additions & 7 deletions src/imp/libc/net/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use bitflags::bitflags;
#[doc(hidden)]
pub type RawSocketType = u32;

/// `SOCK_*` constants for [`socket`].
/// `SOCK_*` constants for use with [`socket`].
///
/// [`socket`]: crate::net::socket
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
Expand Down Expand Up @@ -505,22 +505,22 @@ impl Protocol {
}
}

/// `SHUT_*` constants for [`shutdown`].
/// `SHUT_*` constants for use with [`shutdown`].
///
/// [`shutdown`]: crate::net::shutdown
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
#[repr(i32)]
pub enum Shutdown {
/// `SHUT_RD`
/// `SHUT_RD`—Disable further read operations.
Read = c::SHUT_RD,
/// `SHUT_WR`
/// `SHUT_WR`—Disable further write operations.
Write = c::SHUT_WR,
/// `SHUT_RDWR`
/// `SHUT_RDWR`—Disable further read and write operations.
ReadWrite = c::SHUT_RDWR,
}

bitflags! {
/// `SOCK_*` constants for [`accept_with`] and [`acceptfrom_with`].
/// `SOCK_*` constants for use with [`accept_with`] and [`acceptfrom_with`].
///
/// [`accept_with`]: crate::net::accept_with
/// [`acceptfrom_with`]: crate::net::acceptfrom_with
Expand All @@ -536,7 +536,7 @@ bitflags! {
}

bitflags! {
/// `SOCK_*` constants for [`socket`].
/// `SOCK_*` constants for use with [`socket`].
///
/// [`socket`]: crate::net::socket
pub struct SocketFlags: c::c_int {
Expand Down
4 changes: 3 additions & 1 deletion src/imp/libc/process/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ pub(crate) use c::{
target_os = "dragonfly"
))]
pub(crate) mod cpu_set;
#[cfg(not(target_os = "wasi"))]
pub(crate) use types::RawUname;
#[cfg(not(any(target_os = "fuchsia", target_os = "redox", target_os = "wasi")))]
pub use types::Resource;
#[cfg(any(
Expand All @@ -35,5 +37,5 @@ pub(crate) use types::{raw_cpu_set_new, RawCpuSet, CPU_SETSIZE};
#[cfg(any(target_os = "android", target_os = "linux"))]
pub use types::{MembarrierCommand, RawCpuid};
#[cfg(not(target_os = "wasi"))]
pub use types::{RawGid, RawPid, RawUid, RawUname, EXIT_SIGNALED_SIGABRT};
pub use types::{RawGid, RawPid, RawUid, EXIT_SIGNALED_SIGABRT};
pub use types::{EXIT_FAILURE, EXIT_SUCCESS};
6 changes: 5 additions & 1 deletion src/imp/libc/process/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,21 @@ pub const EXIT_FAILURE: c::c_int = c::EXIT_FAILURE;
#[cfg(not(target_os = "wasi"))]
pub const EXIT_SIGNALED_SIGABRT: c::c_int = 128 + c::SIGABRT;

/// A process identifier as a raw integer.
#[cfg(not(target_os = "wasi"))]
pub type RawPid = c::pid_t;
/// A group identifier as a raw integer.
#[cfg(not(target_os = "wasi"))]
pub type RawGid = c::gid_t;
/// A user identifier as a raw integer.
#[cfg(not(target_os = "wasi"))]
pub type RawUid = c::uid_t;
/// A CPU identifier as a raw integer.
#[cfg(any(target_os = "android", target_os = "linux"))]
pub type RawCpuid = u32;

#[cfg(not(target_os = "wasi"))]
pub type RawUname = c::utsname;
pub(crate) type RawUname = c::utsname;

#[cfg(any(
target_os = "linux",
Expand Down
7 changes: 5 additions & 2 deletions src/imp/libc/rand/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ use bitflags::bitflags;

#[cfg(target_os = "linux")]
bitflags! {
/// `GRND_*` flags for use with [`getrandom`].
///
/// [`getrandom`]: crate::rand::getrandom
pub struct GetRandomFlags: u32 {
/// GRND_RANDOM
/// `GRND_RANDOM`
const RANDOM = c::GRND_RANDOM;
/// GRND_NONBLOCK
/// `GRND_NONBLOCK`
const NONBLOCK = c::GRND_NONBLOCK;
}
}
5 changes: 5 additions & 0 deletions src/imp/libc/time/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ use super::super::fd::BorrowedFd;
/// `struct timespec`
pub type Timespec = c::timespec;

/// A type for the `tv_sec` field of [`Timespec`].
#[allow(deprecated)]
pub type Secs = c::time_t;

/// A type for the `tv_nsec` field of [`Timespec`].
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
pub type Nsecs = i64;

/// A type for the `tv_nsec` field of [`Timespec`].
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
pub type Nsecs = c::c_long;

Expand Down
5 changes: 5 additions & 0 deletions src/imp/linux_raw/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use linux_raw_sys::general::{__kernel_clockid_t, socklen_t};

/// Convert `SYS_*` constants for socketcall.
#[cfg(target_arch = "x86")]
#[inline]
pub(super) fn x86_sys<'a, Num: ArgNumber>(sys: u32) -> ArgReg<'a, Num> {
raw_arg(sys as usize)
}
Expand Down Expand Up @@ -233,6 +234,7 @@ pub(super) fn dev_t<'a, Num: ArgNumber>(dev: u64) -> io::Result<ArgReg<'a, Num>>
}

#[cfg(target_pointer_width = "32")]
#[inline]
fn oflags_bits(oflags: OFlags) -> c::c_uint {
let mut bits = oflags.bits();
// Add `O_LARGEFILE`, unless `O_PATH` is set, as Linux returns `EINVAL`
Expand All @@ -244,14 +246,17 @@ fn oflags_bits(oflags: OFlags) -> c::c_uint {
}

#[cfg(target_pointer_width = "64")]
#[inline]
fn oflags_bits(oflags: OFlags) -> c::c_uint {
oflags.bits()
}

#[inline]
pub(super) fn oflags<'a, Num: ArgNumber>(oflags: OFlags) -> ArgReg<'a, Num> {
raw_arg(oflags_bits(oflags) as usize)
}

#[inline]
pub(super) fn oflags_for_open_how(oflags: OFlags) -> u64 {
u64::from(oflags_bits(oflags))
}
Expand Down
1 change: 1 addition & 0 deletions src/imp/linux_raw/fs/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,4 +512,5 @@ pub type FsWord = linux_raw_sys::general::__fsword_t;

pub use linux_raw_sys::general::{UTIME_NOW, UTIME_OMIT};

/// `PROC_SUPER_MAGIC`—The magic number for the procfs filesystem.
pub const PROC_SUPER_MAGIC: FsWord = linux_raw_sys::general::PROC_SUPER_MAGIC as FsWord;
1 change: 1 addition & 0 deletions src/imp/linux_raw/io/epoll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
//! ```

#![allow(unsafe_code)]
#![allow(missing_docs)] // TODO: Write more docs.

use super::super::c;
use crate::fd::{AsFd, AsRawFd, BorrowedFd, RawFd};
Expand Down
1 change: 1 addition & 0 deletions src/imp/linux_raw/io/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
//! Linux uses error codes in `-4095..0`; we use rustc attributes to describe
//! this restricted range of values.
#![allow(unsafe_code)]
#![allow(missing_docs)]
#![cfg_attr(not(rustc_attrs), allow(unused_unsafe))]

use super::super::c;
Expand Down
9 changes: 7 additions & 2 deletions src/imp/linux_raw/io/poll_fd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use super::super::fd::{AsFd, BorrowedFd};
use bitflags::bitflags;

bitflags! {
/// `POLL*`
/// `POLL*` flags for use with [`poll`].
///
/// [`poll`]: rustix::io::poll
pub struct PollFlags: u16 {
/// `POLLIN`
const IN = linux_raw_sys::general::POLLIN as u16;
Expand All @@ -29,7 +31,10 @@ bitflags! {
}
}

/// `struct pollfd`
/// `struct pollfd`—File descriptor and flags for use with [`poll`].
///
/// [`poll`]: rustix::io::poll
#[doc(alias = "pollfd")]
#[repr(C)]
#[derive(Debug, Clone)]
pub struct PollFd<'fd> {
Expand Down
Loading