1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-11-06 04:01:44 +00:00

fatal: improve start address detection

This commit is contained in:
Michael Scire 2019-03-26 09:04:32 -07:00
parent 93745dc40c
commit 106ae81614

View file

@ -239,29 +239,45 @@ void TryCollectDebugInformation(FatalThrowContext *ctx, u64 pid) {
} }
} }
/* Parse the starting address. */ /* Helper to guess start address. */
{ auto TryGuessStartAddress = [&](u64 guess) {
u64 guess = thread_ctx.pc.x;
MemoryInfo mi; MemoryInfo mi;
u32 pi; u32 pi;
if (R_FAILED(svcQueryDebugProcessMemory(&mi, &pi, debug_handle, guess)) || mi.perm != Perm_Rx) { if (R_FAILED(svcQueryDebugProcessMemory(&mi, &pi, debug_handle, guess)) || mi.perm != Perm_Rx) {
return; return false;
} }
/* Iterate backwards until we find the memory before the code region. */ /* Iterate backwards until we find the memory before the code region. */
while (mi.addr > 0) { while (mi.addr > 0) {
if (R_FAILED(svcQueryDebugProcessMemory(&mi, &pi, debug_handle, guess))) { if (R_FAILED(svcQueryDebugProcessMemory(&mi, &pi, debug_handle, guess))) {
return; return false;
} }
if (mi.type == MemType_Unmapped) { if (mi.type == MemType_Unmapped) {
/* Code region will be at the end of the unmapped region preceding it. */ /* Code region will be at the end of the unmapped region preceding it. */
ctx->cpu_ctx.aarch64_ctx.start_address = mi.addr + mi.size; ctx->cpu_ctx.aarch64_ctx.start_address = mi.addr + mi.size;
break; return true;
} }
guess -= 4; guess -= 4;
} }
return false;
};
/* Parse the starting address. */
{
if (TryGuessStartAddress(thread_ctx.pc.x)) {
return;
}
if (TryGuessStartAddress(thread_ctx.lr)) {
return;
}
for (size_t i = 0; i < ctx->cpu_ctx.aarch64_ctx.stack_trace_size; i++) {
if (TryGuessStartAddress(ctx->cpu_ctx.aarch64_ctx.stack_trace[i])) {
return;
}
}
} }
} }
} }