[PATCH] D44713: More OpenBSD fixes

Vitaly Buka via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 22 13:46:59 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL328239: More OpenBSD fixes (authored by vitalybuka, committed by ).
Herald added a subscriber: delcypher.

Changed prior to commit:
  https://reviews.llvm.org/D44713?vs=139477&id=139504#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D44713

Files:
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc


Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc
===================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc
@@ -68,6 +68,7 @@
 #include <ucontext.h>
 #endif
 #if SANITIZER_OPENBSD
+#include <signal.h>
 #include <sys/futex.h>
 #endif
 #include <unistd.h>
@@ -391,9 +392,12 @@
 }
 
 uptr internal_readlink(const char *path, char *buf, uptr bufsize) {
-#if SANITIZER_USES_CANONICAL_LINUX_SYSCALLS || SANITIZER_OPENBSD
+#if SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
   return internal_syscall(SYSCALL(readlinkat), AT_FDCWD, (uptr)path, (uptr)buf,
                           bufsize);
+#elif SANITIZER_OPENBSD
+  return internal_syscall_ptr(SYSCALL(readlinkat), AT_FDCWD, (uptr)path,
+                              (uptr)buf, bufsize);
 #else
   return internal_syscall_ptr(SYSCALL(readlink), path, buf, bufsize);
 #endif
@@ -1702,21 +1706,28 @@
 }
 #endif
 
+#if SANITIZER_OPENBSD
+using Context = sigcontext;
+#else
+using Context = ucontext;
+#endif // !SANITIZER_OPENBSD
+
 SignalContext::WriteFlag SignalContext::GetWriteFlag() const {
-#if !SANITIZER_OPENBSD
   ucontext_t *ucontext = (ucontext_t *)context;
 #if defined(__x86_64__) || defined(__i386__)
   static const uptr PF_WRITE = 1U << 1;
 #if SANITIZER_FREEBSD
   uptr err = ucontext->uc_mcontext.mc_err;
 #elif SANITIZER_NETBSD
   uptr err = ucontext->uc_mcontext.__gregs[_REG_ERR];
+#elif SANITIZER_OPENBSD
+  uptr err = ucontext->sc_err;
 #elif SANITIZER_SOLARIS && defined(__i386__)
-# define ERR 13
-  uptr err = ucontext->uc_mcontext.gregs[ERR];
+  const int Err = 13;
+  uptr err = ucontext->uc_mcontext.gregs[Err];
 #else
   uptr err = ucontext->uc_mcontext.gregs[REG_ERR];
-#endif
+#endif // SANITIZER_FREEBSD
   return err & PF_WRITE ? WRITE : READ;
 #elif defined(__arm__)
   static const uptr FSR_WRITE = 1U << 11;
@@ -1737,9 +1748,6 @@
   (void)ucontext;
   return UNKNOWN;  // FIXME: Implement.
 #endif
-#else  // !SANITIZER_OPENBSD
-  return UNKNOWN;
-#endif // !SANITIZER_OPENBSD
 }
 
 void SignalContext::DumpAllRegisters(void *context) {
@@ -1775,6 +1783,11 @@
   *pc = ucontext->uc_mcontext.mc_rip;
   *bp = ucontext->uc_mcontext.mc_rbp;
   *sp = ucontext->uc_mcontext.mc_rsp;
+#elif SANITIZER_OPENBSD
+  sigcontext *ucontext = (sigcontext *)context;
+  *pc = ucontext->sc_rip;
+  *bp = ucontext->sc_rbp;
+  *sp = ucontext->sc_rsp;
 # else
   ucontext_t *ucontext = (ucontext_t*)context;
   *pc = ucontext->uc_mcontext.gregs[REG_RIP];
@@ -1787,6 +1800,11 @@
   *pc = ucontext->uc_mcontext.mc_eip;
   *bp = ucontext->uc_mcontext.mc_ebp;
   *sp = ucontext->uc_mcontext.mc_esp;
+#elif SANITIZER_OPENBSD
+  sigcontext *ucontext = (sigcontext *)context;
+  *pc = ucontext->sc_eip;
+  *bp = ucontext->sc_ebp;
+  *sp = ucontext->sc_esp;
 # else
   ucontext_t *ucontext = (ucontext_t*)context;
 # if SANITIZER_SOLARIS


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44713.139504.patch
Type: text/x-patch
Size: 2934 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180322/adccf4e9/attachment.bin>


More information about the llvm-commits mailing list