aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Support/Windows/ThreadLocal.inc
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2012-06-12 00:21:31 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2012-06-12 00:21:31 +0000
commit793537d21f8aa46458a5733d96816ba8bddeef50 (patch)
tree441f269114a3f3b693c2f8fb15ad7fef979f2562 /lib/Support/Windows/ThreadLocal.inc
parent0eb3a3524e9d68642e574780d19c781386ed4469 (diff)
downloadexternal_llvm-793537d21f8aa46458a5733d96816ba8bddeef50.zip
external_llvm-793537d21f8aa46458a5733d96816ba8bddeef50.tar.gz
external_llvm-793537d21f8aa46458a5733d96816ba8bddeef50.tar.bz2
For llvm::sys::ThreadLocalImpl instead of malloc'ing the platform-specific
thread local data, embed them in the class using a uint64_t and make sure we get compiler errors if there's a platform where this is not big enough. This makes ThreadLocal more safe for using it in conjunction with CrashRecoveryContext. Related to crash in rdar://11434201. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158342 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/Windows/ThreadLocal.inc')
-rw-r--r--lib/Support/Windows/ThreadLocal.inc13
1 files changed, 6 insertions, 7 deletions
diff --git a/lib/Support/Windows/ThreadLocal.inc b/lib/Support/Windows/ThreadLocal.inc
index 512462d..99c6f4f 100644
--- a/lib/Support/Windows/ThreadLocal.inc
+++ b/lib/Support/Windows/ThreadLocal.inc
@@ -22,26 +22,25 @@
namespace llvm {
using namespace sys;
-ThreadLocalImpl::ThreadLocalImpl() {
- DWORD* tls = new DWORD;
+ThreadLocalImpl::ThreadLocalImpl() : data(0) {
+ typedef int SIZE_TOO_BIG[sizeof(DWORD) <= sizeof(data) ? 1 : -1];
+ DWORD* tls = reinterpret_cast<DWORD*>(&data);
*tls = TlsAlloc();
assert(*tls != TLS_OUT_OF_INDEXES);
- data = tls;
}
ThreadLocalImpl::~ThreadLocalImpl() {
- DWORD* tls = static_cast<DWORD*>(data);
+ DWORD* tls = reinterpret_cast<DWORD*>(&data);
TlsFree(*tls);
- delete tls;
}
const void* ThreadLocalImpl::getInstance() {
- DWORD* tls = static_cast<DWORD*>(data);
+ DWORD* tls = reinterpret_cast<DWORD*>(&data);
return TlsGetValue(*tls);
}
void ThreadLocalImpl::setInstance(const void* d){
- DWORD* tls = static_cast<DWORD*>(data);
+ DWORD* tls = reinterpret_cast<DWORD*>(&data);
int errorcode = TlsSetValue(*tls, const_cast<void*>(d));
assert(errorcode != 0);
(void)errorcode;