From 5caeb46b67461c1cf61cdd6ffe98e003d0726b29 Mon Sep 17 00:00:00 2001 From: Dominik Maier Date: Mon, 23 Aug 2021 09:45:25 +0200 Subject: [PATCH] renamed target_os macos to target_vendor apple (#273) * renamed target_os macos to target_vendor apple * fix yaml --- .github/workflows/build_and_test.yml | 17 ++++++++++++ libafl/src/bolts/os/unix_shmem_server.rs | 8 +++--- libafl/src/bolts/shmem.rs | 18 +++++-------- libafl/src/executors/inprocess.rs | 6 +---- libafl_cc/Cargo.toml | 2 +- libafl_cc/build.rs | 14 +++++----- libafl_cc/src/clang.rs | 8 +++--- libafl_frida/src/alloc.rs | 4 +-- libafl_frida/src/asan_rt.rs | 34 ++++++++++++------------ libafl_frida/src/helper.rs | 4 +-- 10 files changed, 61 insertions(+), 54 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 38978e76d6..288d26d01f 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -165,6 +165,23 @@ jobs: run: ./scripts/shmem_limits_macos.sh - name: Build and run example fuzzers run: ./scripts/test_all_fuzzers.sh + other_targets: + runs-on: macOS-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + - uses: Swatinem/rust-cache@v1 + - name: install ios + run: rustup target add aarch64-apple-ios + #- name: install android + # run: rustup target add aarch64-linux-android + - name: Build iOS + run: cargo build --target aarch64-apple-ios + #- name: Build Android + # run: cargo build --target aarch64-linux-android # TODO: Figure out how to properly build stuff with clang #- name: Add clang path to $PATH env # if: runner.os == 'Windows' diff --git a/libafl/src/bolts/os/unix_shmem_server.rs b/libafl/src/bolts/os/unix_shmem_server.rs index 7085226b7c..10504adffe 100644 --- a/libafl/src/bolts/os/unix_shmem_server.rs +++ b/libafl/src/bolts/os/unix_shmem_server.rs @@ -23,7 +23,7 @@ use std::{ thread::JoinHandle, }; -#[cfg(any(target_os = "macos", target_os = "ios"))] +#[cfg(target_vendor = "apple")] use std::fs; #[cfg(all(feature = "std", unix))] @@ -42,10 +42,10 @@ use std::{ use uds::{UnixListenerExt, UnixSocketAddr, UnixStreamExt}; /// The default server name for our abstract shmem server -#[cfg(all(unix, not(any(target_os = "ios", target_os = "macos"))))] +#[cfg(all(unix, not(target_vendor = "apple")))] const UNIX_SERVER_NAME: &str = "@libafl_unix_shmem_server"; /// `MacOS` server name is on disk, since `MacOS` doesn't support abtract domain sockets. -#[cfg(any(target_os = "ios", target_os = "macos"))] +#[cfg(target_vendor = "apple")] const UNIX_SERVER_NAME: &str = "./libafl_unix_shmem_server"; /// Env variable. If set, we won't try to spawn the service @@ -331,7 +331,7 @@ impl Drop for ShMemServiceThread { .expect("Failed to join ShMemService thread!") .expect("Error in ShMemService background thread!"); // try to remove the file from fs, and ignore errors. - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(target_vendor = "apple")] fs::remove_file(&UNIX_SERVER_NAME).unwrap(); env::remove_var(AFL_SHMEM_SERVICE_STARTED); diff --git a/libafl/src/bolts/shmem.rs b/libafl/src/bolts/shmem.rs index 63bcd594b6..5fb7016bcf 100644 --- a/libafl/src/bolts/shmem.rs +++ b/libafl/src/bolts/shmem.rs @@ -32,30 +32,30 @@ pub type StdShMem = RcShMem>; #[cfg(all(target_os = "android", feature = "std"))] pub type StdShMemService = ShMemService; -#[cfg(all(feature = "std", any(target_os = "ios", target_os = "macos")))] +#[cfg(all(feature = "std", target_vendor = "apple"))] pub type StdShMemProvider = RcShMemProvider>; -#[cfg(all(feature = "std", any(target_os = "ios", target_os = "macos")))] +#[cfg(all(feature = "std", target_vendor = "apple"))] pub type StdShMem = RcShMem>; -#[cfg(all(feature = "std", any(target_os = "ios", target_os = "macos")))] +#[cfg(all(feature = "std", target_vendor = "apple"))] pub type StdShMemService = ShMemService; /// The default [`ShMemProvider`] for this os. #[cfg(all( feature = "std", unix, - not(any(target_os = "android", target_os = "ios", target_os = "macos")) + not(any(target_os = "android", target_vendor = "apple")) ))] pub type StdShMemProvider = UnixShMemProvider; /// The default [`ShMemProvider`] for this os. #[cfg(all( feature = "std", unix, - not(any(target_os = "android", target_os = "ios", target_os = "macos")) + not(any(target_os = "android", target_vendor = "apple")) ))] pub type StdShMem = UnixShMem; #[cfg(any( - not(any(target_os = "android", target_os = "macos", target_os = "ios")), + not(any(target_os = "android", target_vendor = "apple")), not(feature = "std") ))] pub type StdShMemService = DummyShMemService; @@ -67,12 +67,6 @@ use std::{ env, }; -#[cfg(all( - unix, - feature = "std", - any(target_os = "ios", target_os = "macos", target_os = "android") -))] -use super::os::unix_shmem_server::ServedShMem; #[cfg(all(unix, feature = "std"))] use crate::bolts::os::pipes::Pipe; #[cfg(all(unix, feature = "std"))] diff --git a/libafl/src/executors/inprocess.rs b/libafl/src/executors/inprocess.rs index b2d65f3fa3..1953a4401f 100644 --- a/libafl/src/executors/inprocess.rs +++ b/libafl/src/executors/inprocess.rs @@ -524,11 +524,7 @@ mod unix_signal_handler { } #[allow(clippy::non_ascii_literal)] - #[cfg(all( - feature = "std", - any(target_os = "macos", target_os = "ios"), - target_arch = "aarch64" - ))] + #[cfg(all(feature = "std", target_vendor = "apple", target_arch = "aarch64"))] { let mcontext = *_context.uc_mcontext; println!("{:━^100}", " CRASH "); diff --git a/libafl_cc/Cargo.toml b/libafl_cc/Cargo.toml index 0376f65a39..2adb10e024 100644 --- a/libafl_cc/Cargo.toml +++ b/libafl_cc/Cargo.toml @@ -15,7 +15,7 @@ edition = "2018" [build-dependencies] cc = { version = "1.0", features = ["parallel"] } -[target.'cfg(target_os = "macos")'.build-dependencies] +[target.'cfg(target_vendor = "apple")'.build-dependencies] glob = "0.3" [dependencies] diff --git a/libafl_cc/build.rs b/libafl_cc/build.rs index 613f5fa202..bc7a43db24 100644 --- a/libafl_cc/build.rs +++ b/libafl_cc/build.rs @@ -1,9 +1,9 @@ use std::{env, fs::File, io::Write, path::Path, process::Command, str}; -#[cfg(target_os = "macos")] +#[cfg(target_vendor = "apple")] use glob::glob; -#[cfg(target_os = "macos")] +#[cfg(target_vendor = "apple")] use std::path::PathBuf; fn dll_extension<'a>() -> &'a str { @@ -16,7 +16,7 @@ fn dll_extension<'a>() -> &'a str { /// Github Actions for `MacOS` seems to have troubles finding `llvm-config`. /// Hence, we go look for it ourselves. -#[cfg(target_os = "macos")] +#[cfg(target_vendor = "apple")] fn find_llvm_config_brew() -> Result { match Command::new("brew").arg("--cellar").output() { Ok(output) => { @@ -43,7 +43,7 @@ fn find_llvm_config_brew() -> Result { fn find_llvm_config() -> String { env::var("LLVM_CONFIG").unwrap_or_else(|_| { // for Ghithub Actions, we check if we find llvm-config in brew. - #[cfg(target_os = "macos")] + #[cfg(target_vendor = "apple")] match find_llvm_config_brew() { Ok(llvm_dir) => llvm_dir.to_str().unwrap().to_string(), Err(err) => { @@ -52,7 +52,7 @@ fn find_llvm_config() -> String { "llvm-config".to_string() } } - #[cfg(not(target_os = "macos"))] + #[cfg(not(target_vendor = "apple"))] "llvm-config".to_string() }) } @@ -103,10 +103,10 @@ fn main() { let cxxflags: Vec<&str> = cxxflags.trim().split_whitespace().collect(); let mut ldflags: Vec<&str> = ldflags.trim().split_whitespace().collect(); - match env::var("CARGO_CFG_TARGET_OS").unwrap().as_str() { + match env::var("CARGO_CFG_TARGET_VENDOR").unwrap().as_str() { // Needed on macos. // Explanation at https://github.com/banach-space/llvm-tutor/blob/787b09ed31ff7f0e7bdd42ae20547d27e2991512/lib/CMakeLists.txt#L59 - "macos" | "ios" => { + "apple" => { ldflags.push("-undefined"); ldflags.push("dynamic_lookup"); } diff --git a/libafl_cc/src/clang.rs b/libafl_cc/src/clang.rs index 7567af10d3..92423a88cc 100644 --- a/libafl_cc/src/clang.rs +++ b/libafl_cc/src/clang.rs @@ -13,7 +13,7 @@ use crate::{CompilerWrapper, Error, LIB_EXT, LIB_PREFIX}; fn dll_extension<'a>() -> &'a str { if cfg!(target_os = "windows") { "dll" - } else if cfg!(any(target_os = "ios", target_os = "macos")) { + } else if cfg!(target_vendor = "apple") { "dylib" } else { "so" @@ -130,7 +130,7 @@ impl CompilerWrapper for ClangWrapper { new_args.push("-lAdvapi32".into()); } // MacOS has odd linker behavior sometimes - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(target_vendor = "apple")] if linking { new_args.push("-undefined".into()); new_args.push("dynamic_lookup".into()); @@ -168,7 +168,7 @@ impl CompilerWrapper for ClangWrapper { where S: AsRef, { - if cfg!(any(target_os = "macos", target_os = "ios")) { + if cfg!(target_vendor = "apple") { //self.add_link_arg("-force_load".into())?; } else { self.add_link_arg("-Wl,--whole-archive"); @@ -179,7 +179,7 @@ impl CompilerWrapper for ClangWrapper { .into_string() .unwrap(), ); - if cfg!(any(target_os = "macos", target_os = "ios")) { + if cfg!(target_vendor = "apple") { self } else { self.add_link_arg("-Wl,-no-whole-archive") diff --git a/libafl_frida/src/alloc.rs b/libafl_frida/src/alloc.rs index 5b18c6bf0f..f65048542d 100644 --- a/libafl_frida/src/alloc.rs +++ b/libafl_frida/src/alloc.rs @@ -35,9 +35,9 @@ pub(crate) struct Allocator { current_mapping_addr: usize, } -#[cfg(any(target_os = "macos", target_os = "ios"))] +#[cfg(target_vendor = "apple")] const ANONYMOUS_FLAG: MapFlags = MapFlags::MAP_ANON; -#[cfg(not(any(target_os = "macos", target_os = "ios")))] +#[cfg(not(target_vendor = "apple"))] const ANONYMOUS_FLAG: MapFlags = MapFlags::MAP_ANONYMOUS; macro_rules! map_to_shadow { diff --git a/libafl_frida/src/asan_rt.rs b/libafl_frida/src/asan_rt.rs index edf10d5c8c..2386637901 100644 --- a/libafl_frida/src/asan_rt.rs +++ b/libafl_frida/src/asan_rt.rs @@ -29,9 +29,9 @@ use frida_gum::{Gum, ModuleMap}; use libc::RLIMIT_STACK; #[cfg(target_arch = "aarch64")] use libc::{c_char, wchar_t}; -#[cfg(any(target_os = "macos", target_os = "ios"))] +#[cfg(target_vendor = "apple")] use libc::{getrlimit, rlimit}; -#[cfg(all(unix, not(any(target_os = "macos", target_os = "ios"))))] +#[cfg(all(unix, not(target_vendor = "apple")))] use libc::{getrlimit64, rlimit64}; use std::{ffi::c_void, ptr::write_volatile}; @@ -50,9 +50,9 @@ extern "C" { fn tls_ptr() -> *const c_void; } -#[cfg(any(target_os = "macos", target_os = "ios"))] +#[cfg(target_vendor = "apple")] const ANONYMOUS_FLAG: MapFlags = MapFlags::MAP_ANON; -#[cfg(not(any(target_os = "macos", target_os = "ios")))] +#[cfg(not(target_vendor = "apple"))] const ANONYMOUS_FLAG: MapFlags = MapFlags::MAP_ANONYMOUS; /// The frida address sanitizer runtime, providing address sanitization. @@ -210,7 +210,7 @@ impl AsanRuntime { /// Get the maximum stack size for the current stack #[must_use] - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(target_vendor = "apple")] fn max_stack_size() -> usize { let mut stack_rlimit = rlimit { rlim_cur: 0, @@ -223,7 +223,7 @@ impl AsanRuntime { /// Get the maximum stack size for the current stack #[must_use] - #[cfg(all(unix, not(any(target_os = "macos", target_os = "ios"))))] + #[cfg(all(unix, not(target_vendor = "apple")))] fn max_stack_size() -> usize { let mut stack_rlimit = rlimit64 { rlim_cur: 0, @@ -254,7 +254,7 @@ impl AsanRuntime { let max_start = end - Self::max_stack_size(); let flags = ANONYMOUS_FLAG | MapFlags::MAP_FIXED | MapFlags::MAP_PRIVATE; - #[cfg(not(any(target_os = "macos", target_os = "ios")))] + #[cfg(not(target_vendor = "apple"))] let flags = flags | MapFlags::MAP_STACK; if start != max_start { @@ -399,7 +399,7 @@ impl AsanRuntime { } } - #[cfg(all(target_arch = "aarch64", not(target_os = "macos")))] + #[cfg(all(target_arch = "aarch64", not(target_vendor = "apple")))] #[inline] fn hook_memalign(&mut self, alignment: usize, size: usize) -> *mut c_void { unsafe { self.allocator.alloc(size, alignment) } @@ -420,7 +420,7 @@ impl AsanRuntime { } #[inline] - #[cfg(all(target_arch = "aarch64", not(target_os = "macos")))] + #[cfg(all(target_arch = "aarch64", not(target_vendor = "apple")))] fn hook_malloc_usable_size(&mut self, ptr: *mut c_void) -> usize { self.allocator.get_usable_size(ptr) } @@ -708,7 +708,7 @@ impl AsanRuntime { } #[inline] - #[cfg(all(target_arch = "aarch64", not(target_os = "macos")))] + #[cfg(all(target_arch = "aarch64", not(target_vendor = "apple")))] fn hook_mempcpy(&mut self, dest: *mut c_void, src: *const c_void, n: usize) -> *mut c_void { extern "C" { fn mempcpy(dest: *mut c_void, src: *const c_void, n: usize) -> *mut c_void; @@ -810,7 +810,7 @@ impl AsanRuntime { } #[inline] - #[cfg(all(target_arch = "aarch64", not(target_os = "macos")))] + #[cfg(all(target_arch = "aarch64", not(target_vendor = "apple")))] fn hook_memrchr(&mut self, s: *mut c_void, c: i32, n: usize) -> *mut c_void { extern "C" { fn memrchr(s: *mut c_void, c: i32, n: usize) -> *mut c_void; @@ -894,7 +894,7 @@ impl AsanRuntime { #[cfg(all( not(target_os = "android"), target_arch = "aarch64", - not(target_os = "macos") + not(target_vendor = "apple") ))] #[inline] fn hook_explicit_bzero(&mut self, s: *mut c_void, n: usize) { @@ -1594,7 +1594,7 @@ impl AsanRuntime { 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_with_check!(None, free, (ptr: *mut c_void), ()); - #[cfg(not(target_os = "macos"))] + #[cfg(not(target_vendor = "apple"))] hook_func!(None, memalign, (size: usize, alignment: usize), *mut c_void); hook_func!( None, @@ -1602,7 +1602,7 @@ impl AsanRuntime { (pptr: *mut *mut c_void, size: usize, alignment: usize), i32 ); - #[cfg(not(target_os = "macos"))] + #[cfg(not(target_vendor = "apple"))] hook_func!(None, malloc_usable_size, (ptr: *mut c_void), usize); hook_func!(None, _Znam, (size: usize), *mut c_void); hook_func!( @@ -1736,7 +1736,7 @@ impl AsanRuntime { (dest: *mut c_void, src: *const c_void, n: usize), *mut c_void ); - #[cfg(not(target_os = "macos"))] + #[cfg(not(target_vendor = "apple"))] hook_func!( None, mempcpy, @@ -1761,7 +1761,7 @@ impl AsanRuntime { (s: *mut c_void, c: i32, n: usize), *mut c_void ); - #[cfg(not(target_os = "macos"))] + #[cfg(not(target_vendor = "apple"))] hook_func!( None, memrchr, @@ -1781,7 +1781,7 @@ impl AsanRuntime { ); #[cfg(not(target_os = "android"))] hook_func!(None, bzero, (s: *mut c_void, n: usize), ()); - #[cfg(not(any(target_os = "macos", target_os = "android")))] + #[cfg(not(any(target_os = "android", target_vendor = "apple")))] hook_func!(None, explicit_bzero, (s: *mut c_void, n: usize), ()); #[cfg(not(target_os = "android"))] hook_func!( diff --git a/libafl_frida/src/helper.rs b/libafl_frida/src/helper.rs index 23dce4e5b0..441ed86337 100644 --- a/libafl_frida/src/helper.rs +++ b/libafl_frida/src/helper.rs @@ -46,9 +46,9 @@ enum CmplogOperandType { Mem(capstone::RegId, capstone::RegId, i32, u32), } -#[cfg(any(target_os = "macos", target_os = "ios"))] +#[cfg(target_vendor = "apple")] const ANONYMOUS_FLAG: MapFlags = MapFlags::MAP_ANON; -#[cfg(not(any(target_os = "macos", target_os = "ios")))] +#[cfg(not(target_vendor = "apple"))] const ANONYMOUS_FLAG: MapFlags = MapFlags::MAP_ANONYMOUS; /// An helper that feeds [`FridaInProcessExecutor`] with user-supplied instrumentation