Skip to content

Commit 1fa893e

Browse files
committed
fallback to systemtime on non-x86
1 parent 6cc1e96 commit 1fa893e

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

fuzzers/libfuzzer_libpng/Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ run: all
1818
sleep 0.2
1919
./$(FUZZER_NAME) >/dev/null 2>/dev/null &
2020

21+
short_test: all
22+
timeout 11s ./$(FUZZER_NAME) &
23+
sleep 0.2
24+
timeout 10s taskset -c 0 ./$(FUZZER_NAME) >/dev/null 2>/dev/null &
25+
timeout 10s taskset -c 1 ./$(FUZZER_NAME) >/dev/null 2>/dev/null &
26+
timeout 10s taskset -c 2 ./$(FUZZER_NAME) >/dev/null 2>/dev/null &
27+
timeout 10s taskset -c 3 ./$(FUZZER_NAME) >/dev/null 2>/dev/null &
28+
2129
test: all
2230
timeout 60s ./$(FUZZER_NAME) &
2331
sleep 0.2

libafl/src/cpu.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,31 @@
11
//! Architecture agnostic processor features
22
3-
/// Read time counter using [`llvmint::readcyclecounter`]
3+
#[cfg(not(any(target_arch = "x86_64", target_arch = "x86")))]
4+
use crate::utils::current_nanos;
5+
6+
// TODO: Add more architectures, using C code, see
7+
// https://github.com/google/benchmark/blob/master/src/cycleclock.h
8+
// Or using llvm intrinsics (if they ever should become available in stable rust?)
9+
10+
/// Read a timestamp for measurements.
411
///
5-
/// This function is a wrapper around [`llvmint`] to make it easier to test various
6-
/// implementations of reading a cycle counter. In this way, an experiment only has to
12+
/// This function is a wrapper around different ways to get a timestamp, fast
13+
/// In this way, an experiment only has to
714
/// change this implementation rather than every instead of [`cpu::read_time_counter`]
8-
#[cfg(target_arch = "x86_64")]
15+
/// It is using [`rdtsc`] on `x86_64` and `x86`.
16+
#[cfg(any(target_arch = "x86_64", target_arch = "x86"))]
917
#[must_use]
1018
pub fn read_time_counter() -> u64 {
1119
unsafe { core::arch::x86_64::_rdtsc() }
1220
}
21+
22+
/// Read a timestamp for measurements.
23+
///
24+
/// This function is a wrapper around different ways to get a timestamp, fast
25+
/// In this way, an experiment only has to
26+
/// change this implementation rather than every instead of [`cpu::read_time_counter`]
27+
/// On unsupported architectures, it's falling back to normal system time, in millis.
28+
#[cfg(not(any(target_arch = "x86_64", target_arch = "x86")))]
29+
pub fn read_time_counter() -> u64 {
30+
current_nanos()
31+
}

0 commit comments

Comments
 (0)