mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-29 16:52:28 +00:00
Apply fixup to cthread initialization (#301)
Cosmopolitan Threads are currently Linux-only (with some NetBSD and Windows support too!). This change ensures we only initialize the high-level threading runtime when Cosmopolitan Threads are used.
This commit is contained in:
parent
45a7435788
commit
91d783352a
3 changed files with 13 additions and 9 deletions
|
@ -45,7 +45,6 @@ cosmo: push %rbp
|
||||||
pop %rax
|
pop %rax
|
||||||
#endif
|
#endif
|
||||||
call _init
|
call _init
|
||||||
call _main_thread_init # FIXME: use .init.start macro
|
|
||||||
ezlea __init_array_start,ax # static ctors in forward order
|
ezlea __init_array_start,ax # static ctors in forward order
|
||||||
.weak __init_array_start # could be called multiple times
|
.weak __init_array_start # could be called multiple times
|
||||||
ezlea __init_array_end,cx # idempotency recommended
|
ezlea __init_array_end,cx # idempotency recommended
|
||||||
|
|
|
@ -26,18 +26,17 @@
|
||||||
#include "libc/sysv/consts/prot.h"
|
#include "libc/sysv/consts/prot.h"
|
||||||
#include "libc/thread/create.h"
|
#include "libc/thread/create.h"
|
||||||
|
|
||||||
|
STATIC_YOINK("_main_thread_ctor");
|
||||||
|
|
||||||
// TLS boundaries
|
// TLS boundaries
|
||||||
extern char _tbss_start, _tbss_end, _tdata_start, _tdata_end;
|
extern char _tbss_start, _tbss_end, _tdata_start, _tdata_end;
|
||||||
|
|
||||||
static cthread_t _thread_allocate(const cthread_attr_t* attr) {
|
static cthread_t _thread_allocate(const cthread_attr_t* attr) {
|
||||||
//extern void _main_thread_init(void);
|
|
||||||
//void (*dummy)(void) = &_main_thread_init;
|
|
||||||
//asm(""::"r"(dummy));
|
|
||||||
size_t stacksize = attr->stacksize;
|
size_t stacksize = attr->stacksize;
|
||||||
size_t guardsize = attr->guardsize;
|
size_t guardsize = attr->guardsize;
|
||||||
size_t tbsssize = &_tbss_end - &_tbss_start;
|
size_t tbsssize = &_tbss_end - &_tbss_start;
|
||||||
size_t tdatasize = &_tdata_end - &_tdata_start;
|
size_t tdatasize = &_tdata_end - &_tdata_start;
|
||||||
size_t tlssize = tbsssize + tdatasize;
|
size_t tlssize = tbsssize + tdatasize;
|
||||||
|
|
||||||
size_t totalsize =
|
size_t totalsize =
|
||||||
3 * guardsize + stacksize + tlssize + sizeof(struct cthread_descriptor_t);
|
3 * guardsize + stacksize + tlssize + sizeof(struct cthread_descriptor_t);
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/calls/calls.h"
|
#include "libc/calls/calls.h"
|
||||||
|
#include "libc/dce.h"
|
||||||
#include "libc/runtime/runtime.h"
|
#include "libc/runtime/runtime.h"
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
#include "libc/sysv/consts/map.h"
|
#include "libc/sysv/consts/map.h"
|
||||||
|
@ -27,10 +28,11 @@
|
||||||
// TLS boundaries
|
// TLS boundaries
|
||||||
extern char _tbss_start, _tbss_end, _tdata_start, _tdata_end;
|
extern char _tbss_start, _tbss_end, _tdata_start, _tdata_end;
|
||||||
|
|
||||||
void _main_thread_init(void) {
|
static textstartup void _main_thread_init(void) {
|
||||||
size_t tbsssize = &_tbss_end - &_tbss_start;
|
if (!IsLinux()) return; /* TODO */
|
||||||
|
size_t tbsssize = &_tbss_end - &_tbss_start;
|
||||||
size_t tdatasize = &_tdata_end - &_tdata_start;
|
size_t tdatasize = &_tdata_end - &_tdata_start;
|
||||||
size_t tlssize = tbsssize + tdatasize;
|
size_t tlssize = tbsssize + tdatasize;
|
||||||
size_t totalsize = tlssize + sizeof(struct cthread_descriptor_t);
|
size_t totalsize = tlssize + sizeof(struct cthread_descriptor_t);
|
||||||
totalsize = (totalsize + PAGESIZE - 1) & -PAGESIZE;
|
totalsize = (totalsize + PAGESIZE - 1) & -PAGESIZE;
|
||||||
|
|
||||||
|
@ -66,3 +68,7 @@ void _main_thread_init(void) {
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const void* const _main_thread_ctor[] initarray = {
|
||||||
|
_main_thread_init,
|
||||||
|
};
|
Loading…
Add table
Add a link
Reference in a new issue