Skip to content

Commit

Permalink
libafl_frida: Allow compilation for iOS (#1023)
Browse files Browse the repository at this point in the history
iOS does not have any TLS, so we don't need to keep track of it.
This allows compiling for the aarch64-apple-ios target.
  • Loading branch information
fabianfreyer committed Jan 30, 2023
1 parent 33ddce2 commit afa506c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 4 additions & 1 deletion libafl_frida/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// build.rs

fn main() {
cc::Build::new().file("src/gettls.c").compile("libgettls.a");
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
if target_os != "ios" {
cc::Build::new().file("src/gettls.c").compile("libgettls.a");
}

// Force linking against libc++
#[cfg(unix)]
Expand Down
14 changes: 14 additions & 0 deletions libafl_frida/src/asan/asan_rt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ extern "C" {
fn __register_frame(begin: *mut c_void);
}

#[cfg(not(target_os = "ios"))]
extern "C" {
fn tls_ptr() -> *const c_void;
}
Expand Down Expand Up @@ -390,6 +391,7 @@ impl AsanRuntime {
/// Register the current thread with the runtime, implementing shadow memory for its stack and
/// tls mappings.
#[allow(clippy::unused_self)]
#[cfg(not(target_os = "ios"))]
pub fn register_thread(&mut self) {
let (stack_start, stack_end) = Self::current_stack();
self.allocator
Expand All @@ -403,6 +405,17 @@ impl AsanRuntime {
);
}

/// Register the current thread with the runtime, implementing shadow memory for its stack mapping.
#[allow(clippy::unused_self)]
#[cfg(target_os = "ios")]
pub fn register_thread(&mut self) {
let (stack_start, stack_end) = Self::current_stack();
self.allocator
.map_shadow_for_region(stack_start, stack_end, true);

println!("registering thread with stack {stack_start:x}:{stack_end:x}");
}

/// Get the maximum stack size for the current stack
#[must_use]
#[cfg(target_vendor = "apple")]
Expand Down Expand Up @@ -470,6 +483,7 @@ impl AsanRuntime {

/// Determine the tls start, end for the currently running thread
#[must_use]
#[cfg(not(target_os = "ios"))]
fn current_tls() -> (usize, usize) {
let tls_address = unsafe { tls_ptr() } as usize;

Expand Down

0 comments on commit afa506c

Please sign in to comment.