summaryrefslogtreecommitdiffstats
path: root/contrib/restricted/emscripten/system/lib/pthread/pthread_self_stub.c
blob: a233f8863c6268644331c28dbad4bb08bd936260 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
 * Copyright 2021 The Emscripten Authors.  All rights reserved.
 * Emscripten is available under two separate licenses, the MIT license and the
 * University of Illinois/NCSA Open Source License.  Both these licenses can be
 * found in the LICENSE file.
 */

#include "pthread_impl.h"
#include <unistd.h>
#include <emscripten/stack.h>

static struct pthread __main_pthread;

uintptr_t __get_tp(void) {
  return (uintptr_t)&__main_pthread;
}

// In case the stub syscall is not linked it
static int dummy_getpid() {
  return 42;
}
weak_alias(dummy_getpid, __syscall_getpid);

pthread_t emscripten_main_runtime_thread_id() {
  return &__main_pthread;
}

extern int __stack_high;
extern int __stack_low;

__attribute__((constructor))
static void init_pthread_self(void) {
  __main_pthread.locale = &libc.global_locale;
  __main_pthread.tid = getpid();
  __main_pthread.stack = &__stack_high;
  __main_pthread.stack_size = ((size_t)&__stack_high) - ((size_t)&__stack_low);
  __main_pthread.guard_size = __default_guardsize;
}