]> git.proxmox.com Git - wasi-libc.git/blame - libc-bottom-half/crt/crt1.c
Add support for `__main_argc_argv`.
[wasi-libc.git] / libc-bottom-half / crt / crt1.c
CommitLineData
446cb3f1 1#include <wasi/api.h>
320054e8 2extern void __wasm_call_ctors(void);
afbf94c3 3extern int __original_main(void);
320054e8 4extern void __prepare_for_exit(void);
320054e8
DG
5
6void _start(void) {
1f11b91e 7 // The linker synthesizes this to call constructors.
320054e8
DG
8 __wasm_call_ctors();
9
d9066a87
DG
10 // Call `__original_main` which will either be the application's zero-argument
11 // `__original_main` function or a libc routine which calls `__main_void`.
12 // TODO: Call `main` directly once we no longer have to support old compilers.
afbf94c3 13 int r = __original_main();
320054e8 14
1f11b91e 15 // Call atexit functions, destructors, stdio cleanup, etc.
320054e8
DG
16 __prepare_for_exit();
17
410c6607
DG
18 // If main exited successfully, just return, otherwise call
19 // `__wasi_proc_exit`.
320054e8 20 if (r != 0) {
410c6607 21 __wasi_proc_exit(r);
320054e8
DG
22 }
23}