diff options
author | Dmitry Vyukov <dvyukov@google.com> | 2013-10-15 12:25:29 +0000 |
---|---|---|
committer | Dmitry Vyukov <dvyukov@google.com> | 2013-10-15 12:25:29 +0000 |
commit | b48c2b2072c8cc17dc1579a6b20ce6c2a575821d (patch) | |
tree | 727a3818c4aa133984e5753e7da6330b31844fc9 /lib/sanitizer_common | |
parent | e910a1630be10685b2985a383c1a012f5df6bf62 (diff) |
tsan: use sanitizer::CommonFlags in tsan
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@192692 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/sanitizer_common')
-rw-r--r-- | lib/sanitizer_common/sanitizer_common.cc | 22 | ||||
-rw-r--r-- | lib/sanitizer_common/sanitizer_flags.cc | 2 | ||||
-rw-r--r-- | lib/sanitizer_common/sanitizer_flags.h | 9 | ||||
-rw-r--r-- | lib/sanitizer_common/sanitizer_internal_defs.h | 6 |
4 files changed, 19 insertions, 20 deletions
diff --git a/lib/sanitizer_common/sanitizer_common.cc b/lib/sanitizer_common/sanitizer_common.cc index 4cf694aac..76f90712c 100644 --- a/lib/sanitizer_common/sanitizer_common.cc +++ b/lib/sanitizer_common/sanitizer_common.cc @@ -202,7 +202,8 @@ using namespace __sanitizer; // NOLINT extern "C" { void __sanitizer_set_report_path(const char *path) { - if (!path) return; + if (!path) + return; uptr len = internal_strlen(path); if (len > sizeof(report_path_prefix) - 100) { Report("ERROR: Path is too long: %c%c%c%c%c%c%c%c...\n", @@ -210,18 +211,21 @@ void __sanitizer_set_report_path(const char *path) { path[4], path[5], path[6], path[7]); Die(); } - internal_strncpy(report_path_prefix, path, sizeof(report_path_prefix)); - report_path_prefix[len] = '\0'; - report_fd = kInvalidFd; - log_to_file = true; -} - -void __sanitizer_set_report_fd(int fd) { if (report_fd != kStdoutFd && report_fd != kStderrFd && report_fd != kInvalidFd) internal_close(report_fd); - report_fd = fd; + report_fd = kInvalidFd; + log_to_file = false; + if (internal_strcmp(path, "stdout") == 0) { + report_fd = kStdoutFd; + } else if (internal_strcmp(path, "stderr") == 0) { + report_fd = kStderrFd; + } else { + internal_strncpy(report_path_prefix, path, sizeof(report_path_prefix)); + report_path_prefix[len] = '\0'; + log_to_file = true; + } } void NOINLINE __sanitizer_sandbox_on_notify(void *reserved) { diff --git a/lib/sanitizer_common/sanitizer_flags.cc b/lib/sanitizer_common/sanitizer_flags.cc index 036f97b9d..4c9f4e7e0 100644 --- a/lib/sanitizer_common/sanitizer_flags.cc +++ b/lib/sanitizer_common/sanitizer_flags.cc @@ -18,8 +18,6 @@ namespace __sanitizer { -CommonFlags common_flags_dont_use_directly; - void ParseCommonFlagsFromString(const char *str) { CommonFlags *f = common_flags(); ParseFlag(str, &f->malloc_context_size, "malloc_context_size"); diff --git a/lib/sanitizer_common/sanitizer_flags.h b/lib/sanitizer_common/sanitizer_flags.h index 43632e65c..7740b240f 100644 --- a/lib/sanitizer_common/sanitizer_flags.h +++ b/lib/sanitizer_common/sanitizer_flags.h @@ -37,7 +37,9 @@ struct CommonFlags { bool handle_ioctl; // Max number of stack frames kept for each allocation/deallocation. int malloc_context_size; - // Write logs to "log_path.pid" instead of stderr. + // Write logs to "log_path.pid". + // The special values are "stdout" and "stderr". + // The default is "stderr". const char *log_path; // Enable memory leak detection. bool detect_leaks; @@ -49,10 +51,9 @@ struct CommonFlags { bool allocator_may_return_null; }; -extern CommonFlags common_flags_dont_use_directly; - inline CommonFlags *common_flags() { - return &common_flags_dont_use_directly; + static CommonFlags f; + return &f; } void ParseCommonFlagsFromString(const char *str); diff --git a/lib/sanitizer_common/sanitizer_internal_defs.h b/lib/sanitizer_common/sanitizer_internal_defs.h index 77bc967c5..1087f8190 100644 --- a/lib/sanitizer_common/sanitizer_internal_defs.h +++ b/lib/sanitizer_common/sanitizer_internal_defs.h @@ -83,14 +83,10 @@ typedef u64 OFF64_T; extern "C" { // Tell the tools to write their reports to "path.<pid>" instead of stderr. + // The special values are "stdout" and "stderr". SANITIZER_INTERFACE_ATTRIBUTE void __sanitizer_set_report_path(const char *path); - // Tell the tools to write their reports to given file descriptor instead of - // stderr. - SANITIZER_INTERFACE_ATTRIBUTE - void __sanitizer_set_report_fd(int fd); - // Notify the tools that the sandbox is going to be turned on. The reserved // parameter will be used in the future to hold a structure with functions // that the tools may call to bypass the sandbox. |