[compiler-rt] r345323 - [sanitizer] Fix mallopt interceptor.
Evgeniy Stepanov via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 25 15:15:44 PDT 2018
Author: eugenis
Date: Thu Oct 25 15:15:44 2018
New Revision: 345323
URL: http://llvm.org/viewvc/llvm-project?rev=345323&view=rev
Log:
[sanitizer] Fix mallopt interceptor.
On error, mallopt is supposed to return 0, not -1.
Added:
compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/mallopt.cc
Modified:
compiler-rt/trunk/lib/asan/asan_malloc_linux.cc
compiler-rt/trunk/lib/hwasan/hwasan_interceptors.cc
compiler-rt/trunk/lib/lsan/lsan_interceptors.cc
compiler-rt/trunk/lib/msan/msan_interceptors.cc
compiler-rt/trunk/lib/scudo/scudo_malloc.cpp
Modified: compiler-rt/trunk/lib/asan/asan_malloc_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_malloc_linux.cc?rev=345323&r1=345322&r2=345323&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_malloc_linux.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_malloc_linux.cc Thu Oct 25 15:15:44 2018
@@ -209,7 +209,7 @@ INTERCEPTOR(struct fake_mallinfo, mallin
}
INTERCEPTOR(int, mallopt, int cmd, int value) {
- return -1;
+ return 0;
}
#endif // SANITIZER_INTERCEPT_MALLOPT_AND_MALLINFO
Modified: compiler-rt/trunk/lib/hwasan/hwasan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/hwasan/hwasan_interceptors.cc?rev=345323&r1=345322&r2=345323&view=diff
==============================================================================
--- compiler-rt/trunk/lib/hwasan/hwasan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/hwasan/hwasan_interceptors.cc Thu Oct 25 15:15:44 2018
@@ -186,7 +186,7 @@ struct __sanitizer_struct_mallinfo __san
}
int __sanitizer_mallopt(int cmd, int value) {
- return -1;
+ return 0;
}
void __sanitizer_malloc_stats(void) {
Modified: compiler-rt/trunk/lib/lsan/lsan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lsan_interceptors.cc?rev=345323&r1=345322&r2=345323&view=diff
==============================================================================
--- compiler-rt/trunk/lib/lsan/lsan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/lsan/lsan_interceptors.cc Thu Oct 25 15:15:44 2018
@@ -153,7 +153,7 @@ INTERCEPTOR(struct fake_mallinfo, mallin
#define LSAN_MAYBE_INTERCEPT_MALLINFO INTERCEPT_FUNCTION(mallinfo)
INTERCEPTOR(int, mallopt, int cmd, int value) {
- return -1;
+ return 0;
}
#define LSAN_MAYBE_INTERCEPT_MALLOPT INTERCEPT_FUNCTION(mallopt)
#else
Modified: compiler-rt/trunk/lib/msan/msan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_interceptors.cc?rev=345323&r1=345322&r2=345323&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_interceptors.cc Thu Oct 25 15:15:44 2018
@@ -265,7 +265,7 @@ INTERCEPTOR(void, mallinfo, __sanitizer_
#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
INTERCEPTOR(int, mallopt, int cmd, int value) {
- return -1;
+ return 0;
}
#define MSAN_MAYBE_INTERCEPT_MALLOPT INTERCEPT_FUNCTION(mallopt)
#else
Modified: compiler-rt/trunk/lib/scudo/scudo_malloc.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/scudo_malloc.cpp?rev=345323&r1=345322&r2=345323&view=diff
==============================================================================
--- compiler-rt/trunk/lib/scudo/scudo_malloc.cpp (original)
+++ compiler-rt/trunk/lib/scudo/scudo_malloc.cpp Thu Oct 25 15:15:44 2018
@@ -79,7 +79,7 @@ INTERCEPTOR_ATTRIBUTE size_t malloc_usab
#if SANITIZER_INTERCEPT_MALLOPT_AND_MALLINFO
INTERCEPTOR_ATTRIBUTE int mallopt(int cmd, int value) {
- return -1;
+ return 0;
}
#endif
} // extern "C"
Added: compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/mallopt.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/mallopt.cc?rev=345323&view=auto
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/mallopt.cc (added)
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/mallopt.cc Thu Oct 25 15:15:44 2018
@@ -0,0 +1,9 @@
+// Check that mallopt does not return invalid values (ex. -1).
+// RUN: %clangxx -O2 %s -o %t && %run %t
+#include <assert.h>
+#include <malloc.h>
+
+int main() {
+ int res = mallopt(M_ARENA_MAX, 0);
+ assert(res == 0 || res == 1);
+}
More information about the llvm-commits
mailing list