Skip to content
This repository was archived by the owner on May 22, 2026. It is now read-only.

Commit 21117ac

Browse files
committed
macos: add signal shim for downstream rust-vmm crates
Adds macOS compatibility for the `signal` module so downstream rust-vmm crates (`vhost`, `vhost-user-backend`, `virtiofsd`, …) can build and run on macOS without code changes. All macOS code is gated behind `#[cfg(target_os = "macos")]` and adds no new dependencies; Linux and Android builds are unaffected. The crate stays at `BSD-3-Clause` and no third-party code is vendored. Host-signal validation uses `1..=SIGUSR2` because macOS signal numbers do not match Linux's: SIGSYS=12, SIGTERM=15, SIGUSR2=31. The `SIGHUP..=SIGSYS` range used on Linux would reject valid macOS signals. Pending-signal clearing goes via unblock-then-reblock because macOS does not expose `sigtimedwait`. What this PR no longer ships, and why: - No `eventfd` shim. The cross-platform `EventConsumer` / `EventNotifier` primitive added in #244 already covers the daemon side of `vhost-user-backend`. The remaining macOS callers of `vmm_sys_util::eventfd::EventFd` are inside the `vhost` crate's `VhostBackend` / `VhostBackendMut` traits, whose only consumers are Linux-only (kernel vhost drivers, vhost-user frontends inside Linux-only VMMs). A small follow-up PR to `vhost` gates those trait methods on Linux, after which nothing in the macOS build path references `vmm_sys_util::eventfd` and a shim is genuinely unnecessary. - No `epoll` shim. Consumers needing epoll-shaped polling on macOS should use `mio` (see vhost #316), which gives proper cross-platform event polling backed by `kqueue` on macOS — a cleaner architectural answer than shimming the Linux API. Tests: - `macos::signal::tests` — validator range, register/block/unblock/kill round-trips, pending-signal clearing. Pre-existing failures in `rand` and `unix::tempdir` on macOS are out of scope for this PR. Signed-off-by: Chris Thomas <chris.thomas@antimatter-studios.com>
1 parent 273e5d4 commit 21117ac

5 files changed

Lines changed: 420 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
**/*.rs.bk
44
Cargo.lock
55

6+
.DS_Store

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Added
66

77
- [[#254](https://github.com/rust-vmm/vmm-sys-util/pull/254)]: Support `TFD_NONBLOCK` for `timerfd::TimerFd`.
8+
- [[#268](https://github.com/rust-vmm/vmm-sys-util/pull/268)]: Add macOS support for the `signal` module. The shim is gated behind `#[cfg(target_os = "macos")]` and adds no new dependencies; Linux and Android builds are unaffected. macOS consumers needing epoll-shaped polling should use `mio` (see vhost #316). `eventfd` is not provided: the cross-platform `EventConsumer`/`EventNotifier` primitive added in #244 already covers the daemon use case, and `vhost`'s public traits that take `&EventFd` are Linux-only callers (a follow-up gates them on Linux).
89

910
## v0.15.0
1011

src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ mod linux;
1212
#[cfg(any(target_os = "linux", target_os = "android"))]
1313
pub use crate::linux::*;
1414

15+
#[cfg(target_os = "macos")]
16+
mod macos;
17+
#[cfg(target_os = "macos")]
18+
pub use crate::macos::*;
19+
1520
#[cfg(unix)]
1621
mod unix;
1722
#[cfg(unix)]

src/macos/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Copyright 2024 rust-vmm Authors. All Rights Reserved.
2+
// SPDX-License-Identifier: BSD-3-Clause
3+
4+
//! macOS-specific modules providing compatibility shims for Linux-only APIs.
5+
6+
pub mod signal;

0 commit comments

Comments
 (0)