libafl_nyx: Add documentation to NyxSettings fields

This commit is contained in:
Maurice 2024-03-23 15:20:35 +01:00 committed by GitHub
parent 44c841ffb1
commit a0d4a5b240
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 30 additions and 21 deletions

View File

@ -35,8 +35,6 @@ fn main() {
// nyx stuff // nyx stuff
let settings = NyxSettings::builder() let settings = NyxSettings::builder()
.cpu_id(0) .cpu_id(0)
.snap_mode(true)
.parallel_mode(true)
.parent_cpu_id(Some(parent_cpu_id.0 as u32)) .parent_cpu_id(Some(parent_cpu_id.0 as u32))
.build(); .build();
let helper = NyxHelper::new("/tmp/nyx_libxml2/", settings).unwrap(); let helper = NyxHelper::new("/tmp/nyx_libxml2/", settings).unwrap();

View File

@ -21,12 +21,7 @@ use libafl_nyx::{executor::NyxExecutor, helper::NyxHelper, settings::NyxSettings
fn main() { fn main() {
// nyx stuff // nyx stuff
let settings = NyxSettings::builder() let settings = NyxSettings::builder().cpu_id(0).parent_cpu_id(None).build();
.cpu_id(0)
.snap_mode(true)
.parallel_mode(false)
.parent_cpu_id(None)
.build();
let helper = NyxHelper::new("/tmp/nyx_libxml2/", settings).unwrap(); let helper = NyxHelper::new("/tmp/nyx_libxml2/", settings).unwrap();
let observer = let observer =
unsafe { StdMapObserver::from_mut_ptr("trace", helper.bitmap_buffer, helper.bitmap_size) }; unsafe { StdMapObserver::from_mut_ptr("trace", helper.bitmap_buffer, helper.bitmap_size) };

View File

@ -39,18 +39,10 @@ impl NyxHelper {
.to_str() .to_str()
.ok_or(Error::illegal_argument("`work_dir` contains invalid UTF-8"))?; .ok_or(Error::illegal_argument("`work_dir` contains invalid UTF-8"))?;
let nyx_process_type = match (settings.parallel_mode, settings.parent_cpu_id) { let nyx_process_type = match settings.parent_cpu_id {
(false, _) => NyxProcessType::ALONE, None => NyxProcessType::ALONE,
(true, Some(parent_cpu_id)) if settings.cpu_id == parent_cpu_id => { Some(parent_cpu_id) if settings.cpu_id == parent_cpu_id => NyxProcessType::PARENT,
NyxProcessType::PARENT _ => NyxProcessType::CHILD,
}
(true, Some(_)) => NyxProcessType::CHILD,
(true, _) => {
return Err(Error::illegal_argument(
"`parent_cpu_id` is required in nyx parallel mode",
))
}
}; };
let mut nyx_process = (match nyx_process_type { let mut nyx_process = (match nyx_process_type {
NyxProcessType::ALONE => NyxProcess::new( NyxProcessType::ALONE => NyxProcess::new(

View File

@ -3,21 +3,45 @@ use typed_builder::TypedBuilder;
const DEFAULT_INPUT_BUFFER_SIZE: u32 = 1024 * 1024; const DEFAULT_INPUT_BUFFER_SIZE: u32 = 1024 * 1024;
const DEFAULT_TIMEOUT_SECS: u8 = 2; const DEFAULT_TIMEOUT_SECS: u8 = 2;
const DEFAULT_TIMEOUT_MICRO_SECS: u32 = 0; const DEFAULT_TIMEOUT_MICRO_SECS: u32 = 0;
const DEFAULT_SNAP_MODE: bool = true;
#[derive(Debug, Clone, Copy, TypedBuilder)] #[derive(Debug, Clone, Copy, TypedBuilder)]
pub struct NyxSettings { pub struct NyxSettings {
/// The CPU core for the Nyx process.
///
/// Depending on the value of `parent_cpu_id`, the created Nyx process
/// will be one of the following types:
/// * Standalone: `parent_cpu_id.is_none()`.
/// * Parent: `parent_cpu_id.is_some_and(|parent_cpu_id| parent_cpu_id == cpu_id)`.
/// * Child: `parent_cpu_id.is_some_and(|parent_cpu_id| parent_cpu_id != cpu_id)`.
pub cpu_id: u32, pub cpu_id: u32,
/// The CPU core for the Nyx parent process. The parent process
/// creates the fuzzing snapshot that can then be used by the child
/// processes.
///
/// Not specifying this will start the Nyx process in standalone mode.
pub parent_cpu_id: Option<u32>, pub parent_cpu_id: Option<u32>,
/// Reload the VM by using the fuzzing snapshot. You probably want
/// this to be `true`.
#[builder(default = DEFAULT_SNAP_MODE)]
pub snap_mode: bool, pub snap_mode: bool,
pub parallel_mode: bool,
/// The input buffer size (in bytes) used to pass the input to the
/// QEMU-Nyx VM.
///
/// Default is `1MB`.
#[builder(default = DEFAULT_INPUT_BUFFER_SIZE)] #[builder(default = DEFAULT_INPUT_BUFFER_SIZE)]
pub input_buffer_size: u32, pub input_buffer_size: u32,
/// The timeout for a single execution in seconds (until the
/// hypervisor restore snapshot call).
#[builder(default = DEFAULT_TIMEOUT_SECS)] #[builder(default = DEFAULT_TIMEOUT_SECS)]
pub timeout_secs: u8, pub timeout_secs: u8,
/// Additional timeout in microseconds that gets added to
/// `timeout_secs`.
#[builder(default = DEFAULT_TIMEOUT_MICRO_SECS)] #[builder(default = DEFAULT_TIMEOUT_MICRO_SECS)]
pub timeout_micro_secs: u32, pub timeout_micro_secs: u32,
} }