mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2024-11-09 22:56:35 +00:00
Stratosphere: Implement ldr:dmnt->GetNsoInfos()
This commit is contained in:
parent
b2660c661c
commit
b843938b1a
3 changed files with 53 additions and 8 deletions
|
@ -1,7 +1,10 @@
|
||||||
#include <switch.h>
|
#include <switch.h>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include "ldr_debug_monitor.hpp"
|
#include "ldr_debug_monitor.hpp"
|
||||||
#include "ldr_launch_queue.hpp"
|
#include "ldr_launch_queue.hpp"
|
||||||
|
#include "ldr_registration.hpp"
|
||||||
|
|
||||||
Result DebugMonitorService::dispatch(IpcParsedCommand *r, IpcCommand *out_c, u32 *cmd_buf, u32 cmd_id, u32 *in_rawdata, u32 in_rawdata_size, u32 *out_rawdata, u32 *out_raw_data_count) {
|
Result DebugMonitorService::dispatch(IpcParsedCommand *r, IpcCommand *out_c, u32 *cmd_buf, u32 cmd_id, u32 *in_rawdata, u32 in_rawdata_size, u32 *out_rawdata, u32 *out_raw_data_count) {
|
||||||
|
|
||||||
|
@ -64,6 +67,11 @@ Result DebugMonitorService::clear_launch_queue() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Result DebugMonitorService::get_nso_info(u64 pid, void *out, size_t out_size, u32 *out_num_nsos) {
|
Result DebugMonitorService::get_nso_info(u64 pid, void *out, size_t out_size, u32 *out_num_nsos) {
|
||||||
/* TODO, once I've defined struct NsoInfo elsewhere (in ldr_RegisteredProcesses.hpp) */
|
u32 max_out = out_size / (sizeof(Registration::NsoInfo));
|
||||||
return 0;
|
|
||||||
|
Registration::NsoInfo *nso_out = (Registration::NsoInfo *)out;
|
||||||
|
|
||||||
|
std::fill(nso_out, nso_out + max_out, (const Registration::NsoInfo){0});
|
||||||
|
|
||||||
|
return Registration::get_nso_infos_for_process_id(nso_out, max_out, pid, out_num_nsos);
|
||||||
}
|
}
|
|
@ -26,6 +26,16 @@ Registration::Process *Registration::get_process(u64 index) {
|
||||||
return &g_registration_list.processes[i];
|
return &g_registration_list.processes[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Registration::Process *Registration::get_process_by_process_id(u64 pid) {
|
||||||
|
unsigned int i;
|
||||||
|
for (i = 0; !g_registration_list.processes[i].in_use || g_registration_list.processes[i].process_id != pid; i++) {
|
||||||
|
if (i >= REGISTRATION_LIST_MAX) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return &g_registration_list.processes[i];
|
||||||
|
}
|
||||||
|
|
||||||
bool Registration::register_tid_sid(const TidSid *tid_sid, u64 *out_index) {
|
bool Registration::register_tid_sid(const TidSid *tid_sid, u64 *out_index) {
|
||||||
Registration::Process *free_process = get_free_process();
|
Registration::Process *free_process = get_free_process();
|
||||||
if (free_process == NULL) {
|
if (free_process == NULL) {
|
||||||
|
@ -70,11 +80,32 @@ void Registration::add_nso_info(u64 index, u64 base_address, u64 size, const uns
|
||||||
|
|
||||||
for (unsigned int i = 0; i < NSO_INFO_MAX; i++) {
|
for (unsigned int i = 0; i < NSO_INFO_MAX; i++) {
|
||||||
if (!target_process->nso_infos[i].in_use) {
|
if (!target_process->nso_infos[i].in_use) {
|
||||||
target_process->nso_infos[i].base_address = base_address;
|
target_process->nso_infos[i].info.base_address = base_address;
|
||||||
target_process->nso_infos[i].size = size;
|
target_process->nso_infos[i].info.size = size;
|
||||||
std::copy(build_id, build_id + sizeof(target_process->nso_infos[i].build_id), target_process->nso_infos[i].build_id);
|
std::copy(build_id, build_id + sizeof(target_process->nso_infos[i].info.build_id), target_process->nso_infos[i].info.build_id);
|
||||||
target_process->nso_infos[i].in_use = true;
|
target_process->nso_infos[i].in_use = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Result Registration::get_nso_infos_for_process_id(Registration::NsoInfo *out, u32 max_out, u64 process_id, u32 *num_written) {
|
||||||
|
Registration::Process *target_process = get_process_by_process_id(process_id);
|
||||||
|
if (target_process == NULL) {
|
||||||
|
return 0x1009;
|
||||||
|
}
|
||||||
|
u32 cur = 0;
|
||||||
|
|
||||||
|
if (max_out > 0) {
|
||||||
|
for (unsigned int i = 0; i < NSO_INFO_MAX && cur < max_out; i++) {
|
||||||
|
if (target_process->nso_infos[i].in_use) {
|
||||||
|
out[cur++] = target_process->nso_infos[i].info;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*num_written = cur;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
|
@ -8,12 +8,16 @@
|
||||||
class Registration {
|
class Registration {
|
||||||
public:
|
public:
|
||||||
struct NsoInfo {
|
struct NsoInfo {
|
||||||
bool in_use;
|
|
||||||
u64 base_address;
|
u64 base_address;
|
||||||
u64 size;
|
u64 size;
|
||||||
unsigned char build_id[0x20];
|
unsigned char build_id[0x20];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct NsoInfoHolder {
|
||||||
|
bool in_use;
|
||||||
|
NsoInfo info;
|
||||||
|
};
|
||||||
|
|
||||||
struct TidSid {
|
struct TidSid {
|
||||||
u64 title_id;
|
u64 title_id;
|
||||||
FsStorageId storage_id;
|
FsStorageId storage_id;
|
||||||
|
@ -25,7 +29,7 @@ class Registration {
|
||||||
u64 process_id;
|
u64 process_id;
|
||||||
u64 title_id_min;
|
u64 title_id_min;
|
||||||
Registration::TidSid tid_sid;
|
Registration::TidSid tid_sid;
|
||||||
Registration::NsoInfo nso_infos[NSO_INFO_MAX];
|
Registration::NsoInfoHolder nso_infos[NSO_INFO_MAX];
|
||||||
u64 _0x730;
|
u64 _0x730;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -36,8 +40,10 @@ class Registration {
|
||||||
|
|
||||||
static Registration::Process *get_free_process();
|
static Registration::Process *get_free_process();
|
||||||
static Registration::Process *get_process(u64 index);
|
static Registration::Process *get_process(u64 index);
|
||||||
|
static Registration::Process *get_process_by_process_id(u64 pid);
|
||||||
static bool register_tid_sid(const TidSid *tid_sid, u64 *out_index);
|
static bool register_tid_sid(const TidSid *tid_sid, u64 *out_index);
|
||||||
static bool unregister_index(u64 index);
|
static bool unregister_index(u64 index);
|
||||||
static void set_process_id_and_tid_min(u64 index, u64 process_id, u64 tid_min);
|
static void set_process_id_and_tid_min(u64 index, u64 process_id, u64 tid_min);
|
||||||
static void add_nso_info(u64 index, u64 base_address, u64 size, const unsigned char *build_id);
|
static void add_nso_info(u64 index, u64 base_address, u64 size, const unsigned char *build_id);
|
||||||
|
static Result get_nso_infos_for_process_id(NsoInfo *out, u32 max_out, u64 process_id, u32 *num_written);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue