pkgsrc-WIP-changes archive

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

compiler-rt-netbsd: tsan fixes for NetBSD



Module Name:	pkgsrc-wip
Committed By:	Kamil Rytarowski <n54%gmx.com@localhost>
Pushed By:	kamil
Date:		Tue Oct 3 15:19:05 2017 +0200
Changeset:	54db6695fcef651d59b4e48134b3b38e29f93e4d

Modified Files:
	compiler-rt-netbsd/distinfo
	compiler-rt-netbsd/patches/patch-lib_tsan_rtl_tsan__platform__linux.cc
Added Files:
	compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__linux.cc

Log Message:
compiler-rt-netbsd: tsan fixes for NetBSD

Fix syscall(2)/__syscall(2) calls.
Include sanitizer_platform_limits_netbsd.h unconditionally.
Port GetArgsAndEnv() to NetBSD using "external ps_strings".
Fix ReExec() on NetBSD.

Sponsored by <The NetBSD Foundation>

To see a diff of this commit:
https://wip.pkgsrc.org/cgi-bin/gitweb.cgi?p=pkgsrc-wip.git;a=commitdiff;h=54db6695fcef651d59b4e48134b3b38e29f93e4d

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

diffstat:
 compiler-rt-netbsd/distinfo                        |   3 +-
 ...patch-lib_sanitizer__common_sanitizer__linux.cc | 248 +++++++++++++++++++++
 .../patch-lib_tsan_rtl_tsan__platform__linux.cc    |  10 +-
 3 files changed, 253 insertions(+), 8 deletions(-)

diffs:
diff --git a/compiler-rt-netbsd/distinfo b/compiler-rt-netbsd/distinfo
index af02f4f8b6..9e499aee83 100644
--- a/compiler-rt-netbsd/distinfo
+++ b/compiler-rt-netbsd/distinfo
@@ -2,8 +2,9 @@ $NetBSD: distinfo,v 1.35 2015/09/11 01:21:57 tnn Exp $
 
 SHA1 (patch-cmake_config-ix.cmake) = 5b1842f08cc8c2b96e0529b552b09c7adf2065dc
 SHA1 (patch-lib_fuzzer_tests_CMakeLists.txt) = eaffd9f8f2621ad465b5c734a764bdff0243af3d
+SHA1 (patch-lib_sanitizer__common_sanitizer__linux.cc) = 50046339fbfbc5f796f081c8d5860958680a634b
 SHA1 (patch-lib_tsan_go_buildgo.sh) = fe64b3389bbf6ae2ddf187df3e0600b2f817f51d
-SHA1 (patch-lib_tsan_rtl_tsan__platform__linux.cc) = e572f99e72257dbaa17838378b34cde40e91bd54
+SHA1 (patch-lib_tsan_rtl_tsan__platform__linux.cc) = 21424d5506d02887a15183285ecb564d9560f215
 SHA1 (patch-lib_tsan_rtl_tsan__rtl__amd64.S) = 95591667c23372ceb72334b2ceae800d32574ac6
 SHA1 (patch-lib_tsan_tests_rtl_tsan__test__util__posix.cc) = 302c72dab4fe5a0c94d7de0d728033e616811e5e
 SHA1 (patch-test_tsan_lit.cfg) = c849d08c3df59a3de45c6515e05c3d9fac5424e7
diff --git a/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__linux.cc b/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__linux.cc
new file mode 100644
index 0000000000..5d0158b045
--- /dev/null
+++ b/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__linux.cc
@@ -0,0 +1,248 @@
+$NetBSD$
+
+--- lib/sanitizer_common/sanitizer_linux.cc.orig	2017-10-02 13:17:02.000000000 +0000
++++ lib/sanitizer_common/sanitizer_linux.cc
+@@ -186,7 +186,9 @@ uptr internal_close(fd_t fd) {
+ }
+ 
+ uptr internal_open(const char *filename, int flags) {
+-#if SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
++#if SANITIZER_NETBSD
++  return internal_syscall_ptr(SYSCALL(open), (uptr)filename, flags);
++#elif SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
+   return internal_syscall(SYSCALL(openat), AT_FDCWD, (uptr)filename, flags);
+ #else
+   return internal_syscall(SYSCALL(open), (uptr)filename, flags);
+@@ -194,7 +196,9 @@ uptr internal_open(const char *filename,
+ }
+ 
+ uptr internal_open(const char *filename, int flags, u32 mode) {
+-#if SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
++#if SANITIZER_NETBSD
++  return internal_syscall_ptr(SYSCALL(open), (uptr)filename, flags, mode);
++#elif SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
+   return internal_syscall(SYSCALL(openat), AT_FDCWD, (uptr)filename, flags,
+                           mode);
+ #else
+@@ -227,7 +231,7 @@ uptr internal_write(fd_t fd, const void 
+ uptr internal_ftruncate(fd_t fd, uptr size) {
+   sptr res;
+ #if SANITIZER_NETBSD
+-  HANDLE_EINTR(res, internal_syscall(SYSCALL(ftruncate), fd, 0, (s64)size));
++  HANDLE_EINTR(res, internal_syscall64(SYSCALL(ftruncate), fd, 0, (s64)size));
+ #else
+   HANDLE_EINTR(res, (sptr)internal_syscall(SYSCALL(ftruncate), fd,
+                (OFF_T)size));
+@@ -303,9 +307,12 @@ static void kernel_stat_to_stat(struct k
+ #endif
+ 
+ uptr internal_stat(const char *path, void *buf) {
+-#if SANITIZER_FREEBSD || SANITIZER_NETBSD
++#if SANITIZER_FREEBSD
+   return internal_syscall(SYSCALL(fstatat), AT_FDCWD, (uptr)path,
+                           (uptr)buf, 0);
++#elif SANITIZER_NETBSD
++  return internal_syscall_ptr(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);
+@@ -329,7 +336,7 @@ uptr internal_stat(const char *path, voi
+ 
+ uptr internal_lstat(const char *path, void *buf) {
+ #if SANITIZER_NETBSD
+-  return internal_syscall(SYSCALL(lstat), path, buf);
++  return internal_syscall_ptr(SYSCALL(lstat), path, buf);
+ #elif SANITIZER_FREEBSD
+   return internal_syscall(SYSCALL(fstatat), AT_FDCWD, (uptr)path,
+                           (uptr)buf, AT_SYMLINK_NOFOLLOW);
+@@ -355,7 +362,9 @@ uptr internal_lstat(const char *path, vo
+ }
+ 
+ uptr internal_fstat(fd_t fd, void *buf) {
+-#if SANITIZER_FREEBSD || SANITIZER_LINUX_USES_64BIT_SYSCALLS || SANITIZER_NETBSD
++#if SANITIZER_NETBSD
++  return internal_syscall_ptr(SYSCALL(fstat), fd, (uptr)buf);
++#elif SANITIZER_FREEBSD || SANITIZER_LINUX_USES_64BIT_SYSCALLS
+ # if SANITIZER_MIPS64
+   // For mips64, fstat syscall fills buffer in the format of kernel_stat
+   struct kernel_stat kbuf;
+@@ -400,7 +409,9 @@ uptr internal_readlink(const char *path,
+ }
+ 
+ uptr internal_unlink(const char *path) {
+-#if SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
++#if SANITIZER_NETBSD
++  return internal_syscall_ptr(SYSCALL(unlink), (uptr)path);
++#elif SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
+   return internal_syscall(SYSCALL(unlinkat), AT_FDCWD, (uptr)path, 0);
+ #else
+   return internal_syscall(SYSCALL(unlink), (uptr)path);
+@@ -408,7 +419,9 @@ uptr internal_unlink(const char *path) {
+ }
+ 
+ uptr internal_rename(const char *oldpath, const char *newpath) {
+-#if SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
++#if SANITIZER_NETBSD
++  return internal_syscall_ptr(SYSCALL(rename), (uptr)oldpath, (uptr)newpath);
++#elif SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
+   return internal_syscall(SYSCALL(renameat), AT_FDCWD, (uptr)oldpath, AT_FDCWD,
+                           (uptr)newpath);
+ #else
+@@ -433,15 +446,24 @@ unsigned int internal_sleep(unsigned int
+   struct timespec ts;
+   ts.tv_sec = 1;
+   ts.tv_nsec = 0;
++#if SANITIZER_NETBSD
++  int res = internal_syscall_ptr(SYSCALL(nanosleep), &ts, &ts);
++#else
+   int res = internal_syscall(SYSCALL(nanosleep), &ts, &ts);
++#endif
+   if (res) return ts.tv_sec;
+   return 0;
+ }
+ 
+ uptr internal_execve(const char *filename, char *const argv[],
+                      char *const envp[]) {
++#if SANITIZER_NETBSD
++  return internal_syscall_ptr(SYSCALL(execve), (uptr)filename, (uptr)argv,
++                          (uptr)envp);
++#else
+   return internal_syscall(SYSCALL(execve), (uptr)filename, (uptr)argv,
+                           (uptr)envp);
++#endif
+ }
+ 
+ // ----------------- sanitizer_common.h
+@@ -524,13 +546,13 @@ const char *GetEnv(const char *name) {
+ #endif
+ }
+ 
+-#if !SANITIZER_FREEBSD
++#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
+ extern "C" {
+   SANITIZER_WEAK_ATTRIBUTE extern void *__libc_stack_end;
+ }
+ #endif
+ 
+-#if !SANITIZER_GO && !SANITIZER_FREEBSD
++#if !SANITIZER_GO && !SANITIZER_FREEBSD && !SANITIZER_NETBSD
+ static void ReadNullSepFileToArray(const char *path, char ***arr,
+                                    int arr_size) {
+   char *buff;
+@@ -555,8 +577,29 @@ static void ReadNullSepFileToArray(const
+ }
+ #endif
+ 
++#if SANITIZER_NETBSD
++#include <sys/exec.h>
++
++extern struct ps_strings *__ps_strings;
++#endif
++
+ static void GetArgsAndEnv(char ***argv, char ***envp) {
+-#if !SANITIZER_FREEBSD
++#if SANITIZER_FREEBSD
++  // On FreeBSD, retrieving the argument and environment arrays is done via the
++  // kern.ps_strings sysctl, which returns a pointer to a structure containing
++  // this information. See also <sys/exec.h>.
++  ps_strings *pss;
++  size_t sz = sizeof(pss);
++  if (sysctlbyname("kern.ps_strings", &pss, &sz, NULL, 0) == -1) {
++    Printf("sysctl kern.ps_strings failed\n");
++    Die();
++  }
++  *argv = pss->ps_argvstr;
++  *envp = pss->ps_envstr;
++#elif SANITIZER_NETBSD
++  *argv = __ps_strings->ps_argvstr;
++  *argv = __ps_strings->ps_envstr;
++#else
+ #if !SANITIZER_GO
+   if (&__libc_stack_end) {
+ #endif
+@@ -571,18 +614,6 @@ static void GetArgsAndEnv(char ***argv, 
+     ReadNullSepFileToArray("/proc/self/environ", envp, kMaxEnvp);
+   }
+ #endif
+-#else
+-  // On FreeBSD, retrieving the argument and environment arrays is done via the
+-  // kern.ps_strings sysctl, which returns a pointer to a structure containing
+-  // this information. See also <sys/exec.h>.
+-  ps_strings *pss;
+-  size_t sz = sizeof(pss);
+-  if (sysctlbyname("kern.ps_strings", &pss, &sz, NULL, 0) == -1) {
+-    Printf("sysctl kern.ps_strings failed\n");
+-    Die();
+-  }
+-  *argv = pss->ps_argvstr;
+-  *envp = pss->ps_envstr;
+ #endif
+ }
+ 
+@@ -594,8 +625,22 @@ char **GetArgv() {
+ 
+ void ReExec() {
+   char **argv, **envp;
++  const char *pathname = "/proc/self/exe";
++
++#if SANITIZER_NETBSD
++  static const int name[] = {
++    CTL_KERN, KERN_PROC_ARGS, -1, KERN_PROC_PATHNAME,
++  };
++  char path[MAXPATHLEN];
++  size_t len;
++
++  len = sizeof(path);
++  if (sysctl(name, __arraycount(name), path, &len, NULL, 0) != -1)
++    pathname = path;
++#endif
++
+   GetArgsAndEnv(&argv, &envp);
+-  uptr rv = internal_execve("/proc/self/exe", argv, envp);
++  uptr rv = internal_execve(pathname, argv, envp);
+   int rverrno;
+   CHECK_EQ(internal_iserror(rv, &rverrno), true);
+   Printf("execve failed, errno %d\n", rverrno);
+@@ -699,7 +744,7 @@ uptr internal_ptrace(int request, int pi
+ 
+ uptr internal_waitpid(int pid, int *status, int options) {
+ #if SANITIZER_NETBSD
+-  return internal_syscall(SYSCALL(wait4), pid, status, options,
++  return internal_syscall_ptr(SYSCALL(wait4), pid, status, options,
+                           NULL /* rusage */);
+ #else
+   return internal_syscall(SYSCALL(wait4), pid, (uptr)status, options,
+@@ -717,7 +762,7 @@ uptr internal_getppid() {
+ 
+ uptr internal_getdents(fd_t fd, struct linux_dirent *dirp, unsigned int count) {
+ #if SANITIZER_NETBSD
+-  return internal_syscall(SYSCALL(getdents), fd, dirp, (uptr)count);
++  return internal_syscall64(SYSCALL(getdents), fd, dirp, (uptr)count);
+ #elif SANITIZER_FREEBSD
+   return internal_syscall(SYSCALL(getdirentries), fd, (uptr)dirp, count, NULL);
+ #elif SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
+@@ -742,7 +787,11 @@ uptr internal_prctl(int option, uptr arg
+ #endif
+ 
+ uptr internal_sigaltstack(const void *ss, void *oss) {
++#if SANITIZER_NETBSD
++  return internal_syscall_ptr(SYSCALL(sigaltstack), (uptr)ss, (uptr)oss);
++#else
+   return internal_syscall(SYSCALL(sigaltstack), (uptr)ss, (uptr)oss);
++#endif
+ }
+ 
+ int internal_fork() {
+@@ -823,8 +872,10 @@ int internal_sigaction_syscall(int signu
+ 
+ uptr internal_sigprocmask(int how, __sanitizer_sigset_t *set,
+     __sanitizer_sigset_t *oldset) {
+-#if SANITIZER_FREEBSD || SANITIZER_NETBSD
++#if SANITIZER_FREEBSD 
+   return internal_syscall(SYSCALL(sigprocmask), how, set, oldset);
++#elif SANITIZER_NETBSD
++  return internal_syscall_ptr(SYSCALL(sigprocmask), how, set, oldset);
+ #else
+   __sanitizer_kernel_sigset_t *k_set = (__sanitizer_kernel_sigset_t *)set;
+   __sanitizer_kernel_sigset_t *k_oldset = (__sanitizer_kernel_sigset_t *)oldset;
diff --git a/compiler-rt-netbsd/patches/patch-lib_tsan_rtl_tsan__platform__linux.cc b/compiler-rt-netbsd/patches/patch-lib_tsan_rtl_tsan__platform__linux.cc
index 551ac30926..4ee3f00a1d 100644
--- a/compiler-rt-netbsd/patches/patch-lib_tsan_rtl_tsan__platform__linux.cc
+++ b/compiler-rt-netbsd/patches/patch-lib_tsan_rtl_tsan__platform__linux.cc
@@ -2,7 +2,7 @@ $NetBSD$
 
 --- lib/tsan/rtl/tsan_platform_linux.cc.orig	2017-07-16 22:40:10.000000000 +0000
 +++ lib/tsan/rtl/tsan_platform_linux.cc
-@@ -14,12 +14,16 @@
+@@ -14,11 +14,12 @@
  
  
  #include "sanitizer_common/sanitizer_platform.h"
@@ -12,15 +12,11 @@ $NetBSD$
  #include "sanitizer_common/sanitizer_common.h"
  #include "sanitizer_common/sanitizer_libc.h"
  #include "sanitizer_common/sanitizer_linux.h"
-+#if SANITIZER_NETBSD
 +#include "sanitizer_common/sanitizer_platform_limits_netbsd.h"
-+#else
  #include "sanitizer_common/sanitizer_platform_limits_posix.h"
-+#endif
  #include "sanitizer_common/sanitizer_posix.h"
  #include "sanitizer_common/sanitizer_procmaps.h"
- #include "sanitizer_common/sanitizer_stoptheworld.h"
-@@ -62,7 +66,7 @@
+@@ -62,7 +63,7 @@
  # undef sa_sigaction
  #endif
  
@@ -29,7 +25,7 @@ $NetBSD$
  extern "C" void *__libc_stack_end;
  void *__libc_stack_end = 0;
  #endif
-@@ -401,4 +405,4 @@ void cur_thread_finalize() {
+@@ -401,4 +402,4 @@ void cur_thread_finalize() {
  
  }  // namespace __tsan
  


Home | Main Index | Thread Index | Old Index