pgl: implement bool tracking commands

This commit is contained in:
Michael Scire 2020-04-16 03:02:23 -07:00
parent e53a592f72
commit e4653eeaef
8 changed files with 84 additions and 11 deletions

View file

@ -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);

View file

@ -51,7 +51,7 @@ namespace ams::pgl::sf {
virtual Result EnableApplicationCrashReport(bool enabled) = 0;
virtual Result IsApplicationCrashReportEnabled(ams::sf::Out<bool> 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<std::shared_ptr<pgl::sf::IEventObserver>> out) = 0;
public:

View file

@ -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) {

View file

@ -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 */
}
}

View file

@ -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);
}

View file

@ -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<bool> 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<const char *>(arg.GetPointer()));
}
Result ShellInterface::GetShellEventObserver(ams::sf::Out<std::shared_ptr<pgl::sf::IEventObserver>> out) {

View file

@ -42,7 +42,7 @@ namespace ams::pgl::srv {
virtual Result EnableApplicationCrashReport(bool enabled) override final;
virtual Result IsApplicationCrashReportEnabled(ams::sf::Out<bool> 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<std::shared_ptr<pgl::sf::IEventObserver>> out) override final;
};

View file

@ -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);
}