mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-05 02:38:31 +00:00
parent
e961385e55
commit
d71da7fc72
13 changed files with 71 additions and 40 deletions
|
@ -55,11 +55,13 @@ privileged void __morph_tls(void) {
|
|||
// address 0x30 was promised to us, according to Go team
|
||||
// https://github.com/golang/go/issues/23617
|
||||
dis = 0x30;
|
||||
} else {
|
||||
} else if (IsWindows()) {
|
||||
// MSVC __declspec(thread) generates binary code for this
|
||||
// %gs:0x1480 abi. So long as TlsAlloc() isn't called >64
|
||||
// times we should be good.
|
||||
dis = 0x1480 + __tls_index * 8;
|
||||
} else {
|
||||
dis = 0;
|
||||
}
|
||||
|
||||
// iterate over modifiable code looking for 9 byte instruction
|
||||
|
@ -112,6 +114,7 @@ privileged void __morph_tls(void) {
|
|||
}
|
||||
}
|
||||
|
||||
__tls_morphed = true;
|
||||
__morph_end();
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -26,6 +26,9 @@
|
|||
#include "libc/thread/tls.h"
|
||||
#include "libc/thread/tls2.internal.h"
|
||||
|
||||
#define AMD64_SET_FSBASE 129
|
||||
#define AMD64_SET_GSBASE 131
|
||||
|
||||
int sys_set_tls();
|
||||
|
||||
textstartup void __set_tls(struct CosmoTib *tib) {
|
||||
|
@ -36,9 +39,9 @@ textstartup void __set_tls(struct CosmoTib *tib) {
|
|||
npassert(0 <= __tls_index && __tls_index < 64);
|
||||
asm("mov\t%1,%%gs:%0" : "=m"(*((long *)0x1480 + __tls_index)) : "r"(tib));
|
||||
} else if (IsFreebsd()) {
|
||||
sys_set_tls(129 /*AMD64_SET_FSBASE*/, tib);
|
||||
sys_set_tls(__tls_morphed ? AMD64_SET_GSBASE : AMD64_SET_FSBASE, tib);
|
||||
} else if (IsLinux()) {
|
||||
sys_set_tls(ARCH_SET_FS, tib);
|
||||
sys_set_tls(__tls_morphed ? ARCH_SET_GS : ARCH_SET_FS, tib);
|
||||
} else if (IsNetbsd()) {
|
||||
// netbsd has sysarch(X86_SET_FSBASE) but we can't use that because
|
||||
// signal handlers will cause it to be reset due to not setting the
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue