ams: revamp assertion system

This commit is contained in:
Michael Scire 2020-02-22 23:05:14 -08:00
parent 9572fb2ce3
commit 40400aee1f
168 changed files with 1014 additions and 696 deletions

View file

@ -123,10 +123,10 @@ namespace ams::dmnt::cheat::impl {
void CloseActiveCheatProcess() {
if (this->cheat_process_debug_handle != INVALID_HANDLE) {
/* Knock out the debug events thread. */
R_ASSERT(this->debug_events_thread.CancelSynchronization());
R_ABORT_UNLESS(this->debug_events_thread.CancelSynchronization());
/* Close resources. */
R_ASSERT(svcCloseHandle(this->cheat_process_debug_handle));
R_ABORT_UNLESS(svcCloseHandle(this->cheat_process_debug_handle));
this->cheat_process_debug_handle = INVALID_HANDLE;
/* Save cheat toggles. */
@ -176,18 +176,18 @@ namespace ams::dmnt::cheat::impl {
Handle HookToCreateApplicationProcess() const {
Handle h = INVALID_HANDLE;
R_ASSERT(pm::dmnt::HookToCreateApplicationProcess(&h));
R_ABORT_UNLESS(pm::dmnt::HookToCreateApplicationProcess(&h));
return h;
}
void StartProcess(os::ProcessId process_id) const {
R_ASSERT(pm::dmnt::StartProcess(process_id));
R_ABORT_UNLESS(pm::dmnt::StartProcess(process_id));
}
public:
CheatProcessManager() {
/* Create cheat process detection event. */
R_ASSERT(this->cheat_process_event.InitializeAsInterProcessEvent());
R_ABORT_UNLESS(this->cheat_process_event.InitializeAsInterProcessEvent());
/* Learn whether we should enable cheats by default. */
{
@ -203,14 +203,14 @@ namespace ams::dmnt::cheat::impl {
}
/* Spawn application detection thread, spawn cheat vm thread. */
R_ASSERT(this->detect_thread.Initialize(&CheatProcessManager::DetectLaunchThread, this, this->detect_thread_stack, ThreadStackSize, DetectThreadPriority));
R_ASSERT(this->vm_thread.Initialize(&CheatProcessManager::VirtualMachineThread, this, this->vm_thread_stack, ThreadStackSize, VirtualMachineThreadPriority));
R_ASSERT(this->debug_events_thread.Initialize(&CheatProcessManager::DebugEventsThread, this, this->debug_events_thread_stack, ThreadStackSize, DebugEventsThreadPriority));
R_ABORT_UNLESS(this->detect_thread.Initialize(&CheatProcessManager::DetectLaunchThread, this, this->detect_thread_stack, ThreadStackSize, DetectThreadPriority));
R_ABORT_UNLESS(this->vm_thread.Initialize(&CheatProcessManager::VirtualMachineThread, this, this->vm_thread_stack, ThreadStackSize, VirtualMachineThreadPriority));
R_ABORT_UNLESS(this->debug_events_thread.Initialize(&CheatProcessManager::DebugEventsThread, this, this->debug_events_thread_stack, ThreadStackSize, DebugEventsThreadPriority));
/* Start threads. */
R_ASSERT(this->detect_thread.Start());
R_ASSERT(this->vm_thread.Start());
R_ASSERT(this->debug_events_thread.Start());
R_ABORT_UNLESS(this->detect_thread.Start());
R_ABORT_UNLESS(this->vm_thread.Start());
R_ABORT_UNLESS(this->debug_events_thread.Start());
}
bool GetHasActiveCheatProcess() {
@ -588,9 +588,9 @@ namespace ams::dmnt::cheat::impl {
}
}
#define R_ASSERT_IF_NEW_PROCESS(res) \
#define R_ABORT_UNLESS_IF_NEW_PROCESS(res) \
if (on_process_launch) { \
R_ASSERT(res); \
R_ABORT_UNLESS(res); \
} else { \
R_TRY(res); \
}
@ -610,7 +610,7 @@ namespace ams::dmnt::cheat::impl {
}
/* Get the application process's ID. */
R_ASSERT_IF_NEW_PROCESS(pm::dmnt::GetApplicationProcessId(&this->cheat_process_metadata.process_id));
R_ABORT_UNLESS_IF_NEW_PROCESS(pm::dmnt::GetApplicationProcessId(&this->cheat_process_metadata.process_id));
auto proc_guard = SCOPE_GUARD {
if (on_process_launch) {
this->StartProcess(this->cheat_process_metadata.process_id);
@ -623,14 +623,14 @@ namespace ams::dmnt::cheat::impl {
Handle proc_h = INVALID_HANDLE;
ncm::ProgramLocation loc = {};
cfg::OverrideStatus status = {};
ON_SCOPE_EXIT { if (proc_h != INVALID_HANDLE) { R_ASSERT(svcCloseHandle(proc_h)); } };
ON_SCOPE_EXIT { if (proc_h != INVALID_HANDLE) { R_ABORT_UNLESS(svcCloseHandle(proc_h)); } };
R_ASSERT_IF_NEW_PROCESS(pm::dmnt::AtmosphereGetProcessInfo(&proc_h, &loc, &status, this->cheat_process_metadata.process_id));
R_ABORT_UNLESS_IF_NEW_PROCESS(pm::dmnt::AtmosphereGetProcessInfo(&proc_h, &loc, &status, this->cheat_process_metadata.process_id));
this->cheat_process_metadata.program_id = loc.program_id;
{
map::AddressSpaceInfo as_info;
R_ASSERT(map::GetProcessAddressSpaceInfo(&as_info, proc_h));
R_ABORT_UNLESS(map::GetProcessAddressSpaceInfo(&as_info, proc_h));
this->cheat_process_metadata.heap_extents.base = as_info.heap_base;
this->cheat_process_metadata.heap_extents.size = as_info.heap_size;
this->cheat_process_metadata.alias_extents.base = as_info.alias_base;
@ -651,7 +651,7 @@ namespace ams::dmnt::cheat::impl {
s32 num_modules;
/* TODO: ldr::dmnt:: */
R_ASSERT_IF_NEW_PROCESS(ldrDmntGetProcessModuleInfo(static_cast<u64>(this->cheat_process_metadata.process_id), proc_modules, util::size(proc_modules), &num_modules));
R_ABORT_UNLESS_IF_NEW_PROCESS(ldrDmntGetProcessModuleInfo(static_cast<u64>(this->cheat_process_metadata.process_id), proc_modules, util::size(proc_modules), &num_modules));
/* All applications must have two modules. */
/* Only accept one (which means we're attaching to HBL) */
@ -678,7 +678,7 @@ namespace ams::dmnt::cheat::impl {
}
/* Open a debug handle. */
R_ASSERT_IF_NEW_PROCESS(svcDebugActiveProcess(&this->cheat_process_debug_handle, static_cast<u64>(this->cheat_process_metadata.process_id)));
R_ABORT_UNLESS_IF_NEW_PROCESS(svcDebugActiveProcess(&this->cheat_process_debug_handle, static_cast<u64>(this->cheat_process_metadata.process_id)));
/* Cancel process guard. */
proc_guard.Cancel();
@ -697,7 +697,7 @@ namespace ams::dmnt::cheat::impl {
return ResultSuccess();
}
#undef R_ASSERT_IF_NEW_PROCESS
#undef R_ABORT_UNLESS_IF_NEW_PROCESS
bool CheatProcessManager::ParseCheats(const char *s, size_t len) {
/* Trigger a VM reload. */