Skip to content

Commit a013ad6

Browse files
authored
bolts for haiku update (#1673)
core_affinity using available_parallelism which also support this platform. further tests disabling.
1 parent 57296a6 commit a013ad6

File tree

5 files changed

+51
-17
lines changed

5 files changed

+51
-17
lines changed

libafl_bolts/examples/llmp_test/main.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,37 @@ This shows how llmp can be used directly, without libafl abstractions
33
*/
44
extern crate alloc;
55

6-
#[cfg(feature = "std")]
6+
#[cfg(all(feature = "std", not(target_os = "haiku")))]
77
use core::time::Duration;
8-
#[cfg(feature = "std")]
8+
#[cfg(all(feature = "std", not(target_os = "haiku")))]
99
use std::{num::NonZeroUsize, thread, time};
1010

11-
#[cfg(feature = "std")]
11+
#[cfg(all(feature = "std", not(target_os = "haiku")))]
1212
use libafl_bolts::{
1313
llmp::{self, Tag},
1414
shmem::{ShMemProvider, StdShMemProvider},
1515
ClientId, Error, SimpleStderrLogger,
1616
};
1717

18-
#[cfg(feature = "std")]
18+
#[cfg(all(feature = "std", not(target_os = "haiku")))]
1919
const _TAG_SIMPLE_U32_V1: Tag = Tag(0x5130_0321);
20-
#[cfg(feature = "std")]
20+
#[cfg(all(feature = "std", not(target_os = "haiku")))]
2121
const _TAG_MATH_RESULT_V1: Tag = Tag(0x7747_4331);
22-
#[cfg(feature = "std")]
22+
#[cfg(all(feature = "std", not(target_os = "haiku")))]
2323
const _TAG_1MEG_V1: Tag = Tag(0xB111_1161);
2424

2525
/// The time the broker will wait for things to happen before printing a message
26-
#[cfg(feature = "std")]
26+
#[cfg(all(feature = "std", not(target_os = "haiku")))]
2727
const BROKER_TIMEOUT: Duration = Duration::from_secs(10);
2828

2929
/// How long the broker may sleep between forwarding a new chunk of sent messages
30-
#[cfg(feature = "std")]
30+
#[cfg(all(feature = "std", not(target_os = "haiku")))]
3131
const SLEEP_BETWEEN_FORWARDS: Duration = Duration::from_millis(5);
3232

33-
#[cfg(feature = "std")]
33+
#[cfg(all(feature = "std", not(target_os = "haiku")))]
3434
static LOGGER: SimpleStderrLogger = SimpleStderrLogger::new();
3535

36-
#[cfg(feature = "std")]
36+
#[cfg(all(feature = "std", not(target_os = "haiku")))]
3737
fn adder_loop(port: u16) -> Result<(), Box<dyn std::error::Error>> {
3838
let shmem_provider = StdShMemProvider::new()?;
3939
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>> {
7171
}
7272
}
7373

74-
#[cfg(feature = "std")]
74+
#[cfg(all(feature = "std", not(target_os = "haiku")))]
7575
fn large_msg_loop(port: u16) -> Result<(), Box<dyn std::error::Error>> {
7676
let mut client = llmp::LlmpClient::create_attach_to_tcp(StdShMemProvider::new()?, port)?;
7777

@@ -91,7 +91,7 @@ fn large_msg_loop(port: u16) -> Result<(), Box<dyn std::error::Error>> {
9191
}
9292

9393
#[allow(clippy::unnecessary_wraps)]
94-
#[cfg(feature = "std")]
94+
#[cfg(all(feature = "std", not(target_os = "haiku")))]
9595
fn broker_message_hook(
9696
msg_or_timeout: Option<(ClientId, llmp::Tag, llmp::Flags, &[u8])>,
9797
) -> Result<llmp::LlmpMsgHookResult, Error> {
@@ -126,12 +126,12 @@ fn broker_message_hook(
126126
}
127127
}
128128

129-
#[cfg(not(any(unix, windows)))]
129+
#[cfg(target_os = "haiku")]
130130
fn main() {
131131
eprintln!("LLMP example is currently not supported on no_std. Implement ShMem for no_std.");
132132
}
133133

134-
#[cfg(any(unix, windows))]
134+
#[cfg(not(target_os = "haiku"))]
135135
fn main() -> Result<(), Box<dyn std::error::Error>> {
136136
/* The main node has a broker, and a few worker threads */
137137

libafl_bolts/src/core_affinity.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ mod linux {
353353
#[allow(clippy::unnecessary_wraps)]
354354
#[inline]
355355
fn get_core_ids_helper() -> Result<Vec<CoreId>, Error> {
356-
Ok(Vec::new())
356+
haiku::get_core_ids()
357357
}
358358

359359
#[cfg(target_os = "haiku")]
@@ -363,6 +363,21 @@ fn set_for_current_helper(_core_id: CoreId) -> Result<(), Error> {
363363
Ok(())
364364
}
365365

366+
#[cfg(target_os = "haiku")]
367+
mod haiku {
368+
use alloc::vec::Vec;
369+
use std::thread::available_parallelism;
370+
371+
use crate::core_affinity::{CoreId, Error};
372+
373+
#[allow(clippy::unnecessary_wraps)]
374+
pub fn get_core_ids() -> Result<Vec<CoreId>, Error> {
375+
Ok((0..(usize::from(available_parallelism()?)))
376+
.map(CoreId)
377+
.collect::<Vec<_>>())
378+
}
379+
}
380+
366381
// Windows Section
367382

368383
#[cfg(target_os = "windows")]
@@ -735,18 +750,21 @@ mod freebsd {
735750
unsafe { mem::zeroed::<cpuset_t>() }
736751
}
737752

753+
// FIXME: unstable for now on freebsd
738754
#[cfg(test)]
739755
mod tests {
740756
use libc::CPU_ISSET;
741757

742758
use super::*;
743759

744760
#[test]
761+
#[ignore]
745762
fn test_freebsd_get_affinity_mask() {
746763
get_affinity_mask().unwrap();
747764
}
748765

749766
#[test]
767+
#[ignore]
750768
fn test_freebsd_set_for_current() {
751769
let ids = get_core_ids().unwrap();
752770

libafl_bolts/src/llmp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3173,7 +3173,7 @@ where
31733173
}
31743174

31753175
#[cfg(test)]
3176-
#[cfg(all(unix, feature = "std"))]
3176+
#[cfg(all(unix, feature = "std", not(target_os = "haiku")))]
31773177
mod tests {
31783178

31793179
use std::{thread::sleep, time::Duration};

libafl_bolts/src/minibsod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,21 @@ fn write_crash<W: Write>(
654654
Ok(())
655655
}
656656

657+
#[cfg(all(target_os = "haiku", target_arch = "x86_64"))]
658+
fn write_crash<W: Write>(
659+
writer: &mut BufWriter<W>,
660+
signal: Signal,
661+
ucontext: &ucontext_t,
662+
) -> Result<(), std::io::Error> {
663+
writeln!(
664+
writer,
665+
"Received signal {} at {:#016x}",
666+
signal, ucontext.uc_mcontext.rip
667+
)?;
668+
669+
Ok(())
670+
}
671+
657672
#[cfg(not(any(
658673
target_vendor = "apple",
659674
target_os = "linux",
@@ -662,6 +677,7 @@ fn write_crash<W: Write>(
662677
target_os = "dragonfly",
663678
target_os = "openbsd",
664679
target_os = "netbsd",
680+
target_os = "haiku",
665681
any(target_os = "solaris", target_os = "illumos"),
666682
)))]
667683
fn write_crash<W: Write>(

libafl_bolts/src/shmem.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1537,7 +1537,7 @@ impl<T: ShMem> std::io::Seek for ShMemCursor<T> {
15371537
}
15381538
}
15391539

1540-
#[cfg(feature = "std")]
1540+
#[cfg(all(feature = "std", not(target_os = "haiku")))]
15411541
#[cfg(test)]
15421542
mod tests {
15431543
use serial_test::serial;

0 commit comments

Comments
 (0)