--- lib/sanitizer_common/sanitizer_linux.cc.orig 2017-01-07 07:57:47.000000000 +1100 +++ lib/sanitizer_common/sanitizer_linux.cc 2020-05-22 11:51:53.463182000 +1000 @@ -14,7 +14,7 @@ #include "sanitizer_platform.h" -#if SANITIZER_FREEBSD || SANITIZER_LINUX +#if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_BSDSUNIX #include "sanitizer_common.h" #include "sanitizer_flags.h" @@ -27,7 +27,7 @@ #include "sanitizer_stacktrace.h" #include "sanitizer_symbolizer.h" -#if !SANITIZER_FREEBSD +#if !SANITIZER_FREEBSD && !SANITIZER_BSDSUNIX #include #endif @@ -59,11 +59,9 @@ #include #include -#if SANITIZER_FREEBSD +#if SANITIZER_FREEBSD || SANITIZER_BSDSUNIX #include #include -#include -#include #include extern "C" { // must be included after and on @@ -71,7 +69,7 @@ #include } extern char **environ; // provided by crt1 -#endif // SANITIZER_FREEBSD +#endif // SANITIZER_FREEBSD || SANITIZER_BSDSUNIX #if !SANITIZER_ANDROID #include @@ -119,7 +117,7 @@ #if !SANITIZER_S390 uptr internal_mmap(void *addr, uptr length, int prot, int flags, int fd, OFF_T offset) { -#if SANITIZER_FREEBSD || SANITIZER_LINUX_USES_64BIT_SYSCALLS +#if SANITIZER_FREEBSD || SANITIZER_LINUX_USES_64BIT_SYSCALLS || SANITIZER_BSDSUNIX return internal_syscall(SYSCALL(mmap), (uptr)addr, length, prot, flags, fd, offset); #else @@ -181,7 +179,7 @@ return res; } -#if !SANITIZER_LINUX_USES_64BIT_SYSCALLS && !SANITIZER_FREEBSD +#if !SANITIZER_LINUX_USES_64BIT_SYSCALLS && !SANITIZER_FREEBSD && !SANITIZER_BSDSUNIX static void stat64_to_stat(struct stat64 *in, struct stat *out) { internal_memset(out, 0, sizeof(*out)); out->st_dev = in->st_dev; @@ -222,8 +220,9 @@ #endif uptr internal_stat(const char *path, void *buf) { -#if SANITIZER_FREEBSD - return internal_syscall(SYSCALL(stat), path, buf); +#if SANITIZER_FREEBSD || SANITIZER_BSDSUNIX + return internal_syscall(SYSCALL(fstatat), AT_FDCWD, (uptr)path, + (uptr)buf, 0); #elif SANITIZER_USES_CANONICAL_LINUX_SYSCALLS return internal_syscall(SYSCALL(newfstatat), AT_FDCWD, (uptr)path, (uptr)buf, 0); @@ -246,8 +245,9 @@ } uptr internal_lstat(const char *path, void *buf) { -#if SANITIZER_FREEBSD - return internal_syscall(SYSCALL(lstat), path, buf); +#if SANITIZER_FREEBSD || SANITIZER_BSDSUNIX + return internal_syscall(SYSCALL(fstatat), AT_FDCWD, (uptr)path, + (uptr)buf, AT_SYMLINK_NOFOLLOW); #elif SANITIZER_USES_CANONICAL_LINUX_SYSCALLS return internal_syscall(SYSCALL(newfstatat), AT_FDCWD, (uptr)path, (uptr)buf, AT_SYMLINK_NOFOLLOW); @@ -270,7 +270,7 @@ } uptr internal_fstat(fd_t fd, void *buf) { -#if SANITIZER_FREEBSD || SANITIZER_LINUX_USES_64BIT_SYSCALLS +#if SANITIZER_FREEBSD || SANITIZER_LINUX_USES_64BIT_SYSCALLS || SANITIZER_BSDSUNIX # if SANITIZER_MIPS64 // For mips64, fstat syscall fills buffer in the format of kernel_stat struct kernel_stat kbuf; @@ -334,7 +334,7 @@ } void internal__exit(int exitcode) { -#if SANITIZER_FREEBSD +#if SANITIZER_FREEBSD || SANITIZER_BSDSUNIX internal_syscall(SYSCALL(exit), exitcode); #else internal_syscall(SYSCALL(exit_group), exitcode); @@ -371,7 +371,7 @@ } uptr GetTid() { -#if SANITIZER_FREEBSD +#if SANITIZER_FREEBSD || SANITIZER_BSDSUNIX return (uptr)pthread_self(); #else return internal_syscall(SYSCALL(gettid)); @@ -379,7 +379,7 @@ } u64 NanoTime() { -#if SANITIZER_FREEBSD +#if SANITIZER_FREEBSD || SANITIZER_BSDSUNIX timeval tv; #else kernel_timeval tv; @@ -393,7 +393,7 @@ // 'environ' array (on FreeBSD) and does not use libc. This function should be // called first inside __asan_init. const char *GetEnv(const char *name) { -#if SANITIZER_FREEBSD +#if SANITIZER_FREEBSD || SANITIZER_BSDSUNIX if (::environ != 0) { uptr NameLen = internal_strlen(name); for (char **Env = ::environ; *Env != 0; Env++) { @@ -431,13 +431,13 @@ #endif } -#if !SANITIZER_FREEBSD +#if !SANITIZER_FREEBSD && !SANITIZER_BSDSUNIX extern "C" { SANITIZER_WEAK_ATTRIBUTE extern void *__libc_stack_end; } #endif -#if !SANITIZER_GO && !SANITIZER_FREEBSD +#if !SANITIZER_GO && !SANITIZER_FREEBSD && !SANITIZER_BSDSUNIX static void ReadNullSepFileToArray(const char *path, char ***arr, int arr_size) { char *buff; @@ -463,7 +463,7 @@ #endif static void GetArgsAndEnv(char ***argv, char ***envp) { -#if !SANITIZER_FREEBSD +#if !SANITIZER_FREEBSD && !SANITIZER_BSDSUNIX #if !SANITIZER_GO if (&__libc_stack_end) { #endif @@ -525,7 +525,7 @@ if (atomic_exchange(m, MtxLocked, memory_order_acquire) == MtxUnlocked) return; while (atomic_exchange(m, MtxSleeping, memory_order_acquire) != MtxUnlocked) { -#if SANITIZER_FREEBSD +#if SANITIZER_FREEBSD || SANITIZER_BSDSUNIX _umtx_op(m, UMTX_OP_WAIT_UINT, MtxSleeping, 0, 0); #else internal_syscall(SYSCALL(futex), (uptr)m, FUTEX_WAIT, MtxSleeping, 0, 0, 0); @@ -538,7 +538,7 @@ u32 v = atomic_exchange(m, MtxUnlocked, memory_order_relaxed); CHECK_NE(v, MtxUnlocked); if (v == MtxSleeping) { -#if SANITIZER_FREEBSD +#if SANITIZER_FREEBSD || SANITIZER_BSDSUNIX _umtx_op(m, UMTX_OP_WAKE, 1, 0, 0); #else internal_syscall(SYSCALL(futex), (uptr)m, FUTEX_WAKE, 1, 0, 0, 0); @@ -590,7 +590,9 @@ } uptr internal_getdents(fd_t fd, struct linux_dirent *dirp, unsigned int count) { -#if SANITIZER_USES_CANONICAL_LINUX_SYSCALLS +#if SANITIZER_FREEBSD || SANITIZER_BSDSUNIX + return internal_syscall(SYSCALL(getdirentries), fd, (uptr)dirp, count, NULL); +#elif SANITIZER_USES_CANONICAL_LINUX_SYSCALLS return internal_syscall(SYSCALL(getdents64), fd, (uptr)dirp, count); #else return internal_syscall(SYSCALL(getdents), fd, (uptr)dirp, count); @@ -690,7 +692,7 @@ uptr internal_sigprocmask(int how, __sanitizer_sigset_t *set, __sanitizer_sigset_t *oldset) { -#if SANITIZER_FREEBSD +#if SANITIZER_FREEBSD || SANITIZER_BSDSUNIX return internal_syscall(SYSCALL(sigprocmask), how, set, oldset); #else __sanitizer_kernel_sigset_t *k_set = (__sanitizer_kernel_sigset_t *)set; @@ -811,7 +813,7 @@ } uptr ReadBinaryName(/*out*/char *buf, uptr buf_len) { -#if SANITIZER_FREEBSD +#if SANITIZER_FREEBSD || SANITIZER_BSDSUNIX const int Mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 }; const char *default_module_name = "kern.proc.pathname"; size_t Size = buf_len; @@ -867,10 +869,10 @@ // Call cb for each region mapped by map. void ForEachMappedRegion(link_map *map, void (*cb)(const void *, uptr)) { CHECK_NE(map, nullptr); -#if !SANITIZER_FREEBSD +#if !SANITIZER_FREEBSD && !SANITIZER_BSDSUNIX typedef ElfW(Phdr) Elf_Phdr; typedef ElfW(Ehdr) Elf_Ehdr; -#endif // !SANITIZER_FREEBSD +#endif // !SANITIZER_FREEBSD && !SANITIZER_BSDSUNIX char *base = (char *)map->l_addr; Elf_Ehdr *ehdr = (Elf_Ehdr *)base; char *phdrs = base + ehdr->e_phoff; @@ -1283,7 +1285,7 @@ ucontext_t *ucontext = (ucontext_t *)context; #if defined(__x86_64__) || defined(__i386__) static const uptr PF_WRITE = 1U << 1; -#if SANITIZER_FREEBSD +#if SANITIZER_FREEBSD || SANITIZER_BSDSUNIX uptr err = ucontext->uc_mcontext.mc_err; #else uptr err = ucontext->uc_mcontext.gregs[REG_ERR]; @@ -1326,7 +1328,7 @@ *bp = ucontext->uc_mcontext.sc_gr[3]; *sp = ucontext->uc_mcontext.sc_gr[30]; #elif defined(__x86_64__) -# if SANITIZER_FREEBSD +# if SANITIZER_FREEBSD || SANITIZER_BSDSUNIX ucontext_t *ucontext = (ucontext_t*)context; *pc = ucontext->uc_mcontext.mc_rip; *bp = ucontext->uc_mcontext.mc_rbp; @@ -1338,7 +1340,7 @@ *sp = ucontext->uc_mcontext.gregs[REG_RSP]; # endif #elif defined(__i386__) -# if SANITIZER_FREEBSD +# if SANITIZER_FREEBSD || SANITIZER_BSDSUNIX ucontext_t *ucontext = (ucontext_t*)context; *pc = ucontext->uc_mcontext.mc_eip; *bp = ucontext->uc_mcontext.mc_ebp; @@ -1402,4 +1404,4 @@ } // namespace __sanitizer -#endif // SANITIZER_FREEBSD || SANITIZER_LINUX +#endif // SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_BSDSUNIX