]> git.proxmox.com Git - wasi-libc.git/blob - basics/libc/crt1.c
WASI libc prototype implementation.
[wasi-libc.git] / basics / libc / crt1.c
1 extern void __wasm_call_ctors(void);
2 extern int main(int, char *[]);
3 extern void __prepare_for_exit(void);
4 void _Exit(int) __attribute__((noreturn));
5
6 void _start(void) {
7 /* The linker synthesizes this to call constructors. */
8 __wasm_call_ctors();
9
10 /* Call main with no arguments. */
11 int r = main(0, 0);
12
13 /* Call atexit functions, destructors, stdio cleanup, etc. */
14 __prepare_for_exit();
15
16 /* If main exited successfully, just return, otherwise call _Exit. */
17 if (r != 0) {
18 _Exit(r);
19 }
20 }