summaryrefslogtreecommitdiffstats
path: root/compiler-rt
diff options
context:
space:
mode:
authorEvgeniy Stepanov <eugeni.stepanov@gmail.com>2013-11-27 12:29:10 +0000
committerEvgeniy Stepanov <eugeni.stepanov@gmail.com>2013-11-27 12:29:10 +0000
commitb76b6876283ddfcb7da746434404d4b58cbe0f6d (patch)
treec7e900bec7bb771bf8d92f2eace153bd488f2c3a /compiler-rt
parent085bf66e607312728f690bde93018113d16f4353 (diff)
downloadbcm5719-llvm-b76b6876283ddfcb7da746434404d4b58cbe0f6d.tar.gz
bcm5719-llvm-b76b6876283ddfcb7da746434404d4b58cbe0f6d.zip
[sanitizer] Intercept __xpg_strerror_r.
llvm-svn: 195839
Diffstat (limited to 'compiler-rt')
-rw-r--r--compiler-rt/lib/msan/lit_tests/strerror_r-non-gnu.c18
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc16
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h1
-rw-r--r--compiler-rt/lib/tsan/rtl/tsan_stat.cc1
-rw-r--r--compiler-rt/lib/tsan/rtl/tsan_stat.h1
5 files changed, 37 insertions, 0 deletions
diff --git a/compiler-rt/lib/msan/lit_tests/strerror_r-non-gnu.c b/compiler-rt/lib/msan/lit_tests/strerror_r-non-gnu.c
new file mode 100644
index 00000000000..8fb47055814
--- /dev/null
+++ b/compiler-rt/lib/msan/lit_tests/strerror_r-non-gnu.c
@@ -0,0 +1,18 @@
+// RUN: %clang_msan -std=c99 -O0 -g %s -o %t && %t
+
+// strerror_r under a weird set of circumstances can be redirected to
+// __xpg_strerror_r. Test that MSan handles this correctly.
+
+#define _POSIX_C_SOURCE 200112
+#include <assert.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+
+int main() {
+ char buf[1000];
+ int res = strerror_r(EINVAL, buf, sizeof(buf));
+ assert(!res);
+ volatile int z = strlen(buf);
+ return 0;
+}
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
index 6122049bf3d..9e43e8d146f 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -1848,6 +1848,21 @@ INTERCEPTOR(char *, strerror_r, int errnum, char *buf, SIZE_T buflen) {
#define INIT_STRERROR_R
#endif
+#if SANITIZER_INTERCEPT_XPG_STRERROR_R
+INTERCEPTOR(int, __xpg_strerror_r, int errnum, char *buf, SIZE_T buflen) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, __xpg_strerror_r, errnum, buf, buflen);
+ int res = REAL(__xpg_strerror_r)(errnum, buf, buflen);
+ // This version always returns a null-terminated string.
+ if (buf && buflen)
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, REAL(strlen)(buf) + 1);
+ return res;
+}
+#define INIT_XPG_STRERROR_R COMMON_INTERCEPT_FUNCTION(__xpg_strerror_r);
+#else
+#define INIT_XPG_STRERROR_R
+#endif
+
#if SANITIZER_INTERCEPT_SCANDIR
typedef int (*scandir_filter_f)(const struct __sanitizer_dirent *);
typedef int (*scandir_compar_f)(const struct __sanitizer_dirent **,
@@ -2895,6 +2910,7 @@ INTERCEPTOR(SSIZE_T, getdelim, char **lineptr, SIZE_T *n, int delim,
INIT_SCHED_GETAFFINITY; \
INIT_STRERROR; \
INIT_STRERROR_R; \
+ INIT_XPG_STRERROR_R; \
INIT_SCANDIR; \
INIT_SCANDIR64; \
INIT_GETGROUPS; \
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
index 78d1f5adef7..e79b8c83e13 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -120,6 +120,7 @@
# define SANITIZER_INTERCEPT_SCHED_GETAFFINITY SI_LINUX_NOT_ANDROID
# define SANITIZER_INTERCEPT_STRERROR SI_NOT_WINDOWS
# define SANITIZER_INTERCEPT_STRERROR_R SI_NOT_WINDOWS
+# define SANITIZER_INTERCEPT_XPG_STRERROR_R SI_LINUX_NOT_ANDROID
# define SANITIZER_INTERCEPT_SCANDIR SI_LINUX_NOT_ANDROID
# define SANITIZER_INTERCEPT_SCANDIR64 SI_LINUX_NOT_ANDROID
# define SANITIZER_INTERCEPT_GETGROUPS SI_NOT_WINDOWS
diff --git a/compiler-rt/lib/tsan/rtl/tsan_stat.cc b/compiler-rt/lib/tsan/rtl/tsan_stat.cc
index f9dbf121cef..dcf28c8d49b 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_stat.cc
+++ b/compiler-rt/lib/tsan/rtl/tsan_stat.cc
@@ -361,6 +361,7 @@ void StatOutput(u64 *stat) {
name[StatInt_sched_getaffinity] = " sched_getaffinity ";
name[StatInt_strerror] = " strerror ";
name[StatInt_strerror_r] = " strerror_r ";
+ name[StatInt___xpg_strerror_r] = " __xpg_strerror_r ";
name[StatInt_scandir] = " scandir ";
name[StatInt_scandir64] = " scandir64 ";
name[StatInt_getgroups] = " getgroups ";
diff --git a/compiler-rt/lib/tsan/rtl/tsan_stat.h b/compiler-rt/lib/tsan/rtl/tsan_stat.h
index a44edfcd65c..1869c9d1fd8 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_stat.h
+++ b/compiler-rt/lib/tsan/rtl/tsan_stat.h
@@ -356,6 +356,7 @@ enum StatType {
StatInt_sched_getaffinity,
StatInt_strerror,
StatInt_strerror_r,
+ StatInt___xpg_strerror_r,
StatInt_scandir,
StatInt_scandir64,
StatInt_getgroups,
OpenPOWER on IntegriCloud