gcc/libsanitizer/sanitizer_common/sanitizer_tls_get_addr.h
Max Ostapenko 696d846a56 libsanitizer merge from upstream r250806.
libsanitizer/

2015-10-20  Maxim Ostapenko  <m.ostapenko@partner.samsung.com>

	* All source files: Merge from upstream r250806.
	* configure.ac (link_sanitizer_common): Add -lrt flag.
	* configure.tgt: Enable TSAN and LSAN for aarch64-linux targets.
	Set CXX_ABI_NEEDED=true for darwin.
	* asan/Makefile.am (asan_files): Add new files.
	(DEFS): Add DCAN_SANITIZE_UB=0 and remove unused and legacy
	DASAN_FLEXIBLE_MAPPING_AND_OFFSET=0.
	* asan/Makefile.in: Regenerate.
	* ubsan/Makefile.am (ubsan_files): Add new files.
	(DEFS): Add DCAN_SANITIZE_UB=1.
	(libubsan_la_LIBADD): Add -lc++abi if CXX_ABI_NEEDED is true.
	* ubsan/Makefile.in: Regenerate.
	* tsan/Makefile.am (tsan_files): Add new files.
	(DEFS): Add DCAN_SANITIZE_UB=0.
	* tsan/Makefile.in: Regenerate.
	* sanitizer_common/Makefile.am (sanitizer_common_files): Add new files.
	* sanitizer_common/Makefile.in: Regenerate.
	* asan/libtool-version: Bump the libasan SONAME.

From-SVN: r229111
2015-10-21 10:32:45 +03:00

60 lines
2.0 KiB
C++

//===-- sanitizer_tls_get_addr.h --------------------------------*- C++ -*-===//
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Handle the __tls_get_addr call.
//
// All this magic is specific to glibc and is required to workaround
// the lack of interface that would tell us about the Dynamic TLS (DTLS).
// https://sourceware.org/bugzilla/show_bug.cgi?id=16291
//
// The matters get worse because the glibc implementation changed between
// 2.18 and 2.19:
// https://groups.google.com/forum/#!topic/address-sanitizer/BfwYD8HMxTM
//
// Before 2.19, every DTLS chunk is allocated with __libc_memalign,
// which we intercept and thus know where is the DTLS.
// Since 2.19, DTLS chunks are allocated with __signal_safe_memalign,
// which is an internal function that wraps a mmap call, neither of which
// we can intercept. Luckily, __signal_safe_memalign has a simple parseable
// header which we can use.
//
//===----------------------------------------------------------------------===//
#ifndef SANITIZER_TLS_GET_ADDR_H
#define SANITIZER_TLS_GET_ADDR_H
#include "sanitizer_common.h"
namespace __sanitizer {
struct DTLS {
// Array of DTLS chunks for the current Thread.
// If beg == 0, the chunk is unused.
struct DTV {
uptr beg, size;
};
uptr dtv_size;
DTV *dtv; // dtv_size elements, allocated by MmapOrDie.
// Auxiliary fields, don't access them outside sanitizer_tls_get_addr.cc
uptr last_memalign_size;
uptr last_memalign_ptr;
};
// Returns pointer and size of a linker-allocated TLS block.
// Each block is returned exactly once.
DTLS::DTV *DTLS_on_tls_get_addr(void *arg, void *res, uptr static_tls_begin,
uptr static_tls_end);
void DTLS_on_libc_memalign(void *ptr, uptr size);
DTLS *DTLS_Get();
void DTLS_Destroy(); // Make sure to call this before the thread is destroyed.
} // namespace __sanitizer
#endif // SANITIZER_TLS_GET_ADDR_H