[compiler-rt] r204800 - [sanitizer] Intercept __aeabi_mem(set|cpy|move).
Evgeniy Stepanov
eugeni.stepanov at gmail.com
Wed Mar 26 05:14:34 PDT 2014
Author: eugenis
Date: Wed Mar 26 07:14:34 2014
New Revision: 204800
URL: http://llvm.org/viewvc/llvm-project?rev=204800&view=rev
Log:
[sanitizer] Intercept __aeabi_mem(set|cpy|move).
Added:
compiler-rt/trunk/test/asan/TestCases/memset_test.cc (with props)
Modified:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc?rev=204800&r1=204799&r2=204800&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Wed Mar 26 07:14:34 2014
@@ -3411,6 +3411,65 @@ INTERCEPTOR(int, capset, void *hdrp, con
#define INIT_CAPGET
#endif
+#if SANITIZER_INTERCEPT_AEABI_MEM
+DECLARE_REAL_AND_INTERCEPTOR(void *, memmove, void *, const void *, uptr);
+DECLARE_REAL_AND_INTERCEPTOR(void *, memcpy, void *, const void *, uptr);
+DECLARE_REAL_AND_INTERCEPTOR(void *, memset, void *, int, uptr);
+
+INTERCEPTOR(void *, __aeabi_memmove, void *to, const void *from, uptr size) {
+ return WRAP(memmove)(to, from, size);
+}
+INTERCEPTOR(void *, __aeabi_memmove4, void *to, const void *from, uptr size) {
+ return WRAP(memmove)(to, from, size);
+}
+INTERCEPTOR(void *, __aeabi_memmove8, void *to, const void *from, uptr size) {
+ return WRAP(memmove)(to, from, size);
+}
+INTERCEPTOR(void *, __aeabi_memcpy, void *to, const void *from, uptr size) {
+ return WRAP(memcpy)(to, from, size);
+}
+INTERCEPTOR(void *, __aeabi_memcpy4, void *to, const void *from, uptr size) {
+ return WRAP(memcpy)(to, from, size);
+}
+INTERCEPTOR(void *, __aeabi_memcpy8, void *to, const void *from, uptr size) {
+ return WRAP(memcpy)(to, from, size);
+}
+// Note the argument order.
+INTERCEPTOR(void *, __aeabi_memset, void *block, uptr size, int c) {
+ return WRAP(memset)(block, c, size);
+}
+INTERCEPTOR(void *, __aeabi_memset4, void *block, uptr size, int c) {
+ return WRAP(memset)(block, c, size);
+}
+INTERCEPTOR(void *, __aeabi_memset8, void *block, uptr size, int c) {
+ return WRAP(memset)(block, c, size);
+}
+INTERCEPTOR(void *, __aeabi_memclr, void *block, uptr size) {
+ return WRAP(memset)(block, 0, size);
+}
+INTERCEPTOR(void *, __aeabi_memclr4, void *block, uptr size) {
+ return WRAP(memset)(block, 0, size);
+}
+INTERCEPTOR(void *, __aeabi_memclr8, void *block, uptr size) {
+ return WRAP(memset)(block, 0, size);
+}
+#define INIT_AEABI_MEM \
+ COMMON_INTERCEPT_FUNCTION(__aeabi_memmove); \
+ COMMON_INTERCEPT_FUNCTION(__aeabi_memmove4); \
+ COMMON_INTERCEPT_FUNCTION(__aeabi_memmove8); \
+ COMMON_INTERCEPT_FUNCTION(__aeabi_memcpy); \
+ COMMON_INTERCEPT_FUNCTION(__aeabi_memcpy4); \
+ COMMON_INTERCEPT_FUNCTION(__aeabi_memcpy8); \
+ COMMON_INTERCEPT_FUNCTION(__aeabi_memset); \
+ COMMON_INTERCEPT_FUNCTION(__aeabi_memset4); \
+ COMMON_INTERCEPT_FUNCTION(__aeabi_memset8); \
+ COMMON_INTERCEPT_FUNCTION(__aeabi_memclr); \
+ COMMON_INTERCEPT_FUNCTION(__aeabi_memclr4); \
+ COMMON_INTERCEPT_FUNCTION(__aeabi_memclr8);
+#else
+#define INIT_AEABI_MEM
+#endif // SANITIZER_INTERCEPT_AEABI_MEM
+
#define SANITIZER_COMMON_INTERCEPTORS_INIT \
INIT_TEXTDOMAIN; \
INIT_STRCMP; \
@@ -3532,5 +3591,6 @@ INTERCEPTOR(int, capset, void *hdrp, con
INIT_GETRESID; \
INIT_GETIFADDRS; \
INIT_IF_INDEXTONAME; \
- INIT_CAPGET;
+ INIT_CAPGET; \
+ INIT_AEABI_MEM;
/**/
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h?rev=204800&r1=204799&r2=204800&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Wed Mar 26 07:14:34 2014
@@ -187,5 +187,6 @@
#define SANITIZER_INTERCEPT_GETIFADDRS SI_LINUX_NOT_ANDROID || SI_MAC
#define SANITIZER_INTERCEPT_IF_INDEXTONAME SI_LINUX_NOT_ANDROID || SI_MAC
#define SANITIZER_INTERCEPT_CAPGET SI_LINUX_NOT_ANDROID
+#define SANITIZER_INTERCEPT_AEABI_MEM SI_LINUX && defined(__arm__)
#endif // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H
Added: compiler-rt/trunk/test/asan/TestCases/memset_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/memset_test.cc?rev=204800&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/memset_test.cc (added)
+++ compiler-rt/trunk/test/asan/TestCases/memset_test.cc Wed Mar 26 07:14:34 2014
@@ -0,0 +1,61 @@
+// Test that large memset/memcpy/memmove check the entire range.
+
+// RUN: %clangxx_asan -O0 -DTEST_MEMSET %s -o %t && not %t 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CHECK-MEMSET
+// RUN: %clangxx_asan -O1 -DTEST_MEMSET %s -o %t && not %t 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CHECK-MEMSET
+// RUN: %clangxx_asan -O2 -DTEST_MEMSET %s -o %t && not %t 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CHECK-MEMSET
+// RUN: %clangxx_asan -O3 -DTEST_MEMSET %s -o %t && not %t 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CHECK-MEMSET
+
+// RUN: %clangxx_asan -O0 -DTEST_MEMCPY %s -o %t && not %t 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CHECK-MEMCPY
+// RUN: %clangxx_asan -O1 -DTEST_MEMCPY %s -o %t && not %t 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CHECK-MEMCPY
+// RUN: %clangxx_asan -O2 -DTEST_MEMCPY %s -o %t && not %t 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CHECK-MEMCPY
+// RUN: %clangxx_asan -O3 -DTEST_MEMCPY %s -o %t && not %t 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CHECK-MEMCPY
+
+// RUN: %clangxx_asan -O0 -DTEST_MEMMOVE %s -o %t && not %t 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CHECK-MEMMOVE
+// RUN: %clangxx_asan -O1 -DTEST_MEMMOVE %s -o %t && not %t 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CHECK-MEMMOVE
+// RUN: %clangxx_asan -O2 -DTEST_MEMMOVE %s -o %t && not %t 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CHECK-MEMMOVE
+// RUN: %clangxx_asan -O3 -DTEST_MEMMOVE %s -o %t && not %t 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CHECK-MEMMOVE
+
+#include <assert.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#include <sanitizer/asan_interface.h>
+
+int main(int argc, char **argv) {
+ char * volatile p = (char *)malloc(3000);
+ __asan_poison_memory_region(p + 512, 16);
+#if defined(TEST_MEMSET)
+ memset(p, 0, 3000);
+ assert(p[1] == 0);
+ // CHECK-MEMSET: AddressSanitizer: use-after-poison on address
+ // CHECK-MEMSET: in {{.*}}memset
+#else
+ char * volatile q = (char *)malloc(3000);
+#if defined(TEST_MEMCPY)
+ memcpy(q, p, 3000);
+ // CHECK-MEMCPY: AddressSanitizer: use-after-poison on address
+ // CHECK-MEMCPY: in {{.*}}memcpy
+#elif defined(TEST_MEMMOVE)
+ memmove(q, p, 3000);
+ // CHECK-MEMMOVE: AddressSanitizer: use-after-poison on address
+ // CHECK-MEMMOVE: in {{.*}}memmove
+#endif
+ assert(q[1] == 0);
+ free(q);
+#endif
+ free(p);
+ return 0;
+}
Propchange: compiler-rt/trunk/test/asan/TestCases/memset_test.cc
------------------------------------------------------------------------------
svn:eol-style = LF
More information about the llvm-commits
mailing list