strat: use svc:: over ::svc

This commit is contained in:
Michael Scire
2021-10-04 14:54:13 -07:00
parent 77fe5cf6f5
commit 6f680fe63b
47 changed files with 557 additions and 563 deletions

View File

@@ -165,7 +165,7 @@ namespace ams::creport {
void CrashReport::ProcessExceptions() {
/* Loop all debug events. */
svc::DebugEventInfo d;
while (R_SUCCEEDED(svcGetDebugEvent(reinterpret_cast<u8 *>(&d), this->debug_handle))) {
while (R_SUCCEEDED(svc::GetDebugEvent(std::addressof(d), this->debug_handle))) {
switch (d.type) {
case svc::DebugEvent_CreateProcess:
this->HandleDebugEventInfoCreateProcess(d);
@@ -200,7 +200,7 @@ namespace ams::creport {
u64 userdata_size = 0;
/* Read userdata address. */
if (R_FAILED(svcReadDebugProcessMemory(&userdata_address, this->debug_handle, address, sizeof(userdata_address)))) {
if (R_FAILED(svc::ReadDebugProcessMemory(reinterpret_cast<uintptr_t>(std::addressof(userdata_address)), this->debug_handle, address, sizeof(userdata_address)))) {
return;
}
@@ -210,7 +210,7 @@ namespace ams::creport {
}
/* Read userdata size. */
if (R_FAILED(svcReadDebugProcessMemory(&userdata_size, this->debug_handle, address + sizeof(userdata_address), sizeof(userdata_size)))) {
if (R_FAILED(svc::ReadDebugProcessMemory(reinterpret_cast<uintptr_t>(std::addressof(userdata_size)), this->debug_handle, address + sizeof(userdata_address), sizeof(userdata_size)))) {
return;
}
@@ -244,7 +244,7 @@ namespace ams::creport {
this->result = ResultUserBreak();
/* Try to parse out the user break result. */
if (hos::GetVersion() >= hos::Version_5_0_0) {
svcReadDebugProcessMemory(&this->result, this->debug_handle, d.info.exception.specific.user_break.address, sizeof(this->result));
svc::ReadDebugProcessMemory(reinterpret_cast<uintptr_t>(std::addressof(this->result)), this->debug_handle, d.info.exception.specific.user_break.address, sizeof(this->result));
}
break;
case svc::DebugException_UndefinedSystemCall:
@@ -289,7 +289,7 @@ namespace ams::creport {
}
/* Read the dying message. */
svcReadDebugProcessMemory(this->dying_message, this->debug_handle, this->dying_message_address, this->dying_message_size);
svc::ReadDebugProcessMemory(reinterpret_cast<uintptr_t>(this->dying_message), this->debug_handle, this->dying_message_address, this->dying_message_size);
}
void CrashReport::SaveReport(bool enable_screenshot) {
@@ -299,7 +299,7 @@ namespace ams::creport {
/* Get a timestamp. */
u64 timestamp;
if (!TryGetCurrentTimestamp(&timestamp)) {
timestamp = svcGetSystemTick();
timestamp = os::GetSystemTick().GetInt64Value();
}
/* Save files. */

View File

@@ -25,7 +25,7 @@ namespace ams::creport {
static constexpr size_t MemoryHeapSize = 512_KB;
static_assert(MemoryHeapSize >= DyingMessageSizeMax + sizeof(ModuleList) + sizeof(ThreadList) + os::MemoryPageSize);
private:
Handle debug_handle = INVALID_HANDLE;
os::NativeHandle debug_handle = os::InvalidNativeHandle;
bool has_extra_info = true;
Result result = ResultIncompleteReport();
@@ -63,7 +63,7 @@ namespace ams::creport {
}
bool IsOpen() const {
return this->debug_handle != INVALID_HANDLE;
return this->debug_handle != os::InvalidNativeHandle;
}
bool IsApplication() const {
@@ -79,14 +79,12 @@ namespace ams::creport {
}
bool OpenProcess(os::ProcessId process_id) {
return R_SUCCEEDED(svcDebugActiveProcess(&this->debug_handle, static_cast<u64>(process_id)));
return R_SUCCEEDED(svc::DebugActiveProcess(std::addressof(this->debug_handle), process_id.value));
}
void Close() {
if (this->IsOpen()) {
svcCloseHandle(this->debug_handle);
this->debug_handle = INVALID_HANDLE;
}
os::CloseNativeHandle(this->debug_handle);
this->debug_handle = os::InvalidNativeHandle;
}
void Initialize();

View File

@@ -58,7 +58,7 @@ namespace ams::creport {
}
}
void ModuleList::FindModulesFromThreadInfo(Handle debug_handle, const ThreadInfo &thread) {
void ModuleList::FindModulesFromThreadInfo(os::NativeHandle debug_handle, const ThreadInfo &thread) {
/* Set the debug handle, for access in other member functions. */
this->debug_handle = debug_handle;
@@ -92,14 +92,14 @@ namespace ams::creport {
uintptr_t cur_address = base_address;
while (this->num_modules < ModuleCountMax) {
/* Get the region extents. */
MemoryInfo mi;
u32 pi;
if (R_FAILED(svcQueryDebugProcessMemory(&mi, &pi, this->debug_handle, cur_address))) {
svc::MemoryInfo mi;
svc::PageInfo pi;
if (R_FAILED(svc::QueryDebugProcessMemory(&mi, &pi, this->debug_handle, cur_address))) {
break;
}
/* Parse module. */
if (mi.perm == Perm_Rx) {
if (mi.perm == svc::MemoryPermission_ReadExecute) {
auto& module = this->modules[this->num_modules++];
module.start_address = mi.addr;
module.end_address = mi.addr + mi.size;
@@ -112,7 +112,7 @@ namespace ams::creport {
}
/* If we're out of readable memory, we're done reading code. */
if (mi.type == MemType_Unmapped || mi.type == MemType_Reserved) {
if (mi.state == svc::MemoryState_Free || mi.state == svc::MemoryState_Inaccessible) {
break;
}
@@ -127,39 +127,39 @@ namespace ams::creport {
bool ModuleList::TryFindModule(uintptr_t *out_address, uintptr_t guess) {
/* Query the memory region our guess falls in. */
MemoryInfo mi;
u32 pi;
if (R_FAILED(svcQueryDebugProcessMemory(&mi, &pi, this->debug_handle, guess))) {
svc::MemoryInfo mi;
svc::PageInfo pi;
if (R_FAILED(svc::QueryDebugProcessMemory(&mi, &pi, this->debug_handle, guess))) {
return false;
}
/* If we fall into a RW region, it may be rwdata. Query the region before it, which may be rodata or text. */
if (mi.perm == Perm_Rw) {
if (R_FAILED(svcQueryDebugProcessMemory(&mi, &pi, debug_handle, mi.addr - 4))) {
if (mi.perm == svc::MemoryPermission_ReadWrite) {
if (R_FAILED(svc::QueryDebugProcessMemory(&mi, &pi, debug_handle, mi.addr - 4))) {
return false;
}
}
/* If we fall into an RO region, it may be rodata. Query the region before it, which should be text. */
if (mi.perm == Perm_R) {
if (R_FAILED(svcQueryDebugProcessMemory(&mi, &pi, debug_handle, mi.addr - 4))) {
if (mi.perm == svc::MemoryPermission_Read) {
if (R_FAILED(svc::QueryDebugProcessMemory(&mi, &pi, debug_handle, mi.addr - 4))) {
return false;
}
}
/* We should, at this point, be looking at an executable region (text). */
if (mi.perm != Perm_Rx) {
if (mi.perm != svc::MemoryPermission_ReadExecute) {
return false;
}
/* Modules are a series of contiguous (text/rodata/rwdata) regions. */
/* Iterate backwards until we find unmapped memory, to find the start of the set of modules loaded here. */
while (mi.addr > 0) {
if (R_FAILED(svcQueryDebugProcessMemory(&mi, &pi, debug_handle, mi.addr - 4))) {
if (R_FAILED(svc::QueryDebugProcessMemory(&mi, &pi, debug_handle, mi.addr - 4))) {
return false;
}
if (mi.type == MemType_Unmapped) {
if (mi.state == svc::MemoryState_Free) {
/* We've found unmapped memory, so output the mapped memory afterwards. */
*out_address = mi.addr + mi.size;
return true;
@@ -177,11 +177,11 @@ namespace ams::creport {
/* Read module path from process memory. */
RoDataStart rodata_start;
{
MemoryInfo mi;
u32 pi;
svc::MemoryInfo mi;
svc::PageInfo pi;
/* Verify .rodata is read-only. */
if (R_FAILED(svcQueryDebugProcessMemory(&mi, &pi, this->debug_handle, ro_start_address)) || mi.perm != Perm_R) {
if (R_FAILED(svc::QueryDebugProcessMemory(&mi, &pi, this->debug_handle, ro_start_address)) || mi.perm != svc::MemoryPermission_Read) {
return;
}
@@ -189,7 +189,7 @@ namespace ams::creport {
const u64 rw_start_address = mi.addr + mi.size;
/* Read start of .rodata. */
if (R_FAILED(svcReadDebugProcessMemory(&rodata_start, this->debug_handle, ro_start_address, sizeof(rodata_start)))) {
if (R_FAILED(svc::ReadDebugProcessMemory(reinterpret_cast<uintptr_t>(std::addressof(rodata_start)), this->debug_handle, ro_start_address, sizeof(rodata_start)))) {
return;
}
@@ -226,15 +226,15 @@ namespace ams::creport {
std::memset(out_build_id, 0, ModuleBuildIdLength);
/* Verify .rodata is read-only. */
MemoryInfo mi;
u32 pi;
if (R_FAILED(svcQueryDebugProcessMemory(&mi, &pi, this->debug_handle, ro_start_address)) || mi.perm != Perm_R) {
svc::MemoryInfo mi;
svc::PageInfo pi;
if (R_FAILED(svc::QueryDebugProcessMemory(&mi, &pi, this->debug_handle, ro_start_address)) || mi.perm != svc::MemoryPermission_Read) {
return;
}
/* We want to read the last two pages of .rodata. */
const size_t read_size = mi.size >= sizeof(g_last_rodata_pages) ? sizeof(g_last_rodata_pages) : (sizeof(g_last_rodata_pages) / 2);
if (R_FAILED(svcReadDebugProcessMemory(g_last_rodata_pages, this->debug_handle, mi.addr + mi.size - read_size, read_size))) {
if (R_FAILED(svc::ReadDebugProcessMemory(reinterpret_cast<uintptr_t>(g_last_rodata_pages), this->debug_handle, mi.addr + mi.size - read_size, read_size))) {
return;
}

View File

@@ -32,14 +32,14 @@ namespace ams::creport {
u64 end_address;
};
private:
Handle debug_handle;
os::NativeHandle debug_handle;
size_t num_modules;
ModuleInfo modules[ModuleCountMax];
/* For pretty-printing. */
char address_str_buf[0x280];
public:
ModuleList() : debug_handle(INVALID_HANDLE), num_modules(0) {
ModuleList() : debug_handle(os::InvalidNativeHandle), num_modules(0) {
std::memset(this->modules, 0, sizeof(this->modules));
}
@@ -51,7 +51,7 @@ namespace ams::creport {
return this->modules[i].start_address;
}
void FindModulesFromThreadInfo(Handle debug_handle, const ThreadInfo &thread);
void FindModulesFromThreadInfo(os::NativeHandle debug_handle, const ThreadInfo &thread);
const char *GetFormattedAddressString(uintptr_t address);
void SaveToFile(ScopedFile &file);
private:

View File

@@ -34,7 +34,7 @@ namespace ams::creport {
/* Helpers. */
template<typename T>
void ReadStackTrace(size_t *out_trace_size, u64 *out_trace, size_t max_out_trace_size, Handle debug_handle, u64 fp) {
void ReadStackTrace(size_t *out_trace_size, u64 *out_trace, size_t max_out_trace_size, os::NativeHandle debug_handle, u64 fp) {
size_t trace_size = 0;
u64 cur_fp = fp;
@@ -46,7 +46,7 @@ namespace ams::creport {
/* Read a new frame. */
StackFrame<T> cur_frame;
if (R_FAILED(svcReadDebugProcessMemory(&cur_frame, debug_handle, cur_fp, sizeof(cur_frame)))) {
if (R_FAILED(svc::ReadDebugProcessMemory(reinterpret_cast<uintptr_t>(std::addressof(cur_frame)), debug_handle, cur_fp, sizeof(cur_frame)))) {
break;
}
@@ -79,12 +79,12 @@ namespace ams::creport {
file.WriteFormat(" Registers:\n");
{
for (unsigned int i = 0; i <= 28; i++) {
file.WriteFormat(" X[%02u]: %s\n", i, this->module_list->GetFormattedAddressString(this->context.cpu_gprs[i].x));
file.WriteFormat(" X[%02u]: %s\n", i, this->module_list->GetFormattedAddressString(this->context.r[i]));
}
file.WriteFormat(" FP: %s\n", this->module_list->GetFormattedAddressString(this->context.fp));
file.WriteFormat(" LR: %s\n", this->module_list->GetFormattedAddressString(this->context.lr));
file.WriteFormat(" SP: %s\n", this->module_list->GetFormattedAddressString(this->context.sp));
file.WriteFormat(" PC: %s\n", this->module_list->GetFormattedAddressString(this->context.pc.x));
file.WriteFormat(" PC: %s\n", this->module_list->GetFormattedAddressString(this->context.pc));
}
if (this->stack_trace_size != 0) {
file.WriteFormat(" Stack Trace:\n");
@@ -113,7 +113,7 @@ namespace ams::creport {
}
}
bool ThreadInfo::ReadFromProcess(Handle debug_handle, ThreadTlsMap &tls_map, u64 thread_id, bool is_64_bit) {
bool ThreadInfo::ReadFromProcess(os::NativeHandle debug_handle, ThreadTlsMap &tls_map, u64 thread_id, bool is_64_bit) {
/* Set thread id. */
this->thread_id = thread_id;
@@ -121,7 +121,7 @@ namespace ams::creport {
{
u64 _;
u32 _thread_state;
if (R_FAILED(svcGetDebugThreadParam(&_, &_thread_state, debug_handle, this->thread_id, DebugThreadParam_State))) {
if (R_FAILED(svc::GetDebugThreadParam(&_, &_thread_state, debug_handle, this->thread_id, svc::DebugThreadParam_State))) {
return false;
}
@@ -132,29 +132,29 @@ namespace ams::creport {
}
/* Get the thread context. */
if (R_FAILED(svcGetDebugThreadContext(&this->context, debug_handle, this->thread_id, svc::ThreadContextFlag_All))) {
if (R_FAILED(svc::GetDebugThreadContext(&this->context, debug_handle, this->thread_id, svc::ThreadContextFlag_All))) {
return false;
}
/* In aarch32 mode svcGetDebugThreadContext does not set the LR, FP, and SP registers correctly. */
/* In aarch32 mode svc::GetDebugThreadContext does not set the LR, FP, and SP registers correctly. */
if (!is_64_bit) {
this->context.fp = this->context.cpu_gprs[11].x;
this->context.sp = this->context.cpu_gprs[13].x;
this->context.lr = this->context.cpu_gprs[14].x;
this->context.fp = this->context.r[11];
this->context.sp = this->context.r[13];
this->context.lr = this->context.r[14];
}
/* Read TLS, if present. */
/* TODO: struct definitions for nnSdk's ThreadType/TLS Layout? */
this->tls_address = 0;
if (tls_map.GetThreadTls(std::addressof(this->tls_address), thread_id)) {
u8 thread_tls[0x200];
if (R_SUCCEEDED(svcReadDebugProcessMemory(thread_tls, debug_handle, this->tls_address, sizeof(thread_tls)))) {
u8 thread_tls[sizeof(svc::ThreadLocalRegion)];
if (R_SUCCEEDED(svc::ReadDebugProcessMemory(reinterpret_cast<uintptr_t>(thread_tls), debug_handle, this->tls_address, sizeof(thread_tls)))) {
std::memcpy(this->tls, thread_tls, sizeof(this->tls));
/* Try to detect libnx threads, and skip name parsing then. */
if (*(reinterpret_cast<u32 *>(&thread_tls[0x1E0])) != LibnxThreadVarMagic) {
u8 thread_type[0x1C0];
const u64 thread_type_addr = *(reinterpret_cast<u64 *>(&thread_tls[0x1F8]));
if (R_SUCCEEDED(svcReadDebugProcessMemory(thread_type, debug_handle, thread_type_addr, sizeof(thread_type)))) {
if (R_SUCCEEDED(svc::ReadDebugProcessMemory(reinterpret_cast<uintptr_t>(thread_type), debug_handle, thread_type_addr, sizeof(thread_type)))) {
/* Get the thread version. */
const u16 thread_version = *reinterpret_cast<u16 *>(&thread_type[0x46]);
if (thread_version == 0 || thread_version == 0xFFFF) {
@@ -187,18 +187,18 @@ namespace ams::creport {
return true;
}
void ThreadInfo::TryGetStackInfo(Handle debug_handle) {
void ThreadInfo::TryGetStackInfo(os::NativeHandle debug_handle) {
/* Query stack region. */
MemoryInfo mi;
u32 pi;
if (R_FAILED(svcQueryDebugProcessMemory(&mi, &pi, debug_handle, this->context.sp))) {
svc::MemoryInfo mi;
svc::PageInfo pi;
if (R_FAILED(svc::QueryDebugProcessMemory(&mi, &pi, debug_handle, this->context.sp))) {
return;
}
/* Check if sp points into the stack. */
if (mi.type != MemType_MappedMemory) {
if (mi.state != svc::MemoryState_Stack) {
/* It's possible that sp is below the stack... */
if (R_FAILED(svcQueryDebugProcessMemory(&mi, &pi, debug_handle, mi.addr + mi.size)) || mi.type != MemType_MappedMemory) {
if (R_FAILED(svc::QueryDebugProcessMemory(&mi, &pi, debug_handle, mi.addr + mi.size)) || mi.state != svc::MemoryState_Stack) {
return;
}
}
@@ -212,7 +212,7 @@ namespace ams::creport {
this->stack_dump_base = std::min(std::max(this->context.sp & ~0xFul, this->stack_bottom), this->stack_top - sizeof(this->stack_dump));
/* Try to read stack. */
if (R_FAILED(svcReadDebugProcessMemory(this->stack_dump, debug_handle, this->stack_dump_base, sizeof(this->stack_dump)))) {
if (R_FAILED(svc::ReadDebugProcessMemory(reinterpret_cast<uintptr_t>(this->stack_dump), debug_handle, this->stack_dump_base, sizeof(this->stack_dump)))) {
this->stack_dump_base = 0;
}
}
@@ -252,7 +252,7 @@ namespace ams::creport {
}
}
void ThreadList::ReadFromProcess(Handle debug_handle, ThreadTlsMap &tls_map, bool is_64_bit) {
void ThreadList::ReadFromProcess(os::NativeHandle debug_handle, ThreadTlsMap &tls_map, bool is_64_bit) {
this->thread_count = 0;
/* Get thread list. */

View File

@@ -60,7 +60,7 @@ namespace ams::creport {
static constexpr size_t StackTraceSizeMax = 0x20;
static constexpr size_t NameLengthMax = 0x20;
private:
ThreadContext context = {};
svc::ThreadContext context = {};
u64 thread_id = 0;
u64 stack_top = 0;
u64 stack_bottom = 0;
@@ -74,11 +74,11 @@ namespace ams::creport {
ModuleList *module_list = nullptr;
public:
u64 GetGeneralPurposeRegister(size_t i) const {
return this->context.cpu_gprs[i].x;
return this->context.r[i];
}
u64 GetPC() const {
return this->context.pc.x;
return this->context.pc;
}
u64 GetLR() const {
@@ -109,11 +109,11 @@ namespace ams::creport {
this->module_list = ml;
}
bool ReadFromProcess(Handle debug_handle, ThreadTlsMap &tls_map, u64 thread_id, bool is_64_bit);
bool ReadFromProcess(os::NativeHandle debug_handle, ThreadTlsMap &tls_map, u64 thread_id, bool is_64_bit);
void SaveToFile(ScopedFile &file);
void DumpBinary(ScopedFile &file);
private:
void TryGetStackInfo(Handle debug_handle);
void TryGetStackInfo(os::NativeHandle debug_handle);
};
class ThreadList {
@@ -135,7 +135,7 @@ namespace ams::creport {
}
}
void ReadFromProcess(Handle debug_handle, ThreadTlsMap &tls_map, bool is_64_bit);
void ReadFromProcess(os::NativeHandle debug_handle, ThreadTlsMap &tls_map, bool is_64_bit);
void SaveToFile(ScopedFile &file);
void DumpBinary(ScopedFile &file, u64 crashed_thread_id);
};