upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/shims/process.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/shims/process.cpp')
-rw-r--r--runtime/shims/process.cpp54
1 files changed, 0 insertions, 54 deletions
diff --git a/runtime/shims/process.cpp b/runtime/shims/process.cpp
index aa33fe750..2c37292e2 100644
--- a/runtime/shims/process.cpp
+++ b/runtime/shims/process.cpp
@@ -21,7 +21,6 @@
21// umbrella libraries a GDK title links (OneCore_apiset.lib, mincore.lib) bind them to. The retail package's own DLLs 21// umbrella libraries a GDK title links (OneCore_apiset.lib, mincore.lib) bind them to. The retail package's own DLLs
22// import ExitProcess from api-ms-win-core-processthreads-l1-1-0.dll. 22// import ExitProcess from api-ms-win-core-processthreads-l1-1-0.dll.
23#include <windows.h> 23#include <windows.h>
24#include <intrin.h>
25 24
26#include <atomic> 25#include <atomic>
27#include <cerrno> 26#include <cerrno>
@@ -514,52 +513,6 @@ int run_entry(void* entry, size_t stack_bytes) {
514 513
515namespace { 514namespace {
516using namespace rt::process; 515using namespace rt::process;
517
518// The title's debug output goes to the log, as VIctory's kernel.rs OutputDebugStringA/W do (GPL-3.0-or-later): no
519// debugger needs to be attached to read what the title says about itself. "[title] <text>", one line per call, the
520// trailing newline dropped; LEONIDA_TITLE_DEBUG_OUTPUT=0 silences it. The host's function still gets the text, so an
521// attached debugger sees it as before.
522bool title_debug_output_on() {
523 static const bool on = [] {
524 char v[8] = {};
525 const DWORD n = GetEnvironmentVariableA("LEONIDA_TITLE_DEBUG_OUTPUT", v, sizeof(v));
526 return !(n > 0 && n < sizeof(v) && v[0] == '0');
527 }();
528 return on;
529}
530void log_title_text(std::string text) {
531 while (!text.empty() && (text.back() == '\n' || text.back() == '\r')) text.pop_back();
532 std::fprintf(stderr, "[title] %s\n", text.c_str());
533}
534void WINAPI game_output_debug_string_a(LPCSTR text) {
535 if (text && title_debug_output_on()) log_title_text(text);
536 OutputDebugStringA(text);
537}
538void WINAPI game_output_debug_string_w(LPCWSTR text) {
539 if (text && title_debug_output_on()) {
540 const int n = WideCharToMultiByte(CP_UTF8, 0, text, -1, nullptr, 0, nullptr, nullptr);
541 std::string utf8(n > 1 ? static_cast<size_t>(n - 1) : 0, ' ');
542 if (n > 1) WideCharToMultiByte(CP_UTF8, 0, text, -1, utf8.data(), n, nullptr, nullptr);
543 log_title_text(std::move(utf8));
544 }
545 OutputDebugStringW(text);
546}
547
548// TerminateProcess of the game's own process ends gta6rt without a word otherwise; it is logged with its code and
549// caller first (VIctory kernel.rs TerminateProcess), then done as asked.
550BOOL WINAPI game_terminate_process(HANDLE process, UINT code) {
551 if (process == GetCurrentProcess() || GetProcessId(process) == GetCurrentProcessId()) {
552 std::fprintf(stderr, "[rt] process: the game called TerminateProcess(code %u) from %s\n", code,
553 rt::shims::module_offset(reinterpret_cast<uint64_t>(_ReturnAddress())).c_str());
554 std::fflush(nullptr);
555 }
556 return TerminateProcess(process, code);
557}
558
559#define DEBUG_OUTPUT(dll) \
560 {dll, "OutputDebugStringA", reinterpret_cast<void*>(&game_output_debug_string_a)}, \
561 {dll, "OutputDebugStringW", reinterpret_cast<void*>(&game_output_debug_string_w)}
562#define TERMINATE_PROCESS(dll) {dll, "TerminateProcess", reinterpret_cast<void*>(&game_terminate_process)}
563#define UCRT(dll) \ 516#define UCRT(dll) \
564 {dll, "exit", reinterpret_cast<void*>(&game_exit)}, {dll, "_exit", reinterpret_cast<void*>(&game_quick_exit)}, \ 517 {dll, "exit", reinterpret_cast<void*>(&game_exit)}, {dll, "_exit", reinterpret_cast<void*>(&game_quick_exit)}, \
565 {dll, "_Exit", reinterpret_cast<void*>(&game_quick_exit)}, \ 518 {dll, "_Exit", reinterpret_cast<void*>(&game_quick_exit)}, \
@@ -619,12 +572,5 @@ SHIM_TABLE(process,
619 POOL_AFFINITY("kernelbase.dll"), 572 POOL_AFFINITY("kernelbase.dll"),
620 COMMAND_LINE("kernel32.dll"), 573 COMMAND_LINE("kernel32.dll"),
621 COMMAND_LINE("kernelbase.dll"), 574 COMMAND_LINE("kernelbase.dll"),
622 DEBUG_OUTPUT("kernel32.dll"),
623 DEBUG_OUTPUT("kernelbase.dll"),
624 DEBUG_OUTPUT("api-ms-win-core-debug-l1-1-0.dll"),
625 DEBUG_OUTPUT("api-ms-win-core-debug-l1-1-1.dll"),
626 TERMINATE_PROCESS("kernel32.dll"),
627 TERMINATE_PROCESS("kernelbase.dll"),
628 TERMINATE_PROCESS("api-ms-win-core-processthreads-l1-1-0.dll"),
629 COMMAND_LINE("api-ms-win-core-processenvironment-l1-1-0.dll"), 575 COMMAND_LINE("api-ms-win-core-processenvironment-l1-1-0.dll"),
630); 576);