moved std sharedmem to mod
This commit is contained in:
parent
db5183d43f
commit
8b4896df28
@ -1,63 +1,16 @@
|
|||||||
//! A generic sharememory region to be used by any functions (queues or feedbacks
|
//! A generic sharememory region to be used by any functions (queues or feedbacks
|
||||||
// too.)
|
// too.)
|
||||||
|
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
pub use shmem::AflShmem;
|
||||||
|
|
||||||
use alloc::string::{String, ToString};
|
use alloc::string::{String, ToString};
|
||||||
use core::fmt::Debug;
|
use core::fmt::Debug;
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
use core::{mem::size_of, slice};
|
use std::env;
|
||||||
#[cfg(feature = "std")]
|
|
||||||
use libc::{c_char, c_int, c_long, c_uchar, c_uint, c_ulong, c_ushort, c_void};
|
|
||||||
#[cfg(feature = "std")]
|
|
||||||
use std::{env, ffi::CStr};
|
|
||||||
|
|
||||||
use crate::AflError;
|
use crate::AflError;
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
#[cfg(feature = "std")]
|
|
||||||
fn snprintf(_: *mut c_char, _: c_ulong, _: *const c_char, _: ...) -> c_int;
|
|
||||||
#[cfg(feature = "std")]
|
|
||||||
fn strncpy(_: *mut c_char, _: *const c_char, _: c_ulong) -> *mut c_char;
|
|
||||||
#[cfg(feature = "std")]
|
|
||||||
fn shmctl(__shmid: c_int, __cmd: c_int, __buf: *mut shmid_ds) -> c_int;
|
|
||||||
#[cfg(feature = "std")]
|
|
||||||
fn shmget(__key: c_int, __size: c_ulong, __shmflg: c_int) -> c_int;
|
|
||||||
#[cfg(feature = "std")]
|
|
||||||
fn shmat(__shmid: c_int, __shmaddr: *const c_void, __shmflg: c_int) -> *mut c_void;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
|
||||||
#[derive(Copy, Clone)]
|
|
||||||
#[repr(C)]
|
|
||||||
struct ipc_perm {
|
|
||||||
pub __key: c_int,
|
|
||||||
pub uid: c_uint,
|
|
||||||
pub gid: c_uint,
|
|
||||||
pub cuid: c_uint,
|
|
||||||
pub cgid: c_uint,
|
|
||||||
pub mode: c_ushort,
|
|
||||||
pub __pad1: c_ushort,
|
|
||||||
pub __seq: c_ushort,
|
|
||||||
pub __pad2: c_ushort,
|
|
||||||
pub __glibc_reserved1: c_ulong,
|
|
||||||
pub __glibc_reserved2: c_ulong,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
|
||||||
#[derive(Copy, Clone)]
|
|
||||||
#[repr(C)]
|
|
||||||
struct shmid_ds {
|
|
||||||
pub shm_perm: ipc_perm,
|
|
||||||
pub shm_segsz: c_ulong,
|
|
||||||
pub shm_atime: c_long,
|
|
||||||
pub shm_dtime: c_long,
|
|
||||||
pub shm_ctime: c_long,
|
|
||||||
pub shm_cpid: c_int,
|
|
||||||
pub shm_lpid: c_int,
|
|
||||||
pub shm_nattch: c_ulong,
|
|
||||||
pub __glibc_reserved4: c_ulong,
|
|
||||||
pub __glibc_reserved5: c_ulong,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A Shared map
|
/// A Shared map
|
||||||
pub trait ShMem: Sized + Debug {
|
pub trait ShMem: Sized + Debug {
|
||||||
/// Creates a new map with the given size
|
/// Creates a new map with the given size
|
||||||
@ -119,6 +72,61 @@ pub trait ShMem: Sized + Debug {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
|
pub mod shmem {
|
||||||
|
|
||||||
|
use core::{mem::size_of, slice};
|
||||||
|
use libc::{c_char, c_int, c_long, c_uchar, c_uint, c_ulong, c_ushort, c_void};
|
||||||
|
use std::ffi::CStr;
|
||||||
|
|
||||||
|
use crate::AflError;
|
||||||
|
|
||||||
|
use super::ShMem;
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
fn snprintf(_: *mut c_char, _: c_ulong, _: *const c_char, _: ...) -> c_int;
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
fn strncpy(_: *mut c_char, _: *const c_char, _: c_ulong) -> *mut c_char;
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
fn shmctl(__shmid: c_int, __cmd: c_int, __buf: *mut shmid_ds) -> c_int;
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
fn shmget(__key: c_int, __size: c_ulong, __shmflg: c_int) -> c_int;
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
fn shmat(__shmid: c_int, __shmaddr: *const c_void, __shmflg: c_int) -> *mut c_void;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
#[repr(C)]
|
||||||
|
struct ipc_perm {
|
||||||
|
pub __key: c_int,
|
||||||
|
pub uid: c_uint,
|
||||||
|
pub gid: c_uint,
|
||||||
|
pub cuid: c_uint,
|
||||||
|
pub cgid: c_uint,
|
||||||
|
pub mode: c_ushort,
|
||||||
|
pub __pad1: c_ushort,
|
||||||
|
pub __seq: c_ushort,
|
||||||
|
pub __pad2: c_ushort,
|
||||||
|
pub __glibc_reserved1: c_ulong,
|
||||||
|
pub __glibc_reserved2: c_ulong,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
#[repr(C)]
|
||||||
|
struct shmid_ds {
|
||||||
|
pub shm_perm: ipc_perm,
|
||||||
|
pub shm_segsz: c_ulong,
|
||||||
|
pub shm_atime: c_long,
|
||||||
|
pub shm_dtime: c_long,
|
||||||
|
pub shm_ctime: c_long,
|
||||||
|
pub shm_cpid: c_int,
|
||||||
|
pub shm_lpid: c_int,
|
||||||
|
pub shm_nattch: c_ulong,
|
||||||
|
pub __glibc_reserved4: c_ulong,
|
||||||
|
pub __glibc_reserved5: c_ulong,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The default Sharedmap impl for unix using shmctl & shmget
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct AflShmem {
|
pub struct AflShmem {
|
||||||
pub shm_str: [u8; 20],
|
pub shm_str: [u8; 20],
|
||||||
@ -127,7 +135,6 @@ pub struct AflShmem {
|
|||||||
pub map_size: usize,
|
pub map_size: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
|
||||||
impl ShMem for AflShmem {
|
impl ShMem for AflShmem {
|
||||||
fn existing_from_shm_slice(
|
fn existing_from_shm_slice(
|
||||||
map_str_bytes: &[u8; 20],
|
map_str_bytes: &[u8; 20],
|
||||||
@ -156,7 +163,6 @@ impl ShMem for AflShmem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
|
||||||
/// Deinit sharedmaps on drop
|
/// Deinit sharedmaps on drop
|
||||||
impl Drop for AflShmem {
|
impl Drop for AflShmem {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
@ -166,7 +172,6 @@ impl Drop for AflShmem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
|
||||||
/// Create an uninitialized shmap
|
/// Create an uninitialized shmap
|
||||||
const fn afl_shmem_unitialized() -> AflShmem {
|
const fn afl_shmem_unitialized() -> AflShmem {
|
||||||
AflShmem {
|
AflShmem {
|
||||||
@ -177,7 +182,6 @@ const fn afl_shmem_unitialized() -> AflShmem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
|
||||||
impl AflShmem {
|
impl AflShmem {
|
||||||
pub fn from_str(shm_str: &CStr, map_size: usize) -> Result<Self, AflError> {
|
pub fn from_str(shm_str: &CStr, map_size: usize) -> Result<Self, AflError> {
|
||||||
let mut ret = afl_shmem_unitialized();
|
let mut ret = afl_shmem_unitialized();
|
||||||
@ -206,7 +210,6 @@ impl AflShmem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
|
||||||
/// Deinitialize this shmem instance
|
/// Deinitialize this shmem instance
|
||||||
unsafe fn afl_shmem_deinit(shm: *mut AflShmem) {
|
unsafe fn afl_shmem_deinit(shm: *mut AflShmem) {
|
||||||
if shm.is_null() || (*shm).map.is_null() {
|
if shm.is_null() || (*shm).map.is_null() {
|
||||||
@ -219,7 +222,6 @@ unsafe fn afl_shmem_deinit(shm: *mut AflShmem) {
|
|||||||
(*shm).map = 0 as *mut c_uchar;
|
(*shm).map = 0 as *mut c_uchar;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
|
||||||
/// Functions to create Shared memory region, for observation channels and
|
/// Functions to create Shared memory region, for observation channels and
|
||||||
/// opening inputs and stuff.
|
/// opening inputs and stuff.
|
||||||
unsafe fn afl_shmem_init(shm: *mut AflShmem, map_size: usize) -> *mut c_uchar {
|
unsafe fn afl_shmem_init(shm: *mut AflShmem, map_size: usize) -> *mut c_uchar {
|
||||||
@ -253,9 +255,12 @@ unsafe fn afl_shmem_init(shm: *mut AflShmem, map_size: usize) -> *mut c_uchar {
|
|||||||
return (*shm).map;
|
return (*shm).map;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
|
||||||
/// Uses a shmap id string to open a shared map
|
/// Uses a shmap id string to open a shared map
|
||||||
unsafe fn afl_shmem_by_str(shm: *mut AflShmem, shm_str: &CStr, map_size: usize) -> *mut c_uchar {
|
unsafe fn afl_shmem_by_str(
|
||||||
|
shm: *mut AflShmem,
|
||||||
|
shm_str: &CStr,
|
||||||
|
map_size: usize,
|
||||||
|
) -> *mut c_uchar {
|
||||||
if shm.is_null() || shm_str.to_bytes().len() == 0 || map_size == 0 {
|
if shm.is_null() || shm_str.to_bytes().len() == 0 || map_size == 0 {
|
||||||
return 0 as *mut c_uchar;
|
return 0 as *mut c_uchar;
|
||||||
}
|
}
|
||||||
@ -280,6 +285,7 @@ unsafe fn afl_shmem_by_str(shm: *mut AflShmem, shm_str: &CStr, map_size: usize)
|
|||||||
}
|
}
|
||||||
return (*shm).map;
|
return (*shm).map;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
pub mod inmemory;
|
pub mod inmemory;
|
||||||
|
pub use inmemory::InMemoryExecutor;
|
||||||
#[cfg(feature = "runtime")]
|
#[cfg(feature = "runtime")]
|
||||||
pub mod runtime;
|
pub mod runtime;
|
||||||
|
|
||||||
@ -113,11 +114,9 @@ where
|
|||||||
mod test {
|
mod test {
|
||||||
use core::marker::PhantomData;
|
use core::marker::PhantomData;
|
||||||
|
|
||||||
use crate::executors::Executor;
|
use super::{Executor, NopExecutor};
|
||||||
use crate::inputs::BytesInput;
|
use crate::inputs::BytesInput;
|
||||||
|
|
||||||
use super::NopExecutor;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn nop_executor() {
|
fn nop_executor() {
|
||||||
let empty_input = BytesInput::new(vec![]);
|
let empty_input = BytesInput::new(vec![]);
|
||||||
|
@ -304,16 +304,14 @@ where
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::inputs::BytesInput;
|
|
||||||
use crate::mutators::scheduled::StdScheduledMutator;
|
|
||||||
use crate::utils::{Rand, XKCDRand};
|
|
||||||
use crate::{
|
use crate::{
|
||||||
corpus::{Corpus, InMemoryCorpus, Testcase},
|
corpus::{Corpus, InMemoryCorpus, Testcase},
|
||||||
|
inputs::BytesInput,
|
||||||
inputs::HasBytesVec,
|
inputs::HasBytesVec,
|
||||||
|
mutators::scheduled::{mutation_splice, StdScheduledMutator},
|
||||||
|
utils::{Rand, XKCDRand},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::mutation_splice;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_mut_splice() {
|
fn test_mut_splice() {
|
||||||
// With the current impl, seed of 1 will result in a split at pos 2.
|
// With the current impl, seed of 1 will result in a split at pos 2.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user