mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-02 01:08:32 +00:00
Complete the Windows TLS fix made in e437bed00
This commit is contained in:
parent
72511ff0ac
commit
61370983e1
1 changed files with 17 additions and 14 deletions
|
@ -141,24 +141,23 @@ textstartup void __enable_tls(void) {
|
||||||
size_t siz = ROUNDUP(I(_tls_size) + sizeof(struct CosmoTib), TLS_ALIGNMENT);
|
size_t siz = ROUNDUP(I(_tls_size) + sizeof(struct CosmoTib), TLS_ALIGNMENT);
|
||||||
if (siz <= sizeof(__static_tls)) {
|
if (siz <= sizeof(__static_tls)) {
|
||||||
// if tls requirement is small then use the static tls block
|
// if tls requirement is small then use the static tls block
|
||||||
// which helps avoid a system call for appes with little tls
|
// which helps avoid a system call for apes with little tls.
|
||||||
// this is crucial to keeping life.com 16 kilobytes in size!
|
// this is crucial to keeping life.com 16 kilobytes in size!
|
||||||
mem = __static_tls;
|
mem = __static_tls;
|
||||||
} else {
|
} else {
|
||||||
// if this binary needs a hefty tls block then we'll bank on
|
// if a binary needs this much thread_local storage, then it
|
||||||
// malloc() being linked, which links _mapanon(). otherwise
|
// surely must have linked the mmap() function at some point
|
||||||
// if you exceed this, you need to __static_yoink("_mapanon").
|
// we can't call mmap() because it's too early for sig block
|
||||||
// please note that it's probably too early to call calloc()
|
mem = _weaken(__mmap)(0, siz, PROT_READ | PROT_WRITE,
|
||||||
mem = _weaken(_mapanon)(siz);
|
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct CosmoTib *tib = (struct CosmoTib *)(mem + siz - sizeof(*tib));
|
struct CosmoTib *tib = (struct CosmoTib *)(mem + siz - sizeof(*tib));
|
||||||
char *tls = mem + siz - sizeof(*tib) - I(_tls_size);
|
char *tls = mem + siz - sizeof(*tib) - I(_tls_size);
|
||||||
|
|
||||||
// copy in initialized data section
|
// copy in initialized data section
|
||||||
if (I(_tdata_size)) {
|
if (I(_tdata_size))
|
||||||
memcpy(tls, _tdata_start, I(_tdata_size));
|
memcpy(tls, _tdata_start, I(_tdata_size));
|
||||||
}
|
|
||||||
|
|
||||||
#elif defined(__aarch64__)
|
#elif defined(__aarch64__)
|
||||||
|
|
||||||
|
@ -169,10 +168,16 @@ textstartup void __enable_tls(void) {
|
||||||
|
|
||||||
char *mem;
|
char *mem;
|
||||||
if (I(_tls_align) <= TLS_ALIGNMENT && size <= sizeof(__static_tls)) {
|
if (I(_tls_align) <= TLS_ALIGNMENT && size <= sizeof(__static_tls)) {
|
||||||
|
// if tls requirement is small then use the static tls block
|
||||||
|
// which helps avoid a system call for apes with little tls.
|
||||||
|
// this is crucial to keeping life.com 16 kilobytes in size!
|
||||||
mem = __static_tls;
|
mem = __static_tls;
|
||||||
} else {
|
} else {
|
||||||
mem = __mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS,
|
// if a binary needs this much thread_local storage, then it
|
||||||
-1, 0);
|
// surely must have linked the mmap() function at some point
|
||||||
|
// we can't call mmap() because it's too early for sig block
|
||||||
|
mem = _weaken(__mmap)(0, size, PROT_READ | PROT_WRITE,
|
||||||
|
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct CosmoTib *tib =
|
struct CosmoTib *tib =
|
||||||
|
@ -184,9 +189,8 @@ textstartup void __enable_tls(void) {
|
||||||
size_t dtv_size = sizeof(uintptr_t) * 2;
|
size_t dtv_size = sizeof(uintptr_t) * 2;
|
||||||
|
|
||||||
char *tdata = (char *)dtv + ROUNDUP(dtv_size, I(_tdata_align));
|
char *tdata = (char *)dtv + ROUNDUP(dtv_size, I(_tdata_align));
|
||||||
if (I(_tdata_size)) {
|
if (I(_tdata_size))
|
||||||
memmove(tdata, _tdata_start, I(_tdata_size));
|
memmove(tdata, _tdata_start, I(_tdata_size));
|
||||||
}
|
|
||||||
|
|
||||||
// Set the DTV.
|
// Set the DTV.
|
||||||
//
|
//
|
||||||
|
@ -251,9 +255,8 @@ textstartup void __enable_tls(void) {
|
||||||
|
|
||||||
#ifdef __x86_64__
|
#ifdef __x86_64__
|
||||||
// rewrite the executable tls opcodes in memory
|
// rewrite the executable tls opcodes in memory
|
||||||
if (IsWindows() || IsOpenbsd() || IsNetbsd()) {
|
if (IsWindows() || IsOpenbsd() || IsNetbsd())
|
||||||
__morph_tls();
|
__morph_tls();
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// we are now allowed to use tls
|
// we are now allowed to use tls
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue