~mmach/netext73/wasi-libc

« back to all changes in this revision

Viewing changes to libc-bottom-half/crt/crt1.c

  • Committer: mmach
  • Date: 2023-09-12 15:53:36 UTC
  • Revision ID: netbit73@gmail.com-20230912155336-s1r5z5xnszz99zzo
0.0~git20230113.4362b18

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include <wasi/api.h>
2
 
extern void __wasm_call_ctors(void);
3
 
extern int __original_main(void);
4
 
extern void __wasm_call_dtors(void);
5
 
 
6
 
__attribute__((export_name("_start")))
7
 
void _start(void) {
8
 
    // The linker synthesizes this to call constructors.
9
 
    __wasm_call_ctors();
10
 
 
11
 
    // Call `__original_main` which will either be the application's zero-argument
12
 
    // `__original_main` function or a libc routine which calls `__main_void`.
13
 
    // TODO: Call `main` directly once we no longer have to support old compilers.
14
 
    int r = __original_main();
15
 
 
16
 
    // Call atexit functions, destructors, stdio cleanup, etc.
17
 
    __wasm_call_dtors();
18
 
 
19
 
    // If main exited successfully, just return, otherwise call
20
 
    // `__wasi_proc_exit`.
21
 
    if (r != 0) {
22
 
        __wasi_proc_exit(r);
23
 
    }
24
 
}
 
1
// We compile a plain crt1.o for toolchain compatibility, but it's
 
2
// identical to crt1-command.o.
 
3
#include "crt1-command.c"