2014-01-29 17:29:16 +08:00
|
|
|
//===-- sanitizer_tls_get_addr.h --------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
2014-05-15 10:22:34 +08:00
|
|
|
// Auxiliary fields, don't access them outside sanitizer_tls_get_addr.cc
|
2014-01-29 17:29:16 +08:00
|
|
|
uptr last_memalign_size;
|
|
|
|
uptr last_memalign_ptr;
|
|
|
|
};
|
|
|
|
|
2014-06-25 19:30:35 +08:00
|
|
|
// Returns pointer and size of a linker-allocated TLS block.
|
|
|
|
// Each block is returned exactly once.
|
2015-05-16 08:34:15 +08:00
|
|
|
DTLS::DTV *DTLS_on_tls_get_addr(void *arg, void *res, uptr static_tls_begin,
|
|
|
|
uptr static_tls_end);
|
2014-01-29 17:29:16 +08:00
|
|
|
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.
|
2017-04-06 15:42:27 +08:00
|
|
|
// Returns true if DTLS of suspended thread is in destruction process.
|
|
|
|
bool DTLSInDestruction(DTLS *dtls);
|
2014-01-29 17:29:16 +08:00
|
|
|
|
|
|
|
} // namespace __sanitizer
|
|
|
|
|
|
|
|
#endif // SANITIZER_TLS_GET_ADDR_H
|