bolts for haiku update (#1673)

core_affinity using available_parallelism which also support this
platform. further tests disabling.
This commit is contained in:
David CARLIER 2023-11-19 22:58:30 +00:00 committed by GitHub
parent 57296a6750
commit a013ad6085
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 51 additions and 17 deletions

View File

@ -3,37 +3,37 @@ This shows how llmp can be used directly, without libafl abstractions
*/ */
extern crate alloc; extern crate alloc;
#[cfg(feature = "std")] #[cfg(all(feature = "std", not(target_os = "haiku")))]
use core::time::Duration; use core::time::Duration;
#[cfg(feature = "std")] #[cfg(all(feature = "std", not(target_os = "haiku")))]
use std::{num::NonZeroUsize, thread, time}; use std::{num::NonZeroUsize, thread, time};
#[cfg(feature = "std")] #[cfg(all(feature = "std", not(target_os = "haiku")))]
use libafl_bolts::{ use libafl_bolts::{
llmp::{self, Tag}, llmp::{self, Tag},
shmem::{ShMemProvider, StdShMemProvider}, shmem::{ShMemProvider, StdShMemProvider},
ClientId, Error, SimpleStderrLogger, ClientId, Error, SimpleStderrLogger,
}; };
#[cfg(feature = "std")] #[cfg(all(feature = "std", not(target_os = "haiku")))]
const _TAG_SIMPLE_U32_V1: Tag = Tag(0x5130_0321); const _TAG_SIMPLE_U32_V1: Tag = Tag(0x5130_0321);
#[cfg(feature = "std")] #[cfg(all(feature = "std", not(target_os = "haiku")))]
const _TAG_MATH_RESULT_V1: Tag = Tag(0x7747_4331); const _TAG_MATH_RESULT_V1: Tag = Tag(0x7747_4331);
#[cfg(feature = "std")] #[cfg(all(feature = "std", not(target_os = "haiku")))]
const _TAG_1MEG_V1: Tag = Tag(0xB111_1161); const _TAG_1MEG_V1: Tag = Tag(0xB111_1161);
/// The time the broker will wait for things to happen before printing a message /// The time the broker will wait for things to happen before printing a message
#[cfg(feature = "std")] #[cfg(all(feature = "std", not(target_os = "haiku")))]
const BROKER_TIMEOUT: Duration = Duration::from_secs(10); const BROKER_TIMEOUT: Duration = Duration::from_secs(10);
/// How long the broker may sleep between forwarding a new chunk of sent messages /// How long the broker may sleep between forwarding a new chunk of sent messages
#[cfg(feature = "std")] #[cfg(all(feature = "std", not(target_os = "haiku")))]
const SLEEP_BETWEEN_FORWARDS: Duration = Duration::from_millis(5); const SLEEP_BETWEEN_FORWARDS: Duration = Duration::from_millis(5);
#[cfg(feature = "std")] #[cfg(all(feature = "std", not(target_os = "haiku")))]
static LOGGER: SimpleStderrLogger = SimpleStderrLogger::new(); static LOGGER: SimpleStderrLogger = SimpleStderrLogger::new();
#[cfg(feature = "std")] #[cfg(all(feature = "std", not(target_os = "haiku")))]
fn adder_loop(port: u16) -> Result<(), Box<dyn std::error::Error>> { fn adder_loop(port: u16) -> Result<(), Box<dyn std::error::Error>> {
let shmem_provider = StdShMemProvider::new()?; let shmem_provider = StdShMemProvider::new()?;
let mut client = llmp::LlmpClient::create_attach_to_tcp(shmem_provider, port)?; let mut client = llmp::LlmpClient::create_attach_to_tcp(shmem_provider, port)?;
@ -71,7 +71,7 @@ fn adder_loop(port: u16) -> Result<(), Box<dyn std::error::Error>> {
} }
} }
#[cfg(feature = "std")] #[cfg(all(feature = "std", not(target_os = "haiku")))]
fn large_msg_loop(port: u16) -> Result<(), Box<dyn std::error::Error>> { fn large_msg_loop(port: u16) -> Result<(), Box<dyn std::error::Error>> {
let mut client = llmp::LlmpClient::create_attach_to_tcp(StdShMemProvider::new()?, port)?; let mut client = llmp::LlmpClient::create_attach_to_tcp(StdShMemProvider::new()?, port)?;
@ -91,7 +91,7 @@ fn large_msg_loop(port: u16) -> Result<(), Box<dyn std::error::Error>> {
} }
#[allow(clippy::unnecessary_wraps)] #[allow(clippy::unnecessary_wraps)]
#[cfg(feature = "std")] #[cfg(all(feature = "std", not(target_os = "haiku")))]
fn broker_message_hook( fn broker_message_hook(
msg_or_timeout: Option<(ClientId, llmp::Tag, llmp::Flags, &[u8])>, msg_or_timeout: Option<(ClientId, llmp::Tag, llmp::Flags, &[u8])>,
) -> Result<llmp::LlmpMsgHookResult, Error> { ) -> Result<llmp::LlmpMsgHookResult, Error> {
@ -126,12 +126,12 @@ fn broker_message_hook(
} }
} }
#[cfg(not(any(unix, windows)))] #[cfg(target_os = "haiku")]
fn main() { fn main() {
eprintln!("LLMP example is currently not supported on no_std. Implement ShMem for no_std."); eprintln!("LLMP example is currently not supported on no_std. Implement ShMem for no_std.");
} }
#[cfg(any(unix, windows))] #[cfg(not(target_os = "haiku"))]
fn main() -> Result<(), Box<dyn std::error::Error>> { fn main() -> Result<(), Box<dyn std::error::Error>> {
/* The main node has a broker, and a few worker threads */ /* The main node has a broker, and a few worker threads */

View File

@ -353,7 +353,7 @@ mod linux {
#[allow(clippy::unnecessary_wraps)] #[allow(clippy::unnecessary_wraps)]
#[inline] #[inline]
fn get_core_ids_helper() -> Result<Vec<CoreId>, Error> { fn get_core_ids_helper() -> Result<Vec<CoreId>, Error> {
Ok(Vec::new()) haiku::get_core_ids()
} }
#[cfg(target_os = "haiku")] #[cfg(target_os = "haiku")]
@ -363,6 +363,21 @@ fn set_for_current_helper(_core_id: CoreId) -> Result<(), Error> {
Ok(()) Ok(())
} }
#[cfg(target_os = "haiku")]
mod haiku {
use alloc::vec::Vec;
use std::thread::available_parallelism;
use crate::core_affinity::{CoreId, Error};
#[allow(clippy::unnecessary_wraps)]
pub fn get_core_ids() -> Result<Vec<CoreId>, Error> {
Ok((0..(usize::from(available_parallelism()?)))
.map(CoreId)
.collect::<Vec<_>>())
}
}
// Windows Section // Windows Section
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
@ -735,6 +750,7 @@ mod freebsd {
unsafe { mem::zeroed::<cpuset_t>() } unsafe { mem::zeroed::<cpuset_t>() }
} }
// FIXME: unstable for now on freebsd
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use libc::CPU_ISSET; use libc::CPU_ISSET;
@ -742,11 +758,13 @@ mod freebsd {
use super::*; use super::*;
#[test] #[test]
#[ignore]
fn test_freebsd_get_affinity_mask() { fn test_freebsd_get_affinity_mask() {
get_affinity_mask().unwrap(); get_affinity_mask().unwrap();
} }
#[test] #[test]
#[ignore]
fn test_freebsd_set_for_current() { fn test_freebsd_set_for_current() {
let ids = get_core_ids().unwrap(); let ids = get_core_ids().unwrap();

View File

@ -3173,7 +3173,7 @@ where
} }
#[cfg(test)] #[cfg(test)]
#[cfg(all(unix, feature = "std"))] #[cfg(all(unix, feature = "std", not(target_os = "haiku")))]
mod tests { mod tests {
use std::{thread::sleep, time::Duration}; use std::{thread::sleep, time::Duration};

View File

@ -654,6 +654,21 @@ fn write_crash<W: Write>(
Ok(()) Ok(())
} }
#[cfg(all(target_os = "haiku", target_arch = "x86_64"))]
fn write_crash<W: Write>(
writer: &mut BufWriter<W>,
signal: Signal,
ucontext: &ucontext_t,
) -> Result<(), std::io::Error> {
writeln!(
writer,
"Received signal {} at {:#016x}",
signal, ucontext.uc_mcontext.rip
)?;
Ok(())
}
#[cfg(not(any( #[cfg(not(any(
target_vendor = "apple", target_vendor = "apple",
target_os = "linux", target_os = "linux",
@ -662,6 +677,7 @@ fn write_crash<W: Write>(
target_os = "dragonfly", target_os = "dragonfly",
target_os = "openbsd", target_os = "openbsd",
target_os = "netbsd", target_os = "netbsd",
target_os = "haiku",
any(target_os = "solaris", target_os = "illumos"), any(target_os = "solaris", target_os = "illumos"),
)))] )))]
fn write_crash<W: Write>( fn write_crash<W: Write>(

View File

@ -1537,7 +1537,7 @@ impl<T: ShMem> std::io::Seek for ShMemCursor<T> {
} }
} }
#[cfg(feature = "std")] #[cfg(all(feature = "std", not(target_os = "haiku")))]
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use serial_test::serial; use serial_test::serial;