Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/system/lib/pthread/pthread_self_stub.c
6172 views
1
/*
2
* Copyright 2021 The Emscripten Authors. All rights reserved.
3
* Emscripten is available under two separate licenses, the MIT license and the
4
* University of Illinois/NCSA Open Source License. Both these licenses can be
5
* found in the LICENSE file.
6
*/
7
8
#include "pthread_impl.h"
9
#include <unistd.h>
10
#include <emscripten/stack.h>
11
12
static struct pthread __main_pthread;
13
14
uintptr_t __get_tp(void) {
15
return (uintptr_t)&__main_pthread;
16
}
17
18
// In case the stub syscall is not linked it
19
static int dummy_getpid() {
20
return 42;
21
}
22
weak_alias(dummy_getpid, __syscall_getpid);
23
24
pthread_t emscripten_main_runtime_thread_id() {
25
return &__main_pthread;
26
}
27
28
extern int __stack_high;
29
extern int __stack_low;
30
31
__attribute__((constructor))
32
static void init_pthread_self(void) {
33
__main_pthread.locale = &libc.global_locale;
34
__main_pthread.tid = getpid();
35
__main_pthread.stack = &__stack_high;
36
__main_pthread.stack_size = ((size_t)&__stack_high) - ((size_t)&__stack_low);
37
__main_pthread.guard_size = __default_guardsize;
38
}
39
40