libafl_frida: remove non-gnu hooks on macos (#262)

The following functions are GNU extensions and therefore
not available on superior systems:
- explicit_bzero
- malloc_usable_size
- memalign
- mempcpy
- memrchr
This commit is contained in:
Fabian Freyer 2021-08-15 08:51:47 +02:00 committed by GitHub
parent 6435af3419
commit 15c6e6b73b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -399,7 +399,7 @@ impl AsanRuntime {
} }
} }
#[cfg(target_arch = "aarch64")] #[cfg(all(target_arch = "aarch64", not(target_os = "macos")))]
#[inline] #[inline]
fn hook_memalign(&mut self, alignment: usize, size: usize) -> *mut c_void { fn hook_memalign(&mut self, alignment: usize, size: usize) -> *mut c_void {
unsafe { self.allocator.alloc(size, alignment) } unsafe { self.allocator.alloc(size, alignment) }
@ -420,7 +420,7 @@ impl AsanRuntime {
} }
#[inline] #[inline]
#[cfg(target_arch = "aarch64")] #[cfg(all(target_arch = "aarch64", not(target_os = "macos")))]
fn hook_malloc_usable_size(&mut self, ptr: *mut c_void) -> usize { fn hook_malloc_usable_size(&mut self, ptr: *mut c_void) -> usize {
self.allocator.get_usable_size(ptr) self.allocator.get_usable_size(ptr)
} }
@ -708,7 +708,7 @@ impl AsanRuntime {
} }
#[inline] #[inline]
#[cfg(target_arch = "aarch64")] #[cfg(all(target_arch = "aarch64", not(target_os = "macos")))]
fn hook_mempcpy(&mut self, dest: *mut c_void, src: *const c_void, n: usize) -> *mut c_void { fn hook_mempcpy(&mut self, dest: *mut c_void, src: *const c_void, n: usize) -> *mut c_void {
extern "C" { extern "C" {
fn mempcpy(dest: *mut c_void, src: *const c_void, n: usize) -> *mut c_void; fn mempcpy(dest: *mut c_void, src: *const c_void, n: usize) -> *mut c_void;
@ -810,7 +810,7 @@ impl AsanRuntime {
} }
#[inline] #[inline]
#[cfg(target_arch = "aarch64")] #[cfg(all(target_arch = "aarch64", not(target_os = "macos")))]
fn hook_memrchr(&mut self, s: *mut c_void, c: i32, n: usize) -> *mut c_void { fn hook_memrchr(&mut self, s: *mut c_void, c: i32, n: usize) -> *mut c_void {
extern "C" { extern "C" {
fn memrchr(s: *mut c_void, c: i32, n: usize) -> *mut c_void; fn memrchr(s: *mut c_void, c: i32, n: usize) -> *mut c_void;
@ -891,7 +891,11 @@ impl AsanRuntime {
unsafe { bzero(s, n) } unsafe { bzero(s, n) }
} }
#[cfg(all(not(target_os = "android"), target_arch = "aarch64"))] #[cfg(all(
not(target_os = "android"),
target_arch = "aarch64",
not(target_os = "macos")
))]
#[inline] #[inline]
fn hook_explicit_bzero(&mut self, s: *mut c_void, n: usize) { fn hook_explicit_bzero(&mut self, s: *mut c_void, n: usize) {
extern "C" { extern "C" {
@ -1590,6 +1594,7 @@ impl AsanRuntime {
hook_func!(None, calloc, (nmemb: usize, size: usize), *mut c_void); hook_func!(None, calloc, (nmemb: usize, size: usize), *mut c_void);
hook_func!(None, realloc, (ptr: *mut c_void, size: usize), *mut c_void); hook_func!(None, realloc, (ptr: *mut c_void, size: usize), *mut c_void);
hook_func_with_check!(None, free, (ptr: *mut c_void), ()); hook_func_with_check!(None, free, (ptr: *mut c_void), ());
#[cfg(not(target_os = "macos"))]
hook_func!(None, memalign, (size: usize, alignment: usize), *mut c_void); hook_func!(None, memalign, (size: usize, alignment: usize), *mut c_void);
hook_func!( hook_func!(
None, None,
@ -1597,6 +1602,7 @@ impl AsanRuntime {
(pptr: *mut *mut c_void, size: usize, alignment: usize), (pptr: *mut *mut c_void, size: usize, alignment: usize),
i32 i32
); );
#[cfg(not(target_os = "macos"))]
hook_func!(None, malloc_usable_size, (ptr: *mut c_void), usize); hook_func!(None, malloc_usable_size, (ptr: *mut c_void), usize);
hook_func!(None, _Znam, (size: usize), *mut c_void); hook_func!(None, _Znam, (size: usize), *mut c_void);
hook_func!( hook_func!(
@ -1730,6 +1736,7 @@ impl AsanRuntime {
(dest: *mut c_void, src: *const c_void, n: usize), (dest: *mut c_void, src: *const c_void, n: usize),
*mut c_void *mut c_void
); );
#[cfg(not(target_os = "macos"))]
hook_func!( hook_func!(
None, None,
mempcpy, mempcpy,
@ -1754,6 +1761,7 @@ impl AsanRuntime {
(s: *mut c_void, c: i32, n: usize), (s: *mut c_void, c: i32, n: usize),
*mut c_void *mut c_void
); );
#[cfg(not(target_os = "macos"))]
hook_func!( hook_func!(
None, None,
memrchr, memrchr,
@ -1773,7 +1781,7 @@ impl AsanRuntime {
); );
#[cfg(not(target_os = "android"))] #[cfg(not(target_os = "android"))]
hook_func!(None, bzero, (s: *mut c_void, n: usize), ()); hook_func!(None, bzero, (s: *mut c_void, n: usize), ());
#[cfg(not(target_os = "android"))] #[cfg(not(any(target_os = "macos", target_os = "android")))]
hook_func!(None, explicit_bzero, (s: *mut c_void, n: usize), ()); hook_func!(None, explicit_bzero, (s: *mut c_void, n: usize), ());
#[cfg(not(target_os = "android"))] #[cfg(not(target_os = "android"))]
hook_func!( hook_func!(