Index: lib/asan/asan_mapping.h =================================================================== --- lib/asan/asan_mapping.h +++ lib/asan/asan_mapping.h @@ -140,6 +140,7 @@ static const u64 kSystemZ_ShadowOffset64 = 1ULL << 52; static const u64 kFreeBSD_ShadowOffset32 = 1ULL << 30; // 0x40000000 static const u64 kFreeBSD_ShadowOffset64 = 1ULL << 46; // 0x400000000000 +static const u64 kFreeBSD_AArch64_ShadowOffset64 = 1ULL << 47; // 0x800000000000 static const u64 kWindowsShadowOffset32 = 3ULL << 28; // 0x30000000 #define SHADOW_SCALE kDefaultShadowScale @@ -170,6 +171,8 @@ # else # define SHADOW_OFFSET __asan_shadow_memory_dynamic_address # endif +# elif defined(__aarch64__) && SANITIZER_FREEBSD +# define SHADOW_OFFSET kFreeBSD_AArch64_ShadowOffset64 # elif defined(__aarch64__) # define SHADOW_OFFSET kAArch64_ShadowOffset64 # elif defined(__powerpc64__) Index: lib/sanitizer_common/sanitizer_linux.cc =================================================================== --- lib/sanitizer_common/sanitizer_linux.cc +++ lib/sanitizer_common/sanitizer_linux.cc @@ -1058,7 +1058,7 @@ : "memory", "$29" ); return res; } -#elif defined(__aarch64__) +#elif defined(__aarch64__) && SANITIZER_LINUX uptr internal_clone(int (*fn)(void *), void *child_stack, int flags, void *arg, int *parent_tidptr, void *newtls, int *child_tidptr) { long long res; @@ -1433,6 +1433,11 @@ #endif #if defined(__aarch64__) +# if SANITIZER_FREEBSD +static bool Aarch64GetESR(ucontext_t *ucontext, u64 *esr) { + return false; +} +#else // Android headers in the older NDK releases miss this definition. struct __sanitizer_esr_context { struct _aarch64_ctx head; @@ -1454,6 +1459,7 @@ return false; } #endif +#endif SignalContext::WriteFlag SignalContext::GetWriteFlag(void *context) { ucontext_t *ucontext = (ucontext_t *)context; @@ -1491,10 +1497,17 @@ *bp = ucontext->uc_mcontext.arm_fp; *sp = ucontext->uc_mcontext.arm_sp; #elif defined(__aarch64__) +# if SANITIZER_FREEBSD + ucontext_t *ucontext = (ucontext_t*)context; + *pc = ucontext->uc_mcontext.mc_gpregs.gp_elr; + *bp = ucontext->uc_mcontext.mc_gpregs.gp_x[29]; + *sp = ucontext->uc_mcontext.mc_gpregs.gp_sp; +# else ucontext_t *ucontext = (ucontext_t*)context; *pc = ucontext->uc_mcontext.pc; *bp = ucontext->uc_mcontext.regs[29]; *sp = ucontext->uc_mcontext.sp; +#endif #elif defined(__hppa__) ucontext_t *ucontext = (ucontext_t*)context; *pc = ucontext->uc_mcontext.sc_iaoq[0]; Index: lib/sanitizer_common/sanitizer_linux_libcdep.cc =================================================================== --- lib/sanitizer_common/sanitizer_linux_libcdep.cc +++ lib/sanitizer_common/sanitizer_linux_libcdep.cc @@ -326,6 +326,8 @@ # elif defined(__x86_64__) // sysarch(AMD64_GET_FSBASE, segbase); __asm __volatile("movq %%fs:0, %0" : "=r" (segbase)); +# elif defined(__aarch64__) + __asm __volatile("mrs %0, tpidr_el0" : "=&r" (segbase)); # else # error "unsupported CPU arch for FreeBSD platform" # endif Index: lib/sanitizer_common/sanitizer_platform_limits_posix.cc =================================================================== --- lib/sanitizer_common/sanitizer_platform_limits_posix.cc +++ lib/sanitizer_common/sanitizer_platform_limits_posix.cc @@ -118,7 +118,8 @@ #if SANITIZER_LINUX || SANITIZER_FREEBSD # include # include -# if defined(__mips64) || defined(__aarch64__) || defined(__arm__) +# if SANITIZER_LINUX && (defined(__mips64) || defined(__aarch64__) || \ + defined(__arm__)) # include # ifdef __arm__ typedef struct user_fpregs elf_fpregset_t; Index: lib/sanitizer_common/sanitizer_syscall_generic.inc =================================================================== --- lib/sanitizer_common/sanitizer_syscall_generic.inc +++ lib/sanitizer_common/sanitizer_syscall_generic.inc @@ -17,7 +17,8 @@ # define SYSCALL(name) __NR_ ## name #endif -#if (SANITIZER_FREEBSD || SANITIZER_MAC) && defined(__x86_64__) +#if (SANITIZER_FREEBSD || SANITIZER_MAC) && (defined(__x86_64__) || \ + defined(__aarch64__)) # define internal_syscall __syscall # else # define internal_syscall syscall