2012-11-22 23:03:11 +01:00
|
|
|
//===-- tsan_platform_linux.cc --------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is a part of ThreadSanitizer (TSan), a race detector.
|
|
|
|
//
|
2014-11-13 21:41:38 +01:00
|
|
|
// Linux- and FreeBSD-specific code.
|
2012-11-22 23:03:11 +01:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-11-04 22:33:31 +01:00
|
|
|
|
|
|
|
#include "sanitizer_common/sanitizer_platform.h"
|
2018-10-31 12:14:23 +01:00
|
|
|
#if SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD
|
2012-11-22 23:03:11 +01:00
|
|
|
|
|
|
|
#include "sanitizer_common/sanitizer_common.h"
|
|
|
|
#include "sanitizer_common/sanitizer_libc.h"
|
2016-11-08 23:04:09 +01:00
|
|
|
#include "sanitizer_common/sanitizer_linux.h"
|
2018-10-31 12:14:23 +01:00
|
|
|
#include "sanitizer_common/sanitizer_platform_limits_netbsd.h"
|
2016-11-08 23:04:09 +01:00
|
|
|
#include "sanitizer_common/sanitizer_platform_limits_posix.h"
|
2015-10-21 09:32:45 +02:00
|
|
|
#include "sanitizer_common/sanitizer_posix.h"
|
2012-11-22 23:03:11 +01:00
|
|
|
#include "sanitizer_common/sanitizer_procmaps.h"
|
2013-12-05 10:18:38 +01:00
|
|
|
#include "sanitizer_common/sanitizer_stoptheworld.h"
|
2014-11-13 21:41:38 +01:00
|
|
|
#include "sanitizer_common/sanitizer_stackdepot.h"
|
2012-11-22 23:03:11 +01:00
|
|
|
#include "tsan_platform.h"
|
|
|
|
#include "tsan_rtl.h"
|
|
|
|
#include "tsan_flags.h"
|
|
|
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <sys/mman.h>
|
2016-11-08 23:04:09 +01:00
|
|
|
#if SANITIZER_LINUX
|
|
|
|
#include <sys/personality.h>
|
|
|
|
#include <setjmp.h>
|
|
|
|
#endif
|
2012-11-22 23:03:11 +01:00
|
|
|
#include <sys/syscall.h>
|
2013-12-05 10:18:38 +01:00
|
|
|
#include <sys/socket.h>
|
2012-11-22 23:03:11 +01:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/resource.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sched.h>
|
|
|
|
#include <dlfcn.h>
|
2014-09-23 19:59:53 +02:00
|
|
|
#if SANITIZER_LINUX
|
2013-02-13 11:46:01 +01:00
|
|
|
#define __need_res_state
|
|
|
|
#include <resolv.h>
|
2014-09-23 19:59:53 +02:00
|
|
|
#endif
|
2012-11-22 23:03:11 +01:00
|
|
|
|
2013-12-05 10:18:38 +01:00
|
|
|
#ifdef sa_handler
|
|
|
|
# undef sa_handler
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef sa_sigaction
|
|
|
|
# undef sa_sigaction
|
|
|
|
#endif
|
|
|
|
|
2014-09-23 19:59:53 +02:00
|
|
|
#if SANITIZER_FREEBSD
|
|
|
|
extern "C" void *__libc_stack_end;
|
|
|
|
void *__libc_stack_end = 0;
|
|
|
|
#endif
|
2012-11-22 23:03:11 +01:00
|
|
|
|
2016-08-12 10:53:07 +02:00
|
|
|
#if SANITIZER_LINUX && defined(__aarch64__)
|
|
|
|
void InitializeGuardPtr() __attribute__((visibility("hidden")));
|
|
|
|
#endif
|
|
|
|
|
2012-11-22 23:03:11 +01:00
|
|
|
namespace __tsan {
|
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
#ifdef TSAN_RUNTIME_VMA
|
|
|
|
// Runtime detected VMA size.
|
|
|
|
uptr vmaSize;
|
|
|
|
#endif
|
2014-11-13 21:41:38 +01:00
|
|
|
|
2014-09-23 19:59:53 +02:00
|
|
|
enum {
|
|
|
|
MemTotal = 0,
|
|
|
|
MemShadow = 1,
|
|
|
|
MemMeta = 2,
|
|
|
|
MemFile = 3,
|
|
|
|
MemMmap = 4,
|
|
|
|
MemTrace = 5,
|
|
|
|
MemHeap = 6,
|
|
|
|
MemOther = 7,
|
|
|
|
MemCount = 8,
|
|
|
|
};
|
|
|
|
|
2014-11-13 21:41:38 +01:00
|
|
|
void FillProfileCallback(uptr p, uptr rss, bool file,
|
2013-11-04 22:33:31 +01:00
|
|
|
uptr *mem, uptr stats_size) {
|
2014-09-23 19:59:53 +02:00
|
|
|
mem[MemTotal] += rss;
|
2016-11-08 23:04:09 +01:00
|
|
|
if (p >= ShadowBeg() && p < ShadowEnd())
|
2014-09-23 19:59:53 +02:00
|
|
|
mem[MemShadow] += rss;
|
2016-11-08 23:04:09 +01:00
|
|
|
else if (p >= MetaShadowBeg() && p < MetaShadowEnd())
|
2014-09-23 19:59:53 +02:00
|
|
|
mem[MemMeta] += rss;
|
2016-11-08 23:04:09 +01:00
|
|
|
#if !SANITIZER_GO
|
|
|
|
else if (p >= HeapMemBeg() && p < HeapMemEnd())
|
2014-11-13 21:41:38 +01:00
|
|
|
mem[MemHeap] += rss;
|
2016-11-08 23:04:09 +01:00
|
|
|
else if (p >= LoAppMemBeg() && p < LoAppMemEnd())
|
2014-09-23 19:59:53 +02:00
|
|
|
mem[file ? MemFile : MemMmap] += rss;
|
2016-11-08 23:04:09 +01:00
|
|
|
else if (p >= HiAppMemBeg() && p < HiAppMemEnd())
|
2014-11-13 21:41:38 +01:00
|
|
|
mem[file ? MemFile : MemMmap] += rss;
|
|
|
|
#else
|
2016-11-08 23:04:09 +01:00
|
|
|
else if (p >= AppMemBeg() && p < AppMemEnd())
|
2014-11-13 21:41:38 +01:00
|
|
|
mem[file ? MemFile : MemMmap] += rss;
|
|
|
|
#endif
|
2016-11-08 23:04:09 +01:00
|
|
|
else if (p >= TraceMemBeg() && p < TraceMemEnd())
|
2014-09-23 19:59:53 +02:00
|
|
|
mem[MemTrace] += rss;
|
|
|
|
else
|
|
|
|
mem[MemOther] += rss;
|
2013-11-04 22:33:31 +01:00
|
|
|
}
|
|
|
|
|
2014-09-23 19:59:53 +02:00
|
|
|
void WriteMemoryProfile(char *buf, uptr buf_size, uptr nthread, uptr nlive) {
|
2016-11-08 23:04:09 +01:00
|
|
|
uptr mem[MemCount];
|
|
|
|
internal_memset(mem, 0, sizeof(mem[0]) * MemCount);
|
2013-11-04 22:33:31 +01:00
|
|
|
__sanitizer::GetMemoryProfile(FillProfileCallback, mem, 7);
|
2014-11-13 21:41:38 +01:00
|
|
|
StackDepotStats *stacks = StackDepotGetStats();
|
2014-09-23 19:59:53 +02:00
|
|
|
internal_snprintf(buf, buf_size,
|
|
|
|
"RSS %zd MB: shadow:%zd meta:%zd file:%zd mmap:%zd"
|
2014-11-13 21:41:38 +01:00
|
|
|
" trace:%zd heap:%zd other:%zd stacks=%zd[%zd] nthr=%zd/%zd\n",
|
2014-09-23 19:59:53 +02:00
|
|
|
mem[MemTotal] >> 20, mem[MemShadow] >> 20, mem[MemMeta] >> 20,
|
|
|
|
mem[MemFile] >> 20, mem[MemMmap] >> 20, mem[MemTrace] >> 20,
|
|
|
|
mem[MemHeap] >> 20, mem[MemOther] >> 20,
|
2014-11-13 21:41:38 +01:00
|
|
|
stacks->allocated >> 20, stacks->n_uniq_ids,
|
2014-09-23 19:59:53 +02:00
|
|
|
nlive, nthread);
|
2012-11-22 23:03:11 +01:00
|
|
|
}
|
|
|
|
|
2014-09-23 19:59:53 +02:00
|
|
|
#if SANITIZER_LINUX
|
2013-12-05 10:18:38 +01:00
|
|
|
void FlushShadowMemoryCallback(
|
|
|
|
const SuspendedThreadsList &suspended_threads_list,
|
|
|
|
void *argument) {
|
ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch builtins...
* ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch
builtins, store max (log2 (align), 0) into uchar field instead of
align into uptr field.
(ubsan_expand_objsize_ifn): Use _v1 suffixed type mismatch builtins,
store uchar 0 field instead of uptr 0 field.
(instrument_nonnull_return): Use _v1 suffixed nonnull return builtin,
instead of passing one address of struct with 2 locations pass
two addresses of structs with 1 location each.
* sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_ABORT): Removed.
(BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1_ABORT): New builtins.
* c-c++-common/ubsan/float-cast-overflow-1.c: Drop value keyword
from expected output regexps.
* c-c++-common/ubsan/float-cast-overflow-2.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-3.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-4.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-5.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-6.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-8.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-9.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-10.c: Likewise.
* g++.dg/ubsan/float-cast-overflow-bf.C: Likewise.
* gcc.dg/ubsan/float-cast-overflow-bf.c: Likewise.
* g++.dg/asan/default-options-1.C (__asan_default_options): Add
used attribute.
* g++.dg/asan/asan_test.C: Run with ASAN_OPTIONS=handle_segv=2
in the environment.
* All source files: Merge from upstream 315899.
* asan/Makefile.am (nodist_saninclude_HEADERS): Add
include/sanitizer/tsan_interface.h.
* asan/libtool-version: Bump the libasan SONAME.
* lsan/Makefile.am (sanitizer_lsan_files): Add lsan_common_mac.cc.
(lsan_files): Add lsan_linux.cc, lsan_mac.cc and lsan_malloc_mac.cc.
* sanitizer_common/Makefile.am (sanitizer_common_files): Add
sancov_flags.cc, sanitizer_allocator_checks.cc,
sanitizer_coverage_libcdep_new.cc, sanitizer_errno.cc,
sanitizer_file.cc, sanitizer_mac_libcdep.cc and
sanitizer_stoptheworld_mac.cc. Remove sanitizer_coverage_libcdep.cc
and sanitizer_coverage_mapping_libcdep.cc.
* tsan/Makefile.am (tsan_files): Add tsan_external.cc.
* ubsan/Makefile.am (DEFS): Add -DUBSAN_CAN_USE_CXXABI=1.
(ubsan_files): Add ubsan_init_standalone.cc and
ubsan_signals_standalone.cc.
* ubsan/libtool-version: Bump the libubsan SONAME.
* asan/Makefile.in: Regenerate.
* lsan/Makefile.in: Regenerate.
* sanitizer_common/Makefile.in: Regenerate.
* tsan/Makefile.in: Regenerate.
* ubsan/Makefile.in: Regenerate.
From-SVN: r253887
2017-10-19 13:23:59 +02:00
|
|
|
ReleaseMemoryPagesToOS(ShadowBeg(), ShadowEnd());
|
2012-11-22 23:03:11 +01:00
|
|
|
}
|
2014-09-23 19:59:53 +02:00
|
|
|
#endif
|
2012-11-22 23:03:11 +01:00
|
|
|
|
2013-12-05 10:18:38 +01:00
|
|
|
void FlushShadowMemory() {
|
2014-09-23 19:59:53 +02:00
|
|
|
#if SANITIZER_LINUX
|
2013-12-05 10:18:38 +01:00
|
|
|
StopTheWorld(FlushShadowMemoryCallback, 0);
|
2014-09-23 19:59:53 +02:00
|
|
|
#endif
|
2013-12-05 10:18:38 +01:00
|
|
|
}
|
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
#if !SANITIZER_GO
|
2013-11-04 22:33:31 +01:00
|
|
|
// Mark shadow for .rodata sections with the special kShadowRodata marker.
|
|
|
|
// Accesses to .rodata can't race, so this saves time, memory and trace space.
|
|
|
|
static void MapRodata() {
|
|
|
|
// First create temp file.
|
|
|
|
const char *tmpdir = GetEnv("TMPDIR");
|
|
|
|
if (tmpdir == 0)
|
|
|
|
tmpdir = GetEnv("TEST_TMPDIR");
|
|
|
|
#ifdef P_tmpdir
|
|
|
|
if (tmpdir == 0)
|
|
|
|
tmpdir = P_tmpdir;
|
|
|
|
#endif
|
|
|
|
if (tmpdir == 0)
|
|
|
|
return;
|
2014-05-22 09:09:21 +02:00
|
|
|
char name[256];
|
|
|
|
internal_snprintf(name, sizeof(name), "%s/tsan.rodata.%d",
|
2013-11-04 22:33:31 +01:00
|
|
|
tmpdir, (int)internal_getpid());
|
2014-05-22 09:09:21 +02:00
|
|
|
uptr openrv = internal_open(name, O_RDWR | O_CREAT | O_EXCL, 0600);
|
2013-11-04 22:33:31 +01:00
|
|
|
if (internal_iserror(openrv))
|
|
|
|
return;
|
2014-05-22 09:09:21 +02:00
|
|
|
internal_unlink(name); // Unlink it now, so that we can reuse the buffer.
|
2013-11-04 22:33:31 +01:00
|
|
|
fd_t fd = openrv;
|
|
|
|
// Fill the file with kShadowRodata.
|
|
|
|
const uptr kMarkerSize = 512 * 1024 / sizeof(u64);
|
2018-10-31 12:14:23 +01:00
|
|
|
InternalMmapVector<u64> marker(kMarkerSize);
|
2014-05-22 09:09:21 +02:00
|
|
|
// volatile to prevent insertion of memset
|
|
|
|
for (volatile u64 *p = marker.data(); p < marker.data() + kMarkerSize; p++)
|
2013-11-04 22:33:31 +01:00
|
|
|
*p = kShadowRodata;
|
2018-10-31 12:14:23 +01:00
|
|
|
internal_write(fd, marker.data(), marker.size() * sizeof(u64));
|
2013-11-04 22:33:31 +01:00
|
|
|
// Map the file into memory.
|
2015-10-21 09:32:45 +02:00
|
|
|
uptr page = internal_mmap(0, GetPageSizeCached(), PROT_READ | PROT_WRITE,
|
2013-11-04 22:33:31 +01:00
|
|
|
MAP_PRIVATE | MAP_ANONYMOUS, fd, 0);
|
|
|
|
if (internal_iserror(page)) {
|
|
|
|
internal_close(fd);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Map the file into shadow of .rodata sections.
|
|
|
|
MemoryMappingLayout proc_maps(/*cache_enabled*/true);
|
2014-05-22 09:09:21 +02:00
|
|
|
// Reusing the buffer 'name'.
|
ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch builtins...
* ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch
builtins, store max (log2 (align), 0) into uchar field instead of
align into uptr field.
(ubsan_expand_objsize_ifn): Use _v1 suffixed type mismatch builtins,
store uchar 0 field instead of uptr 0 field.
(instrument_nonnull_return): Use _v1 suffixed nonnull return builtin,
instead of passing one address of struct with 2 locations pass
two addresses of structs with 1 location each.
* sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_ABORT): Removed.
(BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1_ABORT): New builtins.
* c-c++-common/ubsan/float-cast-overflow-1.c: Drop value keyword
from expected output regexps.
* c-c++-common/ubsan/float-cast-overflow-2.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-3.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-4.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-5.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-6.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-8.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-9.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-10.c: Likewise.
* g++.dg/ubsan/float-cast-overflow-bf.C: Likewise.
* gcc.dg/ubsan/float-cast-overflow-bf.c: Likewise.
* g++.dg/asan/default-options-1.C (__asan_default_options): Add
used attribute.
* g++.dg/asan/asan_test.C: Run with ASAN_OPTIONS=handle_segv=2
in the environment.
* All source files: Merge from upstream 315899.
* asan/Makefile.am (nodist_saninclude_HEADERS): Add
include/sanitizer/tsan_interface.h.
* asan/libtool-version: Bump the libasan SONAME.
* lsan/Makefile.am (sanitizer_lsan_files): Add lsan_common_mac.cc.
(lsan_files): Add lsan_linux.cc, lsan_mac.cc and lsan_malloc_mac.cc.
* sanitizer_common/Makefile.am (sanitizer_common_files): Add
sancov_flags.cc, sanitizer_allocator_checks.cc,
sanitizer_coverage_libcdep_new.cc, sanitizer_errno.cc,
sanitizer_file.cc, sanitizer_mac_libcdep.cc and
sanitizer_stoptheworld_mac.cc. Remove sanitizer_coverage_libcdep.cc
and sanitizer_coverage_mapping_libcdep.cc.
* tsan/Makefile.am (tsan_files): Add tsan_external.cc.
* ubsan/Makefile.am (DEFS): Add -DUBSAN_CAN_USE_CXXABI=1.
(ubsan_files): Add ubsan_init_standalone.cc and
ubsan_signals_standalone.cc.
* ubsan/libtool-version: Bump the libubsan SONAME.
* asan/Makefile.in: Regenerate.
* lsan/Makefile.in: Regenerate.
* sanitizer_common/Makefile.in: Regenerate.
* tsan/Makefile.in: Regenerate.
* ubsan/Makefile.in: Regenerate.
From-SVN: r253887
2017-10-19 13:23:59 +02:00
|
|
|
MemoryMappedSegment segment(name, ARRAY_SIZE(name));
|
|
|
|
while (proc_maps.Next(&segment)) {
|
|
|
|
if (segment.filename[0] != 0 && segment.filename[0] != '[' &&
|
|
|
|
segment.IsReadable() && segment.IsExecutable() &&
|
|
|
|
!segment.IsWritable() && IsAppMem(segment.start)) {
|
2013-11-04 22:33:31 +01:00
|
|
|
// Assume it's .rodata
|
ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch builtins...
* ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch
builtins, store max (log2 (align), 0) into uchar field instead of
align into uptr field.
(ubsan_expand_objsize_ifn): Use _v1 suffixed type mismatch builtins,
store uchar 0 field instead of uptr 0 field.
(instrument_nonnull_return): Use _v1 suffixed nonnull return builtin,
instead of passing one address of struct with 2 locations pass
two addresses of structs with 1 location each.
* sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_ABORT): Removed.
(BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1_ABORT): New builtins.
* c-c++-common/ubsan/float-cast-overflow-1.c: Drop value keyword
from expected output regexps.
* c-c++-common/ubsan/float-cast-overflow-2.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-3.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-4.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-5.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-6.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-8.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-9.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-10.c: Likewise.
* g++.dg/ubsan/float-cast-overflow-bf.C: Likewise.
* gcc.dg/ubsan/float-cast-overflow-bf.c: Likewise.
* g++.dg/asan/default-options-1.C (__asan_default_options): Add
used attribute.
* g++.dg/asan/asan_test.C: Run with ASAN_OPTIONS=handle_segv=2
in the environment.
* All source files: Merge from upstream 315899.
* asan/Makefile.am (nodist_saninclude_HEADERS): Add
include/sanitizer/tsan_interface.h.
* asan/libtool-version: Bump the libasan SONAME.
* lsan/Makefile.am (sanitizer_lsan_files): Add lsan_common_mac.cc.
(lsan_files): Add lsan_linux.cc, lsan_mac.cc and lsan_malloc_mac.cc.
* sanitizer_common/Makefile.am (sanitizer_common_files): Add
sancov_flags.cc, sanitizer_allocator_checks.cc,
sanitizer_coverage_libcdep_new.cc, sanitizer_errno.cc,
sanitizer_file.cc, sanitizer_mac_libcdep.cc and
sanitizer_stoptheworld_mac.cc. Remove sanitizer_coverage_libcdep.cc
and sanitizer_coverage_mapping_libcdep.cc.
* tsan/Makefile.am (tsan_files): Add tsan_external.cc.
* ubsan/Makefile.am (DEFS): Add -DUBSAN_CAN_USE_CXXABI=1.
(ubsan_files): Add ubsan_init_standalone.cc and
ubsan_signals_standalone.cc.
* ubsan/libtool-version: Bump the libubsan SONAME.
* asan/Makefile.in: Regenerate.
* lsan/Makefile.in: Regenerate.
* sanitizer_common/Makefile.in: Regenerate.
* tsan/Makefile.in: Regenerate.
* ubsan/Makefile.in: Regenerate.
From-SVN: r253887
2017-10-19 13:23:59 +02:00
|
|
|
char *shadow_start = (char *)MemToShadow(segment.start);
|
|
|
|
char *shadow_end = (char *)MemToShadow(segment.end);
|
2018-10-31 12:14:23 +01:00
|
|
|
for (char *p = shadow_start; p < shadow_end;
|
|
|
|
p += marker.size() * sizeof(u64)) {
|
|
|
|
internal_mmap(p, Min<uptr>(marker.size() * sizeof(u64), shadow_end - p),
|
2013-11-04 22:33:31 +01:00
|
|
|
PROT_READ, MAP_PRIVATE | MAP_FIXED, fd, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
internal_close(fd);
|
|
|
|
}
|
|
|
|
|
2015-11-23 10:07:18 +01:00
|
|
|
void InitializeShadowMemoryPlatform() {
|
2013-11-04 22:33:31 +01:00
|
|
|
MapRodata();
|
2012-11-22 23:03:11 +01:00
|
|
|
}
|
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
#endif // #if !SANITIZER_GO
|
|
|
|
|
|
|
|
void InitializePlatformEarly() {
|
|
|
|
#ifdef TSAN_RUNTIME_VMA
|
|
|
|
vmaSize =
|
|
|
|
(MostSignificantSetBitIndex(GET_CURRENT_FRAME()) + 1);
|
|
|
|
#if defined(__aarch64__)
|
2018-10-31 12:14:23 +01:00
|
|
|
# if !SANITIZER_GO
|
2016-11-08 23:04:09 +01:00
|
|
|
if (vmaSize != 39 && vmaSize != 42 && vmaSize != 48) {
|
|
|
|
Printf("FATAL: ThreadSanitizer: unsupported VMA range\n");
|
2018-10-31 12:14:23 +01:00
|
|
|
Printf("FATAL: Found %zd - Supported 39, 42 and 48\n", vmaSize);
|
2016-11-08 23:04:09 +01:00
|
|
|
Die();
|
2014-11-13 21:41:38 +01:00
|
|
|
}
|
2018-10-31 12:14:23 +01:00
|
|
|
#else
|
|
|
|
if (vmaSize != 48) {
|
|
|
|
Printf("FATAL: ThreadSanitizer: unsupported VMA range\n");
|
|
|
|
Printf("FATAL: Found %zd - Supported 48\n", vmaSize);
|
|
|
|
Die();
|
|
|
|
}
|
|
|
|
#endif
|
2016-11-08 23:04:09 +01:00
|
|
|
#elif defined(__powerpc64__)
|
2018-10-31 12:14:23 +01:00
|
|
|
# if !SANITIZER_GO
|
2018-08-01 19:17:29 +02:00
|
|
|
if (vmaSize != 44 && vmaSize != 46 && vmaSize != 47) {
|
2016-11-08 23:04:09 +01:00
|
|
|
Printf("FATAL: ThreadSanitizer: unsupported VMA range\n");
|
2018-10-31 12:14:23 +01:00
|
|
|
Printf("FATAL: Found %zd - Supported 44, 46, and 47\n", vmaSize);
|
|
|
|
Die();
|
|
|
|
}
|
|
|
|
# else
|
|
|
|
if (vmaSize != 46 && vmaSize != 47) {
|
|
|
|
Printf("FATAL: ThreadSanitizer: unsupported VMA range\n");
|
|
|
|
Printf("FATAL: Found %zd - Supported 46, and 47\n", vmaSize);
|
2016-11-08 23:04:09 +01:00
|
|
|
Die();
|
2012-11-22 23:03:11 +01:00
|
|
|
}
|
2018-10-31 12:14:23 +01:00
|
|
|
# endif
|
2014-11-13 21:41:38 +01:00
|
|
|
#endif
|
2016-11-08 23:04:09 +01:00
|
|
|
#endif
|
2012-11-22 23:03:11 +01:00
|
|
|
}
|
|
|
|
|
2014-09-23 19:59:53 +02:00
|
|
|
void InitializePlatform() {
|
|
|
|
DisableCoreDumperIfNecessary();
|
2012-11-22 23:03:11 +01:00
|
|
|
|
2013-01-10 13:44:08 +01:00
|
|
|
// Go maps shadow memory lazily and works fine with limited address space.
|
|
|
|
// Unlimited stack is not a problem as well, because the executable
|
|
|
|
// is not compiled with -pie.
|
2016-11-08 23:04:09 +01:00
|
|
|
if (!SANITIZER_GO) {
|
2013-01-10 13:44:08 +01:00
|
|
|
bool reexec = false;
|
|
|
|
// TSan doesn't play well with unlimited stack size (as stack
|
|
|
|
// overlaps with shadow memory). If we detect unlimited stack size,
|
|
|
|
// we re-exec the program with limited stack size as a best effort.
|
2014-09-23 19:59:53 +02:00
|
|
|
if (StackSizeIsUnlimited()) {
|
2013-01-10 13:44:08 +01:00
|
|
|
const uptr kMaxStackSize = 32 * 1024 * 1024;
|
2014-05-22 09:09:21 +02:00
|
|
|
VReport(1, "Program is run with unlimited stack size, which wouldn't "
|
|
|
|
"work with ThreadSanitizer.\n"
|
|
|
|
"Re-execing with stack size limited to %zd bytes.\n",
|
|
|
|
kMaxStackSize);
|
2013-01-10 13:44:08 +01:00
|
|
|
SetStackSizeLimitInBytes(kMaxStackSize);
|
|
|
|
reexec = true;
|
|
|
|
}
|
2012-12-05 14:19:55 +01:00
|
|
|
|
2014-09-23 19:59:53 +02:00
|
|
|
if (!AddressSpaceIsUnlimited()) {
|
2013-01-10 13:44:08 +01:00
|
|
|
Report("WARNING: Program is run with limited virtual address space,"
|
|
|
|
" which wouldn't work with ThreadSanitizer.\n");
|
|
|
|
Report("Re-execing with unlimited virtual address space.\n");
|
2014-09-23 19:59:53 +02:00
|
|
|
SetAddressSpaceUnlimited();
|
2013-01-10 13:44:08 +01:00
|
|
|
reexec = true;
|
|
|
|
}
|
2016-08-12 10:53:07 +02:00
|
|
|
#if SANITIZER_LINUX && defined(__aarch64__)
|
2016-11-08 23:04:09 +01:00
|
|
|
// After patch "arm64: mm: support ARCH_MMAP_RND_BITS." is introduced in
|
|
|
|
// linux kernel, the random gap between stack and mapped area is increased
|
|
|
|
// from 128M to 36G on 39-bit aarch64. As it is almost impossible to cover
|
|
|
|
// this big range, we should disable randomized virtual space on aarch64.
|
|
|
|
int old_personality = personality(0xffffffff);
|
|
|
|
if (old_personality != -1 && (old_personality & ADDR_NO_RANDOMIZE) == 0) {
|
|
|
|
VReport(1, "WARNING: Program is run with randomized virtual address "
|
|
|
|
"space, which wouldn't work with ThreadSanitizer.\n"
|
|
|
|
"Re-execing with fixed virtual address space.\n");
|
|
|
|
CHECK_NE(personality(old_personality | ADDR_NO_RANDOMIZE), -1);
|
|
|
|
reexec = true;
|
|
|
|
}
|
2016-08-12 10:53:07 +02:00
|
|
|
// Initialize the guard pointer used in {sig}{set,long}jump.
|
|
|
|
InitializeGuardPtr();
|
|
|
|
#endif
|
2013-01-10 13:44:08 +01:00
|
|
|
if (reexec)
|
|
|
|
ReExec();
|
|
|
|
}
|
2012-12-05 14:19:55 +01:00
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
#if !SANITIZER_GO
|
2014-11-13 21:41:38 +01:00
|
|
|
CheckAndProtect();
|
2013-11-04 22:33:31 +01:00
|
|
|
InitTlsSize();
|
2012-11-22 23:03:11 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
#if !SANITIZER_GO
|
2013-12-05 10:18:38 +01:00
|
|
|
// Extract file descriptors passed to glibc internal __res_iclose function.
|
|
|
|
// This is required to properly "close" the fds, because we do not see internal
|
|
|
|
// closes within glibc. The code is a pure hack.
|
2013-02-13 11:46:01 +01:00
|
|
|
int ExtractResolvFDs(void *state, int *fds, int nfd) {
|
2016-11-08 23:04:09 +01:00
|
|
|
#if SANITIZER_LINUX && !SANITIZER_ANDROID
|
2013-02-13 11:46:01 +01:00
|
|
|
int cnt = 0;
|
2017-07-14 11:10:45 +02:00
|
|
|
struct __res_state *statp = (struct __res_state*)state;
|
2013-02-13 11:46:01 +01:00
|
|
|
for (int i = 0; i < MAXNS && cnt < nfd; i++) {
|
|
|
|
if (statp->_u._ext.nsaddrs[i] && statp->_u._ext.nssocks[i] != -1)
|
|
|
|
fds[cnt++] = statp->_u._ext.nssocks[i];
|
|
|
|
}
|
|
|
|
return cnt;
|
2014-09-23 19:59:53 +02:00
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
2013-02-13 11:46:01 +01:00
|
|
|
}
|
2013-12-05 10:18:38 +01:00
|
|
|
|
|
|
|
// Extract file descriptors passed via UNIX domain sockets.
|
|
|
|
// This is requried to properly handle "open" of these fds.
|
|
|
|
// see 'man recvmsg' and 'man 3 cmsg'.
|
|
|
|
int ExtractRecvmsgFDs(void *msgp, int *fds, int nfd) {
|
|
|
|
int res = 0;
|
|
|
|
msghdr *msg = (msghdr*)msgp;
|
|
|
|
struct cmsghdr *cmsg = CMSG_FIRSTHDR(msg);
|
|
|
|
for (; cmsg; cmsg = CMSG_NXTHDR(msg, cmsg)) {
|
|
|
|
if (cmsg->cmsg_level != SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS)
|
|
|
|
continue;
|
|
|
|
int n = (cmsg->cmsg_len - CMSG_LEN(0)) / sizeof(fds[0]);
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
fds[res++] = ((int*)CMSG_DATA(cmsg))[i];
|
|
|
|
if (res == nfd)
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
2013-02-13 11:46:01 +01:00
|
|
|
|
ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch builtins...
* ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch
builtins, store max (log2 (align), 0) into uchar field instead of
align into uptr field.
(ubsan_expand_objsize_ifn): Use _v1 suffixed type mismatch builtins,
store uchar 0 field instead of uptr 0 field.
(instrument_nonnull_return): Use _v1 suffixed nonnull return builtin,
instead of passing one address of struct with 2 locations pass
two addresses of structs with 1 location each.
* sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_ABORT): Removed.
(BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1_ABORT): New builtins.
* c-c++-common/ubsan/float-cast-overflow-1.c: Drop value keyword
from expected output regexps.
* c-c++-common/ubsan/float-cast-overflow-2.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-3.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-4.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-5.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-6.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-8.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-9.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-10.c: Likewise.
* g++.dg/ubsan/float-cast-overflow-bf.C: Likewise.
* gcc.dg/ubsan/float-cast-overflow-bf.c: Likewise.
* g++.dg/asan/default-options-1.C (__asan_default_options): Add
used attribute.
* g++.dg/asan/asan_test.C: Run with ASAN_OPTIONS=handle_segv=2
in the environment.
* All source files: Merge from upstream 315899.
* asan/Makefile.am (nodist_saninclude_HEADERS): Add
include/sanitizer/tsan_interface.h.
* asan/libtool-version: Bump the libasan SONAME.
* lsan/Makefile.am (sanitizer_lsan_files): Add lsan_common_mac.cc.
(lsan_files): Add lsan_linux.cc, lsan_mac.cc and lsan_malloc_mac.cc.
* sanitizer_common/Makefile.am (sanitizer_common_files): Add
sancov_flags.cc, sanitizer_allocator_checks.cc,
sanitizer_coverage_libcdep_new.cc, sanitizer_errno.cc,
sanitizer_file.cc, sanitizer_mac_libcdep.cc and
sanitizer_stoptheworld_mac.cc. Remove sanitizer_coverage_libcdep.cc
and sanitizer_coverage_mapping_libcdep.cc.
* tsan/Makefile.am (tsan_files): Add tsan_external.cc.
* ubsan/Makefile.am (DEFS): Add -DUBSAN_CAN_USE_CXXABI=1.
(ubsan_files): Add ubsan_init_standalone.cc and
ubsan_signals_standalone.cc.
* ubsan/libtool-version: Bump the libubsan SONAME.
* asan/Makefile.in: Regenerate.
* lsan/Makefile.in: Regenerate.
* sanitizer_common/Makefile.in: Regenerate.
* tsan/Makefile.in: Regenerate.
* ubsan/Makefile.in: Regenerate.
From-SVN: r253887
2017-10-19 13:23:59 +02:00
|
|
|
void ImitateTlsWrite(ThreadState *thr, uptr tls_addr, uptr tls_size) {
|
|
|
|
// Check that the thr object is in tls;
|
|
|
|
const uptr thr_beg = (uptr)thr;
|
|
|
|
const uptr thr_end = (uptr)thr + sizeof(*thr);
|
|
|
|
CHECK_GE(thr_beg, tls_addr);
|
|
|
|
CHECK_LE(thr_beg, tls_addr + tls_size);
|
|
|
|
CHECK_GE(thr_end, tls_addr);
|
|
|
|
CHECK_LE(thr_end, tls_addr + tls_size);
|
|
|
|
// Since the thr object is huge, skip it.
|
|
|
|
MemoryRangeImitateWrite(thr, /*pc=*/2, tls_addr, thr_beg - tls_addr);
|
|
|
|
MemoryRangeImitateWrite(thr, /*pc=*/2, thr_end,
|
|
|
|
tls_addr + tls_size - thr_end);
|
|
|
|
}
|
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
// Note: this function runs with async signals enabled,
|
|
|
|
// so it must not touch any tsan state.
|
2014-05-22 09:09:21 +02:00
|
|
|
int call_pthread_cancel_with_cleanup(int(*fn)(void *c, void *m,
|
|
|
|
void *abstime), void *c, void *m, void *abstime,
|
|
|
|
void(*cleanup)(void *arg), void *arg) {
|
|
|
|
// pthread_cleanup_push/pop are hardcore macros mess.
|
|
|
|
// We can't intercept nor call them w/o including pthread.h.
|
|
|
|
int res;
|
|
|
|
pthread_cleanup_push(cleanup, arg);
|
|
|
|
res = fn(c, m, abstime);
|
|
|
|
pthread_cleanup_pop(0);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
#endif
|
2013-02-13 11:46:01 +01:00
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
#if !SANITIZER_GO
|
2015-11-23 10:07:18 +01:00
|
|
|
void ReplaceSystemMalloc() { }
|
|
|
|
#endif
|
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
#if !SANITIZER_GO
|
|
|
|
#if SANITIZER_ANDROID
|
|
|
|
// On Android, one thread can call intercepted functions after
|
|
|
|
// DestroyThreadState(), so add a fake thread state for "dead" threads.
|
|
|
|
static ThreadState *dead_thread_state = nullptr;
|
|
|
|
|
|
|
|
ThreadState *cur_thread() {
|
ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch builtins...
* ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch
builtins, store max (log2 (align), 0) into uchar field instead of
align into uptr field.
(ubsan_expand_objsize_ifn): Use _v1 suffixed type mismatch builtins,
store uchar 0 field instead of uptr 0 field.
(instrument_nonnull_return): Use _v1 suffixed nonnull return builtin,
instead of passing one address of struct with 2 locations pass
two addresses of structs with 1 location each.
* sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_ABORT): Removed.
(BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1_ABORT): New builtins.
* c-c++-common/ubsan/float-cast-overflow-1.c: Drop value keyword
from expected output regexps.
* c-c++-common/ubsan/float-cast-overflow-2.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-3.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-4.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-5.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-6.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-8.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-9.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-10.c: Likewise.
* g++.dg/ubsan/float-cast-overflow-bf.C: Likewise.
* gcc.dg/ubsan/float-cast-overflow-bf.c: Likewise.
* g++.dg/asan/default-options-1.C (__asan_default_options): Add
used attribute.
* g++.dg/asan/asan_test.C: Run with ASAN_OPTIONS=handle_segv=2
in the environment.
* All source files: Merge from upstream 315899.
* asan/Makefile.am (nodist_saninclude_HEADERS): Add
include/sanitizer/tsan_interface.h.
* asan/libtool-version: Bump the libasan SONAME.
* lsan/Makefile.am (sanitizer_lsan_files): Add lsan_common_mac.cc.
(lsan_files): Add lsan_linux.cc, lsan_mac.cc and lsan_malloc_mac.cc.
* sanitizer_common/Makefile.am (sanitizer_common_files): Add
sancov_flags.cc, sanitizer_allocator_checks.cc,
sanitizer_coverage_libcdep_new.cc, sanitizer_errno.cc,
sanitizer_file.cc, sanitizer_mac_libcdep.cc and
sanitizer_stoptheworld_mac.cc. Remove sanitizer_coverage_libcdep.cc
and sanitizer_coverage_mapping_libcdep.cc.
* tsan/Makefile.am (tsan_files): Add tsan_external.cc.
* ubsan/Makefile.am (DEFS): Add -DUBSAN_CAN_USE_CXXABI=1.
(ubsan_files): Add ubsan_init_standalone.cc and
ubsan_signals_standalone.cc.
* ubsan/libtool-version: Bump the libubsan SONAME.
* asan/Makefile.in: Regenerate.
* lsan/Makefile.in: Regenerate.
* sanitizer_common/Makefile.in: Regenerate.
* tsan/Makefile.in: Regenerate.
* ubsan/Makefile.in: Regenerate.
From-SVN: r253887
2017-10-19 13:23:59 +02:00
|
|
|
ThreadState* thr = reinterpret_cast<ThreadState*>(*get_android_tls_ptr());
|
2016-11-08 23:04:09 +01:00
|
|
|
if (thr == nullptr) {
|
|
|
|
__sanitizer_sigset_t emptyset;
|
|
|
|
internal_sigfillset(&emptyset);
|
|
|
|
__sanitizer_sigset_t oldset;
|
|
|
|
CHECK_EQ(0, internal_sigprocmask(SIG_SETMASK, &emptyset, &oldset));
|
ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch builtins...
* ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch
builtins, store max (log2 (align), 0) into uchar field instead of
align into uptr field.
(ubsan_expand_objsize_ifn): Use _v1 suffixed type mismatch builtins,
store uchar 0 field instead of uptr 0 field.
(instrument_nonnull_return): Use _v1 suffixed nonnull return builtin,
instead of passing one address of struct with 2 locations pass
two addresses of structs with 1 location each.
* sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_ABORT): Removed.
(BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1_ABORT): New builtins.
* c-c++-common/ubsan/float-cast-overflow-1.c: Drop value keyword
from expected output regexps.
* c-c++-common/ubsan/float-cast-overflow-2.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-3.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-4.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-5.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-6.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-8.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-9.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-10.c: Likewise.
* g++.dg/ubsan/float-cast-overflow-bf.C: Likewise.
* gcc.dg/ubsan/float-cast-overflow-bf.c: Likewise.
* g++.dg/asan/default-options-1.C (__asan_default_options): Add
used attribute.
* g++.dg/asan/asan_test.C: Run with ASAN_OPTIONS=handle_segv=2
in the environment.
* All source files: Merge from upstream 315899.
* asan/Makefile.am (nodist_saninclude_HEADERS): Add
include/sanitizer/tsan_interface.h.
* asan/libtool-version: Bump the libasan SONAME.
* lsan/Makefile.am (sanitizer_lsan_files): Add lsan_common_mac.cc.
(lsan_files): Add lsan_linux.cc, lsan_mac.cc and lsan_malloc_mac.cc.
* sanitizer_common/Makefile.am (sanitizer_common_files): Add
sancov_flags.cc, sanitizer_allocator_checks.cc,
sanitizer_coverage_libcdep_new.cc, sanitizer_errno.cc,
sanitizer_file.cc, sanitizer_mac_libcdep.cc and
sanitizer_stoptheworld_mac.cc. Remove sanitizer_coverage_libcdep.cc
and sanitizer_coverage_mapping_libcdep.cc.
* tsan/Makefile.am (tsan_files): Add tsan_external.cc.
* ubsan/Makefile.am (DEFS): Add -DUBSAN_CAN_USE_CXXABI=1.
(ubsan_files): Add ubsan_init_standalone.cc and
ubsan_signals_standalone.cc.
* ubsan/libtool-version: Bump the libubsan SONAME.
* asan/Makefile.in: Regenerate.
* lsan/Makefile.in: Regenerate.
* sanitizer_common/Makefile.in: Regenerate.
* tsan/Makefile.in: Regenerate.
* ubsan/Makefile.in: Regenerate.
From-SVN: r253887
2017-10-19 13:23:59 +02:00
|
|
|
thr = reinterpret_cast<ThreadState*>(*get_android_tls_ptr());
|
2016-11-08 23:04:09 +01:00
|
|
|
if (thr == nullptr) {
|
|
|
|
thr = reinterpret_cast<ThreadState*>(MmapOrDie(sizeof(ThreadState),
|
|
|
|
"ThreadState"));
|
ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch builtins...
* ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch
builtins, store max (log2 (align), 0) into uchar field instead of
align into uptr field.
(ubsan_expand_objsize_ifn): Use _v1 suffixed type mismatch builtins,
store uchar 0 field instead of uptr 0 field.
(instrument_nonnull_return): Use _v1 suffixed nonnull return builtin,
instead of passing one address of struct with 2 locations pass
two addresses of structs with 1 location each.
* sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_ABORT): Removed.
(BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1_ABORT): New builtins.
* c-c++-common/ubsan/float-cast-overflow-1.c: Drop value keyword
from expected output regexps.
* c-c++-common/ubsan/float-cast-overflow-2.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-3.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-4.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-5.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-6.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-8.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-9.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-10.c: Likewise.
* g++.dg/ubsan/float-cast-overflow-bf.C: Likewise.
* gcc.dg/ubsan/float-cast-overflow-bf.c: Likewise.
* g++.dg/asan/default-options-1.C (__asan_default_options): Add
used attribute.
* g++.dg/asan/asan_test.C: Run with ASAN_OPTIONS=handle_segv=2
in the environment.
* All source files: Merge from upstream 315899.
* asan/Makefile.am (nodist_saninclude_HEADERS): Add
include/sanitizer/tsan_interface.h.
* asan/libtool-version: Bump the libasan SONAME.
* lsan/Makefile.am (sanitizer_lsan_files): Add lsan_common_mac.cc.
(lsan_files): Add lsan_linux.cc, lsan_mac.cc and lsan_malloc_mac.cc.
* sanitizer_common/Makefile.am (sanitizer_common_files): Add
sancov_flags.cc, sanitizer_allocator_checks.cc,
sanitizer_coverage_libcdep_new.cc, sanitizer_errno.cc,
sanitizer_file.cc, sanitizer_mac_libcdep.cc and
sanitizer_stoptheworld_mac.cc. Remove sanitizer_coverage_libcdep.cc
and sanitizer_coverage_mapping_libcdep.cc.
* tsan/Makefile.am (tsan_files): Add tsan_external.cc.
* ubsan/Makefile.am (DEFS): Add -DUBSAN_CAN_USE_CXXABI=1.
(ubsan_files): Add ubsan_init_standalone.cc and
ubsan_signals_standalone.cc.
* ubsan/libtool-version: Bump the libubsan SONAME.
* asan/Makefile.in: Regenerate.
* lsan/Makefile.in: Regenerate.
* sanitizer_common/Makefile.in: Regenerate.
* tsan/Makefile.in: Regenerate.
* ubsan/Makefile.in: Regenerate.
From-SVN: r253887
2017-10-19 13:23:59 +02:00
|
|
|
*get_android_tls_ptr() = reinterpret_cast<uptr>(thr);
|
2016-11-08 23:04:09 +01:00
|
|
|
if (dead_thread_state == nullptr) {
|
|
|
|
dead_thread_state = reinterpret_cast<ThreadState*>(
|
|
|
|
MmapOrDie(sizeof(ThreadState), "ThreadState"));
|
|
|
|
dead_thread_state->fast_state.SetIgnoreBit();
|
|
|
|
dead_thread_state->ignore_interceptors = 1;
|
|
|
|
dead_thread_state->is_dead = true;
|
|
|
|
*const_cast<int*>(&dead_thread_state->tid) = -1;
|
|
|
|
CHECK_EQ(0, internal_mprotect(dead_thread_state, sizeof(ThreadState),
|
|
|
|
PROT_READ));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CHECK_EQ(0, internal_sigprocmask(SIG_SETMASK, &oldset, nullptr));
|
|
|
|
}
|
|
|
|
return thr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cur_thread_finalize() {
|
|
|
|
__sanitizer_sigset_t emptyset;
|
|
|
|
internal_sigfillset(&emptyset);
|
|
|
|
__sanitizer_sigset_t oldset;
|
|
|
|
CHECK_EQ(0, internal_sigprocmask(SIG_SETMASK, &emptyset, &oldset));
|
ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch builtins...
* ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch
builtins, store max (log2 (align), 0) into uchar field instead of
align into uptr field.
(ubsan_expand_objsize_ifn): Use _v1 suffixed type mismatch builtins,
store uchar 0 field instead of uptr 0 field.
(instrument_nonnull_return): Use _v1 suffixed nonnull return builtin,
instead of passing one address of struct with 2 locations pass
two addresses of structs with 1 location each.
* sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_ABORT): Removed.
(BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1_ABORT): New builtins.
* c-c++-common/ubsan/float-cast-overflow-1.c: Drop value keyword
from expected output regexps.
* c-c++-common/ubsan/float-cast-overflow-2.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-3.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-4.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-5.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-6.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-8.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-9.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-10.c: Likewise.
* g++.dg/ubsan/float-cast-overflow-bf.C: Likewise.
* gcc.dg/ubsan/float-cast-overflow-bf.c: Likewise.
* g++.dg/asan/default-options-1.C (__asan_default_options): Add
used attribute.
* g++.dg/asan/asan_test.C: Run with ASAN_OPTIONS=handle_segv=2
in the environment.
* All source files: Merge from upstream 315899.
* asan/Makefile.am (nodist_saninclude_HEADERS): Add
include/sanitizer/tsan_interface.h.
* asan/libtool-version: Bump the libasan SONAME.
* lsan/Makefile.am (sanitizer_lsan_files): Add lsan_common_mac.cc.
(lsan_files): Add lsan_linux.cc, lsan_mac.cc and lsan_malloc_mac.cc.
* sanitizer_common/Makefile.am (sanitizer_common_files): Add
sancov_flags.cc, sanitizer_allocator_checks.cc,
sanitizer_coverage_libcdep_new.cc, sanitizer_errno.cc,
sanitizer_file.cc, sanitizer_mac_libcdep.cc and
sanitizer_stoptheworld_mac.cc. Remove sanitizer_coverage_libcdep.cc
and sanitizer_coverage_mapping_libcdep.cc.
* tsan/Makefile.am (tsan_files): Add tsan_external.cc.
* ubsan/Makefile.am (DEFS): Add -DUBSAN_CAN_USE_CXXABI=1.
(ubsan_files): Add ubsan_init_standalone.cc and
ubsan_signals_standalone.cc.
* ubsan/libtool-version: Bump the libubsan SONAME.
* asan/Makefile.in: Regenerate.
* lsan/Makefile.in: Regenerate.
* sanitizer_common/Makefile.in: Regenerate.
* tsan/Makefile.in: Regenerate.
* ubsan/Makefile.in: Regenerate.
From-SVN: r253887
2017-10-19 13:23:59 +02:00
|
|
|
ThreadState* thr = reinterpret_cast<ThreadState*>(*get_android_tls_ptr());
|
2016-11-08 23:04:09 +01:00
|
|
|
if (thr != dead_thread_state) {
|
ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch builtins...
* ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch
builtins, store max (log2 (align), 0) into uchar field instead of
align into uptr field.
(ubsan_expand_objsize_ifn): Use _v1 suffixed type mismatch builtins,
store uchar 0 field instead of uptr 0 field.
(instrument_nonnull_return): Use _v1 suffixed nonnull return builtin,
instead of passing one address of struct with 2 locations pass
two addresses of structs with 1 location each.
* sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_ABORT): Removed.
(BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1_ABORT): New builtins.
* c-c++-common/ubsan/float-cast-overflow-1.c: Drop value keyword
from expected output regexps.
* c-c++-common/ubsan/float-cast-overflow-2.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-3.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-4.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-5.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-6.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-8.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-9.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-10.c: Likewise.
* g++.dg/ubsan/float-cast-overflow-bf.C: Likewise.
* gcc.dg/ubsan/float-cast-overflow-bf.c: Likewise.
* g++.dg/asan/default-options-1.C (__asan_default_options): Add
used attribute.
* g++.dg/asan/asan_test.C: Run with ASAN_OPTIONS=handle_segv=2
in the environment.
* All source files: Merge from upstream 315899.
* asan/Makefile.am (nodist_saninclude_HEADERS): Add
include/sanitizer/tsan_interface.h.
* asan/libtool-version: Bump the libasan SONAME.
* lsan/Makefile.am (sanitizer_lsan_files): Add lsan_common_mac.cc.
(lsan_files): Add lsan_linux.cc, lsan_mac.cc and lsan_malloc_mac.cc.
* sanitizer_common/Makefile.am (sanitizer_common_files): Add
sancov_flags.cc, sanitizer_allocator_checks.cc,
sanitizer_coverage_libcdep_new.cc, sanitizer_errno.cc,
sanitizer_file.cc, sanitizer_mac_libcdep.cc and
sanitizer_stoptheworld_mac.cc. Remove sanitizer_coverage_libcdep.cc
and sanitizer_coverage_mapping_libcdep.cc.
* tsan/Makefile.am (tsan_files): Add tsan_external.cc.
* ubsan/Makefile.am (DEFS): Add -DUBSAN_CAN_USE_CXXABI=1.
(ubsan_files): Add ubsan_init_standalone.cc and
ubsan_signals_standalone.cc.
* ubsan/libtool-version: Bump the libubsan SONAME.
* asan/Makefile.in: Regenerate.
* lsan/Makefile.in: Regenerate.
* sanitizer_common/Makefile.in: Regenerate.
* tsan/Makefile.in: Regenerate.
* ubsan/Makefile.in: Regenerate.
From-SVN: r253887
2017-10-19 13:23:59 +02:00
|
|
|
*get_android_tls_ptr() = reinterpret_cast<uptr>(dead_thread_state);
|
2016-11-08 23:04:09 +01:00
|
|
|
UnmapOrDie(thr, sizeof(ThreadState));
|
|
|
|
}
|
|
|
|
CHECK_EQ(0, internal_sigprocmask(SIG_SETMASK, &oldset, nullptr));
|
|
|
|
}
|
|
|
|
#endif // SANITIZER_ANDROID
|
|
|
|
#endif // if !SANITIZER_GO
|
|
|
|
|
2012-11-22 23:03:11 +01:00
|
|
|
} // namespace __tsan
|
|
|
|
|
2018-10-31 12:14:23 +01:00
|
|
|
#endif // SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD
|