[compiler-rt] r373239 - [msan] Intercept __getrlimit.
Evgeniy Stepanov via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 30 10:49:48 PDT 2019
Author: eugenis
Date: Mon Sep 30 10:49:48 2019
New Revision: 373239
URL: http://llvm.org/viewvc/llvm-project?rev=373239&view=rev
Log:
[msan] Intercept __getrlimit.
Summary:
This interceptor is useful on its own, but the main purpose of this
change is to intercept libpthread initialization on linux/glibc in
order to run __msan_init before any .preinit_array constructors.
We used to trigger on pthread_initialize_minimal -> getrlimit(), but
that call has changed to __getrlimit at some point.
Reviewers: vitalybuka, pcc
Subscribers: jfb, #sanitizers, llvm-commits
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D68168
Added:
compiler-rt/trunk/test/msan/preinit_array.cpp
Modified:
compiler-rt/trunk/lib/msan/msan_interceptors.cpp
Modified: compiler-rt/trunk/lib/msan/msan_interceptors.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_interceptors.cpp?rev=373239&r1=373238&r2=373239&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_interceptors.cpp (original)
+++ compiler-rt/trunk/lib/msan/msan_interceptors.cpp Mon Sep 30 10:49:48 2019
@@ -765,17 +765,24 @@ INTERCEPTOR(char *, fgets_unlocked, char
#define MSAN_MAYBE_INTERCEPT_FGETS_UNLOCKED
#endif
+#define INTERCEPTOR_GETRLIMIT_BODY(func, resource, rlim) \
+ if (msan_init_is_running) \
+ return REAL(getrlimit)(resource, rlim); \
+ ENSURE_MSAN_INITED(); \
+ int res = REAL(func)(resource, rlim); \
+ if (!res) \
+ __msan_unpoison(rlim, __sanitizer::struct_rlimit_sz); \
+ return res
+
INTERCEPTOR(int, getrlimit, int resource, void *rlim) {
- if (msan_init_is_running)
- return REAL(getrlimit)(resource, rlim);
- ENSURE_MSAN_INITED();
- int res = REAL(getrlimit)(resource, rlim);
- if (!res)
- __msan_unpoison(rlim, __sanitizer::struct_rlimit_sz);
- return res;
+ INTERCEPTOR_GETRLIMIT_BODY(getrlimit, resource, rlim);
}
#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
+INTERCEPTOR(int, __getrlimit, int resource, void *rlim) {
+ INTERCEPTOR_GETRLIMIT_BODY(__getrlimit, resource, rlim);
+}
+
INTERCEPTOR(int, getrlimit64, int resource, void *rlim) {
if (msan_init_is_running) return REAL(getrlimit64)(resource, rlim);
ENSURE_MSAN_INITED();
@@ -806,10 +813,12 @@ INTERCEPTOR(int, prlimit64, int pid, int
return res;
}
+#define MSAN_MAYBE_INTERCEPT___GETRLIMIT INTERCEPT_FUNCTION(__getrlimit)
#define MSAN_MAYBE_INTERCEPT_GETRLIMIT64 INTERCEPT_FUNCTION(getrlimit64)
#define MSAN_MAYBE_INTERCEPT_PRLIMIT INTERCEPT_FUNCTION(prlimit)
#define MSAN_MAYBE_INTERCEPT_PRLIMIT64 INTERCEPT_FUNCTION(prlimit64)
#else
+#define MSAN_MAYBE_INTERCEPT___GETRLIMIT
#define MSAN_MAYBE_INTERCEPT_GETRLIMIT64
#define MSAN_MAYBE_INTERCEPT_PRLIMIT
#define MSAN_MAYBE_INTERCEPT_PRLIMIT64
@@ -1678,6 +1687,7 @@ void InitializeInterceptors() {
INTERCEPT_FUNCTION(socketpair);
MSAN_MAYBE_INTERCEPT_FGETS_UNLOCKED;
INTERCEPT_FUNCTION(getrlimit);
+ MSAN_MAYBE_INTERCEPT___GETRLIMIT;
MSAN_MAYBE_INTERCEPT_GETRLIMIT64;
MSAN_MAYBE_INTERCEPT_PRLIMIT;
MSAN_MAYBE_INTERCEPT_PRLIMIT64;
Added: compiler-rt/trunk/test/msan/preinit_array.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/msan/preinit_array.cpp?rev=373239&view=auto
==============================================================================
--- compiler-rt/trunk/test/msan/preinit_array.cpp (added)
+++ compiler-rt/trunk/test/msan/preinit_array.cpp Mon Sep 30 10:49:48 2019
@@ -0,0 +1,16 @@
+// RUN: %clangxx_msan -O0 %s -o %t && %run %t
+
+#include <sanitizer/msan_interface.h>
+
+volatile int global;
+static void pre_ctor() {
+ volatile int local;
+ global = 42;
+ local = 42;
+}
+
+__attribute__((section(".preinit_array"), used)) void(*__local_pre_ctor)(void) = pre_ctor;
+
+int main(void) {
+ return 0;
+}
More information about the llvm-commits
mailing list