]>
Commit | Line | Data |
---|---|---|
446cb3f1 | 1 | #include <wasi/api.h> |
320054e8 | 2 | extern void __wasm_call_ctors(void); |
afbf94c3 | 3 | extern int __original_main(void); |
320054e8 | 4 | extern void __prepare_for_exit(void); |
320054e8 DG |
5 | |
6 | void _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 | } |