diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:11:57 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:11:57 +0000 |
commit | b53100936633bc1e227c229df05dc969d4dd79e6 (patch) | |
tree | 28743f8667d59adf086ecad3d48961780e3184a0 /libc-bottom-half/crt | |
parent | Releasing progress-linux version 0.0~git20230113.4362b18-3~progress7.99u1. (diff) | |
download | wasi-libc-b53100936633bc1e227c229df05dc969d4dd79e6.tar.xz wasi-libc-b53100936633bc1e227c229df05dc969d4dd79e6.zip |
Merging upstream version 0.0~git20230621.7018e24.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'libc-bottom-half/crt')
-rw-r--r-- | libc-bottom-half/crt/crt1-reactor.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/libc-bottom-half/crt/crt1-reactor.c b/libc-bottom-half/crt/crt1-reactor.c index f507c9e..ea4a84f 100644 --- a/libc-bottom-half/crt/crt1-reactor.c +++ b/libc-bottom-half/crt/crt1-reactor.c @@ -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(); } |