mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-03-03 07:29:23 +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
|
||||
#endif
|
||||
call _init
|
||||
call _main_thread_init # FIXME: use .init.start macro
|
||||
ezlea __init_array_start,ax # static ctors in forward order
|
||||
.weak __init_array_start # could be called multiple times
|
||||
ezlea __init_array_end,cx # idempotency recommended
|
||||
|
|
|
@ -26,18 +26,17 @@
|
|||
#include "libc/sysv/consts/prot.h"
|
||||
#include "libc/thread/create.h"
|
||||
|
||||
STATIC_YOINK("_main_thread_ctor");
|
||||
|
||||
// TLS boundaries
|
||||
extern char _tbss_start, _tbss_end, _tdata_start, _tdata_end;
|
||||
|
||||
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 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 tlssize = tbsssize + tdatasize;
|
||||
size_t tlssize = tbsssize + tdatasize;
|
||||
|
||||
size_t totalsize =
|
||||
3 * guardsize + stacksize + tlssize + sizeof(struct cthread_descriptor_t);
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/map.h"
|
||||
|
@ -27,10 +28,11 @@
|
|||
// TLS boundaries
|
||||
extern char _tbss_start, _tbss_end, _tdata_start, _tdata_end;
|
||||
|
||||
void _main_thread_init(void) {
|
||||
size_t tbsssize = &_tbss_end - &_tbss_start;
|
||||
static textstartup void _main_thread_init(void) {
|
||||
if (!IsLinux()) return; /* TODO */
|
||||
size_t tbsssize = &_tbss_end - &_tbss_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);
|
||||
totalsize = (totalsize + PAGESIZE - 1) & -PAGESIZE;
|
||||
|
||||
|
@ -66,3 +68,7 @@ void _main_thread_init(void) {
|
|||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
const void* const _main_thread_ctor[] initarray = {
|
||||
_main_thread_init,
|
||||
};
|
Loading…
Add table
Reference in a new issue