[compiler-rt] r343840 - Introduce internal_sysctlbyname in place of sysctlbyname
Kamil Rytarowski via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 4 23:58:02 PDT 2018
Author: kamil
Date: Thu Oct 4 23:58:02 2018
New Revision: 343840
URL: http://llvm.org/viewvc/llvm-project?rev=343840&view=rev
Log:
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
Modified:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_netbsd.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.h
compiler-rt/trunk/lib/xray/xray_x86_64.cc
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc?rev=343840&r1=343839&r2=343840&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc Thu Oct 4 23:58:02 2018
@@ -591,7 +591,7 @@ static void GetArgsAndEnv(char ***argv,
// 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, uns
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
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc?rev=343840&r1=343839&r2=343840&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc Thu Oct 4 23:58:02 2018
@@ -219,6 +219,12 @@ int internal_sysctl(const int *name, uns
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;
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_netbsd.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_netbsd.cc?rev=343840&r1=343839&r2=343840&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_netbsd.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_netbsd.cc Thu Oct 4 23:58:02 2018
@@ -297,6 +297,14 @@ DEFINE_INTERNAL(int, sysctl, const int *
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);
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.h?rev=343840&r1=343839&r2=343840&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.h Thu Oct 4 23:58:02 2018
@@ -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.
Modified: compiler-rt/trunk/lib/xray/xray_x86_64.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/xray/xray_x86_64.cc?rev=343840&r1=343839&r2=343840&view=diff
==============================================================================
--- compiler-rt/trunk/lib/xray/xray_x86_64.cc (original)
+++ compiler-rt/trunk/lib/xray/xray_x86_64.cc Thu Oct 4 23:58:02 2018
@@ -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_IN
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 {
More information about the llvm-commits
mailing list