diff --git a/libafl/src/bolts/core_affinity.rs b/libafl/src/bolts/core_affinity.rs index 3185111ac2..5a43c04a40 100644 --- a/libafl/src/bolts/core_affinity.rs +++ b/libafl/src/bolts/core_affinity.rs @@ -816,6 +816,51 @@ mod openbsd { } } +#[cfg(any(target_os = "solaris", target_os = "illumos"))] +#[inline] +fn get_core_ids_helper() -> Result, Error> { + solaris::get_core_ids() +} + +#[cfg(any(target_os = "solaris", target_os = "illumos"))] +#[inline] +fn set_for_current_helper(core_id: CoreId) -> Result<(), Error> { + solaris::set_for_current(core_id) +} + +#[cfg(any(target_os = "solaris", target_os = "illumos"))] +mod solaris { + use alloc::vec::Vec; + use std::thread::available_parallelism; + + use super::CoreId; + use crate::Error; + + #[allow(clippy::unnecessary_wraps)] + pub fn get_core_ids() -> Result, Error> { + Ok((0..(usize::from(available_parallelism()?))) + .into_iter() + .map(|n| CoreId { id: n }) + .collect::>()) + } + + pub fn set_for_current(core_id: CoreId) -> Result<(), Error> { + let result = unsafe { + libc::processor_bind( + libc::P_PID, + libc::PS_MYID, + core_id.id as i32, + std::ptr::null_mut(), + ) + }; + if result < 0 { + Err(Error::unknown("Failed to processor_bind")) + } else { + Ok(()) + } + } +} + #[cfg(test)] mod tests { use std::thread::available_parallelism; diff --git a/libafl/src/bolts/llmp.rs b/libafl/src/bolts/llmp.rs index b4bb3644ea..7e0c2d9dec 100644 --- a/libafl/src/bolts/llmp.rs +++ b/libafl/src/bolts/llmp.rs @@ -74,6 +74,7 @@ use core::{ time::Duration, }; #[cfg(all(unix, feature = "std"))] +#[cfg(not(any(target_os = "solaris", target_os = "illumos")))] use std::os::unix::io::AsRawFd; #[cfg(feature = "std")] use std::{ @@ -87,6 +88,7 @@ use std::{ #[cfg(all(debug_assertions, feature = "llmp_debug", feature = "std"))] use backtrace::Backtrace; #[cfg(all(unix, feature = "std"))] +#[cfg(not(any(target_os = "solaris", target_os = "illumos")))] use nix::sys::socket::{self, sockopt::ReusePort}; use serde::{Deserialize, Serialize}; @@ -380,6 +382,7 @@ fn tcp_bind(port: u16) -> Result { let listener = TcpListener::bind((_LLMP_BIND_ADDR, port))?; #[cfg(unix)] + #[cfg(not(any(target_os = "solaris", target_os = "illumos")))] socket::setsockopt(listener.as_raw_fd(), ReusePort, &true)?; Ok(listener) diff --git a/libafl/src/bolts/shmem.rs b/libafl/src/bolts/shmem.rs index f5b9881584..ee983936d4 100644 --- a/libafl/src/bolts/shmem.rs +++ b/libafl/src/bolts/shmem.rs @@ -800,12 +800,22 @@ pub mod unix_shmem { impl CommonUnixShMem { /// Create a new shared memory mapping, using shmget/shmat + #[allow(unused_qualifications)] pub fn new(map_size: usize) -> Result { + #[cfg(any(target_os = "solaris", target_os = "illumos"))] + const SHM_R: libc::c_int = 0o400; + #[cfg(not(any(target_os = "solaris", target_os = "illumos")))] + const SHM_R: libc::c_int = libc::SHM_R; + #[cfg(any(target_os = "solaris", target_os = "illumos"))] + const SHM_W: libc::c_int = 0o200; + #[cfg(not(any(target_os = "solaris", target_os = "illumos")))] + const SHM_W: libc::c_int = libc::SHM_W; + unsafe { let os_id = shmget( libc::IPC_PRIVATE, map_size, - libc::IPC_CREAT | libc::IPC_EXCL | libc::SHM_R | libc::SHM_W, + libc::IPC_CREAT | libc::IPC_EXCL | SHM_R | SHM_W, ); if os_id < 0_i32 {