-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make reactor_setup a weak external, and factor out common code between the crt1.c implementations into a shared header. This renames basics/include to basics/headers/public, which is more consistent with the directory structures in libc-bottom-half and libc-top-half, and which allows us to have basics/headers/private, for the new crt1.h.
- Loading branch information
1 parent
414e725
commit 1bd89e0
Showing
33 changed files
with
62 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,20 @@ | ||
extern void __wasm_call_ctors(void); | ||
void _Exit(int) __attribute__((noreturn)); | ||
|
||
#ifdef REACTOR_RUNTIME | ||
extern void reactor_setup(int, char *[]); | ||
#else | ||
extern int main(int, char *[]); | ||
extern void __prepare_for_exit(void); | ||
#endif | ||
#include "crt1.h" | ||
|
||
#ifdef REACTOR_RUNTIME | ||
void __wasi_unstable_reactor_start(void) { | ||
#else | ||
void _start(void) { | ||
#endif | ||
/* The linker synthesizes this to call constructors. */ | ||
__wasm_call_ctors(); | ||
/* | ||
* In the basics directory, we don't have a way to pass in command-line | ||
* parameters, so we just use some simple placeholder arguments. For real | ||
* command-line argument handling, see the crt1.c in libc-bottom-half. | ||
*/ | ||
static char *argv[] = { | ||
"program", | ||
NULL | ||
}; | ||
|
||
#ifdef REACTOR_RUNTIME | ||
/* Call reactor_setup with the arguments. */ | ||
reactor_setup(argc, argv); | ||
#else | ||
/* Call main with no arguments. */ | ||
int r = main(0, 0); | ||
|
||
/* Call atexit functions, destructors, stdio cleanup, etc. */ | ||
__prepare_for_exit(); | ||
|
||
/* If main exited successfully, just return, otherwise call _Exit. */ | ||
if (r != 0) { | ||
_Exit(r); | ||
} | ||
#endif | ||
/* Start the program! */ | ||
start_program(1, argv); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Common code for defining the crt1.o object, which defines the program | ||
* entrypoint. | ||
*/ | ||
|
||
extern void __wasm_call_ctors(void); | ||
void _Exit(int) __attribute__((noreturn)); | ||
|
||
#ifdef REACTOR_RUNTIME | ||
extern void reactor_setup(int, char *[]) __attribute__((weak)); | ||
#else | ||
extern int main(int, char *[]); | ||
extern void __prepare_for_exit(void); | ||
#endif | ||
|
||
static inline void start_program(int argc, char *argv[]) { | ||
/* The linker synthesizes this to call constructors. */ | ||
__wasm_call_ctors(); | ||
|
||
#ifdef REACTOR_RUNTIME | ||
/* | ||
* Call reactor_setup with the arguments. It's a weak external, so we | ||
* can skip calling it if it's not defined. | ||
*/ | ||
if (reactor_setup) { | ||
reactor_setup(argc, argv); | ||
} | ||
#else | ||
/* Call main with no arguments. */ | ||
int r = main(0, 0); | ||
|
||
/* Call atexit functions, destructors, stdio cleanup, etc. */ | ||
__prepare_for_exit(); | ||
|
||
/* If main exited successfully, just return, otherwise call _Exit. */ | ||
if (r != 0) { | ||
_Exit(r); | ||
} | ||
#endif | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,4 +68,3 @@ __wasi_sock_send | |
__wasi_sock_shutdown | ||
__wasm_call_ctors | ||
main | ||
reactor_setup |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters