// platform.hpp — Linux substitutes for the Win32 calls used by // Agent_Release_x64.exe (see decomp/Agent_Release_x64/cpp/AgentProcessControl.cpp). #pragma once #include #include #include namespace platform { // Replaces CreateMutexW(L"Global\\RustyHearts_Agent") (0x1400100b0). // Uses an exclusive flock() on a lock file; released automatically on exit. class SingleInstanceLock { public: explicit SingleInstanceLock(const std::string& name); ~SingleInstanceLock(); bool acquired() const { return fd_ >= 0; } private: int fd_ = -1; }; // Replaces CreateProcessW(..., CREATE_NEW_CONSOLE, ..., workDir) (0x1400094e0). // commandLine is split on whitespace (the original passes one string to Windows). // The child gets its own session (setsid) as the nearest analogue of a new console. // Returns pid > 0, or 0 on failure (same contract as the original). pid_t LaunchProcess(const std::string& commandLine, const std::string& workDir); // Replaces the watcher's GetExitCodeProcess polling loop (0x140008c90) with a // blocking waitpid(). Calls onExit(pid) on a detached thread once the child exits. void WatchProcess(pid_t pid, std::function onExit); // Replaces Toolhelp32 + OpenProcess + TerminateProcess (0x140009780). // Scans /proc, matches basename of argv[0] case-insensitively, kills the FIRST // match with SIGKILL (TerminateProcess is unconditional), returns true if killed. bool KillProcessByName(const std::string& exeName); // Replaces Sleep(ms). void SleepMs(unsigned ms); } // namespace platform