Skip to content

Commit f0b4412

Browse files
committed
Bump LibAFL to 0.15.2 with Rust 2024
1 parent 9127205 commit f0b4412

File tree

7 files changed

+40
-17
lines changed

7 files changed

+40
-17
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "xfuzz"
33
version = "0.1.0"
4-
edition = "2021"
4+
edition = "2024"
55
description = "Fuzzing General-Purpose Hardware Designs with Software Fuzzers"
66

77
[features]

LibAFL

Submodule LibAFL updated 964 files

src/coverage.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::sync::{Mutex, OnceLock};
2+
13
/**
24
* Copyright (c) 2023 Institute of Computing Technology, Chinese Academy of Sciences
35
* xfuzz is licensed under Mulan PSL v2.
@@ -59,24 +61,38 @@ impl Coverage {
5961
}
6062
}
6163

62-
static mut ICOVERAGE: Option<Coverage> = None;
64+
static ICOVERAGE: OnceLock<Mutex<Coverage>> = OnceLock::new();
6365

66+
/// Call this once, right after your C test‑bench has told you how many
67+
/// counters are present.
6468
pub(crate) fn cover_init() {
65-
unsafe { ICOVERAGE = Some(Coverage::new(get_cover_number() as usize)) };
69+
let cover = Coverage::new(unsafe { get_cover_number() as usize });
70+
// `set` returns Err if it was already initialised; handle that however
71+
// you prefer (here we just ignore the second call).
72+
let _ = ICOVERAGE.set(Mutex::new(cover));
73+
}
74+
75+
fn cov() -> std::sync::MutexGuard<'static, Coverage> {
76+
ICOVERAGE
77+
.get()
78+
.expect("cover_init() not called")
79+
.lock()
80+
.expect("poisoned mutex")
6681
}
6782

6883
pub(crate) fn cover_len() -> usize {
69-
unsafe { ICOVERAGE.as_ref().unwrap().len() }
84+
cov().len()
7085
}
7186

7287
pub(crate) fn cover_as_mut_ptr() -> *mut i8 {
73-
unsafe { ICOVERAGE.as_ref().unwrap().as_mut_ptr() }
88+
let guard = cov();
89+
guard.as_mut_ptr().cast::<i8>()
7490
}
7591

7692
pub(crate) fn cover_accumulate() {
77-
unsafe { ICOVERAGE.as_mut().unwrap().accumulate() }
93+
cov().accumulate()
7894
}
7995

8096
pub(crate) fn cover_display() {
81-
unsafe { ICOVERAGE.as_ref().unwrap().display() }
97+
cov().display()
8298
}

src/fuzzer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ use crate::coverage::*;
1717
use crate::harness;
1818
use crate::monitor;
1919

20+
use libafl::StdFuzzer;
2021
use libafl::prelude::*;
2122
use libafl::schedulers::QueueScheduler;
2223
use libafl::stages::StdMutationalStage;
2324
use libafl::state::StdState;
24-
use libafl::StdFuzzer;
2525
use libafl_bolts::{current_nanos, rands::StdRand, tuples::tuple_list};
2626

2727
pub(crate) fn run_fuzzer(

src/harness.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::sync::{Mutex, OnceLock};
2+
13
/**
24
* Copyright (c) 2023 Institute of Computing Technology, Chinese Academy of Sciences
35
* xfuzz is licensed under Mulan PSL v2.
@@ -21,7 +23,7 @@ use crate::monitor::store_testcase;
2123
use libafl::prelude::*;
2224
use libc::*;
2325

24-
extern "C" {
26+
unsafe extern "C" {
2527
pub fn sim_main(argc: c_int, argv: *const *const c_char) -> c_int;
2628

2729
pub fn get_cover_number() -> c_uint;
@@ -37,15 +39,20 @@ extern "C" {
3739
pub fn disable_sim_verbose();
3840
}
3941

40-
static mut SIM_ARGS: Vec<String> = vec![];
42+
static SIM_ARGS: OnceLock<Mutex<Vec<String>>> = OnceLock::new();
4143

4244
fn sim_run(workload: &String) -> i32 {
4345
// prepare the simulation arguments in Vec<String> format
4446
let mut sim_args: Vec<String> = vec!["emu".to_string(), "-i".to_string(), workload.to_string()]
4547
.iter()
4648
.map(|s| s.to_string())
4749
.collect();
48-
unsafe { sim_args.extend(SIM_ARGS.iter().cloned()) };
50+
let guard = SIM_ARGS
51+
.get()
52+
.expect("SIM_ARGS not initialized")
53+
.lock()
54+
.unwrap();
55+
sim_args.extend(guard.iter().cloned());
4956

5057
// convert the simulation arguments into c_char**
5158
let sim_args: Vec<_> = sim_args
@@ -150,9 +157,7 @@ pub(crate) fn set_sim_env(
150157
unsafe { MAX_RUNS = max_runs.unwrap() };
151158
}
152159

153-
unsafe {
154-
SIM_ARGS = emu_args;
155-
}
160+
let _ = SIM_ARGS.set(Mutex::new(emu_args));
156161

157162
cover_init();
158163
}

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ struct Arguments {
4949
extra_args: Vec<String>,
5050
}
5151

52-
#[no_mangle]
52+
#[unsafe(no_mangle)]
5353
fn main() -> i32 {
5454
let args = Arguments::parse();
5555

src/monitor.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ pub fn store_testcases(
4343
} else {
4444
-1
4545
};
46-
println!("Corpus {id}: exec_time {exec_time}, scheduled_count {scheduled_count}, parent_id {parent_id}");
46+
println!(
47+
"Corpus {id}: exec_time {exec_time}, scheduled_count {scheduled_count}, parent_id {parent_id}"
48+
);
4749
let x = testcase.input().as_ref().unwrap();
4850
store_testcase(x, &output_dir, Some(id.to_string()));
4951
}

0 commit comments

Comments
 (0)