From 5d91caebe99fb08c33095f2088ea8d299001be94 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Thu, 8 Sep 2022 14:34:17 +0300 Subject: [PATCH] Linux: delete /tmp/perf.map on exit --- Utilities/JIT.cpp | 34 ++++++++++++++++++++++++++++------ rpcs3/main.cpp | 8 ++++++++ 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/Utilities/JIT.cpp b/Utilities/JIT.cpp index 47ca498fac..ed8e472f48 100644 --- a/Utilities/JIT.cpp +++ b/Utilities/JIT.cpp @@ -20,6 +20,34 @@ LOG_CHANNEL(jit_log, "JIT"); void jit_announce(uptr func, usz size, std::string_view name) { +#ifdef __linux__ + static const struct tmp_perf_map + { + std::string name{fmt::format("/tmp/perf-%d.map", getpid())}; + fs::file data{name, fs::rewrite + fs::append}; + + tmp_perf_map() = default; + tmp_perf_map(const tmp_perf_map&) = delete; + tmp_perf_map& operator=(const tmp_perf_map&) = delete; + + ~tmp_perf_map() + { + fs::remove_file(name); + } + } s_map; + + if (size && name.size()) + { + s_map.data.write(fmt::format("%x %x %s\n", func, size, name)); + } + + if (!func && !size && !name.size()) + { + fs::remove_file(s_map.name); + return; + } +#endif + if (!size) { jit_log.error("Empty function announced: %s (%p)", name, func); @@ -83,12 +111,6 @@ void jit_announce(uptr func, usz size, std::string_view name) dump.write(reinterpret_cast(func), size); } } - -#ifdef __linux__ - static const fs::file s_map(fmt::format("/tmp/perf-%d.map", getpid()), fs::rewrite + fs::append); - - s_map.write(fmt::format("%x %x %s\n", func, size, name)); -#endif } static u8* get_jit_memory() diff --git a/rpcs3/main.cpp b/rpcs3/main.cpp index 9ea9594661..5e34f8d84c 100644 --- a/rpcs3/main.cpp +++ b/rpcs3/main.cpp @@ -92,6 +92,8 @@ LOG_CHANNEL(q_debug, "QDEBUG"); [[noreturn]] extern void report_fatal_error(std::string_view _text) { + extern void jit_announce(uptr, usz, std::string_view); + std::string buf; // Check if thread id is in string @@ -124,6 +126,9 @@ LOG_CHANNEL(q_debug, "QDEBUG"); [[maybe_unused]] const auto con_out = freopen("conout$", "w", stderr); #endif std::cerr << fmt::format("RPCS3: %s\n", text); +#ifdef __linux__ + jit_announce(0, 0, ""); +#endif std::abort(); } @@ -207,6 +212,9 @@ LOG_CHANNEL(q_debug, "QDEBUG"); #endif } +#ifdef __linux__ + jit_announce(0, 0, ""); +#endif std::abort(); }