| 535 | } |
| 536 | |
| 537 | static void* DeferredInitThread(void*) |
| 538 | { |
| 539 | // Poll for steamclient.so -- under LD_PRELOAD we load before Steam has |
| 540 | // mapped steamclient, so a fixed delay is insufficient. |
| 541 | DebugLog("[CR] DeferredInit: waiting for steamclient.so\n"); |
| 542 | for (int i = 0; i < 20; i++) { // up to 10 seconds |
| 543 | if (SteamclientMapped()) break; |
| 544 | usleep(500000); |
| 545 | } |
| 546 | DebugLog("[CR] DeferredInit: starting\n"); |
| 547 | |
| 548 | // Install crash guard so a bad memory read aborts correctly |
| 549 | struct sigaction sa = {}, old_segv = {}, old_bus = {}; |
| 550 | sa.sa_handler = ScanCrashHandler; |
| 551 | sigemptyset(&sa.sa_mask); |
| 552 | sa.sa_flags = SA_RESETHAND; // Reset to default on signal (async-signal-safe) |
| 553 | sigaction(SIGSEGV, &sa, &old_segv); |
| 554 | sigaction(SIGBUS, &sa, &old_bus); |
| 555 | |
| 556 | g_inScan = 1; |
| 557 | if (sigsetjmp(g_crashJmpBuf, 1) == 0) { |
| 558 | DoInit(); |
| 559 | } else { |
| 560 | DebugLog("[CR] DeferredInit: CRASHED during init, aborting safely\n"); |
| 561 | Log::Error("Caught signal during init - incompatible steamclient? Hooks NOT installed."); |
| 562 | Notify("Crashed during init - hooks disabled", true); |
| 563 | } |
| 564 | g_inScan = 0; |
| 565 | |
| 566 | // Restore original handlers and install crash dump handler if init succeeded |
| 567 | sigaction(SIGSEGV, &old_segv, nullptr); |
| 568 | sigaction(SIGBUS, &old_bus, nullptr); |
| 569 | |
| 570 | if (g_initialized.load(std::memory_order_acquire)) { |
| 571 | InstallCrashDumpHandler(); |
| 572 | } |
| 573 | |
| 574 | g_initThreadDone.store(true, std::memory_order_release); |
| 575 | return nullptr; |
| 576 | } |
| 577 | |
| 578 | |
| 579 |
nothing calls this directly
no test coverage detected