Created
May 8, 2018 17:37
-
-
Save jhurliman/2598ea8fc9f0ca18a556db2b91839fac to your computer and use it in GitHub Desktop.
Directly access a compiler-generated Thread Local Storage guard variable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Tested with clang-6.0 on Ubuntu 14.04 using: | |
// clang --std=c++14 -stdlib=libstdc++ -lstcd++ -fasm-blocks -O3 tls_guardvar.cpp -o tls_guardvar | |
// I will be genuinely surprised if this works in any other circumstance. | |
#include <iostream> | |
struct S { | |
int x; | |
S() { x = 42; } | |
}; | |
int main() { | |
uint32_t value1; | |
uint32_t value2; | |
__asm { | |
mov eax, fs:[0xfffffffffffffffc] | |
mov value1, eax | |
} | |
static thread_local S s; | |
__asm { | |
mov eax, fs:[0xfffffffffffffffc] | |
mov value2, eax | |
} | |
std::cout << "value1=" << value1 << ", value2=" << value2 << ", s.x=" << s.x << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment