summaryrefslogtreecommitdiffstats
path: root/src/core/hle/service/ldr/ldr.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/core/hle/service/ldr/ldr.cpp56
1 files changed, 31 insertions, 25 deletions
diff --git a/src/core/hle/service/ldr/ldr.cpp b/src/core/hle/service/ldr/ldr.cpp
index 652441bc2..c42489ff9 100644
--- a/src/core/hle/service/ldr/ldr.cpp
+++ b/src/core/hle/service/ldr/ldr.cpp
@@ -9,11 +9,12 @@
#include "common/hex_util.h"
#include "common/scope_exit.h"
#include "core/core.h"
-#include "core/hle/ipc_helpers.h"
#include "core/hle/kernel/k_page_table.h"
#include "core/hle/kernel/svc_results.h"
#include "core/hle/kernel/svc_types.h"
+#include "core/hle/service/ipc_helpers.h"
#include "core/hle/service/ldr/ldr.h"
+#include "core/hle/service/server_manager.h"
#include "core/hle/service/service.h"
#include "core/loader/nro.h"
#include "core/memory.h"
@@ -159,8 +160,7 @@ public:
class RelocatableObject final : public ServiceFramework<RelocatableObject> {
public:
- explicit RelocatableObject(Core::System& system_)
- : ServiceFramework{system_, "ldr:ro", ServiceThreadType::CreateNew} {
+ explicit RelocatableObject(Core::System& system_) : ServiceFramework{system_, "ldr:ro"} {
// clang-format off
static const FunctionInfo functions[] = {
{0, &RelocatableObject::LoadModule, "LoadModule"},
@@ -175,7 +175,7 @@ public:
RegisterHandlers(functions);
}
- void RegisterModuleInfo(Kernel::HLERequestContext& ctx) {
+ void RegisterModuleInfo(HLERequestContext& ctx) {
struct Parameters {
u64_le process_id;
u64_le nrr_address;
@@ -225,7 +225,7 @@ public:
// Read NRR data from memory
std::vector<u8> nrr_data(nrr_size);
- system.Memory().ReadBlock(nrr_address, nrr_data.data(), nrr_size);
+ system.ApplicationMemory().ReadBlock(nrr_address, nrr_data.data(), nrr_size);
NRRHeader header;
std::memcpy(&header, nrr_data.data(), sizeof(NRRHeader));
@@ -246,7 +246,7 @@ public:
return;
}
- if (system.GetCurrentProcessProgramID() != header.application_id) {
+ if (system.GetApplicationProcessProgramID() != header.application_id) {
LOG_ERROR(Service_LDR,
"Attempting to load NRR with title ID other than current process. (actual "
"{:016X})!",
@@ -272,7 +272,7 @@ public:
rb.Push(ResultSuccess);
}
- void UnregisterModuleInfo(Kernel::HLERequestContext& ctx) {
+ void UnregisterModuleInfo(HLERequestContext& ctx) {
IPC::RequestParser rp{ctx};
const auto pid = rp.Pop<u64>();
const auto nrr_address = rp.Pop<VAddr>();
@@ -314,7 +314,7 @@ public:
const auto is_region_available = [&](VAddr addr) {
const auto end_addr = addr + size;
while (addr < end_addr) {
- if (system.Memory().IsValidVirtualAddress(addr)) {
+ if (system.ApplicationMemory().IsValidVirtualAddress(addr)) {
return false;
}
@@ -337,7 +337,7 @@ public:
bool succeeded = false;
const auto map_region_end =
- page_table.GetAliasCodeRegionStart() + page_table.GetAliasCodeRegionSize();
+ GetInteger(page_table.GetAliasCodeRegionStart()) + page_table.GetAliasCodeRegionSize();
while (current_map_addr < map_region_end) {
if (is_region_available(current_map_addr)) {
succeeded = true;
@@ -427,8 +427,8 @@ public:
const VAddr bss_end_addr{
Common::AlignUp(bss_start + nro_header.bss_size, Kernel::PageSize)};
- const auto CopyCode = [this, process](VAddr src_addr, VAddr dst_addr, u64 size) {
- system.Memory().CopyBlock(*process, dst_addr, src_addr, size);
+ const auto CopyCode = [this](VAddr src_addr, VAddr dst_addr, u64 size) {
+ system.ApplicationMemory().CopyBlock(dst_addr, src_addr, size);
};
CopyCode(nro_addr + nro_header.segment_headers[TEXT_INDEX].memory_offset, text_start,
nro_header.segment_headers[TEXT_INDEX].memory_size);
@@ -446,7 +446,7 @@ public:
data_start, bss_end_addr - data_start, Kernel::Svc::MemoryPermission::ReadWrite);
}
- void LoadModule(Kernel::HLERequestContext& ctx) {
+ void LoadModule(HLERequestContext& ctx) {
struct Parameters {
u64_le process_id;
u64_le image_address;
@@ -506,7 +506,7 @@ public:
// Read NRO data from memory
std::vector<u8> nro_data(nro_size);
- system.Memory().ReadBlock(nro_address, nro_data.data(), nro_size);
+ system.ApplicationMemory().ReadBlock(nro_address, nro_data.data(), nro_size);
SHA256Hash hash{};
mbedtls_sha256_ret(nro_data.data(), nro_data.size(), hash.data(), 0);
@@ -542,15 +542,16 @@ public:
}
// Map memory for the NRO
- const auto map_result{MapNro(system.CurrentProcess(), nro_address, nro_size, bss_address,
- bss_size, nro_size + bss_size)};
+ const auto map_result{MapNro(system.ApplicationProcess(), nro_address, nro_size,
+ bss_address, bss_size, nro_size + bss_size)};
if (map_result.Failed()) {
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(map_result.Code());
}
// Load the NRO into the mapped memory
- if (const auto result{LoadNro(system.CurrentProcess(), header, nro_address, *map_result)};
+ if (const auto result{
+ LoadNro(system.ApplicationProcess(), header, nro_address, *map_result)};
result.IsError()) {
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(map_result.Code());
@@ -570,7 +571,7 @@ public:
Result UnmapNro(const NROInfo& info) {
// Each region must be unmapped separately to validate memory state
- auto& page_table{system.CurrentProcess()->PageTable()};
+ auto& page_table{system.ApplicationProcess()->PageTable()};
if (info.bss_size != 0) {
CASCADE_CODE(page_table.UnmapCodeMemory(
@@ -591,7 +592,7 @@ public:
return ResultSuccess;
}
- void UnloadModule(Kernel::HLERequestContext& ctx) {
+ void UnloadModule(HLERequestContext& ctx) {
if (!initialized) {
LOG_ERROR(Service_LDR, "LDR:RO not initialized before use!");
IPC::ResponseBuilder rb{ctx, 2};
@@ -637,11 +638,12 @@ public:
rb.Push(result);
}
- void Initialize(Kernel::HLERequestContext& ctx) {
+ void Initialize(HLERequestContext& ctx) {
LOG_WARNING(Service_LDR, "(STUBBED) called");
initialized = true;
- current_map_addr = system.CurrentProcess()->PageTable().GetAliasCodeRegionStart();
+ current_map_addr =
+ GetInteger(system.ApplicationProcess()->PageTable().GetAliasCodeRegionStart());
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(ResultSuccess);
@@ -681,11 +683,15 @@ private:
}
};
-void InstallInterfaces(SM::ServiceManager& sm, Core::System& system) {
- std::make_shared<DebugMonitor>(system)->InstallAsService(sm);
- std::make_shared<ProcessManager>(system)->InstallAsService(sm);
- std::make_shared<Shell>(system)->InstallAsService(sm);
- std::make_shared<RelocatableObject>(system)->InstallAsService(sm);
+void LoopProcess(Core::System& system) {
+ auto server_manager = std::make_unique<ServerManager>(system);
+
+ server_manager->RegisterNamedService("ldr:dmnt", std::make_shared<DebugMonitor>(system));
+ server_manager->RegisterNamedService("ldr:pm", std::make_shared<ProcessManager>(system));
+ server_manager->RegisterNamedService("ldr:shel", std::make_shared<Shell>(system));
+ server_manager->RegisterNamedService("ldr:ro", std::make_shared<RelocatableObject>(system));
+
+ ServerManager::RunServer(std::move(server_manager));
}
} // namespace Service::LDR