strat: use svc:: over ::svc
This commit is contained in:
@@ -37,8 +37,8 @@ namespace ams::mitm::bpc_ams {
|
||||
void MitmModule::ThreadFunction(void *arg) {
|
||||
/* Create bpc:ams. */
|
||||
{
|
||||
Handle bpcams_h;
|
||||
R_ABORT_UNLESS(svcManageNamedPort(&bpcams_h, AtmosphereServiceName.name, AtmosphereMaxSessions));
|
||||
os::NativeHandle bpcams_h;
|
||||
R_ABORT_UNLESS(svc::ManageNamedPort(&bpcams_h, AtmosphereServiceName.name, AtmosphereMaxSessions));
|
||||
g_server_manager.RegisterObjectForServer(g_ams_service_object.GetShared(), bpcams_h);
|
||||
}
|
||||
|
||||
|
||||
@@ -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(×tamp)) {
|
||||
timestamp = svcGetSystemTick();
|
||||
timestamp = os::GetSystemTick().GetInt64Value();
|
||||
}
|
||||
|
||||
/* Save files. */
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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. */
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace ams::dmnt::cheat {
|
||||
return dmnt::cheat::impl::GetCheatProcessMappingCount(out_count.GetPointer());
|
||||
}
|
||||
|
||||
Result CheatService::GetCheatProcessMappings(const sf::OutArray<MemoryInfo> &mappings, sf::Out<u64> out_count, u64 offset) {
|
||||
Result CheatService::GetCheatProcessMappings(const sf::OutArray<svc::MemoryInfo> &mappings, sf::Out<u64> out_count, u64 offset) {
|
||||
R_UNLESS(mappings.GetPointer() != nullptr, ResultCheatNullBuffer());
|
||||
return dmnt::cheat::impl::GetCheatProcessMappings(mappings.GetPointer(), mappings.GetSize(), out_count.GetPointer(), offset);
|
||||
}
|
||||
@@ -75,7 +75,7 @@ namespace ams::dmnt::cheat {
|
||||
return dmnt::cheat::impl::WriteCheatProcessMemory(address, buffer.GetPointer(), std::min(in_size, buffer.GetSize()));
|
||||
}
|
||||
|
||||
Result CheatService::QueryCheatProcessMemory(sf::Out<MemoryInfo> mapping, u64 address) {
|
||||
Result CheatService::QueryCheatProcessMemory(sf::Out<svc::MemoryInfo> mapping, u64 address) {
|
||||
return dmnt::cheat::impl::QueryCheatProcessMemory(mapping.GetPointer(), address);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,10 +26,10 @@
|
||||
AMS_SF_METHOD_INFO(C, H, 65005, Result, ResumeCheatProcess, (), ()) \
|
||||
AMS_SF_METHOD_INFO(C, H, 65006, Result, ForceCloseCheatProcess, (), ()) \
|
||||
AMS_SF_METHOD_INFO(C, H, 65100, Result, GetCheatProcessMappingCount, (sf::Out<u64> out_count), (out_count)) \
|
||||
AMS_SF_METHOD_INFO(C, H, 65101, Result, GetCheatProcessMappings, (const sf::OutArray<MemoryInfo> &mappings, sf::Out<u64> out_count, u64 offset), (mappings, out_count, offset)) \
|
||||
AMS_SF_METHOD_INFO(C, H, 65101, Result, GetCheatProcessMappings, (const sf::OutArray<svc::MemoryInfo> &mappings, sf::Out<u64> out_count, u64 offset), (mappings, out_count, offset)) \
|
||||
AMS_SF_METHOD_INFO(C, H, 65102, Result, ReadCheatProcessMemory, (const sf::OutBuffer &buffer, u64 address, u64 out_size), (buffer, address, out_size)) \
|
||||
AMS_SF_METHOD_INFO(C, H, 65103, Result, WriteCheatProcessMemory, (const sf::InBuffer &buffer, u64 address, u64 in_size), (buffer, address, in_size)) \
|
||||
AMS_SF_METHOD_INFO(C, H, 65104, Result, QueryCheatProcessMemory, (sf::Out<MemoryInfo> mapping, u64 address), (mapping, address)) \
|
||||
AMS_SF_METHOD_INFO(C, H, 65104, Result, QueryCheatProcessMemory, (sf::Out<svc::MemoryInfo> mapping, u64 address), (mapping, address)) \
|
||||
AMS_SF_METHOD_INFO(C, H, 65200, Result, GetCheatCount, (sf::Out<u64> out_count), (out_count)) \
|
||||
AMS_SF_METHOD_INFO(C, H, 65201, Result, GetCheats, (const sf::OutArray<dmnt::cheat::CheatEntry> &cheats, sf::Out<u64> out_count, u64 offset), (cheats, out_count, offset)) \
|
||||
AMS_SF_METHOD_INFO(C, H, 65202, Result, GetCheatById, (sf::Out<dmnt::cheat::CheatEntry> cheat, u32 cheat_id), (cheat, cheat_id)) \
|
||||
@@ -61,10 +61,10 @@ namespace ams::dmnt::cheat {
|
||||
Result ForceCloseCheatProcess();
|
||||
|
||||
Result GetCheatProcessMappingCount(sf::Out<u64> out_count);
|
||||
Result GetCheatProcessMappings(const sf::OutArray<MemoryInfo> &mappings, sf::Out<u64> out_count, u64 offset);
|
||||
Result GetCheatProcessMappings(const sf::OutArray<svc::MemoryInfo> &mappings, sf::Out<u64> out_count, u64 offset);
|
||||
Result ReadCheatProcessMemory(const sf::OutBuffer &buffer, u64 address, u64 out_size);
|
||||
Result WriteCheatProcessMemory(const sf::InBuffer &buffer, u64 address, u64 in_size);
|
||||
Result QueryCheatProcessMemory(sf::Out<MemoryInfo> mapping, u64 address);
|
||||
Result QueryCheatProcessMemory(sf::Out<svc::MemoryInfo> mapping, u64 address);
|
||||
|
||||
Result GetCheatCount(sf::Out<u64> out_count);
|
||||
Result GetCheats(const sf::OutArray<CheatEntry> &cheats, sf::Out<u64> out_count, u64 offset);
|
||||
|
||||
@@ -307,11 +307,11 @@ namespace ams::dmnt::cheat::impl {
|
||||
}
|
||||
|
||||
Result ReadCheatProcessMemoryUnsafe(u64 proc_addr, void *out_data, size_t size) {
|
||||
return svcReadDebugProcessMemory(out_data, this->GetCheatProcessHandle(), proc_addr, size);
|
||||
return svc::ReadDebugProcessMemory(reinterpret_cast<uintptr_t>(out_data), this->GetCheatProcessHandle(), proc_addr, size);
|
||||
}
|
||||
|
||||
Result WriteCheatProcessMemoryUnsafe(u64 proc_addr, const void *data, size_t size) {
|
||||
R_TRY(svcWriteDebugProcessMemory(this->GetCheatProcessHandle(), data, proc_addr, size));
|
||||
R_TRY(svc::WriteDebugProcessMemory(this->GetCheatProcessHandle(), reinterpret_cast<uintptr_t>(data), proc_addr, size));
|
||||
|
||||
for (auto &entry : this->frozen_addresses_map) {
|
||||
/* Get address/value. */
|
||||
@@ -337,7 +337,7 @@ namespace ams::dmnt::cheat::impl {
|
||||
Result PauseCheatProcessUnsafe() {
|
||||
this->broken_unsafe = true;
|
||||
this->unsafe_break_event.Clear();
|
||||
return svcBreakDebugProcess(this->GetCheatProcessHandle());
|
||||
return svc::BreakDebugProcess(this->GetCheatProcessHandle());
|
||||
}
|
||||
|
||||
Result ResumeCheatProcessUnsafe() {
|
||||
@@ -352,16 +352,15 @@ namespace ams::dmnt::cheat::impl {
|
||||
|
||||
R_TRY(this->EnsureCheatProcess());
|
||||
|
||||
MemoryInfo mem_info;
|
||||
svc::MemoryInfo mem_info;
|
||||
svc::PageInfo page_info;
|
||||
u64 address = 0, count = 0;
|
||||
do {
|
||||
mem_info.perm = Perm_None;
|
||||
u32 tmp;
|
||||
if (R_FAILED(svcQueryDebugProcessMemory(&mem_info, &tmp, this->GetCheatProcessHandle(), address))) {
|
||||
if (R_FAILED(svc::QueryDebugProcessMemory(&mem_info, &page_info, this->GetCheatProcessHandle(), address))) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (mem_info.perm != Perm_None) {
|
||||
if (mem_info.perm != svc::MemoryPermission_None) {
|
||||
count++;
|
||||
}
|
||||
|
||||
@@ -372,21 +371,20 @@ namespace ams::dmnt::cheat::impl {
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result GetCheatProcessMappings(MemoryInfo *mappings, size_t max_count, u64 *out_count, u64 offset) {
|
||||
Result GetCheatProcessMappings(svc::MemoryInfo *mappings, size_t max_count, u64 *out_count, u64 offset) {
|
||||
std::scoped_lock lk(this->cheat_lock);
|
||||
|
||||
R_TRY(this->EnsureCheatProcess());
|
||||
|
||||
MemoryInfo mem_info;
|
||||
svc::MemoryInfo mem_info;
|
||||
svc::PageInfo page_info;
|
||||
u64 address = 0, total_count = 0, written_count = 0;
|
||||
do {
|
||||
mem_info.perm = Perm_None;
|
||||
u32 tmp;
|
||||
if (R_FAILED(svcQueryDebugProcessMemory(&mem_info, &tmp, this->GetCheatProcessHandle(), address))) {
|
||||
if (R_FAILED(svc::QueryDebugProcessMemory(&mem_info, &page_info, this->GetCheatProcessHandle(), address))) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (mem_info.perm != Perm_None) {
|
||||
if (mem_info.perm != svc::MemoryPermission_None) {
|
||||
if (offset <= total_count && written_count < max_count) {
|
||||
mappings[written_count++] = mem_info;
|
||||
}
|
||||
@@ -416,13 +414,13 @@ namespace ams::dmnt::cheat::impl {
|
||||
return this->WriteCheatProcessMemoryUnsafe(proc_addr, data, size);
|
||||
}
|
||||
|
||||
Result QueryCheatProcessMemory(MemoryInfo *mapping, u64 address) {
|
||||
Result QueryCheatProcessMemory(svc::MemoryInfo *mapping, u64 address) {
|
||||
std::scoped_lock lk(this->cheat_lock);
|
||||
|
||||
R_TRY(this->EnsureCheatProcess());
|
||||
|
||||
u32 tmp;
|
||||
return svcQueryDebugProcessMemory(mapping, &tmp, this->GetCheatProcessHandle(), address);
|
||||
svc::PageInfo page_info;
|
||||
return svc::QueryDebugProcessMemory(mapping, &page_info, this->GetCheatProcessHandle(), address);
|
||||
}
|
||||
|
||||
Result PauseCheatProcess() {
|
||||
@@ -693,8 +691,9 @@ namespace ams::dmnt::cheat::impl {
|
||||
/* Atomically wait (and clear) signal for new process. */
|
||||
this_ptr->debug_events_event.Wait();
|
||||
while (true) {
|
||||
Handle cheat_process_handle = this_ptr->GetCheatProcessHandle();
|
||||
while (cheat_process_handle != svc::InvalidHandle && R_SUCCEEDED(svcWaitSynchronizationSingle(this_ptr->GetCheatProcessHandle(), std::numeric_limits<u64>::max()))) {
|
||||
os::NativeHandle cheat_process_handle = this_ptr->GetCheatProcessHandle();
|
||||
s32 dummy;
|
||||
while (cheat_process_handle != os::InvalidNativeHandle && R_SUCCEEDED(svc::WaitSynchronization(std::addressof(dummy), std::addressof(cheat_process_handle), 1, std::numeric_limits<u64>::max()))) {
|
||||
this_ptr->cheat_lock.Lock();
|
||||
ON_SCOPE_EXIT { this_ptr->cheat_lock.Unlock(); };
|
||||
{
|
||||
@@ -758,16 +757,16 @@ namespace ams::dmnt::cheat::impl {
|
||||
const auto &value = entry.GetValue();
|
||||
|
||||
/* Use Write SVC directly, to avoid the usual frozen address update logic. */
|
||||
svcWriteDebugProcessMemory(this_ptr->GetCheatProcessHandle(), &value.value, address, value.width);
|
||||
svc::WriteDebugProcessMemory(this_ptr->GetCheatProcessHandle(), reinterpret_cast<uintptr_t>(std::addressof(value.value)), address, value.width);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Sleep until next potential execution. */
|
||||
constexpr u64 ONE_SECOND = 1'000'000'000ul;
|
||||
constexpr u64 TIMES_PER_SECOND = 12;
|
||||
constexpr u64 DELAY_TIME = ONE_SECOND / TIMES_PER_SECOND;
|
||||
svcSleepThread(DELAY_TIME);
|
||||
constexpr s64 TimesPerSecond = 12;
|
||||
constexpr s64 DelayNanoSeconds = TimeSpan::FromSeconds(1).GetNanoSeconds() / TimesPerSecond;
|
||||
constexpr TimeSpan Delay = TimeSpan::FromNanoSeconds(DelayNanoSeconds);
|
||||
os::SleepThread(Delay);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -803,10 +802,10 @@ namespace ams::dmnt::cheat::impl {
|
||||
|
||||
/* Get process handle, use it to learn memory extents. */
|
||||
{
|
||||
Handle proc_h = svc::InvalidHandle;
|
||||
os::NativeHandle proc_h = os::InvalidNativeHandle;
|
||||
ncm::ProgramLocation loc = {};
|
||||
cfg::OverrideStatus status = {};
|
||||
ON_SCOPE_EXIT { if (proc_h != svc::InvalidHandle) { R_ABORT_UNLESS(svcCloseHandle(proc_h)); } };
|
||||
ON_SCOPE_EXIT { os::CloseNativeHandle(proc_h); };
|
||||
|
||||
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;
|
||||
@@ -1238,7 +1237,7 @@ namespace ams::dmnt::cheat::impl {
|
||||
return GetReference(g_cheat_process_manager).GetCheatProcessMappingCount(out_count);
|
||||
}
|
||||
|
||||
Result GetCheatProcessMappings(MemoryInfo *mappings, size_t max_count, u64 *out_count, u64 offset) {
|
||||
Result GetCheatProcessMappings(svc::MemoryInfo *mappings, size_t max_count, u64 *out_count, u64 offset) {
|
||||
return GetReference(g_cheat_process_manager).GetCheatProcessMappings(mappings, max_count, out_count, offset);
|
||||
}
|
||||
|
||||
@@ -1250,7 +1249,7 @@ namespace ams::dmnt::cheat::impl {
|
||||
return GetReference(g_cheat_process_manager).WriteCheatProcessMemory(proc_addr, data, size);
|
||||
}
|
||||
|
||||
Result QueryCheatProcessMemory(MemoryInfo *mapping, u64 address) {
|
||||
Result QueryCheatProcessMemory(svc::MemoryInfo *mapping, u64 address) {
|
||||
return GetReference(g_cheat_process_manager).QueryCheatProcessMemory(mapping, address);
|
||||
}
|
||||
|
||||
|
||||
@@ -35,10 +35,10 @@ namespace ams::dmnt::cheat::impl {
|
||||
Result ResumeCheatProcessUnsafe();
|
||||
|
||||
Result GetCheatProcessMappingCount(u64 *out_count);
|
||||
Result GetCheatProcessMappings(MemoryInfo *mappings, size_t max_count, u64 *out_count, u64 offset);
|
||||
Result GetCheatProcessMappings(svc::MemoryInfo *mappings, size_t max_count, u64 *out_count, u64 offset);
|
||||
Result ReadCheatProcessMemory(u64 proc_addr, void *out_data, size_t size);
|
||||
Result WriteCheatProcessMemory(u64 proc_addr, const void *data, size_t size);
|
||||
Result QueryCheatProcessMemory(MemoryInfo *mapping, u64 address);
|
||||
Result QueryCheatProcessMemory(svc::MemoryInfo *mapping, u64 address);
|
||||
|
||||
Result GetCheatCount(u64 *out_count);
|
||||
Result GetCheats(CheatEntry *cheats, size_t max_count, u64 *out_count, u64 offset);
|
||||
|
||||
@@ -38,10 +38,10 @@ namespace ams::dmnt::cheat::impl {
|
||||
static void PerCoreThreadFunction(void *_this) {
|
||||
/* This thread will wait on the appropriate message queue. */
|
||||
DebugEventsManager *this_ptr = reinterpret_cast<DebugEventsManager *>(_this);
|
||||
const size_t current_core = svcGetCurrentProcessorNumber();
|
||||
const size_t current_core = svc::GetCurrentProcessorNumber();
|
||||
while (true) {
|
||||
/* Receive handle. */
|
||||
Handle debug_handle = this_ptr->WaitReceiveHandle(current_core);
|
||||
os::NativeHandle debug_handle = this_ptr->WaitReceiveHandle(current_core);
|
||||
|
||||
/* Continue events on the correct core. */
|
||||
Result result = this_ptr->ContinueDebugEvent(debug_handle);
|
||||
@@ -51,7 +51,7 @@ namespace ams::dmnt::cheat::impl {
|
||||
}
|
||||
}
|
||||
|
||||
Result GetTargetCore(size_t *out, const svc::DebugEventInfo &dbg_event, Handle debug_handle) {
|
||||
Result GetTargetCore(size_t *out, const svc::DebugEventInfo &dbg_event, os::NativeHandle debug_handle) {
|
||||
/* If we don't need to continue on a specific core, use the system core. */
|
||||
size_t target_core = NumCores - 1;
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace ams::dmnt::cheat::impl {
|
||||
u64 out64 = 0;
|
||||
u32 out32 = 0;
|
||||
|
||||
R_TRY_CATCH(svcGetDebugThreadParam(&out64, &out32, debug_handle, dbg_event.info.create_thread.thread_id, DebugThreadParam_CurrentCore)) {
|
||||
R_TRY_CATCH(svc::GetDebugThreadParam(&out64, &out32, debug_handle, dbg_event.info.create_thread.thread_id, svc::DebugThreadParam_CurrentCore)) {
|
||||
R_CATCH_RETHROW(svc::ResultProcessTerminated)
|
||||
} R_END_TRY_CATCH_WITH_ABORT_UNLESS;
|
||||
|
||||
@@ -72,21 +72,21 @@ namespace ams::dmnt::cheat::impl {
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
void SendHandle(size_t target_core, Handle debug_handle) {
|
||||
void SendHandle(size_t target_core, os::NativeHandle debug_handle) {
|
||||
this->handle_message_queues[target_core].Send(static_cast<uintptr_t>(debug_handle));
|
||||
}
|
||||
|
||||
Handle WaitReceiveHandle(size_t core_id) {
|
||||
os::NativeHandle WaitReceiveHandle(size_t core_id) {
|
||||
uintptr_t x = 0;
|
||||
this->handle_message_queues[core_id].Receive(&x);
|
||||
return static_cast<Handle>(x);
|
||||
return static_cast<os::NativeHandle>(x);
|
||||
}
|
||||
|
||||
Result ContinueDebugEvent(Handle debug_handle) {
|
||||
Result ContinueDebugEvent(os::NativeHandle debug_handle) {
|
||||
if (hos::GetVersion() >= hos::Version_3_0_0) {
|
||||
return svcContinueDebugEvent(debug_handle, 5, nullptr, 0);
|
||||
return svc::ContinueDebugEvent(debug_handle, svc::ContinueFlag_ExceptionHandled | svc::ContinueFlag_ContinueAll, nullptr, 0);
|
||||
} else {
|
||||
return svcLegacyContinueDebugEvent(debug_handle, 5, 0);
|
||||
return svc::LegacyContinueDebugEvent(debug_handle, svc::ContinueFlag_ExceptionHandled | svc::ContinueFlag_ContinueAll, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -63,40 +63,40 @@ namespace ams::fatal::srv {
|
||||
|
||||
constinit ThreadTlsMap g_thread_id_to_tls_map;
|
||||
|
||||
bool IsThreadFatalCaller(Result result, u32 debug_handle, u64 thread_id, u64 thread_tls_addr, ThreadContext *thread_ctx) {
|
||||
bool IsThreadFatalCaller(Result result, os::NativeHandle debug_handle, u64 thread_id, u64 thread_tls_addr, svc::ThreadContext *thread_ctx) {
|
||||
/* Verify that the thread is running or waiting. */
|
||||
{
|
||||
u64 _;
|
||||
u32 _thread_state;
|
||||
if (R_FAILED(svcGetDebugThreadParam(&_, &_thread_state, debug_handle, thread_id, DebugThreadParam_State))) {
|
||||
if (R_FAILED(svc::GetDebugThreadParam(&_, &_thread_state, debug_handle, thread_id, svc::DebugThreadParam_State))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const svc::ThreadState thread_state = static_cast<svc::ThreadState>(_thread_state);
|
||||
const auto thread_state = static_cast<svc::ThreadState>(_thread_state);
|
||||
if (thread_state != svc::ThreadState_Waiting && thread_state != svc::ThreadState_Running) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* Get the thread context. */
|
||||
if (R_FAILED(svcGetDebugThreadContext(thread_ctx, debug_handle, thread_id, svc::ThreadContextFlag_All))) {
|
||||
if (R_FAILED(svc::GetDebugThreadContext(thread_ctx, debug_handle, thread_id, svc::ThreadContextFlag_All))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Try to read the current instruction. */
|
||||
u32 insn;
|
||||
if (R_FAILED(svcReadDebugProcessMemory(&insn, debug_handle, thread_ctx->pc.x, sizeof(insn)))) {
|
||||
if (R_FAILED(svc::ReadDebugProcessMemory(reinterpret_cast<uintptr_t>(std::addressof(insn)), debug_handle, thread_ctx->pc, sizeof(insn)))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* If the instruction isn't svcSendSyncRequest, it's not the fatal caller. */
|
||||
/* If the instruction isn't svc::SendSyncRequest, it's not the fatal caller. */
|
||||
if (insn != SvcSendSyncRequestInstruction) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Read in the fatal caller's TLS. */
|
||||
u8 thread_tls[0x100];
|
||||
if (R_FAILED(svcReadDebugProcessMemory(thread_tls, debug_handle, thread_tls_addr, sizeof(thread_tls)))) {
|
||||
u8 thread_tls[sizeof(svc::ThreadLocalRegion::message_buffer)];
|
||||
if (R_FAILED(svc::ReadDebugProcessMemory(reinterpret_cast<uintptr_t>(thread_tls), debug_handle, thread_tls_addr, sizeof(thread_tls)))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -156,20 +156,20 @@ namespace ams::fatal::srv {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TryGuessBaseAddress(u64 *out_base_address, u32 debug_handle, u64 guess) {
|
||||
MemoryInfo mi;
|
||||
u32 pi;
|
||||
if (R_FAILED(svcQueryDebugProcessMemory(&mi, &pi, debug_handle, guess)) || mi.perm != Perm_Rx) {
|
||||
bool TryGuessBaseAddress(u64 *out_base_address, os::NativeHandle debug_handle, u64 guess) {
|
||||
svc::MemoryInfo mi;
|
||||
svc::PageInfo pi;
|
||||
if (R_FAILED(svc::QueryDebugProcessMemory(&mi, &pi, debug_handle, guess)) || mi.perm != svc::MemoryPermission_ReadExecute) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Iterate backwards until we find the memory before the code region. */
|
||||
while (mi.addr > 0) {
|
||||
if (R_FAILED(svcQueryDebugProcessMemory(&mi, &pi, debug_handle, guess))) {
|
||||
if (R_FAILED(svc::QueryDebugProcessMemory(&mi, &pi, debug_handle, guess))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mi.type == MemType_Unmapped) {
|
||||
if (mi.state == svc::MemoryState_Free) {
|
||||
/* Code region will be at the end of the unmapped region preceding it. */
|
||||
*out_base_address = mi.addr + mi.size;
|
||||
return true;
|
||||
@@ -181,10 +181,10 @@ namespace ams::fatal::srv {
|
||||
return false;
|
||||
}
|
||||
|
||||
u64 GetBaseAddress(const ThrowContext *throw_ctx, const ThreadContext *thread_ctx, u32 debug_handle) {
|
||||
u64 GetBaseAddress(const ThrowContext *throw_ctx, const svc::ThreadContext *thread_ctx, os::NativeHandle debug_handle) {
|
||||
u64 base_address = 0;
|
||||
|
||||
if (TryGuessBaseAddress(&base_address, debug_handle, thread_ctx->pc.x)) {
|
||||
if (TryGuessBaseAddress(&base_address, debug_handle, thread_ctx->pc)) {
|
||||
return base_address;
|
||||
}
|
||||
|
||||
@@ -205,18 +205,18 @@ namespace ams::fatal::srv {
|
||||
|
||||
void TryCollectDebugInformation(ThrowContext *ctx, os::ProcessId process_id) {
|
||||
/* Try to debug the process. This may fail, if we called into ourself. */
|
||||
Handle debug_handle;
|
||||
if (R_FAILED(svcDebugActiveProcess(std::addressof(debug_handle), static_cast<u64>(process_id)))) {
|
||||
os::NativeHandle debug_handle;
|
||||
if (R_FAILED(svc::DebugActiveProcess(std::addressof(debug_handle), process_id.value))) {
|
||||
return;
|
||||
}
|
||||
ON_SCOPE_EXIT { R_ABORT_UNLESS(svc::CloseHandle(debug_handle)); };
|
||||
ON_SCOPE_EXIT { os::CloseNativeHandle(debug_handle); };
|
||||
|
||||
/* First things first, check if process is 64 bits, and get list of thread infos. */
|
||||
g_thread_id_to_tls_map.ResetThreadTlsMap();
|
||||
{
|
||||
bool got_create_process = false;
|
||||
svc::DebugEventInfo d;
|
||||
while (R_SUCCEEDED(svcGetDebugEvent(reinterpret_cast<u8 *>(&d), debug_handle))) {
|
||||
while (R_SUCCEEDED(svc::GetDebugEvent(std::addressof(d), debug_handle))) {
|
||||
switch (d.type) {
|
||||
case svc::DebugEvent_CreateProcess:
|
||||
ctx->cpu_ctx.architecture = (d.info.create_process.flags & 1) ? CpuContext::Architecture_Aarch64 : CpuContext::Architecture_Aarch32;
|
||||
@@ -247,7 +247,7 @@ namespace ams::fatal::srv {
|
||||
bool found_fatal_caller = false;
|
||||
u64 thread_id = 0;
|
||||
u64 thread_tls = 0;
|
||||
ThreadContext thread_ctx;
|
||||
svc::ThreadContext thread_ctx;
|
||||
{
|
||||
/* We start by trying to get a list of threads. */
|
||||
s32 thread_count;
|
||||
@@ -275,7 +275,7 @@ namespace ams::fatal::srv {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (R_FAILED(svcGetDebugThreadContext(&thread_ctx, debug_handle, thread_id, svc::ThreadContextFlag_All))) {
|
||||
if (R_FAILED(svc::GetDebugThreadContext(&thread_ctx, debug_handle, thread_id, svc::ThreadContextFlag_All))) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -283,7 +283,7 @@ namespace ams::fatal::srv {
|
||||
ctx->cpu_ctx.aarch64_ctx.SetRegisterValue(aarch64::RegisterName_FP, thread_ctx.fp);
|
||||
ctx->cpu_ctx.aarch64_ctx.SetRegisterValue(aarch64::RegisterName_LR, thread_ctx.lr);
|
||||
ctx->cpu_ctx.aarch64_ctx.SetRegisterValue(aarch64::RegisterName_SP, thread_ctx.sp);
|
||||
ctx->cpu_ctx.aarch64_ctx.SetRegisterValue(aarch64::RegisterName_PC, thread_ctx.pc.x);
|
||||
ctx->cpu_ctx.aarch64_ctx.SetRegisterValue(aarch64::RegisterName_PC, thread_ctx.pc);
|
||||
|
||||
/* Parse a stack trace. */
|
||||
u64 cur_fp = thread_ctx.fp;
|
||||
@@ -296,7 +296,7 @@ namespace ams::fatal::srv {
|
||||
|
||||
/* Read a new frame. */
|
||||
StackFrame cur_frame = {};
|
||||
if (R_FAILED(svcReadDebugProcessMemory(&cur_frame, debug_handle, cur_fp, sizeof(StackFrame)))) {
|
||||
if (R_FAILED(svc::ReadDebugProcessMemory(reinterpret_cast<uintptr_t>(std::addressof(cur_frame)), debug_handle, cur_fp, sizeof(StackFrame)))) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -308,7 +308,7 @@ namespace ams::fatal::srv {
|
||||
/* Try to read up to 0x100 of stack. */
|
||||
ctx->stack_dump_base = 0;
|
||||
for (size_t sz = 0x100; sz > 0; sz -= 0x10) {
|
||||
if (R_SUCCEEDED(svcReadDebugProcessMemory(ctx->stack_dump, debug_handle, thread_ctx.sp, sz))) {
|
||||
if (R_SUCCEEDED(svc::ReadDebugProcessMemory(reinterpret_cast<uintptr_t>(ctx->stack_dump), debug_handle, thread_ctx.sp, sz))) {
|
||||
ctx->stack_dump_base = thread_ctx.sp;
|
||||
ctx->stack_dump_size = sz;
|
||||
break;
|
||||
@@ -316,7 +316,7 @@ namespace ams::fatal::srv {
|
||||
}
|
||||
|
||||
/* Try to read the first 0x100 of TLS. */
|
||||
if (R_SUCCEEDED(svcReadDebugProcessMemory(ctx->tls_dump, debug_handle, thread_tls, sizeof(ctx->tls_dump)))) {
|
||||
if (R_SUCCEEDED(svc::ReadDebugProcessMemory(reinterpret_cast<uintptr_t>(ctx->tls_dump), debug_handle, thread_tls, sizeof(ctx->tls_dump)))) {
|
||||
ctx->tls_address = thread_tls;
|
||||
} else {
|
||||
ctx->tls_address = 0;
|
||||
|
||||
@@ -74,7 +74,7 @@ namespace ams::fatal::srv {
|
||||
/* Get a timestamp. */
|
||||
u64 timestamp;
|
||||
if (!TryGetCurrentTimestamp(×tamp)) {
|
||||
timestamp = svcGetSystemTick();
|
||||
timestamp = os::GetSystemTick().GetInt64Value();
|
||||
}
|
||||
|
||||
/* Open report file. */
|
||||
|
||||
@@ -332,7 +332,7 @@ namespace ams::ldr {
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result GetCreateProcessParameter(svc::CreateProcessParameter *out, const Meta *meta, u32 flags, Handle reslimit_h) {
|
||||
Result GetCreateProcessParameter(svc::CreateProcessParameter *out, const Meta *meta, u32 flags, os::NativeHandle reslimit_h) {
|
||||
/* Clear output. */
|
||||
std::memset(out, 0, sizeof(*out));
|
||||
|
||||
@@ -456,7 +456,7 @@ namespace ams::ldr {
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result CreateProcessImpl(ProcessInfo *out, const Meta *meta, const NsoHeader *nso_headers, const bool *has_nso, const args::ArgumentInfo *arg_info, u32 flags, Handle reslimit_h) {
|
||||
Result CreateProcessImpl(ProcessInfo *out, const Meta *meta, const NsoHeader *nso_headers, const bool *has_nso, const args::ArgumentInfo *arg_info, u32 flags, os::NativeHandle reslimit_h) {
|
||||
/* Get CreateProcessParameter. */
|
||||
svc::CreateProcessParameter param;
|
||||
R_TRY(GetCreateProcessParameter(std::addressof(param), meta, flags, reslimit_h));
|
||||
@@ -507,7 +507,7 @@ namespace ams::ldr {
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result LoadNsoIntoProcessMemory(Handle process_handle, fs::FileHandle file, uintptr_t map_address, const NsoHeader *nso_header, uintptr_t nso_address, size_t nso_size) {
|
||||
Result LoadNsoIntoProcessMemory(os::NativeHandle process_handle, fs::FileHandle file, uintptr_t map_address, const NsoHeader *nso_header, uintptr_t nso_address, size_t nso_size) {
|
||||
/* Map and read data from file. */
|
||||
{
|
||||
map::AutoCloseMap mapper(map_address, process_handle, nso_address, nso_size);
|
||||
@@ -542,13 +542,13 @@ namespace ams::ldr {
|
||||
const size_t ro_size = (static_cast<size_t>(nso_header->ro_size) + size_t(0xFFFul)) & ~size_t(0xFFFul);
|
||||
const size_t rw_size = (static_cast<size_t>(nso_header->rw_size + nso_header->bss_size) + size_t(0xFFFul)) & ~size_t(0xFFFul);
|
||||
if (text_size) {
|
||||
R_TRY(svcSetProcessMemoryPermission(process_handle, nso_address + nso_header->text_dst_offset, text_size, Perm_Rx));
|
||||
R_TRY(svc::SetProcessMemoryPermission(process_handle, nso_address + nso_header->text_dst_offset, text_size, svc::MemoryPermission_ReadExecute));
|
||||
}
|
||||
if (ro_size) {
|
||||
R_TRY(svcSetProcessMemoryPermission(process_handle, nso_address + nso_header->ro_dst_offset, ro_size, Perm_R));
|
||||
R_TRY(svc::SetProcessMemoryPermission(process_handle, nso_address + nso_header->ro_dst_offset, ro_size, svc::MemoryPermission_Read));
|
||||
}
|
||||
if (rw_size) {
|
||||
R_TRY(svcSetProcessMemoryPermission(process_handle, nso_address + nso_header->rw_dst_offset, rw_size, Perm_Rw));
|
||||
R_TRY(svc::SetProcessMemoryPermission(process_handle, nso_address + nso_header->rw_dst_offset, rw_size, svc::MemoryPermission_ReadWrite));
|
||||
}
|
||||
|
||||
return ResultSuccess();
|
||||
@@ -587,7 +587,7 @@ namespace ams::ldr {
|
||||
}
|
||||
|
||||
/* Set argument region permissions. */
|
||||
R_TRY(svcSetProcessMemoryPermission(process_info->process_handle, process_info->args_address, process_info->args_size, Perm_Rw));
|
||||
R_TRY(svc::SetProcessMemoryPermission(process_info->process_handle, process_info->args_address, process_info->args_size, svc::MemoryPermission_ReadWrite));
|
||||
}
|
||||
|
||||
return ResultSuccess();
|
||||
@@ -596,7 +596,7 @@ namespace ams::ldr {
|
||||
}
|
||||
|
||||
/* Process Creation API. */
|
||||
Result CreateProcess(Handle *out, PinId pin_id, const ncm::ProgramLocation &loc, const cfg::OverrideStatus &override_status, const char *path, u32 flags, Handle reslimit_h) {
|
||||
Result CreateProcess(os::NativeHandle *out, PinId pin_id, const ncm::ProgramLocation &loc, const cfg::OverrideStatus &override_status, const char *path, u32 flags, os::NativeHandle reslimit_h) {
|
||||
/* Use global storage for NSOs. */
|
||||
NsoHeader *nso_headers = g_nso_headers;
|
||||
bool *has_nso = g_has_nso;
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
namespace ams::ldr {
|
||||
|
||||
/* Process Creation API. */
|
||||
Result CreateProcess(Handle *out, PinId pin_id, const ncm::ProgramLocation &loc, const cfg::OverrideStatus &override_status, const char *path, u32 flags, Handle reslimit_h);
|
||||
Result CreateProcess(os::NativeHandle *out, PinId pin_id, const ncm::ProgramLocation &loc, const cfg::OverrideStatus &override_status, const char *path, u32 flags, os::NativeHandle reslimit_h);
|
||||
Result GetProgramInfo(ProgramInfo *out, cfg::OverrideStatus *out_status, const ncm::ProgramLocation &loc);
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
namespace ams::pm::impl {
|
||||
|
||||
ProcessInfo::ProcessInfo(Handle h, os::ProcessId pid, ldr::PinId pin, const ncm::ProgramLocation &l, const cfg::OverrideStatus &s) : process_id(pid), pin_id(pin), loc(l), status(s), handle(h), state(svc::ProcessState_Created), flags(0) {
|
||||
ProcessInfo::ProcessInfo(os::NativeHandle h, os::ProcessId pid, ldr::PinId pin, const ncm::ProgramLocation &l, const cfg::OverrideStatus &s) : process_id(pid), pin_id(pin), loc(l), status(s), handle(h), state(svc::ProcessState_Created), flags(0) {
|
||||
os::InitializeMultiWaitHolder(std::addressof(this->multi_wait_holder), this->handle);
|
||||
os::SetMultiWaitHolderUserData(std::addressof(this->multi_wait_holder), reinterpret_cast<uintptr_t>(this));
|
||||
}
|
||||
@@ -28,15 +28,15 @@ namespace ams::pm::impl {
|
||||
}
|
||||
|
||||
void ProcessInfo::Cleanup() {
|
||||
if (this->handle != INVALID_HANDLE) {
|
||||
if (this->handle != os::InvalidNativeHandle) {
|
||||
/* Unregister the process. */
|
||||
fsprUnregisterProgram(static_cast<u64>(this->process_id));
|
||||
sm::manager::UnregisterProcess(this->process_id);
|
||||
ldr::pm::UnpinProgram(this->pin_id);
|
||||
|
||||
/* Close the process's handle. */
|
||||
svcCloseHandle(this->handle);
|
||||
this->handle = INVALID_HANDLE;
|
||||
os::CloseNativeHandle(this->handle);
|
||||
this->handle = os::InvalidNativeHandle;
|
||||
|
||||
/* Unlink the process from its multi wait. */
|
||||
os::UnlinkMultiWaitHolder(std::addressof(this->multi_wait_holder));
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace ams::pm::impl {
|
||||
const ldr::PinId pin_id;
|
||||
const ncm::ProgramLocation loc;
|
||||
const cfg::OverrideStatus status;
|
||||
Handle handle;
|
||||
os::NativeHandle handle;
|
||||
svc::ProcessState state;
|
||||
u32 flags;
|
||||
os::MultiWaitHolderType multi_wait_holder;
|
||||
@@ -60,7 +60,7 @@ namespace ams::pm::impl {
|
||||
return (this->flags & flag);
|
||||
}
|
||||
public:
|
||||
ProcessInfo(Handle h, os::ProcessId pid, ldr::PinId pin, const ncm::ProgramLocation &l, const cfg::OverrideStatus &s);
|
||||
ProcessInfo(os::NativeHandle h, os::ProcessId pid, ldr::PinId pin, const ncm::ProgramLocation &l, const cfg::OverrideStatus &s);
|
||||
~ProcessInfo();
|
||||
void Cleanup();
|
||||
|
||||
@@ -68,7 +68,7 @@ namespace ams::pm::impl {
|
||||
os::LinkMultiWaitHolder(std::addressof(multi_wait), std::addressof(this->multi_wait_holder));
|
||||
}
|
||||
|
||||
Handle GetHandle() const {
|
||||
os::NativeHandle GetHandle() const {
|
||||
return this->handle;
|
||||
}
|
||||
|
||||
|
||||
@@ -207,7 +207,7 @@ namespace ams::pm::impl {
|
||||
}
|
||||
|
||||
Result StartProcess(ProcessInfo *process_info, const ldr::ProgramInfo *program_info) {
|
||||
R_TRY(svcStartProcess(process_info->GetHandle(), program_info->main_thread_priority, program_info->default_cpu_id, program_info->main_thread_stack_size));
|
||||
R_TRY(svc::StartProcess(process_info->GetHandle(), program_info->main_thread_priority, program_info->default_cpu_id, program_info->main_thread_stack_size));
|
||||
process_info->SetState(svc::ProcessState_Running);
|
||||
return ResultSuccess();
|
||||
}
|
||||
@@ -242,7 +242,7 @@ namespace ams::pm::impl {
|
||||
resource::WaitResourceAvailable(&program_info);
|
||||
|
||||
/* Actually create the process. */
|
||||
Handle process_handle;
|
||||
os::NativeHandle process_handle;
|
||||
{
|
||||
auto pin_guard = SCOPE_GUARD { ldr::pm::UnpinProgram(pin_id); };
|
||||
R_TRY(ldr::pm::CreateProcess(&process_handle, pin_id, GetLoaderCreateProcessFlags(args.flags), resource::GetResourceLimitHandle(&program_info)));
|
||||
@@ -313,7 +313,7 @@ namespace ams::pm::impl {
|
||||
|
||||
void OnProcessSignaled(ProcessListAccessor &list, ProcessInfo *process_info) {
|
||||
/* Reset the process's signal. */
|
||||
svcResetSignal(process_info->GetHandle());
|
||||
svc::ResetSignal(process_info->GetHandle());
|
||||
|
||||
/* Update the process's state. */
|
||||
const svc::ProcessState old_state = process_info->GetState();
|
||||
@@ -455,7 +455,7 @@ namespace ams::pm::impl {
|
||||
auto process_info = list->Find(process_id);
|
||||
R_UNLESS(process_info != nullptr, pm::ResultProcessNotFound());
|
||||
|
||||
return svcTerminateProcess(process_info->GetHandle());
|
||||
return svc::TerminateProcess(process_info->GetHandle());
|
||||
}
|
||||
|
||||
Result TerminateProgram(ncm::ProgramId program_id) {
|
||||
@@ -464,10 +464,10 @@ namespace ams::pm::impl {
|
||||
auto process_info = list->Find(program_id);
|
||||
R_UNLESS(process_info != nullptr, pm::ResultProcessNotFound());
|
||||
|
||||
return svcTerminateProcess(process_info->GetHandle());
|
||||
return svc::TerminateProcess(process_info->GetHandle());
|
||||
}
|
||||
|
||||
Result GetProcessEventHandle(Handle *out) {
|
||||
Result GetProcessEventHandle(os::NativeHandle *out) {
|
||||
*out = os::GetReadableHandleOfSystemEvent(std::addressof(g_process_event));
|
||||
return ResultSuccess();
|
||||
}
|
||||
@@ -602,7 +602,7 @@ namespace ams::pm::impl {
|
||||
return pm::ResultProcessNotFound();
|
||||
}
|
||||
|
||||
Result AtmosphereGetProcessInfo(Handle *out_process_handle, ncm::ProgramLocation *out_loc, cfg::OverrideStatus *out_status, os::ProcessId process_id) {
|
||||
Result AtmosphereGetProcessInfo(os::NativeHandle *out_process_handle, ncm::ProgramLocation *out_loc, cfg::OverrideStatus *out_status, os::ProcessId process_id) {
|
||||
ProcessListAccessor list(g_process_list);
|
||||
|
||||
auto process_info = list->Find(process_id);
|
||||
@@ -615,8 +615,8 @@ namespace ams::pm::impl {
|
||||
}
|
||||
|
||||
/* Hook API. */
|
||||
Result HookToCreateProcess(Handle *out_hook, ncm::ProgramId program_id) {
|
||||
*out_hook = INVALID_HANDLE;
|
||||
Result HookToCreateProcess(os::NativeHandle *out_hook, ncm::ProgramId program_id) {
|
||||
*out_hook = os::InvalidNativeHandle;
|
||||
|
||||
{
|
||||
ncm::ProgramId old_value = ncm::InvalidProgramId;
|
||||
@@ -627,8 +627,8 @@ namespace ams::pm::impl {
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result HookToCreateApplicationProcess(Handle *out_hook) {
|
||||
*out_hook = INVALID_HANDLE;
|
||||
Result HookToCreateApplicationProcess(os::NativeHandle *out_hook) {
|
||||
*out_hook = os::InvalidNativeHandle;
|
||||
|
||||
{
|
||||
bool old_value = false;
|
||||
@@ -670,7 +670,7 @@ namespace ams::pm::impl {
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result GetBootFinishedEventHandle(Handle *out) {
|
||||
Result GetBootFinishedEventHandle(os::NativeHandle *out) {
|
||||
/* In 8.0.0, Nintendo added this command, which signals that the boot sysmodule has finished. */
|
||||
/* Nintendo only signals it in safe mode FIRM, and this function aborts on normal FIRM. */
|
||||
/* We will signal it always, but only allow this function to succeed on safe mode. */
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace ams::pm::impl {
|
||||
Result StartProcess(os::ProcessId process_id);
|
||||
Result TerminateProcess(os::ProcessId process_id);
|
||||
Result TerminateProgram(ncm::ProgramId program_id);
|
||||
Result GetProcessEventHandle(Handle *out);
|
||||
Result GetProcessEventHandle(os::NativeHandle *out);
|
||||
Result GetProcessEventInfo(ProcessEventInfo *out);
|
||||
Result CleanupProcess(os::ProcessId process_id);
|
||||
Result ClearExceptionOccurred(os::ProcessId process_id);
|
||||
@@ -37,16 +37,16 @@ namespace ams::pm::impl {
|
||||
Result GetProcessId(os::ProcessId *out, ncm::ProgramId program_id);
|
||||
Result GetProgramId(ncm::ProgramId *out, os::ProcessId process_id);
|
||||
Result GetApplicationProcessId(os::ProcessId *out_process_id);
|
||||
Result AtmosphereGetProcessInfo(Handle *out_process_handle, ncm::ProgramLocation *out_loc, cfg::OverrideStatus *out_status, os::ProcessId process_id);
|
||||
Result AtmosphereGetProcessInfo(os::NativeHandle *out_process_handle, ncm::ProgramLocation *out_loc, cfg::OverrideStatus *out_status, os::ProcessId process_id);
|
||||
|
||||
/* Hook API. */
|
||||
Result HookToCreateProcess(Handle *out_hook, ncm::ProgramId program_id);
|
||||
Result HookToCreateApplicationProcess(Handle *out_hook);
|
||||
Result HookToCreateProcess(os::NativeHandle *out_hook, ncm::ProgramId program_id);
|
||||
Result HookToCreateApplicationProcess(os::NativeHandle *out_hook);
|
||||
Result ClearHook(u32 which);
|
||||
|
||||
/* Boot API. */
|
||||
Result NotifyBootFinished();
|
||||
Result GetBootFinishedEventHandle(Handle *out);
|
||||
Result GetBootFinishedEventHandle(os::NativeHandle *out);
|
||||
|
||||
/* Resource Limit API. */
|
||||
Result BoostSystemMemoryResourceLimit(u64 boost_size);
|
||||
|
||||
@@ -72,9 +72,9 @@ namespace ams::ro::impl {
|
||||
const u64 ro_offset = rx_offset + rx_size;
|
||||
const u64 rw_offset = ro_offset + ro_size;
|
||||
|
||||
R_TRY(svcSetProcessMemoryPermission(process_handle, base_address + rx_offset, rx_size, Perm_Rx));
|
||||
R_TRY(svcSetProcessMemoryPermission(process_handle, base_address + ro_offset, ro_size, Perm_R ));
|
||||
R_TRY(svcSetProcessMemoryPermission(process_handle, base_address + rw_offset, rw_size, Perm_Rw));
|
||||
R_TRY(svc::SetProcessMemoryPermission(process_handle, base_address + rx_offset, rx_size, svc::MemoryPermission_ReadExecute));
|
||||
R_TRY(svc::SetProcessMemoryPermission(process_handle, base_address + ro_offset, ro_size, svc::MemoryPermission_Read));
|
||||
R_TRY(svc::SetProcessMemoryPermission(process_handle, base_address + rw_offset, rw_size, svc::MemoryPermission_ReadWrite));
|
||||
|
||||
return ResultSuccess();
|
||||
}
|
||||
@@ -82,16 +82,16 @@ namespace ams::ro::impl {
|
||||
Result UnmapNro(os::NativeHandle process_handle, u64 base_address, u64 nro_heap_address, u64 bss_heap_address, u64 bss_heap_size, u64 code_size, u64 rw_size) {
|
||||
/* First, unmap bss. */
|
||||
if (bss_heap_size > 0) {
|
||||
R_TRY(svcUnmapProcessCodeMemory(process_handle, base_address + code_size + rw_size, bss_heap_address, bss_heap_size));
|
||||
R_TRY(svc::UnmapProcessCodeMemory(process_handle, base_address + code_size + rw_size, bss_heap_address, bss_heap_size));
|
||||
}
|
||||
|
||||
/* Next, unmap .rwdata */
|
||||
if (rw_size > 0) {
|
||||
R_TRY(svcUnmapProcessCodeMemory(process_handle, base_address + code_size, nro_heap_address + code_size, rw_size));
|
||||
R_TRY(svc::UnmapProcessCodeMemory(process_handle, base_address + code_size, nro_heap_address + code_size, rw_size));
|
||||
}
|
||||
|
||||
/* Finally, unmap .text + .rodata. */
|
||||
R_TRY(svcUnmapProcessCodeMemory(process_handle, base_address, nro_heap_address, code_size));
|
||||
R_TRY(svc::UnmapProcessCodeMemory(process_handle, base_address, nro_heap_address, code_size));
|
||||
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
@@ -224,8 +224,8 @@ namespace ams::ro::impl {
|
||||
}
|
||||
|
||||
Result UnmapNrr(os::NativeHandle process_handle, const NrrHeader *header, u64 nrr_heap_address, u64 nrr_heap_size, u64 mapped_code_address) {
|
||||
R_TRY(svcUnmapProcessMemory(reinterpret_cast<void *>(const_cast<NrrHeader *>(header)), process_handle, mapped_code_address, nrr_heap_size));
|
||||
R_TRY(svcUnmapProcessCodeMemory(process_handle, mapped_code_address, nrr_heap_address, nrr_heap_size));
|
||||
R_TRY(svc::UnmapProcessMemory(reinterpret_cast<uintptr_t>(header), process_handle, mapped_code_address, nrr_heap_size));
|
||||
R_TRY(svc::UnmapProcessCodeMemory(process_handle, mapped_code_address, nrr_heap_address, nrr_heap_size));
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
|
||||
@@ -319,7 +319,7 @@ namespace ams::ro::impl {
|
||||
UnmapNrr(context->process_handle, context->nrr_infos[i].mapped_header, context->nrr_infos[i].nrr_heap_address, context->nrr_infos[i].nrr_heap_size, context->nrr_infos[i].mapped_code_address);
|
||||
}
|
||||
}
|
||||
svcCloseHandle(context->process_handle);
|
||||
os::CloseNativeHandle(context->process_handle);
|
||||
}
|
||||
std::memset(context, 0, sizeof(*context));
|
||||
context->in_use = false;
|
||||
|
||||
@@ -226,13 +226,13 @@ namespace ams::spl::impl {
|
||||
u64 dst_addr;
|
||||
u64 src_addr;
|
||||
size_t size;
|
||||
u32 perm;
|
||||
svc::MemoryPermission perm;
|
||||
public:
|
||||
DeviceAddressSpaceMapHelper(Handle h, u64 dst, u64 src, size_t sz, u32 p) : das_hnd(h), dst_addr(dst), src_addr(src), size(sz), perm(p) {
|
||||
R_ABORT_UNLESS(svcMapDeviceAddressSpaceAligned(this->das_hnd, dd::GetCurrentProcessHandle(), this->src_addr, this->size, this->dst_addr, this->perm));
|
||||
DeviceAddressSpaceMapHelper(Handle h, u64 dst, u64 src, size_t sz, svc::MemoryPermission p) : das_hnd(h), dst_addr(dst), src_addr(src), size(sz), perm(p) {
|
||||
R_ABORT_UNLESS(svc::MapDeviceAddressSpaceAligned(this->das_hnd, dd::GetCurrentProcessHandle(), this->src_addr, this->size, this->dst_addr, this->perm));
|
||||
}
|
||||
~DeviceAddressSpaceMapHelper() {
|
||||
R_ABORT_UNLESS(svcUnmapDeviceAddressSpace(this->das_hnd, dd::GetCurrentProcessHandle(), this->src_addr, this->size, this->dst_addr));
|
||||
R_ABORT_UNLESS(svc::UnmapDeviceAddressSpace(this->das_hnd, dd::GetCurrentProcessHandle(), this->src_addr, this->size, this->dst_addr));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -279,16 +279,16 @@ namespace ams::spl::impl {
|
||||
void InitializeDeviceAddressSpace() {
|
||||
|
||||
/* Create Address Space. */
|
||||
R_ABORT_UNLESS(svcCreateDeviceAddressSpace(&g_se_das_hnd, 0, (1ul << 32)));
|
||||
R_ABORT_UNLESS(svc::CreateDeviceAddressSpace(&g_se_das_hnd, 0, (1ul << 32)));
|
||||
|
||||
/* Attach it to the SE. */
|
||||
R_ABORT_UNLESS(svcAttachDeviceAddressSpace(svc::DeviceName_Se, g_se_das_hnd));
|
||||
R_ABORT_UNLESS(svc::AttachDeviceAddressSpace(svc::DeviceName_Se, g_se_das_hnd));
|
||||
|
||||
const u64 work_buffer_addr = reinterpret_cast<u64>(g_work_buffer);
|
||||
g_se_mapped_work_buffer_addr = WorkBufferMapBase + (work_buffer_addr % DeviceAddressSpaceAlign);
|
||||
|
||||
/* Map the work buffer for the SE. */
|
||||
R_ABORT_UNLESS(svcMapDeviceAddressSpaceAligned(g_se_das_hnd, dd::GetCurrentProcessHandle(), work_buffer_addr, sizeof(g_work_buffer), g_se_mapped_work_buffer_addr, 3));
|
||||
R_ABORT_UNLESS(svc::MapDeviceAddressSpaceAligned(g_se_das_hnd, dd::GetCurrentProcessHandle(), work_buffer_addr, sizeof(g_work_buffer), g_se_mapped_work_buffer_addr, svc::MemoryPermission_ReadWrite));
|
||||
}
|
||||
|
||||
/* Internal RNG functionality. */
|
||||
@@ -689,8 +689,8 @@ namespace ams::spl::impl {
|
||||
R_UNLESS(dst_size_page_aligned <= ComputeAesSizeMax, spl::ResultInvalidSize());
|
||||
|
||||
/* Helpers for mapping/unmapping. */
|
||||
DeviceAddressSpaceMapHelper in_mapper(g_se_das_hnd, src_se_map_addr, src_addr_page_aligned, src_size_page_aligned, 1);
|
||||
DeviceAddressSpaceMapHelper out_mapper(g_se_das_hnd, dst_se_map_addr, dst_addr_page_aligned, dst_size_page_aligned, 2);
|
||||
DeviceAddressSpaceMapHelper in_mapper(g_se_das_hnd, src_se_map_addr, src_addr_page_aligned, src_size_page_aligned, svc::MemoryPermission_Read);
|
||||
DeviceAddressSpaceMapHelper out_mapper(g_se_das_hnd, dst_se_map_addr, dst_addr_page_aligned, dst_size_page_aligned, svc::MemoryPermission_Write);
|
||||
|
||||
/* Setup SE linked list entries. */
|
||||
SeCryptContext *crypt_ctx = reinterpret_cast<SeCryptContext *>(g_work_buffer);
|
||||
|
||||
Reference in New Issue
Block a user