wasi-libc/basics/crt/crt1.c
Dan Gohman ca9046d872
Use consistent style for wasi-libc C source files. (#131)
For now, this means using `//`-style comments in .c source files (though
not public header files), and spaces rather than tabs. No strong opinion
here; this is just what the majority of the current code is using.

This also synchronizes basics/crt/crt1.c with libc-bottom-half's
version, though this is just a cleanup as the former isn't currently used
by the main wasi-libc build.
2019-11-08 11:59:57 -08:00

24 lines
740 B
C

extern void __wasm_call_ctors(void);
extern int __original_main(void);
extern void __prepare_for_exit(void);
void _Exit(int) __attribute__((noreturn));
void _start(void) {
// The linker synthesizes this to call constructors.
__wasm_call_ctors();
// Call `__original_main` which will either be the application's
// zero-argument `main` function (renamed by the compiler) or a libc
// routine which populates `argv` and `argc` and calls the application's
// two-argument `main`.
int r = __original_main();
// Call atexit functions, destructors, stdio cleanup, etc.
__prepare_for_exit();
// If main exited successfully, just return, otherwise call _Exit.
if (r != 0) {
_Exit(r);
}
}