Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
20 changes: 20 additions & 0 deletions lib/libc/wasi/libc-bottom-half/crt/crt1-reactor.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
#if defined(_REENTRANT)
#include <stdatomic.h>
extern void __wasi_init_tp(void);
#endif
extern void __wasm_call_ctors(void);

__attribute__((export_name("_initialize")))
void _initialize(void) {
#if defined(_REENTRANT)
static volatile atomic_int initialized = 0;
int expected = 0;
if (!atomic_compare_exchange_strong(&initialized, &expected, 1)) {
__builtin_trap();
}

__wasi_init_tp();
#else
static volatile int initialized = 0;
if (initialized != 0) {
__builtin_trap();
}
initialized = 1;
#endif

// The linker synthesizes this to call constructors.
__wasm_call_ctors();
}
5 changes: 5 additions & 0 deletions lib/libc/wasi/libc-bottom-half/sources/__errno_location.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <errno.h>

int *__errno_location(void) {
return &errno;
}
2 changes: 1 addition & 1 deletion lib/libc/wasi/libc-bottom-half/sources/__wasilibc_real.c
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ __wasi_errno_t __wasi_sock_shutdown(
#ifdef _REENTRANT
int32_t __imported_wasi_thread_spawn(int32_t arg0) __attribute__((
__import_module__("wasi"),
__import_name__("thread_spawn")
__import_name__("thread-spawn")
));

int32_t __wasi_thread_spawn(void* start_arg) {
Expand Down
1 change: 0 additions & 1 deletion lib/libc/wasi/libc-top-half/musl/arch/wasm32/atomic_arch.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#define a_barrier() (__sync_synchronize())
#define a_cas(p, t, s) (__sync_val_compare_and_swap((p), (t), (s)))
#define a_crash() (__builtin_trap())
#define a_clz_32 __builtin_clz
Expand Down
6 changes: 0 additions & 6 deletions lib/libc/wasi/libc-top-half/musl/include/pthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,9 @@ extern "C" {
#define PTHREAD_PROCESS_SHARED 1


#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
#define PTHREAD_MUTEX_INITIALIZER {{{0}}}
#define PTHREAD_RWLOCK_INITIALIZER {{{0}}}
#define PTHREAD_COND_INITIALIZER {{{0}}}
#else
#define PTHREAD_MUTEX_INITIALIZER 0
#define PTHREAD_RWLOCK_INITIALIZER 0
#define PTHREAD_COND_INITIALIZER 0
#endif
#define PTHREAD_ONCE_INIT 0


Expand Down
Loading