Skip to content

Commit 4c5c67e

Browse files
authored
Switch to external getters library (#39)
1 parent 47daa65 commit 4c5c67e

File tree

23 files changed

+196
-295
lines changed

23 files changed

+196
-295
lines changed

Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ members = [
3535

3636
"modules/tsffs/src/util/command-ext",
3737
"modules/tsffs/src/util/ffi-macro",
38-
"modules/tsffs/src/util/getters",
3938
"modules/tsffs/src/util/raw-cstr",
4039
"modules/tsffs/src/util/version-tools",
4140
]
@@ -50,7 +49,6 @@ default-members = [
5049

5150
"modules/tsffs/src/util/command-ext",
5251
"modules/tsffs/src/util/ffi-macro",
53-
"modules/tsffs/src/util/getters",
5452
"modules/tsffs/src/util/raw-cstr",
5553
"modules/tsffs/src/util/version-tools",
5654
]
@@ -65,7 +63,6 @@ ispm-wrapper = { path = "modules/tsffs/src/simics/ispm-wrapper" }
6563

6664
command-ext = { path = "modules/tsffs/src/util/command-ext" }
6765
ffi-macro = { path = "modules/tsffs/src/util/ffi-macro" }
68-
getters = { path = "modules/tsffs/src/util/getters" }
6966
raw-cstr = { path = "modules/tsffs/src/util/raw-cstr" }
7067
version-tools = { path = "modules/tsffs/src/util/version-tools" }
7168

@@ -77,7 +74,7 @@ libafl_targets = { git = "https://github.com/AFLplusplus/LibAFL", default-featur
7774
] }
7875
serde = { version = "1.0.188", features = ["derive"] }
7976
serde_json = { version = "1.0.107" }
80-
versions = { version = "5.0.1", features = ["serde"] }
77+
versions = { version = "6.0.0", features = ["serde"] }
8178

8279

8380
[profile.dev]

modules/tsffs/src/simics/ispm-wrapper/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ version.workspace = true
1717
[dependencies]
1818
anyhow = { workspace = true }
1919
command-ext = { workspace = true }
20+
getters2 = "0.1.2"
2021
serde = { workspace = true, features = ["derive"] }
2122
serde_json = { workspace = true }
2223
version-tools = { workspace = true }
23-
24-
getters.workspace = true
2524
typed-builder = "0.18.0"

modules/tsffs/src/simics/ispm-wrapper/src/data/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! Data deserializable from ISPM commands and configurations
55
66
use anyhow::Result;
7-
use getters::Getters;
7+
use getters2::Getters;
88
use serde::Deserialize;
99
use serde_json::from_slice;
1010
use std::{fmt::Display, fs::read, path::PathBuf};
@@ -159,15 +159,19 @@ impl Settings {
159159
/// A package that is already installed
160160
pub struct InstalledPackage {
161161
#[serde(rename = "pkgNumber")]
162+
#[getters(deref)]
162163
/// The package number
163164
package_number: isize,
164165
#[serde(deserialize_with = "version_constraint_from_string")]
166+
#[getters(clone)]
165167
/// The package version
166168
version: VersionConstraint,
167169
#[builder(setter(into))]
170+
#[getters(clone)]
168171
/// The package name
169172
name: String,
170173
#[builder(default, setter(into))]
174+
#[getters(clone)]
171175
/// Paths to this installed package
172176
paths: Vec<PathBuf>,
173177
}
@@ -204,6 +208,7 @@ pub struct Packages {
204208
/// A package which is added to a project
205209
pub struct ProjectPackage {
206210
#[serde(rename = "pkgNumber")]
211+
#[getters(deref)]
207212
/// The package number
208213
package_number: isize,
209214
#[serde(deserialize_with = "version_constraint_from_string")]

modules/tsffs/src/simics/ispm-wrapper/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub trait ToArgs {
7171
pub mod ispm {
7272
use std::{iter::repeat, path::PathBuf};
7373

74-
use getters::Getters;
74+
use getters2::Getters;
7575
use typed_builder::TypedBuilder;
7676

7777
use crate::{ToArgs, NON_INTERACTIVE_FLAG};
@@ -184,7 +184,7 @@ pub mod ispm {
184184
};
185185
use anyhow::Result;
186186
use command_ext::CommandExtCheck;
187-
use getters::Getters;
187+
use getters2::Getters;
188188
use serde_json::from_slice;
189189
use std::{iter::repeat, path::PathBuf, process::Command};
190190
use typed_builder::TypedBuilder;
@@ -288,7 +288,7 @@ pub mod ispm {
288288
};
289289
use anyhow::{anyhow, Result};
290290
use command_ext::CommandExtCheck;
291-
use getters::Getters;
291+
use getters2::Getters;
292292
use serde_json::from_slice;
293293
use std::{collections::HashSet, iter::once, path::Path, process::Command};
294294
use typed_builder::TypedBuilder;
@@ -311,7 +311,7 @@ pub mod ispm {
311311

312312
impl ToArgs for CreateOptions {
313313
fn to_args(&self) -> Vec<String> {
314-
self.packages()
314+
self.packages_ref()
315315
.iter()
316316
.map(|p| Some(p.to_string()))
317317
.chain(once(

modules/tsffs/src/simics/simics-macro/src/lib.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,8 @@ impl TryIntoAttrValueTypeDictOpts {
12361236
.filter_map(|f| {
12371237
f.ident.clone().map(|i| {
12381238
let ident_name = i.to_string();
1239-
quote!((#ident_name.try_into()?, value.#i().clone().try_into()?))
1239+
let accessor = format_ident!("{}_ref", i);
1240+
quote!((#ident_name.try_into()?, value.#accessor().clone().try_into()?))
12401241
})
12411242
})
12421243
.collect::<Vec<_>>();
@@ -1302,9 +1303,10 @@ impl TryIntoAttrValueTypeListOpts {
13021303
.iter()
13031304
.filter(|f| !f.skip.is_present())
13041305
.filter_map(|f| {
1305-
f.ident
1306-
.clone()
1307-
.map(|i| quote!(value.#i().clone().try_into()?))
1306+
f.ident.clone().map(|i| {
1307+
let accessor = format_ident!("{}_ref", i);
1308+
quote!(value.#accessor().clone().try_into()?)
1309+
})
13081310
})
13091311
.collect::<Vec<_>>();
13101312

modules/tsffs/src/tsffs/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ simics-macro = { workspace = true }
3030
yaxpeax-arch = "0.2.7"
3131
yaxpeax-x86 = "1.2.0"
3232
typed-builder = "0.18.0"
33-
getters.workspace = true
33+
getters2 = "0.1.2"
3434
serde_json.workspace = true
3535
goblin = "0.7.1"
3636
yaxpeax-riscv = { git = "https://github.com/novafacing/yaxpeax-riscv", version = "0.1.0", features = [

modules/tsffs/src/tsffs/src/arch/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ pub trait ArchitectureOperations {
258258
let addr_size =
259259
self.processor_info_v2().get_logical_address_width()? as usize / u8::BITS as usize;
260260
let initial_size =
261-
size.initial_size()
261+
size.initial_size_ref()
262262
.ok_or_else(|| anyhow!("Expected initial size for start"))? as usize;
263263

264264
let physical_memory = self.processor_info_v2().get_physical_memory()?;

modules/tsffs/src/tsffs/src/arch/x86.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ impl ArchitectureOperations for X86ArchitectureOperations {
428428
let physical_memory = self.processor_info_v2().get_physical_memory()?;
429429

430430
let initial_size =
431-
size.initial_size()
431+
size.initial_size_ref()
432432
.ok_or_else(|| anyhow!("Expected initial size for start"))? as usize;
433433

434434
trace!(

modules/tsffs/src/tsffs/src/configuration/mod.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{
33
path::PathBuf,
44
};
55

6-
use getters::Getters;
6+
use getters2::Getters;
77
use simics::api::{lookup_file, BreakpointId};
88
use simics_macro::TryIntoAttrValueTypeDict;
99
use typed_builder::TypedBuilder;
@@ -33,7 +33,7 @@ impl Configuration {
3333
}
3434

3535
#[derive(TypedBuilder, Getters, Debug, Clone, TryIntoAttrValueTypeDict)]
36-
#[getters(mutable)]
36+
#[getters(deref, mutable)]
3737
pub struct Configuration {
3838
#[builder(default = false)]
3939
/// Whether any breakpoint that occurs during fuzzing is treated as a fault
@@ -42,9 +42,11 @@ pub struct Configuration {
4242
/// Whether any CPU exception that occurs during fuzzing is treated as a solution
4343
all_exceptions_are_solutions: bool,
4444
#[builder(default)]
45+
#[getters(skip_deref, clone)]
4546
/// The set of specific exception numbers that are treated as a solution
4647
exceptions: BTreeSet<i64>,
4748
#[builder(default)]
49+
#[getters(skip_deref, clone)]
4850
/// The set of breakpoints to treat as solutions
4951
breakpoints: BTreeSet<BreakpointId>,
5052
#[builder(default = Configuration::DEFAULT_TIMEOUT_SECONDS)]
@@ -66,14 +68,18 @@ pub struct Configuration {
6668
#[builder(default, setter(strip_option))]
6769
iterations: Option<usize>,
6870
#[builder(default)]
71+
#[getters(skip_deref, clone)]
6972
tokens: Vec<Vec<u8>>,
7073
#[builder(default = lookup_file("%simics%").expect("No simics project root found").join(Configuration::DEFAULT_CORPUS_DIRECTORY_NAME))]
74+
#[getters(skip_deref, clone)]
7175
corpus_directory: PathBuf,
7276
#[builder(default = lookup_file("%simics%").expect("No simics project root found").join(Configuration::DEFAULT_SOLUTIONS_DIRECTORY_NAME))]
77+
#[getters(skip_deref, clone)]
7378
solutions_directory: PathBuf,
7479
#[builder(default = false)]
7580
generate_random_corpus: bool,
7681
#[builder(default)]
82+
#[getters(skip_deref, clone)]
7783
token_files: Vec<PathBuf>,
7884
#[builder(default = Configuration::DEFAULT_EXECUTOR_TIMEOUT)]
7985
/// The executor timeout in seconds
@@ -83,6 +89,7 @@ pub struct Configuration {
8389
#[builder(default = true)]
8490
cmplog: bool,
8591
#[builder(default)]
92+
#[getters(skip_deref, clone)]
8693
architecture_hints: HashMap<i32, ArchitectureHint>,
8794
}
8895

modules/tsffs/src/tsffs/src/fuzzer/mod.rs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use crate::Tsffs;
55
use anyhow::{anyhow, Result};
6-
use getters::Getters;
6+
use getters2::Getters;
77
use libafl::{
88
feedback_or, feedback_or_fast,
99
prelude::{
@@ -41,7 +41,9 @@ pub mod tokenize;
4141

4242
#[derive(Getters, Clone, PartialEq, Eq)]
4343
pub struct Testcase {
44+
#[getters(clone)]
4445
testcase: Vec<u8>,
46+
#[getters(deref)]
4547
cmplog: bool,
4648
}
4749

@@ -79,7 +81,7 @@ impl Tsffs {
7981

8082
/// Start the fuzzing thread.
8183
pub fn start_fuzzer_thread(&mut self) -> Result<()> {
82-
if self.fuzz_thread().is_some() {
84+
if self.fuzz_thread_ref().is_some() {
8385
warn!(self.as_conf_object(), "Fuzz thread already started but start_fuzzer_thread called. Returning without error.");
8486
// We can only start the thread once
8587
return Ok(());
@@ -98,16 +100,16 @@ impl Tsffs {
98100
self.fuzzer_messages = Some(mrx);
99101

100102
let client = RefCell::new((otx, orx));
101-
let configuration = self.configuration().clone();
103+
let configuration = self.configuration_clone();
102104
let coverage_map = unsafe {
103105
from_raw_parts_mut(
104106
self.coverage_map_mut().as_mut_slice().as_mut_ptr(),
105107
Self::COVERAGE_MAP_SIZE,
106108
)
107109
};
108-
let aflpp_cmp_map = Box::leak(unsafe { Box::from_raw(*self.aflpp_cmp_map_ptr()) });
109-
let aflpp_cmp_map_dup = Box::leak(unsafe { Box::from_raw(*self.aflpp_cmp_map_ptr()) });
110-
let cmplog_enabled = *self.configuration().cmplog();
110+
let aflpp_cmp_map = Box::leak(unsafe { Box::from_raw(*self.aflpp_cmp_map_ptr_ref()) });
111+
let aflpp_cmp_map_dup = Box::leak(unsafe { Box::from_raw(*self.aflpp_cmp_map_ptr_ref()) });
112+
let cmplog_enabled = *self.configuration_ref().cmplog_ref();
111113

112114
// NOTE: We do *not* use `run_in_thread` because it causes the fuzzer to block when HAPs arrive
113115
// which prevents forward progress.
@@ -174,12 +176,12 @@ impl Tsffs {
174176
let timeout_feedback = TimeFeedback::new(Self::TIMEOUT_FEEDBACK_NAME);
175177

176178
let solutions = OnDiskCorpus::with_meta_format(
177-
configuration.solutions_directory(),
179+
configuration.solutions_directory_ref(),
178180
OnDiskMetadataFormat::JsonPretty,
179181
)?;
180182

181183
let corpus = CachedOnDiskCorpus::with_meta_format(
182-
configuration.corpus_directory(),
184+
configuration.corpus_directory_ref(),
183185
Self::CORPUS_CACHE_SIZE,
184186
Some(OnDiskMetadataFormat::Json),
185187
)?;
@@ -203,10 +205,10 @@ impl Tsffs {
203205

204206
let mut tokens = Tokens::default();
205207
configuration
206-
.token_files()
208+
.token_files_ref()
207209
.iter()
208210
.try_for_each(|f| tokens.add_from_file(f).map(|_| ()))?;
209-
tokens.add_tokens(configuration.tokens());
211+
tokens.add_tokens(configuration.tokens_ref());
210212
state.add_metadata(tokens);
211213

212214
let scheduler =
@@ -270,29 +272,29 @@ impl Tsffs {
270272
);
271273
let tracing_stage = TracingStage::new(tracing_executor);
272274
let synchronize_corpus_stage =
273-
SyncFromDiskStage::with_from_file(configuration.corpus_directory().clone());
275+
SyncFromDiskStage::with_from_file(configuration.corpus_directory_clone());
274276
let dump_corpus_stage = DumpToDiskStage::new(
275277
|input: &BytesInput, _state: &_| input.target_bytes().as_slice().to_vec(),
276-
configuration.corpus_directory(),
277-
configuration.solutions_directory(),
278+
configuration.corpus_directory_ref(),
279+
configuration.solutions_directory_ref(),
278280
)?;
279281

280282
if state.must_load_initial_inputs() {
281283
state.load_initial_inputs(
282284
&mut fuzzer,
283285
&mut executor,
284286
&mut manager,
285-
&[configuration.corpus_directory().clone()],
287+
&[configuration.corpus_directory_ref().clone()],
286288
)?;
287289

288-
if state.corpus().count() < 1 && *configuration.generate_random_corpus() {
290+
if state.corpus().count() < 1 && *configuration.generate_random_corpus_ref() {
289291
let mut generator = RandBytesGenerator::new(64);
290292
state.generate_initial_inputs(
291293
&mut fuzzer,
292294
&mut executor,
293295
&mut generator,
294296
&mut manager,
295-
*configuration.initial_random_corpus_size(),
297+
configuration.initial_random_corpus_size_deref(),
296298
)?;
297299
}
298300
}
@@ -366,7 +368,7 @@ impl Tsffs {
366368
}
367369

368370
pub fn get_testcase(&mut self) -> Result<Testcase> {
369-
let testcase = if let Some(testcase) = self.repro_testcase() {
371+
let testcase = if let Some(testcase) = self.repro_testcase_ref() {
370372
debug!(self.as_conf_object(), "Using repro testcase");
371373
Testcase {
372374
testcase: testcase.clone(),

0 commit comments

Comments
 (0)