Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions libc-bottom-half/cloudlibc/src/libc/stdlib/_Exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,22 @@
//
// SPDX-License-Identifier: BSD-2-Clause

#ifdef __wasilibc_use_wasip2
#include <wasi/wasip2.h>
#else
#include <wasi/api.h>
#endif
#include <_/cdefs.h>
#include <stdnoreturn.h>
#include <unistd.h>

noreturn void _Exit(int status) {
#ifdef __wasilibc_use_wasip2
exit_result_void_void_t exit_status = { .is_err = status != 0 };
exit_exit(&exit_status);
#else
__wasi_proc_exit(status);
#endif
}

__strong_reference(_Exit, _exit);
11 changes: 11 additions & 0 deletions libc-bottom-half/crt/crt1-command.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
#include <stdatomic.h>
extern void __wasi_init_tp(void);
#endif
#ifdef __wasilibc_use_wasip2
#include <wasi/wasip2.h>
#else
#include <wasi/api.h>
#endif
extern void __wasm_call_ctors(void);
extern int __main_void(void);
extern void __wasm_call_dtors(void);
Expand Down Expand Up @@ -47,7 +51,14 @@ void _start(void) {

// If main exited successfully, just return, otherwise call
// `__wasi_proc_exit`.
#ifdef __wasilibc_use_wasip2
if (r != 0) {
exit_result_void_void_t status = { .is_err = true };
exit_exit(&status);
}
#else
if (r != 0) {
__wasi_proc_exit(r);
}
#endif
}
2 changes: 1 addition & 1 deletion libc-bottom-half/headers/public/wasi/wasip2.h
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,7 @@ extern bool environment_initial_cwd(wasip2_string_t *ret);

// Imported Functions from `wasi:cli/[email protected]`
// Exit the current instance and any linked instances.
extern void exit_exit(exit_result_void_void_t *status);
_Noreturn extern void exit_exit(exit_result_void_void_t *status);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since editing these files is unexpected, but I agree necessary in this case, please add to the comment here noting this signature has been edited from the generated code. I'm not sure if anyone will ever read the comment, but it might make it stick out more in a git diff if the files get regenerated in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 58c47bc


// Imported Functions from `wasi:io/[email protected]`
// Returns a string that is suitable to assist humans in debugging
Expand Down
4 changes: 2 additions & 2 deletions libc-bottom-half/sources/wasip2.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ __attribute__((__import_module__("wasi:cli/[email protected]"), __import_name__(
extern void __wasm_import_environment_initial_cwd(int32_t);

__attribute__((__import_module__("wasi:cli/[email protected]"), __import_name__("exit")))
extern void __wasm_import_exit_exit(int32_t);
_Noreturn extern void __wasm_import_exit_exit(int32_t);

__attribute__((__import_module__("wasi:io/[email protected]"), __import_name__("[method]error.to-debug-string")))
extern void __wasm_import_io_error_method_error_to_debug_string(int32_t, int32_t);
Expand Down Expand Up @@ -1068,7 +1068,7 @@ bool environment_initial_cwd(wasip2_string_t *ret) {
return option.is_some;
}

void exit_exit(exit_result_void_void_t *status) {
_Noreturn void exit_exit(exit_result_void_void_t *status) {
int32_t result;
if ((*status).is_err) {
result = 1;
Expand Down