[PATCH] D27659: [sanitizer] intercept bstring functions
Kuang-che Wu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Dec 11 13:38:48 PST 2016
kcwu created this revision.
kcwu added a reviewer: kcc.
kcwu added a subscriber: llvm-commits.
Herald added a subscriber: kubabrecka.
Make all sanitizers intercept bzero, bcopy, and bcmp. Despite these functions are deprecated, they are quite popular in legacy codes.
https://github.com/google/sanitizers/issues/750
https://reviews.llvm.org/D27659
Files:
lib/msan/msan_interceptors.cc
lib/sanitizer_common/sanitizer_common_interceptors.inc
lib/sanitizer_common/sanitizer_platform_interceptors.h
Index: lib/sanitizer_common/sanitizer_platform_interceptors.h
===================================================================
--- lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -274,6 +274,9 @@
#define SANITIZER_INTERCEPT_AEABI_MEM 0
#endif
#define SANITIZER_INTERCEPT___BZERO SI_MAC
+#define SANITIZER_INTERCEPT_BZERO 1
+#define SANITIZER_INTERCEPT_BCOPY 1
+#define SANITIZER_INTERCEPT_BCMP 1
#define SANITIZER_INTERCEPT_FTIME !SI_FREEBSD && SI_NOT_WINDOWS
#define SANITIZER_INTERCEPT_XDR SI_LINUX_NOT_ANDROID
#define SANITIZER_INTERCEPT_TSEARCH SI_LINUX_NOT_ANDROID || SI_MAC
Index: lib/sanitizer_common/sanitizer_common_interceptors.inc
===================================================================
--- lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -4906,6 +4906,39 @@
#define INIT___BZERO
#endif // SANITIZER_INTERCEPT___BZERO
+#if SANITIZER_INTERCEPT_BZERO
+DECLARE_REAL_AND_INTERCEPTOR(void *, memset, void *, int, uptr)
+
+INTERCEPTOR(void, bzero, void *block, uptr size) {
+ WRAP(memset)(block, 0, size);
+}
+#define INIT_BZERO COMMON_INTERCEPT_FUNCTION(bzero);
+#else
+#define INIT_BZERO
+#endif // SANITIZER_INTERCEPT_BZERO
+
+#if SANITIZER_INTERCEPT_BCOPY
+DECLARE_REAL_AND_INTERCEPTOR(void *, memmove, void *, const void *, uptr)
+
+INTERCEPTOR(void, bcopy, const void *src, void *dest, uptr size) {
+ WRAP(memmove)(dest, src, size);
+}
+#define INIT_BCOPY COMMON_INTERCEPT_FUNCTION(bcopy);
+#else
+#define INIT_BCOPY
+#endif // SANITIZER_INTERCEPT_BCOPY
+
+#if SANITIZER_INTERCEPT_BCMP
+DECLARE_REAL_AND_INTERCEPTOR(int, memcmp, const void *, const void *, uptr)
+
+INTERCEPTOR(int, bcmp, const void *s1, const void *s2, uptr size) {
+ return WRAP(memcmp)(s1, s2, size);
+}
+#define INIT_BCMP COMMON_INTERCEPT_FUNCTION(bcmp);
+#else
+#define INIT_BCMP
+#endif // SANITIZER_INTERCEPT_BCMP
+
#if SANITIZER_INTERCEPT_FTIME
INTERCEPTOR(int, ftime, __sanitizer_timeb *tp) {
void *ctx;
@@ -6056,6 +6089,9 @@
INIT_CAPGET;
INIT_AEABI_MEM;
INIT___BZERO;
+ INIT_BZERO;
+ INIT_BCOPY;
+ INIT_BCMP;
INIT_FTIME;
INIT_XDR;
INIT_TSEARCH;
Index: lib/msan/msan_interceptors.cc
===================================================================
--- lib/msan/msan_interceptors.cc
+++ lib/msan/msan_interceptors.cc
@@ -178,10 +178,6 @@
return __msan_memset(s, c, n);
}
-INTERCEPTOR(void *, bcopy, const void *src, void *dest, SIZE_T n) {
- return __msan_memmove(dest, src, n);
-}
-
INTERCEPTOR(int, posix_memalign, void **memptr, SIZE_T alignment, SIZE_T size) {
GET_MALLOC_STACK_TRACE;
CHECK_EQ(alignment & (alignment - 1), 0);
@@ -1519,7 +1515,6 @@
INTERCEPT_FUNCTION(mempcpy);
INTERCEPT_FUNCTION(memset);
INTERCEPT_FUNCTION(memmove);
- INTERCEPT_FUNCTION(bcopy);
INTERCEPT_FUNCTION(wmemset);
INTERCEPT_FUNCTION(wmemcpy);
INTERCEPT_FUNCTION(wmempcpy);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27659.81016.patch
Type: text/x-patch
Size: 2974 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161211/f2c3fd0a/attachment-0001.bin>
More information about the llvm-commits
mailing list