Skip to content

Commit 5c5f428

Browse files
committed
Revert "passes: use trait_upcasting feature (Rust 1.86)"
This reverts commit 58c026a. ErasedInstrumentationPassHelper enum doesn't play nice here.
1 parent 0f2ce39 commit 5c5f428

9 files changed

Lines changed: 51 additions & 16 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "0.1.0"
44
authors = []
55
license = "Apache-2.0 OR MIT"
66
edition = "2021"
7-
rust-version = "1.86"
7+
rust-version = "1.83"
88

99
[dependencies]
1010
wat = "1.0"

src/instrumentation/code_coverage.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ impl CodeCovInstrumentationPass for EdgeCoveragePass {
126126
fn coverage_mut(&mut self) -> &mut CoverageBitset<Self::Key> {
127127
&mut self.coverage
128128
}
129+
130+
fn as_any(&self) -> &dyn std::any::Any {
131+
self as &dyn std::any::Any
132+
}
129133
}
130134

131135
pub(crate) struct FunctionCoveragePass {
@@ -165,6 +169,10 @@ impl CodeCovInstrumentationPass for FunctionCoveragePass {
165169
self.coverage
166170
.instrument(&FuncIdx(ctx.state.fidx), ctx, self);
167171
}
172+
173+
fn as_any(&self) -> &dyn std::any::Any {
174+
self as &dyn std::any::Any
175+
}
168176
}
169177

170178
pub(crate) struct BBCoveragePass {
@@ -197,4 +205,8 @@ impl CodeCovInstrumentationPass for BBCoveragePass {
197205
fn instrument_basic_block(&self, ctx: InstrCtx) {
198206
self.coverage.instrument(&ctx.state.loc(), ctx, self);
199207
}
208+
209+
fn as_any(&self) -> &dyn std::any::Any {
210+
self as &dyn std::any::Any
211+
}
200212
}

src/instrumentation/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,11 @@ impl Passes {
146146
}
147147
}
148148

149-
pub(crate) trait ErasedCovSnapshot: Any {
149+
pub(crate) trait ErasedCovSnapshot {
150150
fn clear(&mut self);
151151
fn update_with(&mut self, other: &dyn ErasedCovSnapshot) -> bool;
152152
fn mem_usage(&self) -> usize;
153+
fn as_any(&self) -> &dyn Any;
153154
}
154155

155156
#[derive(libafl_bolts::SerdeAny)]
@@ -411,13 +412,15 @@ impl<K: Ord + Clone, V: Clone + FeedbackLattice> AssociatedCoverageArray<K, V> {
411412
*self = Self::Full(vec![V::bottom(); len].into_boxed_slice());
412413
}
413414
fn update_with(&mut self, other: &dyn ErasedCovSnapshot) -> bool {
414-
if let Some(other) = (other as &dyn Any).downcast_ref::<Self>() {
415+
if let Some(other) = other.as_any().downcast_ref::<Self>() {
415416
self._update_with(other)
416417
} else {
417418
false
418419
}
419420
}
420-
421+
fn as_any(&self) -> &dyn Any {
422+
self as &dyn Any
423+
}
421424
fn mem_usage(&self) -> usize {
422425
match self {
423426
SparseLatticeBox::Full(x) => x.len() * std::mem::size_of::<V>(),

src/instrumentation/path_hash.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,10 @@ impl HashBitsetInstrumentationPass for FuncPathHashPass {
250250
}
251251
self.coverage.mix_and_instrument(key, ctx, self);
252252
}
253+
254+
fn as_any(&self) -> &dyn std::any::Any {
255+
self as &dyn std::any::Any
256+
}
253257
}
254258

255259
pub(crate) struct EdgePathHashPass {
@@ -294,4 +298,8 @@ impl HashBitsetInstrumentationPass for EdgePathHashPass {
294298
}
295299
self.coverage.mix_and_instrument(key, ctx, self);
296300
}
301+
302+
fn as_any(&self) -> &dyn std::any::Any {
303+
self as &dyn std::any::Any
304+
}
297305
}

src/instrumentation/swarm.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ impl ErasedInstrumentationPass for SwarmShortCircuitPass {
106106
"swarm-short-circuit"
107107
}
108108

109+
fn as_any(&self) -> &dyn std::any::Any {
110+
self as &dyn std::any::Any
111+
}
112+
109113
fn instrument_function(&self, mut ctx: InstrCtx) {
110114
let f = ctx.state.loc().function;
111115
if self.config.avoid_functions.contains(&f) {

src/instrumentation/traits.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ macro_rules! instrumentation_hook_fn_defs {
5454

5555
macro_rules! impl_kv_instrumentation_pass {
5656
() => {
57+
fn as_any(&self) -> &dyn std::any::Any {
58+
self as &dyn std::any::Any
59+
}
5760
fn coverage(&self) -> &AssociatedCoverageArray<Self::Key, Self::Value> {
5861
&self.coverage
5962
}
@@ -70,13 +73,14 @@ macro_rules! impl_kv_instrumentation_pass {
7073
}
7174
pub(crate) use impl_kv_instrumentation_pass;
7275

73-
pub(crate) trait KVInstrumentationPass: Any {
76+
pub(crate) trait KVInstrumentationPass {
7477
type Key: Into<Location> + Ord + Clone; // = Location
7578
type Value: FeedbackLattice + 'static;
7679

7780
/// Returns a short string (<12 chars) that describes this specific pass
7881
fn shortcode(&self) -> &'static str;
7982

83+
fn as_any(&self) -> &dyn Any;
8084
fn coverage(&self) -> &AssociatedCoverageArray<Self::Key, Self::Value>;
8185
fn coverage_mut(&mut self) -> &mut AssociatedCoverageArray<Self::Key, Self::Value>;
8286

@@ -137,6 +141,8 @@ pub(crate) trait CodeCovInstrumentationPass {
137141
.unwrap(),
138142
)
139143
}
144+
145+
fn as_any(&self) -> &dyn Any;
140146
}
141147

142148
pub(crate) trait HashBitsetInstrumentationPass {
@@ -166,16 +172,19 @@ pub(crate) trait HashBitsetInstrumentationPass {
166172
.unwrap(),
167173
)
168174
}
175+
176+
fn as_any(&self) -> &dyn Any;
169177
}
170178

171-
pub trait ErasedInstrumentationPass: Any {
179+
pub trait ErasedInstrumentationPass {
172180
instrumentation_hook_fn_defs!(no_body);
173181

174182
fn update_and_scan_coverage(&mut self) -> bool;
175183
fn reset_coverage(&mut self);
176184
fn reset_coverage_keep_saved(&mut self);
177185
fn snapshot_coverage(&self) -> CovSnapshot;
178186
fn shortcode(&self) -> &'static str;
187+
fn as_any(&self) -> &dyn Any;
179188
}
180189

181190
macro_rules! dispatch {
@@ -210,4 +219,5 @@ impl<K: Ord + Into<Location> + Clone + 'static, V: FeedbackLattice + 'static>
210219
dispatch!(reset_coverage_keep_saved(&mut self) -> ());
211220
dispatch!(snapshot_coverage(&self) -> CovSnapshot);
212221
dispatch!(shortcode(&self) -> &'static str);
222+
dispatch!(as_any(&self) -> &dyn Any);
213223
}

src/jit/mod.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ pub mod util;
1515
pub mod vmcontext;
1616

1717
use std::{
18-
any::Any,
1918
collections::BTreeSet,
2019
fmt,
2120
sync::Arc,
@@ -980,10 +979,9 @@ impl JitFuzzingSession {
980979
// save malloc coverage
981980
let new_cov = !self.scan_passes_for_coverage().is_empty();
982981
let have_codecov_pass = self.passes.iter().any(|pass| {
983-
let pass = pass as &dyn std::any::Any;
984-
pass.is::<FunctionCoveragePass>()
985-
|| pass.is::<BBCoveragePass>()
986-
|| pass.is::<EdgeCoveragePass>()
982+
pass.as_any().is::<FunctionCoveragePass>()
983+
|| pass.as_any().is::<BBCoveragePass>()
984+
|| pass.as_any().is::<EdgeCoveragePass>()
987985
});
988986
assert!(
989987
new_cov || !have_codecov_pass,
@@ -1139,7 +1137,7 @@ impl JitFuzzingSession {
11391137

11401138
pub(crate) fn get_pass<T: 'static>(&self) -> &T {
11411139
for pass in self.passes.iter() {
1142-
if let Some(pass) = (pass as &dyn Any).downcast_ref::<T>() {
1140+
if let Some(pass) = pass.as_any().downcast_ref::<T>() {
11431141
return pass;
11441142
}
11451143
}
@@ -1149,7 +1147,7 @@ impl JitFuzzingSession {
11491147
pub(crate) fn get_passes<T: 'static>(&self) -> Vec<&T> {
11501148
let mut passes = Vec::new();
11511149
for pass in self.passes.iter() {
1152-
if let Some(pass) = (pass as &dyn Any).downcast_ref::<T>() {
1150+
if let Some(pass) = pass.as_any().downcast_ref::<T>() {
11531151
passes.push(pass);
11541152
}
11551153
}

src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl TestModule {
5050
.arg(&mod_path)
5151
.status()
5252
.expect("failed to compile Rust snippet to WASM");
53-
let module = std::fs::read(&mod_path).expect("failed to read compiled test harness module");
53+
let module = std::fs::read(&mod_path).unwrap();
5454
Self { name, module }
5555
}
5656

wasm-fuzzers/Dockerfile.wasmfuzz

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FROM ubuntu:24.04 AS builder
22
RUN apt-get update && apt-get install -y rustup git clang
3-
RUN rustup toolchain add 1.86 --no-self-update
4-
ARG COMMIT="9f904255398d1006427091953ea9746f7134b9dd"
3+
RUN rustup toolchain add 1.83 --no-self-update
4+
ARG COMMIT="74d05874d2d85cc0921cda9c03dbe1de77df0ea3"
55
RUN git clone https://github.com/CISPA-SysSec/wasmfuzz && git -C wasmfuzz checkout "$COMMIT"
66
RUN cargo install --locked --no-default-features --path /wasmfuzz
77

0 commit comments

Comments
 (0)