Skip to content

Commit 2e980ca

Browse files
authored
bolts: initial haiku support (#1643)
1 parent 745326e commit 2e980ca

File tree

3 files changed

+82
-10
lines changed

3 files changed

+82
-10
lines changed

libafl_bolts/src/core_affinity.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,21 @@ mod linux {
346346
}
347347
}
348348

349+
// Haiku
350+
// FIXME: no sense of cpu granularity (yet ?)
351+
352+
#[cfg(target_os = "haiku")]
353+
#[inline]
354+
fn get_core_ids_helper() -> Result<Vec<CoreId>, Error> {
355+
Ok(Vec::new())
356+
}
357+
358+
#[cfg(target_os = "haiku")]
359+
#[inline]
360+
fn set_for_current_helper(_core_id: CoreId) -> Result<(), Error> {
361+
Ok(())
362+
}
363+
349364
// Windows Section
350365

351366
#[cfg(target_os = "windows")]

libafl_bolts/src/minibsod.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,35 @@ pub fn dump_registers<W: Write>(
393393
Ok(())
394394
}
395395

396+
/// Write the content of all important registers
397+
#[cfg(all(target_os = "haiku", target_arch = "x86_64"))]
398+
#[allow(clippy::similar_names)]
399+
pub fn dump_registers<W: Write>(
400+
writer: &mut BufWriter<W>,
401+
ucontext: &ucontext_t,
402+
) -> Result<(), std::io::Error> {
403+
let mcontext = &ucontext.uc_mcontext;
404+
405+
write!(writer, "r8 : {:#016x}, ", mcontext.r8)?;
406+
write!(writer, "r9 : {:#016x}, ", mcontext.r9)?;
407+
write!(writer, "r10 : {:#016x}, ", mcontext.r10)?;
408+
write!(writer, "r11 : {:#016x}, ", mcontext.r11)?;
409+
write!(writer, "r12 : {:#016x}, ", mcontext.r12)?;
410+
write!(writer, "r13 : {:#016x}, ", mcontext.r13)?;
411+
write!(writer, "r14 : {:#016x}, ", mcontext.r14)?;
412+
write!(writer, "r15 : {:#016x}, ", mcontext.r15)?;
413+
write!(writer, "rdi : {:#016x}, ", mcontext.rdi)?;
414+
write!(writer, "rsi : {:#016x}, ", mcontext.rsi)?;
415+
write!(writer, "rbp : {:#016x}, ", mcontext.rbp)?;
416+
write!(writer, "rbx : {:#016x}, ", mcontext.rbx)?;
417+
write!(writer, "rdx : {:#016x}, ", mcontext.rdx)?;
418+
write!(writer, "rax : {:#016x}, ", mcontext.rax)?;
419+
write!(writer, "rcx : {:#016x}, ", mcontext.rcx)?;
420+
write!(writer, "rsp : {:#016x}, ", mcontext.rsp)?;
421+
write!(writer, "rflags : {:#016x}, ", mcontext.rflags)?;
422+
Ok(())
423+
}
424+
396425
#[allow(clippy::unnecessary_wraps)]
397426
#[cfg(not(any(
398427
target_vendor = "apple",
@@ -402,6 +431,7 @@ pub fn dump_registers<W: Write>(
402431
target_os = "dragonfly",
403432
target_os = "netbsd",
404433
target_os = "openbsd",
434+
target_os = "haiku",
405435
any(target_os = "solaris", target_os = "illumos"),
406436
)))]
407437
fn dump_registers<W: Write>(
@@ -816,10 +846,33 @@ fn write_minibsod<W: Write>(writer: &mut BufWriter<W>) -> Result<(), std::io::Er
816846
Ok(())
817847
}
818848

849+
#[cfg(target_os = "haiku")]
850+
fn write_minibsod<W: Write>(writer: &mut BufWriter<W>) -> Result<(), std::io::Error> {
851+
let mut info: libc::image_info = unsafe { std::mem::zeroed() };
852+
let mut c: i32 = 0;
853+
854+
loop {
855+
if unsafe { libc::get_next_image_info(0, &mut c, &mut info) } == libc::B_OK {
856+
let i = format!(
857+
"{}-{} {:?}\n",
858+
info.text as u64,
859+
info.text as u64 + info.text_size as u64,
860+
info.name
861+
);
862+
writer.write_all(&i.into_bytes())?;
863+
} else {
864+
break;
865+
}
866+
}
867+
868+
Ok(())
869+
}
870+
819871
#[cfg(not(any(
820872
target_os = "freebsd",
821873
target_os = "openbsd",
822874
target_os = "netbsd",
875+
target_os = "haiku",
823876
target_env = "apple",
824877
any(target_os = "linux", target_os = "android"),
825878
any(target_os = "solaris", target_os = "illumos"),

libafl_bolts/src/shmem.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,20 @@ use std::io::Read;
1616
use std::io::Write;
1717

1818
use serde::{Deserialize, Serialize};
19-
#[cfg(all(feature = "std", unix, not(target_os = "android")))]
19+
#[cfg(all(
20+
feature = "std",
21+
unix,
22+
not(any(target_os = "android", target_os = "haiku"))
23+
))]
2024
pub use unix_shmem::{MmapShMem, MmapShMemProvider};
21-
#[cfg(all(feature = "std", unix))]
25+
#[cfg(all(feature = "std", unix, not(target_os = "haiku")))]
2226
pub use unix_shmem::{UnixShMem, UnixShMemProvider};
2327
#[cfg(all(windows, feature = "std"))]
2428
pub use win32_shmem::{Win32ShMem, Win32ShMemProvider};
2529

2630
#[cfg(all(unix, feature = "std"))]
2731
use crate::os::pipes::Pipe;
28-
#[cfg(all(feature = "std", unix))]
32+
#[cfg(all(feature = "std", unix, not(target_os = "haiku")))]
2933
pub use crate::os::unix_shmem_server::{ServedShMemProvider, ShMemService};
3034
use crate::{AsMutSlice, AsSlice, Error};
3135

@@ -49,12 +53,12 @@ pub type StdShMemService = ShMemService<MmapShMemProvider>;
4953
#[cfg(all(
5054
feature = "std",
5155
unix,
52-
not(any(target_os = "android", target_vendor = "apple"))
56+
not(any(target_os = "android", target_vendor = "apple", target_os = "haiku"))
5357
))]
5458
pub type StdShMemProvider = UnixShMemProvider;
5559
/// The standard sharedmem service
5660
#[cfg(any(
57-
not(any(target_os = "android", target_vendor = "apple")),
61+
not(any(target_os = "android", target_vendor = "apple", target_os = "haiku")),
5862
not(feature = "std")
5963
))]
6064
pub type StdShMemService = DummyShMemService;
@@ -71,7 +75,7 @@ pub type StdServedShMemProvider = RcShMemProvider<ServedShMemProvider<MmapShMemP
7175
#[cfg(all(
7276
feature = "std",
7377
unix,
74-
not(any(target_os = "android", target_vendor = "apple"))
78+
not(any(target_os = "android", target_vendor = "apple", target_os = "haiku"))
7579
))]
7680
pub type StdServedShMemProvider = RcShMemProvider<ServedShMemProvider<MmapShMemProvider>>;
7781

@@ -427,7 +431,7 @@ where
427431
//#[cfg(all(unix, feature = "std"))]
428432
//unsafe impl<SP: ShMemProvider> Send for RcShMemProvider<SP> {}
429433

430-
#[cfg(all(unix, feature = "std"))]
434+
#[cfg(all(unix, feature = "std", not(target_os = "haiku")))]
431435
impl<SP> ShMemProvider for RcShMemProvider<SP>
432436
where
433437
SP: ShMemProvider + Debug,
@@ -563,7 +567,7 @@ where
563567
}
564568
}
565569

566-
#[cfg(all(unix, feature = "std"))]
570+
#[cfg(all(unix, feature = "std", not(target_os = "haiku")))]
567571
impl<SP> Default for RcShMemProvider<SP>
568572
where
569573
SP: ShMemProvider + Debug,
@@ -573,7 +577,7 @@ where
573577
}
574578
}
575579

576-
#[cfg(all(unix, feature = "std"))]
580+
#[cfg(all(unix, feature = "std", not(target_os = "haiku")))]
577581
impl<SP> RcShMemProvider<ServedShMemProvider<SP>>
578582
where
579583
SP: ShMemProvider + Debug,
@@ -589,7 +593,7 @@ where
589593
/// On Android, this is partially reused to wrap [`unix_shmem::ashmem::AshmemShMem`],
590594
/// Although for an [`ServedShMemProvider`] using a unix domain socket
591595
/// Is needed on top.
592-
#[cfg(all(unix, feature = "std"))]
596+
#[cfg(all(unix, feature = "std", not(target_os = "haiku")))]
593597
pub mod unix_shmem {
594598
#[cfg(doc)]
595599
use crate::shmem::{ShMem, ShMemProvider};

0 commit comments

Comments
 (0)