mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-12-23 02:42:09 +00:00
dmnt: fix some bugs in init
This commit is contained in:
parent
78a730ddf6
commit
8abee1bdaa
4 changed files with 20 additions and 12 deletions
|
@ -16,6 +16,7 @@
|
||||||
},
|
},
|
||||||
"service_access": [
|
"service_access": [
|
||||||
"pm:dmnt",
|
"pm:dmnt",
|
||||||
|
"pm:info",
|
||||||
"ldr:dmnt",
|
"ldr:dmnt",
|
||||||
"ro:dmnt",
|
"ro:dmnt",
|
||||||
"ns:dev",
|
"ns:dev",
|
||||||
|
|
|
@ -116,6 +116,9 @@ namespace sts::dmnt::cheat::impl {
|
||||||
|
|
||||||
void CloseActiveCheatProcess() {
|
void CloseActiveCheatProcess() {
|
||||||
if (this->cheat_process_debug_handle != INVALID_HANDLE) {
|
if (this->cheat_process_debug_handle != INVALID_HANDLE) {
|
||||||
|
/* Knock out the debug events thread. */
|
||||||
|
R_ASSERT(this->debug_events_thread.CancelSynchronization());
|
||||||
|
|
||||||
/* Close resources. */
|
/* Close resources. */
|
||||||
R_ASSERT(svcCloseHandle(this->cheat_process_debug_handle));
|
R_ASSERT(svcCloseHandle(this->cheat_process_debug_handle));
|
||||||
this->cheat_process_debug_handle = INVALID_HANDLE;
|
this->cheat_process_debug_handle = INVALID_HANDLE;
|
||||||
|
@ -146,6 +149,8 @@ namespace sts::dmnt::cheat::impl {
|
||||||
u64 tmp;
|
u64 tmp;
|
||||||
bool has_cheat_process = this->cheat_process_debug_handle != INVALID_HANDLE;
|
bool has_cheat_process = this->cheat_process_debug_handle != INVALID_HANDLE;
|
||||||
has_cheat_process &= R_SUCCEEDED(svcGetProcessId(&tmp, this->cheat_process_debug_handle));
|
has_cheat_process &= R_SUCCEEDED(svcGetProcessId(&tmp, this->cheat_process_debug_handle));
|
||||||
|
has_cheat_process &= R_SUCCEEDED(pm::dmnt::GetApplicationProcessId(&tmp));
|
||||||
|
has_cheat_process &= (tmp == this->cheat_process_metadata.process_id);
|
||||||
|
|
||||||
if (!has_cheat_process) {
|
if (!has_cheat_process) {
|
||||||
this->CloseActiveCheatProcess();
|
this->CloseActiveCheatProcess();
|
||||||
|
@ -610,9 +615,6 @@ namespace sts::dmnt::cheat::impl {
|
||||||
this->CloseActiveCheatProcess();
|
this->CloseActiveCheatProcess();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Knock out the debug events thread. */
|
|
||||||
R_ASSERT(this->debug_events_thread.CancelSynchronization());
|
|
||||||
|
|
||||||
/* Get the application process's ID. */
|
/* Get the application process's ID. */
|
||||||
R_ASSERT_IF_NEW_PROCESS(pm::dmnt::GetApplicationProcessId(&this->cheat_process_metadata.process_id));
|
R_ASSERT_IF_NEW_PROCESS(pm::dmnt::GetApplicationProcessId(&this->cheat_process_metadata.process_id));
|
||||||
auto proc_guard = SCOPE_GUARD {
|
auto proc_guard = SCOPE_GUARD {
|
||||||
|
|
|
@ -33,7 +33,7 @@ namespace sts::dmnt::cheat::impl {
|
||||||
static void PerCoreThreadFunction(void *_this) {
|
static void PerCoreThreadFunction(void *_this) {
|
||||||
/* This thread will wait on the appropriate message queue. */
|
/* This thread will wait on the appropriate message queue. */
|
||||||
DebugEventsManager *this_ptr = reinterpret_cast<DebugEventsManager *>(_this);
|
DebugEventsManager *this_ptr = reinterpret_cast<DebugEventsManager *>(_this);
|
||||||
const u32 current_core = svcGetCurrentProcessorNumber();
|
const size_t current_core = svcGetCurrentProcessorNumber();
|
||||||
while (true) {
|
while (true) {
|
||||||
/* Receive handle. */
|
/* Receive handle. */
|
||||||
Handle debug_handle = this_ptr->WaitReceiveHandle(current_core);
|
Handle debug_handle = this_ptr->WaitReceiveHandle(current_core);
|
||||||
|
@ -46,9 +46,9 @@ namespace sts::dmnt::cheat::impl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 GetTargetCore(const svc::DebugEventInfo &dbg_event, Handle debug_handle) {
|
size_t GetTargetCore(const svc::DebugEventInfo &dbg_event, Handle debug_handle) {
|
||||||
/* If we don't need to continue on a specific core, use the system core. */
|
/* If we don't need to continue on a specific core, use the system core. */
|
||||||
u32 target_core = NumCores - 1;
|
size_t target_core = NumCores - 1;
|
||||||
|
|
||||||
/* Retrieve correct core for new thread event. */
|
/* Retrieve correct core for new thread event. */
|
||||||
if (dbg_event.type == svc::DebugEventType::AttachThread) {
|
if (dbg_event.type == svc::DebugEventType::AttachThread) {
|
||||||
|
@ -61,11 +61,11 @@ namespace sts::dmnt::cheat::impl {
|
||||||
return target_core;
|
return target_core;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SendHandle(const svc::DebugEventInfo &dbg_event, Handle debug_handle) {
|
void SendHandle(size_t target_core, Handle debug_handle) {
|
||||||
this->message_queues[GetTargetCore(dbg_event, debug_handle)].Send(static_cast<uintptr_t>(debug_handle));
|
this->message_queues[target_core].Send(static_cast<uintptr_t>(debug_handle));
|
||||||
}
|
}
|
||||||
|
|
||||||
Handle WaitReceiveHandle(u32 core_id) {
|
Handle WaitReceiveHandle(size_t core_id) {
|
||||||
uintptr_t x = 0;
|
uintptr_t x = 0;
|
||||||
this->message_queues[core_id].Receive(&x);
|
this->message_queues[core_id].Receive(&x);
|
||||||
return static_cast<Handle>(x);
|
return static_cast<Handle>(x);
|
||||||
|
@ -105,12 +105,15 @@ namespace sts::dmnt::cheat::impl {
|
||||||
void ContinueCheatProcess(Handle cheat_dbg_hnd) {
|
void ContinueCheatProcess(Handle cheat_dbg_hnd) {
|
||||||
/* Loop getting all debug events. */
|
/* Loop getting all debug events. */
|
||||||
svc::DebugEventInfo d;
|
svc::DebugEventInfo d;
|
||||||
|
size_t target_core = NumCores - 1;
|
||||||
while (R_SUCCEEDED(svcGetDebugEvent(reinterpret_cast<u8 *>(&d), cheat_dbg_hnd))) {
|
while (R_SUCCEEDED(svcGetDebugEvent(reinterpret_cast<u8 *>(&d), cheat_dbg_hnd))) {
|
||||||
/* ... */
|
if (d.type == svc::DebugEventType::AttachThread) {
|
||||||
|
target_core = GetTargetCore(d, cheat_dbg_hnd);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Send handle to correct core, wait for continue to finish. */
|
/* Send handle to correct core, wait for continue to finish. */
|
||||||
this->SendHandle(d, cheat_dbg_hnd);
|
this->SendHandle(target_core, cheat_dbg_hnd);
|
||||||
this->WaitContinued();
|
this->WaitContinued();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -31,7 +31,7 @@ extern "C" {
|
||||||
|
|
||||||
u32 __nx_applet_type = AppletType_None;
|
u32 __nx_applet_type = AppletType_None;
|
||||||
|
|
||||||
#define INNER_HEAP_SIZE 0x80000
|
#define INNER_HEAP_SIZE 0xC0000
|
||||||
size_t nx_inner_heap_size = INNER_HEAP_SIZE;
|
size_t nx_inner_heap_size = INNER_HEAP_SIZE;
|
||||||
char nx_inner_heap[INNER_HEAP_SIZE];
|
char nx_inner_heap[INNER_HEAP_SIZE];
|
||||||
|
|
||||||
|
@ -60,6 +60,7 @@ void __appInit(void) {
|
||||||
|
|
||||||
DoWithSmSession([&]() {
|
DoWithSmSession([&]() {
|
||||||
R_ASSERT(pmdmntInitialize());
|
R_ASSERT(pmdmntInitialize());
|
||||||
|
R_ASSERT(pminfoInitialize());
|
||||||
R_ASSERT(ldrDmntInitialize());
|
R_ASSERT(ldrDmntInitialize());
|
||||||
/* TODO: We provide this on every sysver via ro. Do we need a shim? */
|
/* TODO: We provide this on every sysver via ro. Do we need a shim? */
|
||||||
if (GetRuntimeFirmwareVersion() >= FirmwareVersion_300) {
|
if (GetRuntimeFirmwareVersion() >= FirmwareVersion_300) {
|
||||||
|
@ -89,6 +90,7 @@ void __appExit(void) {
|
||||||
nsdevExit();
|
nsdevExit();
|
||||||
roDmntExit();
|
roDmntExit();
|
||||||
ldrDmntExit();
|
ldrDmntExit();
|
||||||
|
pminfoExit();
|
||||||
pmdmntExit();
|
pmdmntExit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue