Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/gpl3/gcc/dist/libsanitizer/sanitizer_common - hack ...



details:   https://anonhg.NetBSD.org/src/rev/3074cbc54139
branches:  trunk
changeset: 345541:3074cbc54139
user:      christos <christos%NetBSD.org@localhost>
date:      Tue May 31 21:35:11 2016 +0000

description:
- hack BlockingMutex
- add NetBSD procmaps
- remove old unused source

diffstat:

 external/gpl3/gcc/dist/libsanitizer/sanitizer_common/sanitizer_linux.cc           |    6 +-
 external/gpl3/gcc/dist/libsanitizer/sanitizer_common/sanitizer_netbsd.cc          |  479 ----------
 external/gpl3/gcc/dist/libsanitizer/sanitizer_common/sanitizer_procmaps_netbsd.cc |   78 +
 3 files changed, 82 insertions(+), 481 deletions(-)

diffs (truncated from 602 to 300 lines):

diff -r 8305dbec7145 -r 3074cbc54139 external/gpl3/gcc/dist/libsanitizer/sanitizer_common/sanitizer_linux.cc
--- a/external/gpl3/gcc/dist/libsanitizer/sanitizer_common/sanitizer_linux.cc   Tue May 31 21:34:13 2016 +0000
+++ b/external/gpl3/gcc/dist/libsanitizer/sanitizer_common/sanitizer_linux.cc   Tue May 31 21:35:11 2016 +0000
@@ -420,7 +420,6 @@
 }
 #endif  // SANITIZER_GO
 
-#if !SANITIZER_NETBSD
 enum MutexState {
   MtxUnlocked = 0,
   MtxLocked = 1,
@@ -442,6 +441,8 @@
   while (atomic_exchange(m, MtxSleeping, memory_order_acquire) != MtxUnlocked) {
 #if SANITIZER_FREEBSD
     _umtx_op(m, UMTX_OP_WAIT_UINT, MtxSleeping, 0, 0);
+#elif SANITIZER_NETBSD
+    sched_yield();     // XXX:
 #else
     internal_syscall(SYSCALL(futex), (uptr)m, FUTEX_WAIT, MtxSleeping, 0, 0, 0);
 #endif
@@ -455,6 +456,8 @@
   if (v == MtxSleeping) {
 #if SANITIZER_FREEBSD
     _umtx_op(m, UMTX_OP_WAKE, 1, 0, 0);
+#elif SANITIZER_NETBSD
+    // XXX:
 #else
     internal_syscall(SYSCALL(futex), (uptr)m, FUTEX_WAKE, 1, 0, 0, 0);
 #endif
@@ -465,7 +468,6 @@
   atomic_uint32_t *m = reinterpret_cast<atomic_uint32_t *>(&opaque_storage_);
   CHECK_NE(MtxUnlocked, atomic_load(m, memory_order_relaxed));
 }
-#endif // !SANITIZER_NETBSD
 
 // ----------------- sanitizer_linux.h
 // The actual size of this structure is specified by d_reclen.
diff -r 8305dbec7145 -r 3074cbc54139 external/gpl3/gcc/dist/libsanitizer/sanitizer_common/sanitizer_netbsd.cc
--- a/external/gpl3/gcc/dist/libsanitizer/sanitizer_common/sanitizer_netbsd.cc  Tue May 31 21:34:13 2016 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,479 +0,0 @@
-//===-- sanitizer_netbsd.cc -----------------------------------------------===//
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file is shared between AddressSanitizer and ThreadSanitizer
-// run-time libraries and implements linux-specific functions from
-// sanitizer_libc.h.
-//===----------------------------------------------------------------------===//
-#ifdef __NetBSD__
-
-#include "sanitizer_common.h"
-#include "sanitizer_internal_defs.h"
-#include "sanitizer_libc.h"
-#include "sanitizer_mutex.h"
-#include "sanitizer_placement_new.h"
-#include "sanitizer_procmaps.h"
-#include "sanitizer_stacktrace.h"
-
-#include <fcntl.h>
-#include <pthread.h>
-#include <sched.h>
-#include <sys/mman.h>
-#include <sys/resource.h>
-#include <sys/stat.h>
-#include <sys/syscall.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <errno.h>
-
-namespace __sanitizer {
-
-// --------------- sanitizer_libc.h
-void *internal_mmap(void *addr, uptr length, int prot, int flags,
-                    int fd, u64 offset) {
-  return (void *)__syscall(SYS_mmap, addr, length, prot, flags,
-  fd, 0, offset);
-}
-
-int internal_munmap(void *addr, uptr length) {
-  return syscall(SYS_munmap, addr, length);
-}
-
-int internal_close(fd_t fd) {
-  return syscall(SYS_close, fd);
-}
-
-fd_t internal_open(const char *filename, int flags) {
-  return syscall(SYS_open, filename, flags);
-}
-
-fd_t internal_open(const char *filename, int flags, u32 mode) {
-  return syscall(SYS_open, filename, flags, mode);
-}
-
-fd_t OpenFile(const char *filename, bool write) {
-  return internal_open(filename,
-      write ? O_WRONLY | O_CREAT /*| O_CLOEXEC*/ : O_RDONLY, 0660);
-}
-
-uptr internal_read(fd_t fd, void *buf, uptr count) {
-  sptr res;
-  HANDLE_EINTR(res, (sptr)syscall(SYS_read, fd, buf, count));
-  return res;
-}
-
-uptr internal_write(fd_t fd, const void *buf, uptr count) {
-  sptr res;
-  HANDLE_EINTR(res, (sptr)syscall(SYS_write, fd, buf, count));
-  return res;
-}
-
-int internal_stat(const char *path, void *buf) {
-  return syscall(SYS___stat50, path, buf);
-}
-
-int internal_lstat(const char *path, void *buf) {
-  return syscall(SYS___lstat50, path, buf);
-}
-
-int internal_fstat(fd_t fd, void *buf) {
-  return syscall(SYS___fstat50, fd, buf);
-}
-
-uptr internal_filesize(fd_t fd) {
-  struct stat st;
-  if (internal_fstat(fd, &st))
-    return -1;
-  return (uptr)st.st_size;
-}
-
-int internal_dup2(int oldfd, int newfd) {
-  return syscall(SYS_dup2, oldfd, newfd);
-}
-
-uptr internal_readlink(const char *path, char *buf, uptr bufsize) {
-  return (uptr)syscall(SYS_readlink, path, buf, bufsize);
-}
-
-int internal_sched_yield() {
-  return syscall(SYS_sched_yield);
-}
-
-void internal__exit(int exitcode) {
-  syscall(SYS_exit, exitcode);
-  Die();  // Unreachable.
-}
-
-// ----------------- sanitizer_common.h
-bool FileExists(const char *filename) {
-  struct stat st;
-  if (syscall(SYS___stat50, filename, &st))
-    return false;
-  // Sanity check: filename is a regular file.
-  return S_ISREG(st.st_mode);
-}
-
-uptr GetTid() {
-  // XXX!
-  return syscall(SYS_getpid);
-}
-
-void GetThreadStackTopAndBottom(bool at_initialization, uptr *stack_top,
-                                uptr *stack_bottom) {
-  static const uptr kMaxThreadStackSize = 256 * (1 << 20);  // 256M
-  CHECK(stack_top);
-  CHECK(stack_bottom);
-  if (at_initialization) {
-    // This is the main thread. Libpthread may not be initialized yet.
-    struct rlimit rl;
-    CHECK_EQ(getrlimit(RLIMIT_STACK, &rl), 0);
-
-    // Find the mapping that contains a stack variable.
-    MemoryMappingLayout proc_maps;
-    uptr start, end, offset;
-    uptr prev_end = 0;
-    while (proc_maps.Next(&start, &end, &offset, 0, 0)) {
-      if ((uptr)&rl < end)
-        break;
-      prev_end = end;
-    }
-    CHECK((uptr)&rl >= start && (uptr)&rl < end);
-
-    // Get stacksize from rlimit, but clip it so that it does not overlap
-    // with other mappings.
-    uptr stacksize = rl.rlim_cur;
-    if (stacksize > end - prev_end)
-      stacksize = end - prev_end;
-    // When running with unlimited stack size, we still want to set some limit.
-    // The unlimited stack size is caused by 'ulimit -s unlimited'.
-    // Also, for some reason, GNU make spawns subprocesses with unlimited stack.
-    if (stacksize > kMaxThreadStackSize)
-      stacksize = kMaxThreadStackSize;
-    *stack_top = end;
-    *stack_bottom = end - stacksize;
-    return;
-  }
-  pthread_attr_t attr;
-  CHECK_EQ(pthread_getattr_np(pthread_self(), &attr), 0);
-  uptr stacksize = 0;
-  void *stackaddr = 0;
-  pthread_attr_getstack(&attr, &stackaddr, (size_t*)&stacksize);
-  pthread_attr_destroy(&attr);
-
-  *stack_top = (uptr)stackaddr + stacksize;
-  *stack_bottom = (uptr)stackaddr;
-  CHECK(stacksize < kMaxThreadStackSize);  // Sanity check.
-}
-
-// Like getenv, but reads env directly from /proc and does not use libc.
-// This function should be called first inside __asan_init.
-extern "C" char **environ;
-const char *GetEnv(const char *name) {
-
-  uptr namelen = internal_strlen(name);
-  for (char **p = environ; *p; p++) {
-    if (!internal_memcmp(*p, name, namelen) && (*p)[namelen] == '=')  // Match.
-      return *p + namelen + 1;  // point after =
-  }
-  return 0;  // Not found.
-}
-
-#ifdef __GLIBC__
-
-extern "C" {
-  extern void *__libc_stack_end;
-}
-
-static void GetArgsAndEnv(char ***argv, char ***envp) {
-  uptr *stack_end = (uptr *)__libc_stack_end;
-  int argc = *stack_end;
-  *argv = (char**)(stack_end + 1);
-  *envp = (char**)(stack_end + argc + 2);
-}
-
-#else  // __GLIBC__
-
-static void ReadNullSepFileToArray(const char *path, char ***arr,
-                                   int arr_size) {
-  char *buff;
-  uptr buff_size = 0;
-  *arr = (char **)MmapOrDie(arr_size * sizeof(char *), "NullSepFileArray");
-  ReadFileToBuffer(path, &buff, &buff_size, 1024 * 1024);
-  (*arr)[0] = buff;
-  int count, i;
-  for (count = 1, i = 1; ; i++) {
-    if (buff[i] == 0) {
-      if (buff[i+1] == 0) break;
-      (*arr)[count] = &buff[i+1];
-      CHECK_LE(count, arr_size - 1);  // FIXME: make this more flexible.
-      count++;
-    }
-  }
-  (*arr)[count] = 0;
-}
-
-static void GetArgsAndEnv(char ***argv, char ***envp) {
-  static const int kMaxArgv = 2000, kMaxEnvp = 2000;
-  ReadNullSepFileToArray("/proc/self/cmdline", argv, kMaxArgv);
-  ReadNullSepFileToArray("/proc/self/environ", envp, kMaxEnvp);
-}
-
-#endif  // __GLIBC__
-
-void ReExec() {
-  char **argv, **envp;
-  GetArgsAndEnv(&argv, &envp);
-  execve("/proc/self/exe", argv, envp);
-  Printf("execve failed, errno %d\n", errno);
-  Die();
-}
-
-void PrepareForSandboxing() {
-  // Some kinds of sandboxes may forbid filesystem access, so we won't be able
-  // to read the file mappings from /proc/self/maps. Luckily, neither the
-  // process will be able to load additional libraries, so it's fine to use the
-  // cached mappings.
-  MemoryMappingLayout::CacheMemoryMappings();
-}
-
-// ----------------- sanitizer_procmaps.h
-// Linker initialized.
-ProcSelfMapsBuff MemoryMappingLayout::cached_proc_self_maps_;
-StaticSpinMutex MemoryMappingLayout::cache_lock_;  // Linker initialized.
-
-MemoryMappingLayout::MemoryMappingLayout() {
-  proc_self_maps_.len =
-      ReadFileToBuffer("/proc/self/maps", &proc_self_maps_.data,
-                       &proc_self_maps_.mmaped_size, 1 << 26);
-  if (proc_self_maps_.mmaped_size == 0) {
-    LoadFromCache();
-    CHECK_GT(proc_self_maps_.len, 0);
-  }
-  // internal_write(2, proc_self_maps_.data, proc_self_maps_.len);
-  Reset();
-  // FIXME: in the future we may want to cache the mappings on demand only.



Home | Main Index | Thread Index | Old Index