summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Rytarowski <n54@gmx.com>2018-10-05 06:58:02 +0000
committerKamil Rytarowski <n54@gmx.com>2018-10-05 06:58:02 +0000
commitee0acb0ceb247cc47ead637b627e0f77e4d01619 (patch)
tree7a1e92ce13d4fb15f4093b43070c48ada287309b
parentf02d47d730c6a4547d56eb77e2bb7b7f5db5d44b (diff)
Introduce internal_sysctlbyname in place of sysctlbyname
Summary: This change will allow to install sysctlbyname() interceptors more easily in sanitizers. Reviewers: vitalybuka, joerg Reviewed By: vitalybuka Subscribers: kubamracek, llvm-commits, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D52793
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_linux.cc12
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_mac.cc6
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_netbsd.cc8
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_posix.h2
-rw-r--r--compiler-rt/lib/xray/xray_x86_64.cc11
5 files changed, 33 insertions, 6 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc
index 2e01149ae07..7633b10877a 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc
@@ -591,7 +591,7 @@ static void GetArgsAndEnv(char ***argv, char ***envp) {
// 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) {
+ if (internal_sysctlbyname("kern.ps_strings", &pss, &sz, NULL, 0) == -1) {
Printf("sysctl kern.ps_strings failed\n");
Die();
}
@@ -796,6 +796,16 @@ int internal_sysctl(const int *name, unsigned int namelen, void *oldp,
return sysctl(name, namelen, oldp, (size_t *)oldlenp, newp, (size_t)newlen);
#endif
}
+
+int internal_sysctlbyname(const char *sname, void *oldp, uptr *oldlenp,
+ const void *newp, uptr newlen) {
+#if SANITIZER_OPENBSD
+ return sysctlbyname(sname, oldp, (size_t *)oldlenp, (void *)newp,
+ (size_t)newlen);
+#else
+ return sysctlbyname(sname, oldp, (size_t *)oldlenp, newp, (size_t)newlen);
+#endif
+}
#endif
#if SANITIZER_LINUX
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cc b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cc
index c9478927568..90bd0881584 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cc
@@ -219,6 +219,12 @@ int internal_sysctl(const int *name, unsigned int namelen, void *oldp,
const_cast<void *>(newp), (size_t)newlen);
}
+int internal_sysctlbyname(const char *sname, void *oldp, uptr *oldlenp,
+ const void *newp, uptr newlen) {
+ return sysctlbyname(sname, oldp, (size_t *)oldlenp, const_cast<void *>(newp),
+ (size_t)newlen);
+}
+
int internal_forkpty(int *amaster) {
int master, slave;
if (openpty(&master, &slave, nullptr, nullptr, nullptr) == -1) return -1;
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_netbsd.cc b/compiler-rt/lib/sanitizer_common/sanitizer_netbsd.cc
index 12316d8c06a..5f4d09f9f73 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_netbsd.cc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_netbsd.cc
@@ -297,6 +297,14 @@ DEFINE_INTERNAL(int, sysctl, const int *name, unsigned int namelen, void *oldp,
return __sysctl(name, namelen, oldp, (size_t *)oldlenp, newp, (size_t)newlen);
}
+DEFINE_INTERNAL(int, sysctlbyname, const char *sname, void *oldp, uptr *oldlenp,
+ const void *newp, uptr newlen) {
+ DEFINE__REAL(int, sysctlbyname, const char *a, void *b, size_t *c,
+ const void *d, size_t e);
+ return _REAL(sysctlbyname, sname, oldp, (size_t *)oldlenp, newp,
+ (size_t)newlen);
+}
+
DEFINE_INTERNAL(uptr, sigprocmask, int how, __sanitizer_sigset_t *set,
__sanitizer_sigset_t *oldset) {
CHECK(&_sys___sigprocmask14);
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_posix.h b/compiler-rt/lib/sanitizer_common/sanitizer_posix.h
index c81eda61cf1..3075a13b980 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_posix.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_posix.h
@@ -62,6 +62,8 @@ int internal_forkpty(int *amaster);
int internal_sysctl(const int *name, unsigned int namelen, void *oldp,
uptr *oldlenp, const void *newp, uptr newlen);
+int internal_sysctlbyname(const char *sname, void *oldp, uptr *oldlenp,
+ const void *newp, uptr newlen);
// These functions call appropriate pthread_ functions directly, bypassing
// the interceptor. They are weak and may not be present in some tools.
diff --git a/compiler-rt/lib/xray/xray_x86_64.cc b/compiler-rt/lib/xray/xray_x86_64.cc
index 508f749c24f..d0411d0fb2e 100644
--- a/compiler-rt/lib/xray/xray_x86_64.cc
+++ b/compiler-rt/lib/xray/xray_x86_64.cc
@@ -1,5 +1,6 @@
#include "cpuid.h"
#include "sanitizer_common/sanitizer_common.h"
+#include "sanitizer_common/sanitizer_posix.h"
#include "xray_defs.h"
#include "xray_interface_internal.h"
@@ -87,14 +88,14 @@ uint64_t getTSCFrequency() XRAY_NEVER_INSTRUMENT {
size_t tscfreqsz = sizeof(TSCFrequency);
#if SANITIZER_OPENBSD
int Mib[2] = { CTL_MACHDEP, CPU_TSCFREQ };
- if (sysctl(Mib, 2, &TSCFrequency, &tscfreqsz, NULL, 0) != -1) {
+ if (internal_sysctl(Mib, 2, &TSCFrequency, &tscfreqsz, NULL, 0) != -1) {
#elif SANITIZER_MAC
- if (sysctlbyname("machdep.tsc.frequency", &TSCFrequency, &tscfreqsz,
- NULL, 0) != -1 ) {
+ if (internal_sysctlbyname("machdep.tsc.frequency", &TSCFrequency,
+ &tscfreqsz, NULL, 0) != -1) {
#else
- if (sysctlbyname("machdep.tsc_freq", &TSCFrequency, &tscfreqsz,
- NULL, 0) != -1) {
+ if (internal_sysctlbyname("machdep.tsc_freq", &TSCFrequency, &tscfreqsz,
+ NULL, 0) != -1) {
#endif
return static_cast<uint64_t>(TSCFrequency);
} else {