From e4653eeaefa519a1e1f75db125662fde963ca5a1 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Thu, 16 Apr 2020 03:02:23 -0700 Subject: [PATCH] pgl: implement bool tracking commands --- .../stratosphere/pgl/pgl_shell_api.hpp | 2 +- .../pgl/sf/pgl_sf_i_shell_interface.hpp | 2 +- .../source/pgl/pgl_shell_api.cpp | 4 +- .../source/pgl/srv/pgl_srv_shell.cpp | 66 +++++++++++++++++++ .../source/pgl/srv/pgl_srv_shell.hpp | 4 ++ .../pgl/srv/pgl_srv_shell_interface.cpp | 13 ++-- .../pgl/srv/pgl_srv_shell_interface.hpp | 2 +- .../include/vapours/results/pgl_results.hpp | 2 +- 8 files changed, 84 insertions(+), 11 deletions(-) diff --git a/libraries/libstratosphere/include/stratosphere/pgl/pgl_shell_api.hpp b/libraries/libstratosphere/include/stratosphere/pgl/pgl_shell_api.hpp index 7dbe28d08..f14621ec3 100644 --- a/libraries/libstratosphere/include/stratosphere/pgl/pgl_shell_api.hpp +++ b/libraries/libstratosphere/include/stratosphere/pgl/pgl_shell_api.hpp @@ -34,7 +34,7 @@ namespace ams::pgl { Result EnableApplicationCrashReport(bool enabled); Result IsApplicationCrashReportEnabled(bool *out); Result EnableApplicationAllThreadDumpOnCrash(bool enabled); - Result TriggerSnapShotDumper(const char *arg, SnapShotDumpType dump_type); + Result TriggerApplicationSnapShotDumper(const char *arg, SnapShotDumpType dump_type); Result GetEventObserver(pgl::EventObserver *out); diff --git a/libraries/libstratosphere/include/stratosphere/pgl/sf/pgl_sf_i_shell_interface.hpp b/libraries/libstratosphere/include/stratosphere/pgl/sf/pgl_sf_i_shell_interface.hpp index 64d464cfd..1d40d1393 100644 --- a/libraries/libstratosphere/include/stratosphere/pgl/sf/pgl_sf_i_shell_interface.hpp +++ b/libraries/libstratosphere/include/stratosphere/pgl/sf/pgl_sf_i_shell_interface.hpp @@ -51,7 +51,7 @@ namespace ams::pgl::sf { virtual Result EnableApplicationCrashReport(bool enabled) = 0; virtual Result IsApplicationCrashReportEnabled(ams::sf::Out out) = 0; virtual Result EnableApplicationAllThreadDumpOnCrash(bool enabled) = 0; - virtual Result TriggerSnapShotDumper(const ams::sf::InBuffer &arg, SnapShotDumpType dump_type) = 0; + virtual Result TriggerApplicationSnapShotDumper(SnapShotDumpType dump_type, const ams::sf::InBuffer &arg) = 0; virtual Result GetShellEventObserver(ams::sf::Out> out) = 0; public: diff --git a/libraries/libstratosphere/source/pgl/pgl_shell_api.cpp b/libraries/libstratosphere/source/pgl/pgl_shell_api.cpp index cbed6bbb3..66c2bc2d0 100644 --- a/libraries/libstratosphere/source/pgl/pgl_shell_api.cpp +++ b/libraries/libstratosphere/source/pgl/pgl_shell_api.cpp @@ -71,8 +71,8 @@ namespace ams::pgl { return ::pglEnableApplicationAllThreadDumpOnCrash(enabled); } - Result TriggerSnapShotDumper(const char *arg, SnapShotDumpType dump_type) { - return ::pglTriggerSnapShotDumper(arg, static_cast<::PglSnapShotDumpType>(dump_type)); + Result TriggerApplicationSnapShotDumper(const char *arg, SnapShotDumpType dump_type) { + return ::pglTriggerApplicationSnapShotDumper(static_cast<::PglSnapShotDumpType>(dump_type), arg); } Result GetEventObserver(pgl::EventObserver *out) { diff --git a/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell.cpp b/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell.cpp index 46e3de9dc..d7aa4c48c 100644 --- a/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell.cpp +++ b/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell.cpp @@ -142,4 +142,70 @@ namespace ams::pgl::srv { return FindProcessData(process_id) != nullptr; } + void EnableApplicationCrashReport(bool enabled) { + /* Get the application process id. */ + auto application_process_id = GetRunningApplicationProcessId(); + if (application_process_id) { + /* Find the data for the application process. */ + std::scoped_lock lk(g_process_data_mutex); + ProcessData *data = FindProcessData(*application_process_id); + + /* It's okay if we aren't tracking the process. */ + if (data != nullptr) { + /* Set or clear the flag. */ + if (enabled) { + data->flags |= ProcessDataFlag_DetailedCrashReportEnabled; + } else { + data->flags &= ~ProcessDataFlag_DetailedCrashReportEnabled; + } + } + } + } + + bool IsApplicationCrashReportEnabled() { + /* Get the application process id. */ + auto application_process_id = GetRunningApplicationProcessId(); + if (!application_process_id) { + return false; + } + + /* Find the data for the process. */ + std::scoped_lock lk(g_process_data_mutex); + if (ProcessData *data = FindProcessData(*application_process_id); data != nullptr) { + return (data->flags & ProcessDataFlag_DetailedCrashReportEnabled) != 0; + } else { + return false; + } + } + + void EnableApplicationAllThreadDumpOnCrash(bool enabled) { + /* Get the application process id. */ + auto application_process_id = GetRunningApplicationProcessId(); + if (application_process_id) { + /* Find the data for the application process. */ + std::scoped_lock lk(g_process_data_mutex); + ProcessData *data = FindProcessData(*application_process_id); + + /* It's okay if we aren't tracking the process. */ + if (data != nullptr) { + /* Set or clear the flag. */ + if (enabled) { + data->flags |= ProcessDataFlag_OutputAllLog; + } else { + data->flags &= ~ProcessDataFlag_OutputAllLog; + } + + /* NOTE: Here Nintendo releases the lock, re-takes the lock, and re-finds the process data. */ + /* This is unnecessary and less efficient, so we will not bother. */ + + /* Note that the flag bit has a meaningful value. */ + data->flags |= ProcessDataFlag_HasLogOption; + } + } + } + + Result TriggerApplicationSnapShotDumper(SnapShotDumpType dump_type, const char *arg) { + /* TODO */ + } + } diff --git a/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell.hpp b/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell.hpp index 8ecdde737..041b0f36e 100644 --- a/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell.hpp +++ b/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell.hpp @@ -25,5 +25,9 @@ namespace ams::pgl::srv { Result GetApplicationProcessId(os::ProcessId *out); Result BoostSystemMemoryResourceLimit(u64 size); bool IsProcessTracked(os::ProcessId process_id); + void EnableApplicationCrashReport(bool enabled); + bool IsApplicationCrashReportEnabled(); + void EnableApplicationAllThreadDumpOnCrash(bool enabled); + Result TriggerApplicationSnapShotDumper(SnapShotDumpType dump_type, const char *arg); } diff --git a/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_interface.cpp b/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_interface.cpp index a24d9882a..f485cf345 100644 --- a/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_interface.cpp +++ b/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_interface.cpp @@ -49,19 +49,22 @@ namespace ams::pgl::srv { } Result ShellInterface::EnableApplicationCrashReport(bool enabled) { - /* TODO */ + pgl::srv::EnableApplicationCrashReport(enabled); + return ResultSuccess(); } Result ShellInterface::IsApplicationCrashReportEnabled(ams::sf::Out out) { - /* TODO */ + out.SetValue(pgl::srv::IsApplicationCrashReportEnabled()); + return ResultSuccess(); } Result ShellInterface::EnableApplicationAllThreadDumpOnCrash(bool enabled) { - /* TODO */ + pgl::srv::EnableApplicationAllThreadDumpOnCrash(enabled); + return ResultSuccess(); } - Result ShellInterface::TriggerSnapShotDumper(const ams::sf::InBuffer &arg, SnapShotDumpType dump_type) { - /* TODO */ + Result ShellInterface::TriggerApplicationSnapShotDumper(SnapShotDumpType dump_type, const ams::sf::InBuffer &arg) { + return pgl::srv::TriggerApplicationSnapShotDumper(dump_type, reinterpret_cast(arg.GetPointer())); } Result ShellInterface::GetShellEventObserver(ams::sf::Out> out) { diff --git a/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_interface.hpp b/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_interface.hpp index 7d3fe13f0..6a9889117 100644 --- a/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_interface.hpp +++ b/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_interface.hpp @@ -42,7 +42,7 @@ namespace ams::pgl::srv { virtual Result EnableApplicationCrashReport(bool enabled) override final; virtual Result IsApplicationCrashReportEnabled(ams::sf::Out out) override final; virtual Result EnableApplicationAllThreadDumpOnCrash(bool enabled) override final; - virtual Result TriggerSnapShotDumper(const ams::sf::InBuffer &arg, SnapShotDumpType dump_type) override final; + virtual Result TriggerApplicationSnapShotDumper(SnapShotDumpType dump_type, const ams::sf::InBuffer &arg) override final; virtual Result GetShellEventObserver(ams::sf::Out> out) override final; }; diff --git a/libraries/libvapours/include/vapours/results/pgl_results.hpp b/libraries/libvapours/include/vapours/results/pgl_results.hpp index 9bbfc5e02..7c6d2240c 100644 --- a/libraries/libvapours/include/vapours/results/pgl_results.hpp +++ b/libraries/libvapours/include/vapours/results/pgl_results.hpp @@ -24,6 +24,6 @@ namespace ams::pgl { R_DEFINE_ERROR_RESULT(ApplicationNotRunning, 3); R_DEFINE_ERROR_RESULT(BufferNotEnough, 4); R_DEFINE_ERROR_RESULT(ApplicationContentNotFound, 5); - R_DEFINE_ERROR_RESULT(ContentMetaNotFound, 4); + R_DEFINE_ERROR_RESULT(ContentMetaNotFound, 6); }