diff options
| author | sds-228 <329233051+sds-228@users.noreply.github.com> | 2026-11-23 01:31:08 +0300 |
|---|---|---|
| committer | sds-228 <329233051+sds-228@users.noreply.github.com> | 2026-11-23 01:31:08 +0300 |
| commit | b2e888f52e33e4f64c46701778ccda06aff6fc40 (patch) | |
| tree | 50ecd772e7e2805af04833af17f74d70c7f7714c /runtime/shims/process.cpp | |
| parent | aa2988cc555bad7ecd508b48a702adbb32fe7c95 (diff) | |
runtime: raise SIGABRT from the guest's abort() when a handler is installed
game_abort() ended the run directly, so a title's own SIGABRT handler never ran. Raise SIGABRT only when a handler is registered (the guest's signal() import binds to the host CRT), leaving the default and ignored cases ending with code 3 so the host is never killed. Add a synthetic fixture with handler, returning-handler, ignore and default modes plus a native-vs-loader exit-code test.
AI-assisted (OpenCode)
Diffstat (limited to 'runtime/shims/process.cpp')
| -rw-r--r-- | runtime/shims/process.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/runtime/shims/process.cpp b/runtime/shims/process.cpp index 1fc4fee7f..0977f5298 100644 --- a/runtime/shims/process.cpp +++ b/runtime/shims/process.cpp | |||
| @@ -16,6 +16,7 @@ | |||
| 16 | #include <windows.h> | 16 | #include <windows.h> |
| 17 | 17 | ||
| 18 | #include <atomic> | 18 | #include <atomic> |
| 19 | #include <csignal> | ||
| 19 | #include <cstdio> | 20 | #include <cstdio> |
| 20 | #include <cstdlib> | 21 | #include <cstdlib> |
| 21 | #include <cstring> | 22 | #include <cstring> |
| @@ -89,6 +90,15 @@ void __cdecl game_exit(int code) { end_run(code); } | |||
| 89 | void __stdcall game_exit_process(UINT code) { end_run(static_cast<int>(code)); } | 90 | void __stdcall game_exit_process(UINT code) { end_run(static_cast<int>(code)); } |
| 90 | void __cdecl game_abort() { | 91 | void __cdecl game_abort() { |
| 91 | std::fprintf(stderr, "[rt] process: the game called abort()\n"); | 92 | std::fprintf(stderr, "[rt] process: the game called abort()\n"); |
| 93 | // The game's signal() import is not shimmed: its handler goes into the host CRT's process-wide table, which | ||
| 94 | // std::signal here reads too. UCRT's abort() raises SIGABRT before it terminates; do the same only when a | ||
| 95 | // handler is installed, because raising it with the default action would terminate the host process. A handler | ||
| 96 | // that exits ends the run itself; one that returns falls through to the CRT's abort code below. | ||
| 97 | const auto previous = std::signal(SIGABRT, SIG_DFL); | ||
| 98 | if (previous != SIG_ERR) { | ||
| 99 | std::signal(SIGABRT, previous); | ||
| 100 | if (previous != SIG_DFL && previous != SIG_IGN) std::raise(SIGABRT); | ||
| 101 | } | ||
| 92 | end_run(3); // the CRT's abort exit code | 102 | end_run(3); // the CRT's abort exit code |
| 93 | } | 103 | } |
| 94 | 104 | ||