Skip to content

Commit

Permalink
Merge branch 'master' into add-vsock-support-for-macos
Browse files Browse the repository at this point in the history
  • Loading branch information
tzneal committed Jul 12, 2023
2 parents 7b892bf + 75a26cd commit f6017ee
Show file tree
Hide file tree
Showing 15 changed files with 43 additions and 31 deletions.
17 changes: 14 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@ This project adheres to [Semantic Versioning](https://semver.org/).
([#2012](https://github.com/nix-rust/nix/pull/2012))

### Fixed
- Fix `SockaddrIn6` bug that was swapping flowinfo and scope_id byte ordering.
([#1964](https://github.com/nix-rust/nix/pull/1964))
- Fix: send ETH_P_ALL in htons format
- Fix: send `ETH_P_ALL` in htons format
([#1925](https://github.com/nix-rust/nix/pull/1925))
- Fix potentially invalid conversions in
`SockaddrIn::from<std::net::SocketAddrV4>`,
`SockaddrIn6::from<std::net::SockaddrV6>`, `IpMembershipRequest::new`, and
`Ipv6MembershipRequest::new` with future Rust versions.
([#2061](https://github.com/nix-rust/nix/pull/2061))

### Removed

Expand All @@ -51,6 +54,14 @@ This project adheres to [Semantic Versioning](https://semver.org/).
`nix::sys::signalfd::SignalFd` instead.
([#1938](https://github.com/nix-rust/nix/pull/1938))

## [0.26.2] - 2023-01-18

### Fixed

- Fix `SockaddrIn6` bug that was swapping `flowinfo` and `scope_id` byte
ordering.
([#1964](https://github.com/nix-rust/nix/pull/1964))

## [0.26.1] - 2022-11-29
### Fixed
- Fix UB with `sys::socket::sockopt::SockType` using `SOCK_PACKET`.
Expand Down
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ targets = [

[dependencies]
libc = { version = "0.2.146", features = ["extra_traits"] }
bitflags = "1.1"
bitflags = "2.3.1"
cfg-if = "1.0"
pin-utils = { version = "0.1.0", optional = true }
static_assertions = "1"
memoffset = { version = "0.9", optional = true }

[features]
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//! * `fs` - File system functionality
//! * `hostname` - Get and set the system's hostname
//! * `inotify` - Linux's `inotify` file system notification API
//! * `ioctl` - The `ioctl` syscall, and wrappers for my specific instances
//! * `ioctl` - The `ioctl` syscall, and wrappers for many specific instances
//! * `kmod` - Load and unload kernel modules
//! * `mman` - Stuff relating to memory management
//! * `mount` - Mount and unmount file systems
Expand Down
2 changes: 2 additions & 0 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ macro_rules! libc_bitflags {
}
) => {
::bitflags::bitflags! {
#[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[repr(transparent)]
$(#[$outer])*
pub struct $BitFlags: $T {
$(
Expand Down
4 changes: 2 additions & 2 deletions src/mount/bsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ impl<'a> Nmount<'a> {

let niov = self.iov.len() as c_uint;
let iovp = self.iov.as_mut_ptr() as *mut libc::iovec;
let res = unsafe { libc::nmount(iovp, niov, flags.bits) };
let res = unsafe { libc::nmount(iovp, niov, flags.bits()) };
match Errno::result(res) {
Ok(_) => Ok(()),
Err(error) => {
Expand Down Expand Up @@ -446,7 +446,7 @@ where
P: ?Sized + NixPath,
{
let res = mountpoint.with_nix_path(|cstr| unsafe {
libc::unmount(cstr.as_ptr(), flags.bits)
libc::unmount(cstr.as_ptr(), flags.bits())
})?;

Errno::result(res).map(drop)
Expand Down
4 changes: 2 additions & 2 deletions src/mount/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ pub fn mount<
s,
t.as_ptr(),
ty,
flags.bits,
flags.bits(),
d as *const libc::c_void,
)
})
Expand All @@ -156,7 +156,7 @@ pub fn umount<P: ?Sized + NixPath>(target: &P) -> Result<()> {
/// See also [`umount`](https://man7.org/linux/man-pages/man2/umount.2.html)
pub fn umount2<P: ?Sized + NixPath>(target: &P, flags: MntFlags) -> Result<()> {
let res = target.with_nix_path(|cstr| unsafe {
libc::umount2(cstr.as_ptr(), flags.bits)
libc::umount2(cstr.as_ptr(), flags.bits())
})?;

Errno::result(res).map(drop)
Expand Down
2 changes: 1 addition & 1 deletion src/mqueue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl MqAttr {
/// Open a message queue
///
/// See also [`mq_open(2)`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_open.html)
// The mode.bits cast is only lossless on some OSes
// The mode.bits() cast is only lossless on some OSes
#[allow(clippy::cast_lossless)]
pub fn mq_open(
name: &CStr,
Expand Down
2 changes: 1 addition & 1 deletion src/sys/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl Kqueue {
timeout as *const timespec
} else {
ptr::null()
}
},
)
};
Errno::result(res).map(|r| r as usize)
Expand Down
5 changes: 4 additions & 1 deletion src/sys/personality.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ pub fn get() -> Result<Persona> {
///
/// Example:
///
/// ```
// Disable test on aarch64 until we know why it fails.
// https://github.com/nix-rust/nix/issues/2060
#[cfg_attr(target_arch = "aarch64", doc = " ```no_run")]
#[cfg_attr(not(target_arch = "aarch64"), doc = " ```")]
/// # use nix::sys::personality::{self, Persona};
/// let mut pers = personality::get().unwrap();
/// assert!(!pers.contains(Persona::ADDR_NO_RANDOMIZE));
Expand Down
16 changes: 6 additions & 10 deletions src/sys/socket/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,17 @@ use std::{fmt, mem, net, ptr, slice};
/// Convert a std::net::Ipv4Addr into the libc form.
#[cfg(feature = "net")]
pub(crate) const fn ipv4addr_to_libc(addr: net::Ipv4Addr) -> libc::in_addr {
static_assertions::assert_eq_size!(net::Ipv4Addr, libc::in_addr);
// Safe because both types have the same memory layout, and no fancy Drop
// impls.
unsafe { mem::transmute(addr) }
libc::in_addr {
s_addr: u32::from_ne_bytes(addr.octets())
}
}

/// Convert a std::net::Ipv6Addr into the libc form.
#[cfg(feature = "net")]
pub(crate) const fn ipv6addr_to_libc(addr: &net::Ipv6Addr) -> libc::in6_addr {
static_assertions::assert_eq_size!(net::Ipv6Addr, libc::in6_addr);
// Safe because both are Newtype wrappers around the same libc type
unsafe { mem::transmute(*addr) }
libc::in6_addr {
s6_addr: addr.octets()
}
}

/// These constants specify the protocol family to be used
Expand Down Expand Up @@ -949,9 +948,6 @@ impl SockaddrLike for () {
}

/// An IPv4 socket address
// This is identical to net::SocketAddrV4. But the standard library
// doesn't allow direct access to the libc fields, which we need. So we
// reimplement it here.
#[cfg(feature = "net")]
#[repr(transparent)]
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
Expand Down
4 changes: 2 additions & 2 deletions src/sys/stat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ pub fn mknod<P: ?Sized + NixPath>(
dev: dev_t,
) -> Result<()> {
let res = path.with_nix_path(|cstr| unsafe {
libc::mknod(cstr.as_ptr(), kind.bits | perm.bits() as mode_t, dev)
libc::mknod(cstr.as_ptr(), kind.bits() | perm.bits() as mode_t, dev)
})?;

Errno::result(res).map(drop)
Expand All @@ -202,7 +202,7 @@ pub fn mknodat<P: ?Sized + NixPath>(
libc::mknodat(
dirfd,
cstr.as_ptr(),
kind.bits | perm.bits() as mode_t,
kind.bits() | perm.bits() as mode_t,
dev,
)
})?;
Expand Down
1 change: 0 additions & 1 deletion src/sys/statvfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use crate::{errno::Errno, NixPath, Result};
#[cfg(not(target_os = "redox"))]
libc_bitflags!(
/// File system mount Flags
#[repr(C)]
#[derive(Default)]
pub struct FsFlags: c_ulong {
/// Read Only
Expand Down
6 changes: 3 additions & 3 deletions src/sys/termios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ impl Termios {
let termios = *self.inner.borrow_mut();
self.input_flags = InputFlags::from_bits_truncate(termios.c_iflag);
self.output_flags = OutputFlags::from_bits_truncate(termios.c_oflag);
self.control_flags = ControlFlags::from_bits_truncate(termios.c_cflag);
self.control_flags = ControlFlags::from_bits_retain(termios.c_cflag);
self.local_flags = LocalFlags::from_bits_truncate(termios.c_lflag);
self.control_chars = termios.c_cc;
#[cfg(any(
Expand Down Expand Up @@ -355,9 +355,9 @@ libc_enum! {
/// enum.
///
/// B0 is special and will disable the port.
#[cfg_attr(all(any(target_os = "haiku"), target_pointer_width = "64"), repr(u8))]
#[cfg_attr(target_os = "haiku", repr(u8))]
#[cfg_attr(all(any(target_os = "ios", target_os = "macos"), target_pointer_width = "64"), repr(u64))]
#[cfg_attr(not(all(any(target_os = "ios", target_os = "macos", target_os = "haiku"), target_pointer_width = "64")), repr(u32))]
#[cfg_attr(all(not(all(any(target_os = "ios", target_os = "macos"), target_pointer_width = "64")), not(target_os = "haiku")), repr(u32))]
#[non_exhaustive]
pub enum BaudRate {
B0,
Expand Down
2 changes: 2 additions & 0 deletions src/sys/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ pub(crate) mod timer {
#[cfg(any(target_os = "android", target_os = "linux"))]
bitflags! {
/// Flags that are used for arming the timer.
#[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct TimerSetTimeFlags: libc::c_int {
const TFD_TIMER_ABSTIME = libc::TFD_TIMER_ABSTIME;
const TFD_TIMER_CANCEL_ON_SET = libc::TFD_TIMER_CANCEL_ON_SET;
Expand All @@ -104,6 +105,7 @@ pub(crate) mod timer {
))]
bitflags! {
/// Flags that are used for arming the timer.
#[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct TimerSetTimeFlags: libc::c_int {
const TFD_TIMER_ABSTIME = libc::TIMER_ABSTIME;
}
Expand Down
4 changes: 2 additions & 2 deletions src/unistd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3375,7 +3375,7 @@ feature! {
/// See [access(2)](https://pubs.opengroup.org/onlinepubs/9699919799/functions/access.html)
pub fn access<P: ?Sized + NixPath>(path: &P, amode: AccessFlags) -> Result<()> {
let res = path.with_nix_path(|cstr| unsafe {
libc::access(cstr.as_ptr(), amode.bits)
libc::access(cstr.as_ptr(), amode.bits())
})?;
Errno::result(res).map(drop)
}
Expand Down Expand Up @@ -3422,7 +3422,7 @@ pub fn faccessat<P: ?Sized + NixPath>(
))]
pub fn eaccess<P: ?Sized + NixPath>(path: &P, mode: AccessFlags) -> Result<()> {
let res = path.with_nix_path(|cstr| unsafe {
libc::eaccess(cstr.as_ptr(), mode.bits)
libc::eaccess(cstr.as_ptr(), mode.bits())
})?;
Errno::result(res).map(drop)
}
Expand Down

0 comments on commit f6017ee

Please sign in to comment.