[compiler-rt] r367551 - compiler-rt: Rename .cc file in lib/{dfsan, stats, ubsan_minimal} to .cpp
Nico Weber via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 1 05:41:23 PDT 2019
Author: nico
Date: Thu Aug 1 05:41:23 2019
New Revision: 367551
URL: http://llvm.org/viewvc/llvm-project?rev=367551&view=rev
Log:
compiler-rt: Rename .cc file in lib/{dfsan,stats,ubsan_minimal} to .cpp
Like r367463, but for dfsan, stats, ubsan_minimal.
Added:
compiler-rt/trunk/lib/dfsan/dfsan.cpp
- copied, changed from r367550, compiler-rt/trunk/lib/dfsan/dfsan.cc
compiler-rt/trunk/lib/dfsan/dfsan_custom.cpp
- copied, changed from r367550, compiler-rt/trunk/lib/dfsan/dfsan_custom.cc
compiler-rt/trunk/lib/dfsan/dfsan_interceptors.cpp
- copied, changed from r367550, compiler-rt/trunk/lib/dfsan/dfsan_interceptors.cc
compiler-rt/trunk/lib/stats/stats.cpp
- copied, changed from r367550, compiler-rt/trunk/lib/stats/stats.cc
compiler-rt/trunk/lib/stats/stats_client.cpp
- copied, changed from r367550, compiler-rt/trunk/lib/stats/stats_client.cc
compiler-rt/trunk/lib/ubsan_minimal/ubsan_minimal_handlers.cpp
- copied unchanged from r367550, compiler-rt/trunk/lib/ubsan_minimal/ubsan_minimal_handlers.cc
Removed:
compiler-rt/trunk/lib/dfsan/dfsan.cc
compiler-rt/trunk/lib/dfsan/dfsan_custom.cc
compiler-rt/trunk/lib/dfsan/dfsan_interceptors.cc
compiler-rt/trunk/lib/stats/stats.cc
compiler-rt/trunk/lib/stats/stats_client.cc
compiler-rt/trunk/lib/ubsan_minimal/ubsan_minimal_handlers.cc
Modified:
compiler-rt/trunk/lib/dfsan/CMakeLists.txt
compiler-rt/trunk/lib/dfsan/scripts/check_custom_wrappers.sh
compiler-rt/trunk/lib/stats/CMakeLists.txt
compiler-rt/trunk/lib/ubsan_minimal/CMakeLists.txt
Modified: compiler-rt/trunk/lib/dfsan/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/dfsan/CMakeLists.txt?rev=367551&r1=367550&r2=367551&view=diff
==============================================================================
--- compiler-rt/trunk/lib/dfsan/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/dfsan/CMakeLists.txt Thu Aug 1 05:41:23 2019
@@ -2,14 +2,16 @@ include_directories(..)
# Runtime library sources and build flags.
set(DFSAN_RTL_SOURCES
- dfsan.cc
- dfsan_custom.cc
- dfsan_interceptors.cc)
+ dfsan.cpp
+ dfsan_custom.cpp
+ dfsan_interceptors.cpp
+ )
set(DFSAN_RTL_HEADERS
dfsan.h
dfsan_flags.inc
- dfsan_platform.h)
+ dfsan_platform.h
+ )
set(DFSAN_COMMON_CFLAGS ${SANITIZER_COMMON_CFLAGS})
append_rtti_flag(OFF DFSAN_COMMON_CFLAGS)
Removed: compiler-rt/trunk/lib/dfsan/dfsan.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/dfsan/dfsan.cc?rev=367550&view=auto
==============================================================================
--- compiler-rt/trunk/lib/dfsan/dfsan.cc (original)
+++ compiler-rt/trunk/lib/dfsan/dfsan.cc (removed)
@@ -1,460 +0,0 @@
-//===-- dfsan.cc ----------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This file is a part of DataFlowSanitizer.
-//
-// DataFlowSanitizer runtime. This file defines the public interface to
-// DataFlowSanitizer as well as the definition of certain runtime functions
-// called automatically by the compiler (specifically the instrumentation pass
-// in llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp).
-//
-// The public interface is defined in include/sanitizer/dfsan_interface.h whose
-// functions are prefixed dfsan_ while the compiler interface functions are
-// prefixed __dfsan_.
-//===----------------------------------------------------------------------===//
-
-#include "sanitizer_common/sanitizer_atomic.h"
-#include "sanitizer_common/sanitizer_common.h"
-#include "sanitizer_common/sanitizer_file.h"
-#include "sanitizer_common/sanitizer_flags.h"
-#include "sanitizer_common/sanitizer_flag_parser.h"
-#include "sanitizer_common/sanitizer_libc.h"
-
-#include "dfsan/dfsan.h"
-
-using namespace __dfsan;
-
-typedef atomic_uint16_t atomic_dfsan_label;
-static const dfsan_label kInitializingLabel = -1;
-
-static const uptr kNumLabels = 1 << (sizeof(dfsan_label) * 8);
-
-static atomic_dfsan_label __dfsan_last_label;
-static dfsan_label_info __dfsan_label_info[kNumLabels];
-
-Flags __dfsan::flags_data;
-
-SANITIZER_INTERFACE_ATTRIBUTE THREADLOCAL dfsan_label __dfsan_retval_tls;
-SANITIZER_INTERFACE_ATTRIBUTE THREADLOCAL dfsan_label __dfsan_arg_tls[64];
-
-SANITIZER_INTERFACE_ATTRIBUTE uptr __dfsan_shadow_ptr_mask;
-
-// On Linux/x86_64, memory is laid out as follows:
-//
-// +--------------------+ 0x800000000000 (top of memory)
-// | application memory |
-// +--------------------+ 0x700000008000 (kAppAddr)
-// | |
-// | unused |
-// | |
-// +--------------------+ 0x200200000000 (kUnusedAddr)
-// | union table |
-// +--------------------+ 0x200000000000 (kUnionTableAddr)
-// | shadow memory |
-// +--------------------+ 0x000000010000 (kShadowAddr)
-// | reserved by kernel |
-// +--------------------+ 0x000000000000
-//
-// To derive a shadow memory address from an application memory address,
-// bits 44-46 are cleared to bring the address into the range
-// [0x000000008000,0x100000000000). Then the address is shifted left by 1 to
-// account for the double byte representation of shadow labels and move the
-// address into the shadow memory range. See the function shadow_for below.
-
-// On Linux/MIPS64, memory is laid out as follows:
-//
-// +--------------------+ 0x10000000000 (top of memory)
-// | application memory |
-// +--------------------+ 0xF000008000 (kAppAddr)
-// | |
-// | unused |
-// | |
-// +--------------------+ 0x2200000000 (kUnusedAddr)
-// | union table |
-// +--------------------+ 0x2000000000 (kUnionTableAddr)
-// | shadow memory |
-// +--------------------+ 0x0000010000 (kShadowAddr)
-// | reserved by kernel |
-// +--------------------+ 0x0000000000
-
-// On Linux/AArch64 (39-bit VMA), memory is laid out as follow:
-//
-// +--------------------+ 0x8000000000 (top of memory)
-// | application memory |
-// +--------------------+ 0x7000008000 (kAppAddr)
-// | |
-// | unused |
-// | |
-// +--------------------+ 0x1200000000 (kUnusedAddr)
-// | union table |
-// +--------------------+ 0x1000000000 (kUnionTableAddr)
-// | shadow memory |
-// +--------------------+ 0x0000010000 (kShadowAddr)
-// | reserved by kernel |
-// +--------------------+ 0x0000000000
-
-// On Linux/AArch64 (42-bit VMA), memory is laid out as follow:
-//
-// +--------------------+ 0x40000000000 (top of memory)
-// | application memory |
-// +--------------------+ 0x3ff00008000 (kAppAddr)
-// | |
-// | unused |
-// | |
-// +--------------------+ 0x1200000000 (kUnusedAddr)
-// | union table |
-// +--------------------+ 0x8000000000 (kUnionTableAddr)
-// | shadow memory |
-// +--------------------+ 0x0000010000 (kShadowAddr)
-// | reserved by kernel |
-// +--------------------+ 0x0000000000
-
-// On Linux/AArch64 (48-bit VMA), memory is laid out as follow:
-//
-// +--------------------+ 0x1000000000000 (top of memory)
-// | application memory |
-// +--------------------+ 0xffff00008000 (kAppAddr)
-// | unused |
-// +--------------------+ 0xaaaab0000000 (top of PIE address)
-// | application PIE |
-// +--------------------+ 0xaaaaa0000000 (top of PIE address)
-// | |
-// | unused |
-// | |
-// +--------------------+ 0x1200000000 (kUnusedAddr)
-// | union table |
-// +--------------------+ 0x8000000000 (kUnionTableAddr)
-// | shadow memory |
-// +--------------------+ 0x0000010000 (kShadowAddr)
-// | reserved by kernel |
-// +--------------------+ 0x0000000000
-
-typedef atomic_dfsan_label dfsan_union_table_t[kNumLabels][kNumLabels];
-
-#ifdef DFSAN_RUNTIME_VMA
-// Runtime detected VMA size.
-int __dfsan::vmaSize;
-#endif
-
-static uptr UnusedAddr() {
- return MappingArchImpl<MAPPING_UNION_TABLE_ADDR>()
- + sizeof(dfsan_union_table_t);
-}
-
-static atomic_dfsan_label *union_table(dfsan_label l1, dfsan_label l2) {
- return &(*(dfsan_union_table_t *) UnionTableAddr())[l1][l2];
-}
-
-// Checks we do not run out of labels.
-static void dfsan_check_label(dfsan_label label) {
- if (label == kInitializingLabel) {
- Report("FATAL: DataFlowSanitizer: out of labels\n");
- Die();
- }
-}
-
-// Resolves the union of two unequal labels. Nonequality is a precondition for
-// this function (the instrumentation pass inlines the equality test).
-extern "C" SANITIZER_INTERFACE_ATTRIBUTE
-dfsan_label __dfsan_union(dfsan_label l1, dfsan_label l2) {
- if (flags().fast16labels)
- return l1 | l2;
- DCHECK_NE(l1, l2);
-
- if (l1 == 0)
- return l2;
- if (l2 == 0)
- return l1;
-
- if (l1 > l2)
- Swap(l1, l2);
-
- atomic_dfsan_label *table_ent = union_table(l1, l2);
- // We need to deal with the case where two threads concurrently request
- // a union of the same pair of labels. If the table entry is uninitialized,
- // (i.e. 0) use a compare-exchange to set the entry to kInitializingLabel
- // (i.e. -1) to mark that we are initializing it.
- dfsan_label label = 0;
- if (atomic_compare_exchange_strong(table_ent, &label, kInitializingLabel,
- memory_order_acquire)) {
- // Check whether l2 subsumes l1. We don't need to check whether l1
- // subsumes l2 because we are guaranteed here that l1 < l2, and (at least
- // in the cases we are interested in) a label may only subsume labels
- // created earlier (i.e. with a lower numerical value).
- if (__dfsan_label_info[l2].l1 == l1 ||
- __dfsan_label_info[l2].l2 == l1) {
- label = l2;
- } else {
- label =
- atomic_fetch_add(&__dfsan_last_label, 1, memory_order_relaxed) + 1;
- dfsan_check_label(label);
- __dfsan_label_info[label].l1 = l1;
- __dfsan_label_info[label].l2 = l2;
- }
- atomic_store(table_ent, label, memory_order_release);
- } else if (label == kInitializingLabel) {
- // Another thread is initializing the entry. Wait until it is finished.
- do {
- internal_sched_yield();
- label = atomic_load(table_ent, memory_order_acquire);
- } while (label == kInitializingLabel);
- }
- return label;
-}
-
-extern "C" SANITIZER_INTERFACE_ATTRIBUTE
-dfsan_label __dfsan_union_load(const dfsan_label *ls, uptr n) {
- dfsan_label label = ls[0];
- for (uptr i = 1; i != n; ++i) {
- dfsan_label next_label = ls[i];
- if (label != next_label)
- label = __dfsan_union(label, next_label);
- }
- return label;
-}
-
-extern "C" SANITIZER_INTERFACE_ATTRIBUTE
-void __dfsan_unimplemented(char *fname) {
- if (flags().warn_unimplemented)
- Report("WARNING: DataFlowSanitizer: call to uninstrumented function %s\n",
- fname);
-}
-
-// Use '-mllvm -dfsan-debug-nonzero-labels' and break on this function
-// to try to figure out where labels are being introduced in a nominally
-// label-free program.
-extern "C" SANITIZER_INTERFACE_ATTRIBUTE void __dfsan_nonzero_label() {
- if (flags().warn_nonzero_labels)
- Report("WARNING: DataFlowSanitizer: saw nonzero label\n");
-}
-
-// Indirect call to an uninstrumented vararg function. We don't have a way of
-// handling these at the moment.
-extern "C" SANITIZER_INTERFACE_ATTRIBUTE void
-__dfsan_vararg_wrapper(const char *fname) {
- Report("FATAL: DataFlowSanitizer: unsupported indirect call to vararg "
- "function %s\n", fname);
- Die();
-}
-
-// Like __dfsan_union, but for use from the client or custom functions. Hence
-// the equality comparison is done here before calling __dfsan_union.
-SANITIZER_INTERFACE_ATTRIBUTE dfsan_label
-dfsan_union(dfsan_label l1, dfsan_label l2) {
- if (l1 == l2)
- return l1;
- return __dfsan_union(l1, l2);
-}
-
-extern "C" SANITIZER_INTERFACE_ATTRIBUTE
-dfsan_label dfsan_create_label(const char *desc, void *userdata) {
- dfsan_label label =
- atomic_fetch_add(&__dfsan_last_label, 1, memory_order_relaxed) + 1;
- dfsan_check_label(label);
- __dfsan_label_info[label].l1 = __dfsan_label_info[label].l2 = 0;
- __dfsan_label_info[label].desc = desc;
- __dfsan_label_info[label].userdata = userdata;
- return label;
-}
-
-extern "C" SANITIZER_INTERFACE_ATTRIBUTE
-void __dfsan_set_label(dfsan_label label, void *addr, uptr size) {
- for (dfsan_label *labelp = shadow_for(addr); size != 0; --size, ++labelp) {
- // Don't write the label if it is already the value we need it to be.
- // In a program where most addresses are not labeled, it is common that
- // a page of shadow memory is entirely zeroed. The Linux copy-on-write
- // implementation will share all of the zeroed pages, making a copy of a
- // page when any value is written. The un-sharing will happen even if
- // the value written does not change the value in memory. Avoiding the
- // write when both |label| and |*labelp| are zero dramatically reduces
- // the amount of real memory used by large programs.
- if (label == *labelp)
- continue;
-
- *labelp = label;
- }
-}
-
-SANITIZER_INTERFACE_ATTRIBUTE
-void dfsan_set_label(dfsan_label label, void *addr, uptr size) {
- __dfsan_set_label(label, addr, size);
-}
-
-SANITIZER_INTERFACE_ATTRIBUTE
-void dfsan_add_label(dfsan_label label, void *addr, uptr size) {
- for (dfsan_label *labelp = shadow_for(addr); size != 0; --size, ++labelp)
- if (*labelp != label)
- *labelp = __dfsan_union(*labelp, label);
-}
-
-// Unlike the other dfsan interface functions the behavior of this function
-// depends on the label of one of its arguments. Hence it is implemented as a
-// custom function.
-extern "C" SANITIZER_INTERFACE_ATTRIBUTE dfsan_label
-__dfsw_dfsan_get_label(long data, dfsan_label data_label,
- dfsan_label *ret_label) {
- *ret_label = 0;
- return data_label;
-}
-
-SANITIZER_INTERFACE_ATTRIBUTE dfsan_label
-dfsan_read_label(const void *addr, uptr size) {
- if (size == 0)
- return 0;
- return __dfsan_union_load(shadow_for(addr), size);
-}
-
-extern "C" SANITIZER_INTERFACE_ATTRIBUTE
-const struct dfsan_label_info *dfsan_get_label_info(dfsan_label label) {
- return &__dfsan_label_info[label];
-}
-
-extern "C" SANITIZER_INTERFACE_ATTRIBUTE int
-dfsan_has_label(dfsan_label label, dfsan_label elem) {
- if (label == elem)
- return true;
- const dfsan_label_info *info = dfsan_get_label_info(label);
- if (info->l1 != 0) {
- return dfsan_has_label(info->l1, elem) || dfsan_has_label(info->l2, elem);
- } else {
- return false;
- }
-}
-
-extern "C" SANITIZER_INTERFACE_ATTRIBUTE dfsan_label
-dfsan_has_label_with_desc(dfsan_label label, const char *desc) {
- const dfsan_label_info *info = dfsan_get_label_info(label);
- if (info->l1 != 0) {
- return dfsan_has_label_with_desc(info->l1, desc) ||
- dfsan_has_label_with_desc(info->l2, desc);
- } else {
- return internal_strcmp(desc, info->desc) == 0;
- }
-}
-
-extern "C" SANITIZER_INTERFACE_ATTRIBUTE uptr
-dfsan_get_label_count(void) {
- dfsan_label max_label_allocated =
- atomic_load(&__dfsan_last_label, memory_order_relaxed);
-
- return static_cast<uptr>(max_label_allocated);
-}
-
-extern "C" SANITIZER_INTERFACE_ATTRIBUTE void
-dfsan_dump_labels(int fd) {
- dfsan_label last_label =
- atomic_load(&__dfsan_last_label, memory_order_relaxed);
-
- for (uptr l = 1; l <= last_label; ++l) {
- char buf[64];
- internal_snprintf(buf, sizeof(buf), "%u %u %u ", l,
- __dfsan_label_info[l].l1, __dfsan_label_info[l].l2);
- WriteToFile(fd, buf, internal_strlen(buf));
- if (__dfsan_label_info[l].l1 == 0 && __dfsan_label_info[l].desc) {
- WriteToFile(fd, __dfsan_label_info[l].desc,
- internal_strlen(__dfsan_label_info[l].desc));
- }
- WriteToFile(fd, "\n", 1);
- }
-}
-
-void Flags::SetDefaults() {
-#define DFSAN_FLAG(Type, Name, DefaultValue, Description) Name = DefaultValue;
-#include "dfsan_flags.inc"
-#undef DFSAN_FLAG
-}
-
-static void RegisterDfsanFlags(FlagParser *parser, Flags *f) {
-#define DFSAN_FLAG(Type, Name, DefaultValue, Description) \
- RegisterFlag(parser, #Name, Description, &f->Name);
-#include "dfsan_flags.inc"
-#undef DFSAN_FLAG
-}
-
-static void InitializeFlags() {
- SetCommonFlagsDefaults();
- flags().SetDefaults();
-
- FlagParser parser;
- RegisterCommonFlags(&parser);
- RegisterDfsanFlags(&parser, &flags());
- parser.ParseStringFromEnv("DFSAN_OPTIONS");
- InitializeCommonFlags();
- if (Verbosity()) ReportUnrecognizedFlags();
- if (common_flags()->help) parser.PrintFlagDescriptions();
-}
-
-static void InitializePlatformEarly() {
- AvoidCVE_2016_2143();
-#ifdef DFSAN_RUNTIME_VMA
- __dfsan::vmaSize =
- (MostSignificantSetBitIndex(GET_CURRENT_FRAME()) + 1);
- if (__dfsan::vmaSize == 39 || __dfsan::vmaSize == 42 ||
- __dfsan::vmaSize == 48) {
- __dfsan_shadow_ptr_mask = ShadowMask();
- } else {
- Printf("FATAL: DataFlowSanitizer: unsupported VMA range\n");
- Printf("FATAL: Found %d - Supported 39, 42, and 48\n", __dfsan::vmaSize);
- Die();
- }
-#endif
-}
-
-static void dfsan_fini() {
- if (internal_strcmp(flags().dump_labels_at_exit, "") != 0) {
- fd_t fd = OpenFile(flags().dump_labels_at_exit, WrOnly);
- if (fd == kInvalidFd) {
- Report("WARNING: DataFlowSanitizer: unable to open output file %s\n",
- flags().dump_labels_at_exit);
- return;
- }
-
- Report("INFO: DataFlowSanitizer: dumping labels to %s\n",
- flags().dump_labels_at_exit);
- dfsan_dump_labels(fd);
- CloseFile(fd);
- }
-}
-
-extern "C" void dfsan_flush() {
- UnmapOrDie((void*)ShadowAddr(), UnusedAddr() - ShadowAddr());
- if (!MmapFixedNoReserve(ShadowAddr(), UnusedAddr() - ShadowAddr()))
- Die();
-}
-
-static void dfsan_init(int argc, char **argv, char **envp) {
- InitializeFlags();
-
- ::InitializePlatformEarly();
-
- if (!MmapFixedNoReserve(ShadowAddr(), UnusedAddr() - ShadowAddr()))
- Die();
-
- // Protect the region of memory we don't use, to preserve the one-to-one
- // mapping from application to shadow memory. But if ASLR is disabled, Linux
- // will load our executable in the middle of our unused region. This mostly
- // works so long as the program doesn't use too much memory. We support this
- // case by disabling memory protection when ASLR is disabled.
- uptr init_addr = (uptr)&dfsan_init;
- if (!(init_addr >= UnusedAddr() && init_addr < AppAddr()))
- MmapFixedNoAccess(UnusedAddr(), AppAddr() - UnusedAddr());
-
- InitializeInterceptors();
-
- // Register the fini callback to run when the program terminates successfully
- // or it is killed by the runtime.
- Atexit(dfsan_fini);
- AddDieCallback(dfsan_fini);
-
- __dfsan_label_info[kInitializingLabel].desc = "<init label>";
-}
-
-#if SANITIZER_CAN_USE_PREINIT_ARRAY
-__attribute__((section(".preinit_array"), used))
-static void (*dfsan_init_ptr)(int, char **, char **) = dfsan_init;
-#endif
Copied: compiler-rt/trunk/lib/dfsan/dfsan.cpp (from r367550, compiler-rt/trunk/lib/dfsan/dfsan.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/dfsan/dfsan.cpp?p2=compiler-rt/trunk/lib/dfsan/dfsan.cpp&p1=compiler-rt/trunk/lib/dfsan/dfsan.cc&r1=367550&r2=367551&rev=367551&view=diff
==============================================================================
--- compiler-rt/trunk/lib/dfsan/dfsan.cc (original)
+++ compiler-rt/trunk/lib/dfsan/dfsan.cpp Thu Aug 1 05:41:23 2019
@@ -1,4 +1,4 @@
-//===-- dfsan.cc ----------------------------------------------------------===//
+//===-- dfsan.cpp ---------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Removed: compiler-rt/trunk/lib/dfsan/dfsan_custom.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/dfsan/dfsan_custom.cc?rev=367550&view=auto
==============================================================================
--- compiler-rt/trunk/lib/dfsan/dfsan_custom.cc (original)
+++ compiler-rt/trunk/lib/dfsan/dfsan_custom.cc (removed)
@@ -1,1156 +0,0 @@
-//===-- dfsan.cc ----------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This file is a part of DataFlowSanitizer.
-//
-// This file defines the custom functions listed in done_abilist.txt.
-//===----------------------------------------------------------------------===//
-
-#include "sanitizer_common/sanitizer_common.h"
-#include "sanitizer_common/sanitizer_internal_defs.h"
-#include "sanitizer_common/sanitizer_linux.h"
-
-#include "dfsan/dfsan.h"
-
-#include <arpa/inet.h>
-#include <assert.h>
-#include <ctype.h>
-#include <dlfcn.h>
-#include <link.h>
-#include <poll.h>
-#include <pthread.h>
-#include <pwd.h>
-#include <sched.h>
-#include <signal.h>
-#include <stdarg.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/resource.h>
-#include <sys/select.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <time.h>
-#include <unistd.h>
-
-using namespace __dfsan;
-
-#define CALL_WEAK_INTERCEPTOR_HOOK(f, ...) \
- do { \
- if (f) \
- f(__VA_ARGS__); \
- } while (false)
-#define DECLARE_WEAK_INTERCEPTOR_HOOK(f, ...) \
-SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE void f(__VA_ARGS__);
-
-extern "C" {
-SANITIZER_INTERFACE_ATTRIBUTE int
-__dfsw_stat(const char *path, struct stat *buf, dfsan_label path_label,
- dfsan_label buf_label, dfsan_label *ret_label) {
- int ret = stat(path, buf);
- if (ret == 0)
- dfsan_set_label(0, buf, sizeof(struct stat));
- *ret_label = 0;
- return ret;
-}
-
-SANITIZER_INTERFACE_ATTRIBUTE int __dfsw_fstat(int fd, struct stat *buf,
- dfsan_label fd_label,
- dfsan_label buf_label,
- dfsan_label *ret_label) {
- int ret = fstat(fd, buf);
- if (ret == 0)
- dfsan_set_label(0, buf, sizeof(struct stat));
- *ret_label = 0;
- return ret;
-}
-
-SANITIZER_INTERFACE_ATTRIBUTE char *__dfsw_strchr(const char *s, int c,
- dfsan_label s_label,
- dfsan_label c_label,
- dfsan_label *ret_label) {
- for (size_t i = 0;; ++i) {
- if (s[i] == c || s[i] == 0) {
- if (flags().strict_data_dependencies) {
- *ret_label = s_label;
- } else {
- *ret_label = dfsan_union(dfsan_read_label(s, i + 1),
- dfsan_union(s_label, c_label));
- }
- return s[i] == 0 ? nullptr : const_cast<char *>(s+i);
- }
- }
-}
-
-DECLARE_WEAK_INTERCEPTOR_HOOK(dfsan_weak_hook_memcmp, uptr caller_pc,
- const void *s1, const void *s2, size_t n,
- dfsan_label s1_label, dfsan_label s2_label,
- dfsan_label n_label)
-
-SANITIZER_INTERFACE_ATTRIBUTE int __dfsw_memcmp(const void *s1, const void *s2,
- size_t n, dfsan_label s1_label,
- dfsan_label s2_label,
- dfsan_label n_label,
- dfsan_label *ret_label) {
- CALL_WEAK_INTERCEPTOR_HOOK(dfsan_weak_hook_memcmp, GET_CALLER_PC(), s1, s2, n,
- s1_label, s2_label, n_label);
- const char *cs1 = (const char *) s1, *cs2 = (const char *) s2;
- for (size_t i = 0; i != n; ++i) {
- if (cs1[i] != cs2[i]) {
- if (flags().strict_data_dependencies) {
- *ret_label = 0;
- } else {
- *ret_label = dfsan_union(dfsan_read_label(cs1, i + 1),
- dfsan_read_label(cs2, i + 1));
- }
- return cs1[i] - cs2[i];
- }
- }
-
- if (flags().strict_data_dependencies) {
- *ret_label = 0;
- } else {
- *ret_label = dfsan_union(dfsan_read_label(cs1, n),
- dfsan_read_label(cs2, n));
- }
- return 0;
-}
-
-DECLARE_WEAK_INTERCEPTOR_HOOK(dfsan_weak_hook_strcmp, uptr caller_pc,
- const char *s1, const char *s2,
- dfsan_label s1_label, dfsan_label s2_label)
-
-SANITIZER_INTERFACE_ATTRIBUTE int __dfsw_strcmp(const char *s1, const char *s2,
- dfsan_label s1_label,
- dfsan_label s2_label,
- dfsan_label *ret_label) {
- CALL_WEAK_INTERCEPTOR_HOOK(dfsan_weak_hook_strcmp, GET_CALLER_PC(), s1, s2,
- s1_label, s2_label);
- for (size_t i = 0;; ++i) {
- if (s1[i] != s2[i] || s1[i] == 0 || s2[i] == 0) {
- if (flags().strict_data_dependencies) {
- *ret_label = 0;
- } else {
- *ret_label = dfsan_union(dfsan_read_label(s1, i + 1),
- dfsan_read_label(s2, i + 1));
- }
- return s1[i] - s2[i];
- }
- }
- return 0;
-}
-
-SANITIZER_INTERFACE_ATTRIBUTE int
-__dfsw_strcasecmp(const char *s1, const char *s2, dfsan_label s1_label,
- dfsan_label s2_label, dfsan_label *ret_label) {
- for (size_t i = 0;; ++i) {
- if (tolower(s1[i]) != tolower(s2[i]) || s1[i] == 0 || s2[i] == 0) {
- if (flags().strict_data_dependencies) {
- *ret_label = 0;
- } else {
- *ret_label = dfsan_union(dfsan_read_label(s1, i + 1),
- dfsan_read_label(s2, i + 1));
- }
- return s1[i] - s2[i];
- }
- }
- return 0;
-}
-
-DECLARE_WEAK_INTERCEPTOR_HOOK(dfsan_weak_hook_strncmp, uptr caller_pc,
- const char *s1, const char *s2, size_t n,
- dfsan_label s1_label, dfsan_label s2_label,
- dfsan_label n_label)
-
-SANITIZER_INTERFACE_ATTRIBUTE int __dfsw_strncmp(const char *s1, const char *s2,
- size_t n, dfsan_label s1_label,
- dfsan_label s2_label,
- dfsan_label n_label,
- dfsan_label *ret_label) {
- if (n == 0) {
- *ret_label = 0;
- return 0;
- }
-
- CALL_WEAK_INTERCEPTOR_HOOK(dfsan_weak_hook_strncmp, GET_CALLER_PC(), s1, s2,
- n, s1_label, s2_label, n_label);
-
- for (size_t i = 0;; ++i) {
- if (s1[i] != s2[i] || s1[i] == 0 || s2[i] == 0 || i == n - 1) {
- if (flags().strict_data_dependencies) {
- *ret_label = 0;
- } else {
- *ret_label = dfsan_union(dfsan_read_label(s1, i + 1),
- dfsan_read_label(s2, i + 1));
- }
- return s1[i] - s2[i];
- }
- }
- return 0;
-}
-
-SANITIZER_INTERFACE_ATTRIBUTE int
-__dfsw_strncasecmp(const char *s1, const char *s2, size_t n,
- dfsan_label s1_label, dfsan_label s2_label,
- dfsan_label n_label, dfsan_label *ret_label) {
- if (n == 0) {
- *ret_label = 0;
- return 0;
- }
-
- for (size_t i = 0;; ++i) {
- if (tolower(s1[i]) != tolower(s2[i]) || s1[i] == 0 || s2[i] == 0 ||
- i == n - 1) {
- if (flags().strict_data_dependencies) {
- *ret_label = 0;
- } else {
- *ret_label = dfsan_union(dfsan_read_label(s1, i + 1),
- dfsan_read_label(s2, i + 1));
- }
- return s1[i] - s2[i];
- }
- }
- return 0;
-}
-
-SANITIZER_INTERFACE_ATTRIBUTE void *__dfsw_calloc(size_t nmemb, size_t size,
- dfsan_label nmemb_label,
- dfsan_label size_label,
- dfsan_label *ret_label) {
- void *p = calloc(nmemb, size);
- dfsan_set_label(0, p, nmemb * size);
- *ret_label = 0;
- return p;
-}
-
-SANITIZER_INTERFACE_ATTRIBUTE size_t
-__dfsw_strlen(const char *s, dfsan_label s_label, dfsan_label *ret_label) {
- size_t ret = strlen(s);
- if (flags().strict_data_dependencies) {
- *ret_label = 0;
- } else {
- *ret_label = dfsan_read_label(s, ret + 1);
- }
- return ret;
-}
-
-
-static void *dfsan_memcpy(void *dest, const void *src, size_t n) {
- dfsan_label *sdest = shadow_for(dest);
- const dfsan_label *ssrc = shadow_for(src);
- internal_memcpy((void *)sdest, (const void *)ssrc, n * sizeof(dfsan_label));
- return internal_memcpy(dest, src, n);
-}
-
-static void dfsan_memset(void *s, int c, dfsan_label c_label, size_t n) {
- internal_memset(s, c, n);
- dfsan_set_label(c_label, s, n);
-}
-
-SANITIZER_INTERFACE_ATTRIBUTE
-void *__dfsw_memcpy(void *dest, const void *src, size_t n,
- dfsan_label dest_label, dfsan_label src_label,
- dfsan_label n_label, dfsan_label *ret_label) {
- *ret_label = dest_label;
- return dfsan_memcpy(dest, src, n);
-}
-
-SANITIZER_INTERFACE_ATTRIBUTE
-void *__dfsw_memset(void *s, int c, size_t n,
- dfsan_label s_label, dfsan_label c_label,
- dfsan_label n_label, dfsan_label *ret_label) {
- dfsan_memset(s, c, c_label, n);
- *ret_label = s_label;
- return s;
-}
-
-SANITIZER_INTERFACE_ATTRIBUTE char *
-__dfsw_strdup(const char *s, dfsan_label s_label, dfsan_label *ret_label) {
- size_t len = strlen(s);
- void *p = malloc(len+1);
- dfsan_memcpy(p, s, len+1);
- *ret_label = 0;
- return static_cast<char *>(p);
-}
-
-SANITIZER_INTERFACE_ATTRIBUTE char *
-__dfsw_strncpy(char *s1, const char *s2, size_t n, dfsan_label s1_label,
- dfsan_label s2_label, dfsan_label n_label,
- dfsan_label *ret_label) {
- size_t len = strlen(s2);
- if (len < n) {
- dfsan_memcpy(s1, s2, len+1);
- dfsan_memset(s1+len+1, 0, 0, n-len-1);
- } else {
- dfsan_memcpy(s1, s2, n);
- }
-
- *ret_label = s1_label;
- return s1;
-}
-
-SANITIZER_INTERFACE_ATTRIBUTE ssize_t
-__dfsw_pread(int fd, void *buf, size_t count, off_t offset,
- dfsan_label fd_label, dfsan_label buf_label,
- dfsan_label count_label, dfsan_label offset_label,
- dfsan_label *ret_label) {
- ssize_t ret = pread(fd, buf, count, offset);
- if (ret > 0)
- dfsan_set_label(0, buf, ret);
- *ret_label = 0;
- return ret;
-}
-
-SANITIZER_INTERFACE_ATTRIBUTE ssize_t
-__dfsw_read(int fd, void *buf, size_t count,
- dfsan_label fd_label, dfsan_label buf_label,
- dfsan_label count_label,
- dfsan_label *ret_label) {
- ssize_t ret = read(fd, buf, count);
- if (ret > 0)
- dfsan_set_label(0, buf, ret);
- *ret_label = 0;
- return ret;
-}
-
-SANITIZER_INTERFACE_ATTRIBUTE int __dfsw_clock_gettime(clockid_t clk_id,
- struct timespec *tp,
- dfsan_label clk_id_label,
- dfsan_label tp_label,
- dfsan_label *ret_label) {
- int ret = clock_gettime(clk_id, tp);
- if (ret == 0)
- dfsan_set_label(0, tp, sizeof(struct timespec));
- *ret_label = 0;
- return ret;
-}
-
-static void unpoison(const void *ptr, uptr size) {
- dfsan_set_label(0, const_cast<void *>(ptr), size);
-}
-
-// dlopen() ultimately calls mmap() down inside the loader, which generally
-// doesn't participate in dynamic symbol resolution. Therefore we won't
-// intercept its calls to mmap, and we have to hook it here.
-SANITIZER_INTERFACE_ATTRIBUTE void *
-__dfsw_dlopen(const char *filename, int flag, dfsan_label filename_label,
- dfsan_label flag_label, dfsan_label *ret_label) {
- void *handle = dlopen(filename, flag);
- link_map *map = GET_LINK_MAP_BY_DLOPEN_HANDLE(handle);
- if (map)
- ForEachMappedRegion(map, unpoison);
- *ret_label = 0;
- return handle;
-}
-
-struct pthread_create_info {
- void *(*start_routine_trampoline)(void *, void *, dfsan_label, dfsan_label *);
- void *start_routine;
- void *arg;
-};
-
-static void *pthread_create_cb(void *p) {
- pthread_create_info pci(*(pthread_create_info *)p);
- free(p);
- dfsan_label ret_label;
- return pci.start_routine_trampoline(pci.start_routine, pci.arg, 0,
- &ret_label);
-}
-
-SANITIZER_INTERFACE_ATTRIBUTE int __dfsw_pthread_create(
- pthread_t *thread, const pthread_attr_t *attr,
- void *(*start_routine_trampoline)(void *, void *, dfsan_label,
- dfsan_label *),
- void *start_routine, void *arg, dfsan_label thread_label,
- dfsan_label attr_label, dfsan_label start_routine_label,
- dfsan_label arg_label, dfsan_label *ret_label) {
- pthread_create_info *pci =
- (pthread_create_info *)malloc(sizeof(pthread_create_info));
- pci->start_routine_trampoline = start_routine_trampoline;
- pci->start_routine = start_routine;
- pci->arg = arg;
- int rv = pthread_create(thread, attr, pthread_create_cb, (void *)pci);
- if (rv != 0)
- free(pci);
- *ret_label = 0;
- return rv;
-}
-
-struct dl_iterate_phdr_info {
- int (*callback_trampoline)(void *callback, struct dl_phdr_info *info,
- size_t size, void *data, dfsan_label info_label,
- dfsan_label size_label, dfsan_label data_label,
- dfsan_label *ret_label);
- void *callback;
- void *data;
-};
-
-int dl_iterate_phdr_cb(struct dl_phdr_info *info, size_t size, void *data) {
- dl_iterate_phdr_info *dipi = (dl_iterate_phdr_info *)data;
- dfsan_set_label(0, *info);
- dfsan_set_label(0, const_cast<char *>(info->dlpi_name),
- strlen(info->dlpi_name) + 1);
- dfsan_set_label(
- 0, const_cast<char *>(reinterpret_cast<const char *>(info->dlpi_phdr)),
- sizeof(*info->dlpi_phdr) * info->dlpi_phnum);
- dfsan_label ret_label;
- return dipi->callback_trampoline(dipi->callback, info, size, dipi->data, 0, 0,
- 0, &ret_label);
-}
-
-SANITIZER_INTERFACE_ATTRIBUTE int __dfsw_dl_iterate_phdr(
- int (*callback_trampoline)(void *callback, struct dl_phdr_info *info,
- size_t size, void *data, dfsan_label info_label,
- dfsan_label size_label, dfsan_label data_label,
- dfsan_label *ret_label),
- void *callback, void *data, dfsan_label callback_label,
- dfsan_label data_label, dfsan_label *ret_label) {
- dl_iterate_phdr_info dipi = { callback_trampoline, callback, data };
- *ret_label = 0;
- return dl_iterate_phdr(dl_iterate_phdr_cb, &dipi);
-}
-
-SANITIZER_INTERFACE_ATTRIBUTE
-char *__dfsw_ctime_r(const time_t *timep, char *buf, dfsan_label timep_label,
- dfsan_label buf_label, dfsan_label *ret_label) {
- char *ret = ctime_r(timep, buf);
- if (ret) {
- dfsan_set_label(dfsan_read_label(timep, sizeof(time_t)), buf,
- strlen(buf) + 1);
- *ret_label = buf_label;
- } else {
- *ret_label = 0;
- }
- return ret;
-}
-
-SANITIZER_INTERFACE_ATTRIBUTE
-char *__dfsw_fgets(char *s, int size, FILE *stream, dfsan_label s_label,
- dfsan_label size_label, dfsan_label stream_label,
- dfsan_label *ret_label) {
- char *ret = fgets(s, size, stream);
- if (ret) {
- dfsan_set_label(0, ret, strlen(ret) + 1);
- *ret_label = s_label;
- } else {
- *ret_label = 0;
- }
- return ret;
-}
-
-SANITIZER_INTERFACE_ATTRIBUTE
-char *__dfsw_getcwd(char *buf, size_t size, dfsan_label buf_label,
- dfsan_label size_label, dfsan_label *ret_label) {
- char *ret = getcwd(buf, size);
- if (ret) {
- dfsan_set_label(0, ret, strlen(ret) + 1);
- *ret_label = buf_label;
- } else {
- *ret_label = 0;
- }
- return ret;
-}
-
-SANITIZER_INTERFACE_ATTRIBUTE
-char *__dfsw_get_current_dir_name(dfsan_label *ret_label) {
- char *ret = get_current_dir_name();
- if (ret) {
- dfsan_set_label(0, ret, strlen(ret) + 1);
- }
- *ret_label = 0;
- return ret;
-}
-
-SANITIZER_INTERFACE_ATTRIBUTE
-int __dfsw_gethostname(char *name, size_t len, dfsan_label name_label,
- dfsan_label len_label, dfsan_label *ret_label) {
- int ret = gethostname(name, len);
- if (ret == 0) {
- dfsan_set_label(0, name, strlen(name) + 1);
- }
- *ret_label = 0;
- return ret;
-}
-
-SANITIZER_INTERFACE_ATTRIBUTE
-int __dfsw_getrlimit(int resource, struct rlimit *rlim,
- dfsan_label resource_label, dfsan_label rlim_label,
- dfsan_label *ret_label) {
- int ret = getrlimit(resource, rlim);
- if (ret == 0) {
- dfsan_set_label(0, rlim, sizeof(struct rlimit));
- }
- *ret_label = 0;
- return ret;
-}
-
-SANITIZER_INTERFACE_ATTRIBUTE
-int __dfsw_getrusage(int who, struct rusage *usage, dfsan_label who_label,
- dfsan_label usage_label, dfsan_label *ret_label) {
- int ret = getrusage(who, usage);
- if (ret == 0) {
- dfsan_set_label(0, usage, sizeof(struct rusage));
- }
- *ret_label = 0;
- return ret;
-}
-
-SANITIZER_INTERFACE_ATTRIBUTE
-char *__dfsw_strcpy(char *dest, const char *src, dfsan_label dst_label,
- dfsan_label src_label, dfsan_label *ret_label) {
- char *ret = strcpy(dest, src);
- if (ret) {
- internal_memcpy(shadow_for(dest), shadow_for(src),
- sizeof(dfsan_label) * (strlen(src) + 1));
- }
- *ret_label = dst_label;
- return ret;
-}
-
-SANITIZER_INTERFACE_ATTRIBUTE
-long int __dfsw_strtol(const char *nptr, char **endptr, int base,
- dfsan_label nptr_label, dfsan_label endptr_label,
- dfsan_label base_label, dfsan_label *ret_label) {
- char *tmp_endptr;
- long int ret = strtol(nptr, &tmp_endptr, base);
- if (endptr) {
- *endptr = tmp_endptr;
- }
- if (tmp_endptr > nptr) {
- // If *tmp_endptr is '\0' include its label as well.
- *ret_label = dfsan_union(
- base_label,
- dfsan_read_label(nptr, tmp_endptr - nptr + (*tmp_endptr ? 0 : 1)));
- } else {
- *ret_label = 0;
- }
- return ret;
-}
-
-SANITIZER_INTERFACE_ATTRIBUTE
-double __dfsw_strtod(const char *nptr, char **endptr,
- dfsan_label nptr_label, dfsan_label endptr_label,
- dfsan_label *ret_label) {
- char *tmp_endptr;
- double ret = strtod(nptr, &tmp_endptr);
- if (endptr) {
- *endptr = tmp_endptr;
- }
- if (tmp_endptr > nptr) {
- // If *tmp_endptr is '\0' include its label as well.
- *ret_label = dfsan_read_label(
- nptr,
- tmp_endptr - nptr + (*tmp_endptr ? 0 : 1));
- } else {
- *ret_label = 0;
- }
- return ret;
-}
-
-SANITIZER_INTERFACE_ATTRIBUTE
-long long int __dfsw_strtoll(const char *nptr, char **endptr, int base,
- dfsan_label nptr_label, dfsan_label endptr_label,
- dfsan_label base_label, dfsan_label *ret_label) {
- char *tmp_endptr;
- long long int ret = strtoll(nptr, &tmp_endptr, base);
- if (endptr) {
- *endptr = tmp_endptr;
- }
- if (tmp_endptr > nptr) {
- // If *tmp_endptr is '\0' include its label as well.
- *ret_label = dfsan_union(
- base_label,
- dfsan_read_label(nptr, tmp_endptr - nptr + (*tmp_endptr ? 0 : 1)));
- } else {
- *ret_label = 0;
- }
- return ret;
-}
-
-SANITIZER_INTERFACE_ATTRIBUTE
-unsigned long int __dfsw_strtoul(const char *nptr, char **endptr, int base,
- dfsan_label nptr_label, dfsan_label endptr_label,
- dfsan_label base_label, dfsan_label *ret_label) {
- char *tmp_endptr;
- unsigned long int ret = strtoul(nptr, &tmp_endptr, base);
- if (endptr) {
- *endptr = tmp_endptr;
- }
- if (tmp_endptr > nptr) {
- // If *tmp_endptr is '\0' include its label as well.
- *ret_label = dfsan_union(
- base_label,
- dfsan_read_label(nptr, tmp_endptr - nptr + (*tmp_endptr ? 0 : 1)));
- } else {
- *ret_label = 0;
- }
- return ret;
-}
-
-SANITIZER_INTERFACE_ATTRIBUTE
-long long unsigned int __dfsw_strtoull(const char *nptr, char **endptr,
- dfsan_label nptr_label,
- int base, dfsan_label endptr_label,
- dfsan_label base_label,
- dfsan_label *ret_label) {
- char *tmp_endptr;
- long long unsigned int ret = strtoull(nptr, &tmp_endptr, base);
- if (endptr) {
- *endptr = tmp_endptr;
- }
- if (tmp_endptr > nptr) {
- // If *tmp_endptr is '\0' include its label as well.
- *ret_label = dfsan_union(
- base_label,
- dfsan_read_label(nptr, tmp_endptr - nptr + (*tmp_endptr ? 0 : 1)));
- } else {
- *ret_label = 0;
- }
- return ret;
-}
-
-SANITIZER_INTERFACE_ATTRIBUTE
-time_t __dfsw_time(time_t *t, dfsan_label t_label, dfsan_label *ret_label) {
- time_t ret = time(t);
- if (ret != (time_t) -1 && t) {
- dfsan_set_label(0, t, sizeof(time_t));
- }
- *ret_label = 0;
- return ret;
-}
-
-SANITIZER_INTERFACE_ATTRIBUTE
-int __dfsw_inet_pton(int af, const char *src, void *dst, dfsan_label af_label,
- dfsan_label src_label, dfsan_label dst_label,
- dfsan_label *ret_label) {
- int ret = inet_pton(af, src, dst);
- if (ret == 1) {
- dfsan_set_label(dfsan_read_label(src, strlen(src) + 1), dst,
- af == AF_INET ? sizeof(struct in_addr) : sizeof(in6_addr));
- }
- *ret_label = 0;
- return ret;
-}
-
-SANITIZER_INTERFACE_ATTRIBUTE
-struct tm *__dfsw_localtime_r(const time_t *timep, struct tm *result,
- dfsan_label timep_label, dfsan_label result_label,
- dfsan_label *ret_label) {
- struct tm *ret = localtime_r(timep, result);
- if (ret) {
- dfsan_set_label(dfsan_read_label(timep, sizeof(time_t)), result,
- sizeof(struct tm));
- *ret_label = result_label;
- } else {
- *ret_label = 0;
- }
- return ret;
-}
-
-SANITIZER_INTERFACE_ATTRIBUTE
-int __dfsw_getpwuid_r(id_t uid, struct passwd *pwd,
- char *buf, size_t buflen, struct passwd **result,
- dfsan_label uid_label, dfsan_label pwd_label,
- dfsan_label buf_label, dfsan_label buflen_label,
- dfsan_label result_label, dfsan_label *ret_label) {
- // Store the data in pwd, the strings referenced from pwd in buf, and the
- // address of pwd in *result. On failure, NULL is stored in *result.
- int ret = getpwuid_r(uid, pwd, buf, buflen, result);
- if (ret == 0) {
- dfsan_set_label(0, pwd, sizeof(struct passwd));
- dfsan_set_label(0, buf, strlen(buf) + 1);
- }
- *ret_label = 0;
- dfsan_set_label(0, result, sizeof(struct passwd*));
- return ret;
-}
-
-SANITIZER_INTERFACE_ATTRIBUTE
-int __dfsw_poll(struct pollfd *fds, nfds_t nfds, int timeout,
- dfsan_label dfs_label, dfsan_label nfds_label,
- dfsan_label timeout_label, dfsan_label *ret_label) {
- int ret = poll(fds, nfds, timeout);
- if (ret >= 0) {
- for (; nfds > 0; --nfds) {
- dfsan_set_label(0, &fds[nfds - 1].revents, sizeof(fds[nfds - 1].revents));
- }
- }
- *ret_label = 0;
- return ret;
-}
-
-SANITIZER_INTERFACE_ATTRIBUTE
-int __dfsw_select(int nfds, fd_set *readfds, fd_set *writefds,
- fd_set *exceptfds, struct timeval *timeout,
- dfsan_label nfds_label, dfsan_label readfds_label,
- dfsan_label writefds_label, dfsan_label exceptfds_label,
- dfsan_label timeout_label, dfsan_label *ret_label) {
- int ret = select(nfds, readfds, writefds, exceptfds, timeout);
- // Clear everything (also on error) since their content is either set or
- // undefined.
- if (readfds) {
- dfsan_set_label(0, readfds, sizeof(fd_set));
- }
- if (writefds) {
- dfsan_set_label(0, writefds, sizeof(fd_set));
- }
- if (exceptfds) {
- dfsan_set_label(0, exceptfds, sizeof(fd_set));
- }
- dfsan_set_label(0, timeout, sizeof(struct timeval));
- *ret_label = 0;
- return ret;
-}
-
-SANITIZER_INTERFACE_ATTRIBUTE
-int __dfsw_sched_getaffinity(pid_t pid, size_t cpusetsize, cpu_set_t *mask,
- dfsan_label pid_label,
- dfsan_label cpusetsize_label,
- dfsan_label mask_label, dfsan_label *ret_label) {
- int ret = sched_getaffinity(pid, cpusetsize, mask);
- if (ret == 0) {
- dfsan_set_label(0, mask, cpusetsize);
- }
- *ret_label = 0;
- return ret;
-}
-
-SANITIZER_INTERFACE_ATTRIBUTE
-int __dfsw_sigemptyset(sigset_t *set, dfsan_label set_label,
- dfsan_label *ret_label) {
- int ret = sigemptyset(set);
- dfsan_set_label(0, set, sizeof(sigset_t));
- return ret;
-}
-
-SANITIZER_INTERFACE_ATTRIBUTE
-int __dfsw_sigaction(int signum, const struct sigaction *act,
- struct sigaction *oldact, dfsan_label signum_label,
- dfsan_label act_label, dfsan_label oldact_label,
- dfsan_label *ret_label) {
- int ret = sigaction(signum, act, oldact);
- if (oldact) {
- dfsan_set_label(0, oldact, sizeof(struct sigaction));
- }
- *ret_label = 0;
- return ret;
-}
-
-SANITIZER_INTERFACE_ATTRIBUTE
-int __dfsw_gettimeofday(struct timeval *tv, struct timezone *tz,
- dfsan_label tv_label, dfsan_label tz_label,
- dfsan_label *ret_label) {
- int ret = gettimeofday(tv, tz);
- if (tv) {
- dfsan_set_label(0, tv, sizeof(struct timeval));
- }
- if (tz) {
- dfsan_set_label(0, tz, sizeof(struct timezone));
- }
- *ret_label = 0;
- return ret;
-}
-
-SANITIZER_INTERFACE_ATTRIBUTE void *__dfsw_memchr(void *s, int c, size_t n,
- dfsan_label s_label,
- dfsan_label c_label,
- dfsan_label n_label,
- dfsan_label *ret_label) {
- void *ret = memchr(s, c, n);
- if (flags().strict_data_dependencies) {
- *ret_label = ret ? s_label : 0;
- } else {
- size_t len =
- ret ? reinterpret_cast<char *>(ret) - reinterpret_cast<char *>(s) + 1
- : n;
- *ret_label =
- dfsan_union(dfsan_read_label(s, len), dfsan_union(s_label, c_label));
- }
- return ret;
-}
-
-SANITIZER_INTERFACE_ATTRIBUTE char *__dfsw_strrchr(char *s, int c,
- dfsan_label s_label,
- dfsan_label c_label,
- dfsan_label *ret_label) {
- char *ret = strrchr(s, c);
- if (flags().strict_data_dependencies) {
- *ret_label = ret ? s_label : 0;
- } else {
- *ret_label =
- dfsan_union(dfsan_read_label(s, strlen(s) + 1),
- dfsan_union(s_label, c_label));
- }
-
- return ret;
-}
-
-SANITIZER_INTERFACE_ATTRIBUTE char *__dfsw_strstr(char *haystack, char *needle,
- dfsan_label haystack_label,
- dfsan_label needle_label,
- dfsan_label *ret_label) {
- char *ret = strstr(haystack, needle);
- if (flags().strict_data_dependencies) {
- *ret_label = ret ? haystack_label : 0;
- } else {
- size_t len = ret ? ret + strlen(needle) - haystack : strlen(haystack) + 1;
- *ret_label =
- dfsan_union(dfsan_read_label(haystack, len),
- dfsan_union(dfsan_read_label(needle, strlen(needle) + 1),
- dfsan_union(haystack_label, needle_label)));
- }
-
- return ret;
-}
-
-SANITIZER_INTERFACE_ATTRIBUTE int __dfsw_nanosleep(const struct timespec *req,
- struct timespec *rem,
- dfsan_label req_label,
- dfsan_label rem_label,
- dfsan_label *ret_label) {
- int ret = nanosleep(req, rem);
- *ret_label = 0;
- if (ret == -1) {
- // Interrupted by a signal, rem is filled with the remaining time.
- dfsan_set_label(0, rem, sizeof(struct timespec));
- }
- return ret;
-}
-
-SANITIZER_INTERFACE_ATTRIBUTE int
-__dfsw_socketpair(int domain, int type, int protocol, int sv[2],
- dfsan_label domain_label, dfsan_label type_label,
- dfsan_label protocol_label, dfsan_label sv_label,
- dfsan_label *ret_label) {
- int ret = socketpair(domain, type, protocol, sv);
- *ret_label = 0;
- if (ret == 0) {
- dfsan_set_label(0, sv, sizeof(*sv) * 2);
- }
- return ret;
-}
-
-// Type of the trampoline function passed to the custom version of
-// dfsan_set_write_callback.
-typedef void (*write_trampoline_t)(
- void *callback,
- int fd, const void *buf, ssize_t count,
- dfsan_label fd_label, dfsan_label buf_label, dfsan_label count_label);
-
-// Calls to dfsan_set_write_callback() set the values in this struct.
-// Calls to the custom version of write() read (and invoke) them.
-static struct {
- write_trampoline_t write_callback_trampoline = nullptr;
- void *write_callback = nullptr;
-} write_callback_info;
-
-SANITIZER_INTERFACE_ATTRIBUTE void
-__dfsw_dfsan_set_write_callback(
- write_trampoline_t write_callback_trampoline,
- void *write_callback,
- dfsan_label write_callback_label,
- dfsan_label *ret_label) {
- write_callback_info.write_callback_trampoline = write_callback_trampoline;
- write_callback_info.write_callback = write_callback;
-}
-
-SANITIZER_INTERFACE_ATTRIBUTE int
-__dfsw_write(int fd, const void *buf, size_t count,
- dfsan_label fd_label, dfsan_label buf_label,
- dfsan_label count_label, dfsan_label *ret_label) {
- if (write_callback_info.write_callback) {
- write_callback_info.write_callback_trampoline(
- write_callback_info.write_callback,
- fd, buf, count,
- fd_label, buf_label, count_label);
- }
-
- *ret_label = 0;
- return write(fd, buf, count);
-}
-} // namespace __dfsan
-
-// Type used to extract a dfsan_label with va_arg()
-typedef int dfsan_label_va;
-
-// Formats a chunk either a constant string or a single format directive (e.g.,
-// '%.3f').
-struct Formatter {
- Formatter(char *str_, const char *fmt_, size_t size_)
- : str(str_), str_off(0), size(size_), fmt_start(fmt_), fmt_cur(fmt_),
- width(-1) {}
-
- int format() {
- char *tmp_fmt = build_format_string();
- int retval =
- snprintf(str + str_off, str_off < size ? size - str_off : 0, tmp_fmt,
- 0 /* used only to avoid warnings */);
- free(tmp_fmt);
- return retval;
- }
-
- template <typename T> int format(T arg) {
- char *tmp_fmt = build_format_string();
- int retval;
- if (width >= 0) {
- retval = snprintf(str + str_off, str_off < size ? size - str_off : 0,
- tmp_fmt, width, arg);
- } else {
- retval = snprintf(str + str_off, str_off < size ? size - str_off : 0,
- tmp_fmt, arg);
- }
- free(tmp_fmt);
- return retval;
- }
-
- char *build_format_string() {
- size_t fmt_size = fmt_cur - fmt_start + 1;
- char *new_fmt = (char *)malloc(fmt_size + 1);
- assert(new_fmt);
- internal_memcpy(new_fmt, fmt_start, fmt_size);
- new_fmt[fmt_size] = '\0';
- return new_fmt;
- }
-
- char *str_cur() { return str + str_off; }
-
- size_t num_written_bytes(int retval) {
- if (retval < 0) {
- return 0;
- }
-
- size_t num_avail = str_off < size ? size - str_off : 0;
- if (num_avail == 0) {
- return 0;
- }
-
- size_t num_written = retval;
- // A return value of {v,}snprintf of size or more means that the output was
- // truncated.
- if (num_written >= num_avail) {
- num_written -= num_avail;
- }
-
- return num_written;
- }
-
- char *str;
- size_t str_off;
- size_t size;
- const char *fmt_start;
- const char *fmt_cur;
- int width;
-};
-
-// Formats the input and propagates the input labels to the output. The output
-// is stored in 'str'. 'size' bounds the number of output bytes. 'format' and
-// 'ap' are the format string and the list of arguments for formatting. Returns
-// the return value vsnprintf would return.
-//
-// The function tokenizes the format string in chunks representing either a
-// constant string or a single format directive (e.g., '%.3f') and formats each
-// chunk independently into the output string. This approach allows to figure
-// out which bytes of the output string depends on which argument and thus to
-// propagate labels more precisely.
-//
-// WARNING: This implementation does not support conversion specifiers with
-// positional arguments.
-static int format_buffer(char *str, size_t size, const char *fmt,
- dfsan_label *va_labels, dfsan_label *ret_label,
- va_list ap) {
- Formatter formatter(str, fmt, size);
-
- while (*formatter.fmt_cur) {
- formatter.fmt_start = formatter.fmt_cur;
- formatter.width = -1;
- int retval = 0;
-
- if (*formatter.fmt_cur != '%') {
- // Ordinary character. Consume all the characters until a '%' or the end
- // of the string.
- for (; *(formatter.fmt_cur + 1) && *(formatter.fmt_cur + 1) != '%';
- ++formatter.fmt_cur) {}
- retval = formatter.format();
- dfsan_set_label(0, formatter.str_cur(),
- formatter.num_written_bytes(retval));
- } else {
- // Conversion directive. Consume all the characters until a conversion
- // specifier or the end of the string.
- bool end_fmt = false;
- for (; *formatter.fmt_cur && !end_fmt; ) {
- switch (*++formatter.fmt_cur) {
- case 'd':
- case 'i':
- case 'o':
- case 'u':
- case 'x':
- case 'X':
- switch (*(formatter.fmt_cur - 1)) {
- case 'h':
- // Also covers the 'hh' case (since the size of the arg is still
- // an int).
- retval = formatter.format(va_arg(ap, int));
- break;
- case 'l':
- if (formatter.fmt_cur - formatter.fmt_start >= 2 &&
- *(formatter.fmt_cur - 2) == 'l') {
- retval = formatter.format(va_arg(ap, long long int));
- } else {
- retval = formatter.format(va_arg(ap, long int));
- }
- break;
- case 'q':
- retval = formatter.format(va_arg(ap, long long int));
- break;
- case 'j':
- retval = formatter.format(va_arg(ap, intmax_t));
- break;
- case 'z':
- case 't':
- retval = formatter.format(va_arg(ap, size_t));
- break;
- default:
- retval = formatter.format(va_arg(ap, int));
- }
- dfsan_set_label(*va_labels++, formatter.str_cur(),
- formatter.num_written_bytes(retval));
- end_fmt = true;
- break;
-
- case 'a':
- case 'A':
- case 'e':
- case 'E':
- case 'f':
- case 'F':
- case 'g':
- case 'G':
- if (*(formatter.fmt_cur - 1) == 'L') {
- retval = formatter.format(va_arg(ap, long double));
- } else {
- retval = formatter.format(va_arg(ap, double));
- }
- dfsan_set_label(*va_labels++, formatter.str_cur(),
- formatter.num_written_bytes(retval));
- end_fmt = true;
- break;
-
- case 'c':
- retval = formatter.format(va_arg(ap, int));
- dfsan_set_label(*va_labels++, formatter.str_cur(),
- formatter.num_written_bytes(retval));
- end_fmt = true;
- break;
-
- case 's': {
- char *arg = va_arg(ap, char *);
- retval = formatter.format(arg);
- va_labels++;
- internal_memcpy(shadow_for(formatter.str_cur()), shadow_for(arg),
- sizeof(dfsan_label) *
- formatter.num_written_bytes(retval));
- end_fmt = true;
- break;
- }
-
- case 'p':
- retval = formatter.format(va_arg(ap, void *));
- dfsan_set_label(*va_labels++, formatter.str_cur(),
- formatter.num_written_bytes(retval));
- end_fmt = true;
- break;
-
- case 'n': {
- int *ptr = va_arg(ap, int *);
- *ptr = (int)formatter.str_off;
- va_labels++;
- dfsan_set_label(0, ptr, sizeof(ptr));
- end_fmt = true;
- break;
- }
-
- case '%':
- retval = formatter.format();
- dfsan_set_label(0, formatter.str_cur(),
- formatter.num_written_bytes(retval));
- end_fmt = true;
- break;
-
- case '*':
- formatter.width = va_arg(ap, int);
- va_labels++;
- break;
-
- default:
- break;
- }
- }
- }
-
- if (retval < 0) {
- return retval;
- }
-
- formatter.fmt_cur++;
- formatter.str_off += retval;
- }
-
- *ret_label = 0;
-
- // Number of bytes written in total.
- return formatter.str_off;
-}
-
-extern "C" {
-SANITIZER_INTERFACE_ATTRIBUTE
-int __dfsw_sprintf(char *str, const char *format, dfsan_label str_label,
- dfsan_label format_label, dfsan_label *va_labels,
- dfsan_label *ret_label, ...) {
- va_list ap;
- va_start(ap, ret_label);
- int ret = format_buffer(str, ~0ul, format, va_labels, ret_label, ap);
- va_end(ap);
- return ret;
-}
-
-SANITIZER_INTERFACE_ATTRIBUTE
-int __dfsw_snprintf(char *str, size_t size, const char *format,
- dfsan_label str_label, dfsan_label size_label,
- dfsan_label format_label, dfsan_label *va_labels,
- dfsan_label *ret_label, ...) {
- va_list ap;
- va_start(ap, ret_label);
- int ret = format_buffer(str, size, format, va_labels, ret_label, ap);
- va_end(ap);
- return ret;
-}
-
-// Default empty implementations (weak). Users should redefine them.
-SANITIZER_INTERFACE_WEAK_DEF(void, __sanitizer_cov_trace_pc_guard, u32 *) {}
-SANITIZER_INTERFACE_WEAK_DEF(void, __sanitizer_cov_trace_pc_guard_init, u32 *,
- u32 *) {}
-SANITIZER_INTERFACE_WEAK_DEF(void, __sanitizer_cov_pcs_init, void) {}
-SANITIZER_INTERFACE_WEAK_DEF(void, __sanitizer_cov_trace_pc_indir, void) {}
-
-SANITIZER_INTERFACE_WEAK_DEF(void, __dfsw___sanitizer_cov_trace_cmp, void) {}
-SANITIZER_INTERFACE_WEAK_DEF(void, __dfsw___sanitizer_cov_trace_cmp1, void) {}
-SANITIZER_INTERFACE_WEAK_DEF(void, __dfsw___sanitizer_cov_trace_cmp2, void) {}
-SANITIZER_INTERFACE_WEAK_DEF(void, __dfsw___sanitizer_cov_trace_cmp4, void) {}
-SANITIZER_INTERFACE_WEAK_DEF(void, __dfsw___sanitizer_cov_trace_cmp8, void) {}
-SANITIZER_INTERFACE_WEAK_DEF(void, __dfsw___sanitizer_cov_trace_const_cmp1,
- void) {}
-SANITIZER_INTERFACE_WEAK_DEF(void, __dfsw___sanitizer_cov_trace_const_cmp2,
- void) {}
-SANITIZER_INTERFACE_WEAK_DEF(void, __dfsw___sanitizer_cov_trace_const_cmp4,
- void) {}
-SANITIZER_INTERFACE_WEAK_DEF(void, __dfsw___sanitizer_cov_trace_const_cmp8,
- void) {}
-SANITIZER_INTERFACE_WEAK_DEF(void, __dfsw___sanitizer_cov_trace_switch, void) {}
-} // extern "C"
Copied: compiler-rt/trunk/lib/dfsan/dfsan_custom.cpp (from r367550, compiler-rt/trunk/lib/dfsan/dfsan_custom.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/dfsan/dfsan_custom.cpp?p2=compiler-rt/trunk/lib/dfsan/dfsan_custom.cpp&p1=compiler-rt/trunk/lib/dfsan/dfsan_custom.cc&r1=367550&r2=367551&rev=367551&view=diff
==============================================================================
--- compiler-rt/trunk/lib/dfsan/dfsan_custom.cc (original)
+++ compiler-rt/trunk/lib/dfsan/dfsan_custom.cpp Thu Aug 1 05:41:23 2019
@@ -1,4 +1,4 @@
-//===-- dfsan.cc ----------------------------------------------------------===//
+//===-- dfsan.cpp ---------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Removed: compiler-rt/trunk/lib/dfsan/dfsan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/dfsan/dfsan_interceptors.cc?rev=367550&view=auto
==============================================================================
--- compiler-rt/trunk/lib/dfsan/dfsan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/dfsan/dfsan_interceptors.cc (removed)
@@ -1,45 +0,0 @@
-//===-- dfsan_interceptors.cc ---------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This file is a part of DataFlowSanitizer.
-//
-// Interceptors for standard library functions.
-//===----------------------------------------------------------------------===//
-
-#include "dfsan/dfsan.h"
-#include "interception/interception.h"
-#include "sanitizer_common/sanitizer_common.h"
-
-using namespace __sanitizer;
-
-INTERCEPTOR(void *, mmap, void *addr, SIZE_T length, int prot, int flags,
- int fd, OFF_T offset) {
- void *res = REAL(mmap)(addr, length, prot, flags, fd, offset);
- if (res != (void*)-1)
- dfsan_set_label(0, res, RoundUpTo(length, GetPageSize()));
- return res;
-}
-
-INTERCEPTOR(void *, mmap64, void *addr, SIZE_T length, int prot, int flags,
- int fd, OFF64_T offset) {
- void *res = REAL(mmap64)(addr, length, prot, flags, fd, offset);
- if (res != (void*)-1)
- dfsan_set_label(0, res, RoundUpTo(length, GetPageSize()));
- return res;
-}
-
-namespace __dfsan {
-void InitializeInterceptors() {
- static int inited = 0;
- CHECK_EQ(inited, 0);
-
- INTERCEPT_FUNCTION(mmap);
- INTERCEPT_FUNCTION(mmap64);
- inited = 1;
-}
-} // namespace __dfsan
Copied: compiler-rt/trunk/lib/dfsan/dfsan_interceptors.cpp (from r367550, compiler-rt/trunk/lib/dfsan/dfsan_interceptors.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/dfsan/dfsan_interceptors.cpp?p2=compiler-rt/trunk/lib/dfsan/dfsan_interceptors.cpp&p1=compiler-rt/trunk/lib/dfsan/dfsan_interceptors.cc&r1=367550&r2=367551&rev=367551&view=diff
==============================================================================
--- compiler-rt/trunk/lib/dfsan/dfsan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/dfsan/dfsan_interceptors.cpp Thu Aug 1 05:41:23 2019
@@ -1,4 +1,4 @@
-//===-- dfsan_interceptors.cc ---------------------------------------------===//
+//===-- dfsan_interceptors.cpp --------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Modified: compiler-rt/trunk/lib/dfsan/scripts/check_custom_wrappers.sh
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/dfsan/scripts/check_custom_wrappers.sh?rev=367551&r1=367550&r2=367551&view=diff
==============================================================================
--- compiler-rt/trunk/lib/dfsan/scripts/check_custom_wrappers.sh (original)
+++ compiler-rt/trunk/lib/dfsan/scripts/check_custom_wrappers.sh Thu Aug 1 05:41:23 2019
@@ -2,7 +2,7 @@
DFSAN_DIR=$(dirname "$0")/../
DFSAN_CUSTOM_TESTS=${DFSAN_DIR}/../../test/dfsan/custom.cc
-DFSAN_CUSTOM_WRAPPERS=${DFSAN_DIR}/dfsan_custom.cc
+DFSAN_CUSTOM_WRAPPERS=${DFSAN_DIR}/dfsan_custom.pp
DFSAN_ABI_LIST=${DFSAN_DIR}/done_abilist.txt
DIFFOUT=$(mktemp -q /tmp/tmp.XXXXXXXXXX)
Modified: compiler-rt/trunk/lib/stats/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/stats/CMakeLists.txt?rev=367551&r1=367550&r2=367551&view=diff
==============================================================================
--- compiler-rt/trunk/lib/stats/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/stats/CMakeLists.txt Thu Aug 1 05:41:23 2019
@@ -24,7 +24,7 @@ add_compiler_rt_runtime(clang_rt.stats
${STATS_LIB_FLAVOR}
ARCHS ${SANITIZER_COMMON_SUPPORTED_ARCH}
OS ${SANITIZER_COMMON_SUPPORTED_OS}
- SOURCES stats.cc
+ SOURCES stats.cpp
ADDITIONAL_HEADERS ${STATS_HEADERS}
OBJECT_LIBS RTSanitizerCommon
RTSanitizerCommonLibc
@@ -38,7 +38,7 @@ add_compiler_rt_runtime(clang_rt.stats_c
STATIC
ARCHS ${SANITIZER_COMMON_SUPPORTED_ARCH}
OS ${SANITIZER_COMMON_SUPPORTED_OS}
- SOURCES stats_client.cc
+ SOURCES stats_client.cpp
ADDITIONAL_HEADERS ${STATS_HEADERS}
CFLAGS ${SANITIZER_COMMON_CFLAGS}
LINK_FLAGS ${WEAK_SYMBOL_LINK_FLAGS}
Removed: compiler-rt/trunk/lib/stats/stats.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/stats/stats.cc?rev=367550&view=auto
==============================================================================
--- compiler-rt/trunk/lib/stats/stats.cc (original)
+++ compiler-rt/trunk/lib/stats/stats.cc (removed)
@@ -1,136 +0,0 @@
-//===-- stats.cc ----------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// Sanitizer statistics gathering. Manages statistics for a process and is
-// responsible for writing the report file.
-//
-//===----------------------------------------------------------------------===//
-
-#include "sanitizer_common/sanitizer_common.h"
-#include "sanitizer_common/sanitizer_file.h"
-#include "sanitizer_common/sanitizer_internal_defs.h"
-#if SANITIZER_POSIX
-#include "sanitizer_common/sanitizer_posix.h"
-#endif
-#include "sanitizer_common/sanitizer_symbolizer.h"
-#include "stats/stats.h"
-#if SANITIZER_POSIX
-#include <signal.h>
-#endif
-
-using namespace __sanitizer;
-
-namespace {
-
-InternalMmapVectorNoCtor<StatModule **> modules;
-StaticSpinMutex modules_mutex;
-
-fd_t stats_fd;
-
-void WriteLE(fd_t fd, uptr val) {
- char chars[sizeof(uptr)];
- for (unsigned i = 0; i != sizeof(uptr); ++i) {
- chars[i] = val >> (i * 8);
- }
- WriteToFile(fd, chars, sizeof(uptr));
-}
-
-void OpenStatsFile(const char *path_env) {
- InternalMmapVector<char> path(kMaxPathLength);
- SubstituteForFlagValue(path_env, path.data(), kMaxPathLength);
-
- error_t err;
- stats_fd = OpenFile(path.data(), WrOnly, &err);
- if (stats_fd == kInvalidFd) {
- Report("stats: failed to open %s for writing (reason: %d)\n", path.data(),
- err);
- return;
- }
- char sizeof_uptr = sizeof(uptr);
- WriteToFile(stats_fd, &sizeof_uptr, 1);
-}
-
-void WriteModuleReport(StatModule **smodp) {
- CHECK(smodp);
- const char *path_env = GetEnv("SANITIZER_STATS_PATH");
- if (!path_env || stats_fd == kInvalidFd)
- return;
- if (!stats_fd)
- OpenStatsFile(path_env);
- const LoadedModule *mod = Symbolizer::GetOrInit()->FindModuleForAddress(
- reinterpret_cast<uptr>(smodp));
- WriteToFile(stats_fd, mod->full_name(),
- internal_strlen(mod->full_name()) + 1);
- for (StatModule *smod = *smodp; smod; smod = smod->next) {
- for (u32 i = 0; i != smod->size; ++i) {
- StatInfo *s = &smod->infos[i];
- if (!s->addr)
- continue;
- WriteLE(stats_fd, s->addr - mod->base_address());
- WriteLE(stats_fd, s->data);
- }
- }
- WriteLE(stats_fd, 0);
- WriteLE(stats_fd, 0);
-}
-
-} // namespace
-
-extern "C"
-SANITIZER_INTERFACE_ATTRIBUTE
-unsigned __sanitizer_stats_register(StatModule **mod) {
- SpinMutexLock l(&modules_mutex);
- modules.push_back(mod);
- return modules.size() - 1;
-}
-
-extern "C"
-SANITIZER_INTERFACE_ATTRIBUTE
-void __sanitizer_stats_unregister(unsigned index) {
- SpinMutexLock l(&modules_mutex);
- WriteModuleReport(modules[index]);
- modules[index] = 0;
-}
-
-namespace {
-
-void WriteFullReport() {
- SpinMutexLock l(&modules_mutex);
- for (StatModule **mod : modules) {
- if (!mod)
- continue;
- WriteModuleReport(mod);
- }
- if (stats_fd != 0 && stats_fd != kInvalidFd) {
- CloseFile(stats_fd);
- stats_fd = kInvalidFd;
- }
-}
-
-#if SANITIZER_POSIX
-void USR2Handler(int sig) {
- WriteFullReport();
-}
-#endif
-
-struct WriteReportOnExitOrSignal {
- WriteReportOnExitOrSignal() {
-#if SANITIZER_POSIX
- struct sigaction sigact;
- internal_memset(&sigact, 0, sizeof(sigact));
- sigact.sa_handler = USR2Handler;
- internal_sigaction(SIGUSR2, &sigact, nullptr);
-#endif
- }
-
- ~WriteReportOnExitOrSignal() {
- WriteFullReport();
- }
-} wr;
-
-} // namespace
Copied: compiler-rt/trunk/lib/stats/stats.cpp (from r367550, compiler-rt/trunk/lib/stats/stats.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/stats/stats.cpp?p2=compiler-rt/trunk/lib/stats/stats.cpp&p1=compiler-rt/trunk/lib/stats/stats.cc&r1=367550&r2=367551&rev=367551&view=diff
==============================================================================
--- compiler-rt/trunk/lib/stats/stats.cc (original)
+++ compiler-rt/trunk/lib/stats/stats.cpp Thu Aug 1 05:41:23 2019
@@ -1,4 +1,4 @@
-//===-- stats.cc ----------------------------------------------------------===//
+//===-- stats.cpp ---------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Removed: compiler-rt/trunk/lib/stats/stats_client.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/stats/stats_client.cc?rev=367550&view=auto
==============================================================================
--- compiler-rt/trunk/lib/stats/stats_client.cc (original)
+++ compiler-rt/trunk/lib/stats/stats_client.cc (removed)
@@ -1,83 +0,0 @@
-//===-- stats_client.cc ---------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// Sanitizer statistics gathering. Manages statistics for a module (executable
-// or DSO) and registers statistics with the process.
-//
-// This is linked into each individual modle and cannot directly use functions
-// declared in sanitizer_common.
-//
-//===----------------------------------------------------------------------===//
-
-#ifdef _WIN32
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
-#else
-#include <dlfcn.h>
-#endif
-#include <stdint.h>
-#include <stdio.h>
-
-#include "sanitizer_common/sanitizer_internal_defs.h"
-#include "stats/stats.h"
-
-using namespace __sanitizer;
-
-namespace {
-
-void *LookupSymbolFromMain(const char *name) {
-#ifdef _WIN32
- return reinterpret_cast<void *>(GetProcAddress(GetModuleHandle(0), name));
-#else
- return dlsym(RTLD_DEFAULT, name);
-#endif
-}
-
-StatModule *list;
-
-struct RegisterSanStats {
- unsigned module_id;
-
- RegisterSanStats() {
- typedef unsigned (*reg_func_t)(StatModule **);
- reg_func_t reg_func = reinterpret_cast<reg_func_t>(
- LookupSymbolFromMain("__sanitizer_stats_register"));
- if (reg_func)
- module_id = reg_func(&list);
- }
-
- ~RegisterSanStats() {
- typedef void (*unreg_func_t)(unsigned);
- unreg_func_t unreg_func = reinterpret_cast<unreg_func_t>(
- LookupSymbolFromMain("__sanitizer_stats_unregister"));
- if (unreg_func)
- unreg_func(module_id);
- }
-} reg;
-
-}
-
-extern "C" void __sanitizer_stat_init(StatModule *mod) {
- mod->next = list;
- list = mod;
-}
-
-extern "C" void __sanitizer_stat_report(StatInfo *s) {
- s->addr = GET_CALLER_PC();
-#if defined(_WIN64) && !defined(__clang__)
- uptr old_data = InterlockedIncrement64(reinterpret_cast<LONG64 *>(&s->data));
-#elif defined(_WIN32) && !defined(__clang__)
- uptr old_data = InterlockedIncrement(&s->data);
-#else
- uptr old_data = __sync_fetch_and_add(&s->data, 1);
-#endif
-
- // Overflow check.
- if (CountFromData(old_data + 1) == 0)
- Trap();
-}
Copied: compiler-rt/trunk/lib/stats/stats_client.cpp (from r367550, compiler-rt/trunk/lib/stats/stats_client.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/stats/stats_client.cpp?p2=compiler-rt/trunk/lib/stats/stats_client.cpp&p1=compiler-rt/trunk/lib/stats/stats_client.cc&r1=367550&r2=367551&rev=367551&view=diff
==============================================================================
--- compiler-rt/trunk/lib/stats/stats_client.cc (original)
+++ compiler-rt/trunk/lib/stats/stats_client.cpp Thu Aug 1 05:41:23 2019
@@ -1,4 +1,4 @@
-//===-- stats_client.cc ---------------------------------------------------===//
+//===-- stats_client.cpp --------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Modified: compiler-rt/trunk/lib/ubsan_minimal/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan_minimal/CMakeLists.txt?rev=367551&r1=367550&r2=367551&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan_minimal/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/ubsan_minimal/CMakeLists.txt Thu Aug 1 05:41:23 2019
@@ -1,7 +1,7 @@
# Build for the minimal undefined behavior sanitizer runtime support library.
set(UBSAN_MINIMAL_SOURCES
- ubsan_minimal_handlers.cc
+ ubsan_minimal_handlers.cpp
)
include_directories(..)
Removed: compiler-rt/trunk/lib/ubsan_minimal/ubsan_minimal_handlers.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan_minimal/ubsan_minimal_handlers.cc?rev=367550&view=auto
==============================================================================
--- compiler-rt/trunk/lib/ubsan_minimal/ubsan_minimal_handlers.cc (original)
+++ compiler-rt/trunk/lib/ubsan_minimal/ubsan_minimal_handlers.cc (removed)
@@ -1,119 +0,0 @@
-#include "sanitizer_common/sanitizer_atomic.h"
-
-#include <stdlib.h>
-#include <stdint.h>
-#include <string.h>
-#include <unistd.h>
-
-#ifdef KERNEL_USE
-extern "C" void ubsan_message(const char *msg);
-static void message(const char *msg) { ubsan_message(msg); }
-#else
-static void message(const char *msg) {
- write(2, msg, strlen(msg));
-}
-#endif
-
-static const int kMaxCallerPcs = 20;
-static __sanitizer::atomic_uintptr_t caller_pcs[kMaxCallerPcs];
-// Number of elements in caller_pcs. A special value of kMaxCallerPcs + 1 means
-// that "too many errors" has already been reported.
-static __sanitizer::atomic_uint32_t caller_pcs_sz;
-
-__attribute__((noinline)) static bool report_this_error(void *caller_p) {
- uintptr_t caller = reinterpret_cast<uintptr_t>(caller_p);
- if (caller == 0) return false;
- while (true) {
- unsigned sz = __sanitizer::atomic_load_relaxed(&caller_pcs_sz);
- if (sz > kMaxCallerPcs) return false; // early exit
- // when sz==kMaxCallerPcs print "too many errors", but only when cmpxchg
- // succeeds in order to not print it multiple times.
- if (sz > 0 && sz < kMaxCallerPcs) {
- uintptr_t p;
- for (unsigned i = 0; i < sz; ++i) {
- p = __sanitizer::atomic_load_relaxed(&caller_pcs[i]);
- if (p == 0) break; // Concurrent update.
- if (p == caller) return false;
- }
- if (p == 0) continue; // FIXME: yield?
- }
-
- if (!__sanitizer::atomic_compare_exchange_strong(
- &caller_pcs_sz, &sz, sz + 1, __sanitizer::memory_order_seq_cst))
- continue; // Concurrent update! Try again from the start.
-
- if (sz == kMaxCallerPcs) {
- message("ubsan: too many errors\n");
- return false;
- }
- __sanitizer::atomic_store_relaxed(&caller_pcs[sz], caller);
- return true;
- }
-}
-
-#if defined(__ANDROID__)
-extern "C" __attribute__((weak)) void android_set_abort_message(const char *);
-static void abort_with_message(const char *msg) {
- if (&android_set_abort_message) android_set_abort_message(msg);
- abort();
-}
-#else
-static void abort_with_message(const char *) { abort(); }
-#endif
-
-#if SANITIZER_DEBUG
-namespace __sanitizer {
-// The DCHECK macro needs this symbol to be defined.
-void NORETURN CheckFailed(const char *file, int, const char *cond, u64, u64) {
- message("Sanitizer CHECK failed: ");
- message(file);
- message(":?? : "); // FIXME: Show line number.
- message(cond);
- abort();
-}
-} // namespace __sanitizer
-#endif
-
-#define INTERFACE extern "C" __attribute__((visibility("default")))
-
-// FIXME: add caller pc to the error message (possibly as "ubsan: error-type
-// @1234ABCD").
-#define HANDLER_RECOVER(name, msg) \
- INTERFACE void __ubsan_handle_##name##_minimal() { \
- if (!report_this_error(__builtin_return_address(0))) return; \
- message("ubsan: " msg "\n"); \
- }
-
-#define HANDLER_NORECOVER(name, msg) \
- INTERFACE void __ubsan_handle_##name##_minimal_abort() { \
- message("ubsan: " msg "\n"); \
- abort_with_message("ubsan: " msg); \
- }
-
-#define HANDLER(name, msg) \
- HANDLER_RECOVER(name, msg) \
- HANDLER_NORECOVER(name, msg)
-
-HANDLER(type_mismatch, "type-mismatch")
-HANDLER(alignment_assumption, "alignment-assumption")
-HANDLER(add_overflow, "add-overflow")
-HANDLER(sub_overflow, "sub-overflow")
-HANDLER(mul_overflow, "mul-overflow")
-HANDLER(negate_overflow, "negate-overflow")
-HANDLER(divrem_overflow, "divrem-overflow")
-HANDLER(shift_out_of_bounds, "shift-out-of-bounds")
-HANDLER(out_of_bounds, "out-of-bounds")
-HANDLER_RECOVER(builtin_unreachable, "builtin-unreachable")
-HANDLER_RECOVER(missing_return, "missing-return")
-HANDLER(vla_bound_not_positive, "vla-bound-not-positive")
-HANDLER(float_cast_overflow, "float-cast-overflow")
-HANDLER(load_invalid_value, "load-invalid-value")
-HANDLER(invalid_builtin, "invalid-builtin")
-HANDLER(function_type_mismatch, "function-type-mismatch")
-HANDLER(implicit_conversion, "implicit-conversion")
-HANDLER(nonnull_arg, "nonnull-arg")
-HANDLER(nonnull_return, "nonnull-return")
-HANDLER(nullability_arg, "nullability-arg")
-HANDLER(nullability_return, "nullability-return")
-HANDLER(pointer_overflow, "pointer-overflow")
-HANDLER(cfi_check_fail, "cfi-check-fail")
More information about the llvm-commits
mailing list