Skip to content

Commit

Permalink
Add support for illumos (#371)
Browse files Browse the repository at this point in the history
With this commit, ipc-channel works and the full test suite passes on illumos.
I've also added a small amount of debug logging that was invaluable to me while
porting over ipc-channel to illumos.

I'm also happy to set up cross-compile CI, and if there's interest then I could
chat with folks at Oxide about providing resources for runtime CI as well.
  • Loading branch information
sunshowers authored Oct 28, 2024
1 parent 97df9fd commit 66453c0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ rand = "0.8"
serde = { version = "1.0", features = ["rc"] }
uuid = { version = "1", features = ["v4"] }

[target.'cfg(any(target_os = "linux", target_os = "openbsd", target_os = "freebsd"))'.dependencies]
[target.'cfg(any(target_os = "linux", target_os = "openbsd", target_os = "freebsd", target_os = "illumos"))'.dependencies]
mio = { version = "1.0", features = ["os-ext"] }
tempfile = "3.4"

Expand Down
14 changes: 12 additions & 2 deletions src/platform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,22 @@

#[cfg(all(
not(feature = "force-inprocess"),
any(target_os = "linux", target_os = "openbsd", target_os = "freebsd")
any(
target_os = "linux",
target_os = "openbsd",
target_os = "freebsd",
target_os = "illumos",
)
))]
mod unix;
#[cfg(all(
not(feature = "force-inprocess"),
any(target_os = "linux", target_os = "openbsd", target_os = "freebsd")
any(
target_os = "linux",
target_os = "openbsd",
target_os = "freebsd",
target_os = "illumos",
)
))]
mod os {
pub use super::unix::*;
Expand Down
20 changes: 14 additions & 6 deletions src/platform/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ const MAX_FDS_IN_CMSG: u32 = 64;
// Empirically, we have to deduct 32 bytes from that.
const RESERVED_SIZE: usize = 32;

#[cfg(target_os = "linux")]
#[cfg(any(target_os = "linux", target_os = "illumos"))]
const SOCK_FLAGS: c_int = libc::SOCK_CLOEXEC;
#[cfg(not(target_os = "linux"))]
#[cfg(not(any(target_os = "linux", target_os = "illumos")))]
const SOCK_FLAGS: c_int = 0;

#[cfg(target_os = "linux")]
Expand Down Expand Up @@ -130,9 +130,15 @@ pub struct OsIpcReceiver {
impl Drop for OsIpcReceiver {
fn drop(&mut self) {
unsafe {
if self.fd.get() >= 0 {
let result = libc::close(self.fd.get());
assert!(thread::panicking() || result == 0);
let fd = self.fd.get();
if fd >= 0 {
let result = libc::close(fd);
assert!(
thread::panicking() || result == 0,
"closed receiver (fd: {}): {}",
fd,
UnixError::last(),
);
}
}
}
Expand Down Expand Up @@ -778,7 +784,9 @@ impl BackingStore {
pub unsafe fn map_file(&self, length: Option<size_t>) -> (*mut u8, size_t) {
let length = length.unwrap_or_else(|| {
let mut st = mem::MaybeUninit::uninit();
assert!(libc::fstat(self.fd, st.as_mut_ptr()) == 0);
if libc::fstat(self.fd, st.as_mut_ptr()) != 0 {
panic!("error stating fd {}: {}", self.fd, UnixError::last());
}
st.assume_init().st_size as size_t
});
if length == 0 {
Expand Down

0 comments on commit 66453c0

Please sign in to comment.