ro: rename ModuleType to reflect reality

This commit is contained in:
Michael Scire
2020-09-08 15:05:15 -07:00
parent 1cccb6efc4
commit b7d99b732a
10 changed files with 39 additions and 39 deletions

View File

@@ -157,7 +157,7 @@ namespace ams::ro::impl {
return ResultSuccess();
}
Result ValidateNrr(const NrrHeader *header, u64 size, ncm::ProgramId program_id, ModuleType expected_type, bool enforce_type) {
Result ValidateNrr(const NrrHeader *header, u64 size, ncm::ProgramId program_id, NrrKind nrr_kind, bool enforce_nrr_kind) {
/* Check magic. */
R_UNLESS(header->IsMagicValid(), ResultInvalidNrr());
@@ -182,9 +182,9 @@ namespace ams::ro::impl {
/* Check program id. */
R_UNLESS(header->GetProgramId() == program_id, ResultInvalidNrr());
/* Check type. */
if (hos::GetVersion() >= hos::Version_7_0_0 && enforce_type) {
R_UNLESS(header->GetType() == expected_type, ResultInvalidNrrType());
/* Check nrr kind. */
if (hos::GetVersion() >= hos::Version_7_0_0 && enforce_nrr_kind) {
R_UNLESS(header->GetNrrKind() == nrr_kind, ResultInvalidNrrKind());
}
}
@@ -194,7 +194,7 @@ namespace ams::ro::impl {
}
/* Utilities for working with NRRs. */
Result MapAndValidateNrr(NrrHeader **out_header, u64 *out_mapped_code_address, void *out_hash, size_t out_hash_size, Handle process_handle, ncm::ProgramId program_id, u64 nrr_heap_address, u64 nrr_heap_size, ModuleType expected_type, bool enforce_type) {
Result MapAndValidateNrr(NrrHeader **out_header, u64 *out_mapped_code_address, void *out_hash, size_t out_hash_size, Handle process_handle, ncm::ProgramId program_id, u64 nrr_heap_address, u64 nrr_heap_size, NrrKind nrr_kind, bool enforce_nrr_kind) {
map::MappedCodeMemory nrr_mcm(ResultInternalError{});
/* First, map the NRR. */
@@ -209,7 +209,7 @@ namespace ams::ro::impl {
R_TRY(nrr_map.GetResult());
NrrHeader *nrr_header = reinterpret_cast<NrrHeader *>(map_address);
R_TRY(ValidateNrr(nrr_header, nrr_heap_size, program_id, expected_type, enforce_type));
R_TRY(ValidateNrr(nrr_header, nrr_heap_size, program_id, nrr_kind, enforce_nrr_kind));
/* Invalidation here actually prevents them from unmapping at scope exit. */
nrr_map.Invalidate();

View File

@@ -20,7 +20,7 @@
namespace ams::ro::impl {
/* Utilities for working with NRRs. */
Result MapAndValidateNrr(NrrHeader **out_header, u64 *out_mapped_code_address, void *out_hash, size_t out_hash_size, Handle process_handle, ncm::ProgramId program_id, u64 nrr_heap_address, u64 nrr_heap_size, ModuleType expected_type, bool enforce_type);
Result MapAndValidateNrr(NrrHeader **out_header, u64 *out_mapped_code_address, void *out_hash, size_t out_hash_size, Handle process_handle, ncm::ProgramId program_id, u64 nrr_heap_address, u64 nrr_heap_size, NrrKind nrr_kind, bool enforce_nrr_kind);
Result UnmapNrr(Handle process_handle, const NrrHeader *header, u64 nrr_heap_address, u64 nrr_heap_size, u64 mapped_code_address);
bool ValidateNrrHashTableEntry(const void *signed_area, size_t signed_area_size, size_t hashes_offset, size_t num_hashes, const void *nrr_hash, const u8 *hash_table, const void *desired_hash);

View File

@@ -413,7 +413,7 @@ namespace ams::ro::impl {
}
/* Service implementations. */
Result RegisterModuleInfo(size_t context_id, Handle process_h, u64 nrr_address, u64 nrr_size, ModuleType expected_type, bool enforce_type) {
Result RegisterModuleInfo(size_t context_id, Handle process_h, u64 nrr_address, u64 nrr_size, NrrKind nrr_kind, bool enforce_nrr_kind) {
/* Get context. */
ProcessContext *context = GetContextById(context_id);
AMS_ABORT_UNLESS(context != nullptr);
@@ -435,7 +435,7 @@ namespace ams::ro::impl {
/* Map. */
NrrHeader *header = nullptr;
u64 mapped_code_address = 0;
R_TRY(MapAndValidateNrr(&header, &mapped_code_address, std::addressof(signed_area_hash), sizeof(signed_area_hash), context->process_handle, program_id, nrr_address, nrr_size, expected_type, enforce_type));
R_TRY(MapAndValidateNrr(&header, &mapped_code_address, std::addressof(signed_area_hash), sizeof(signed_area_hash), context->process_handle, program_id, nrr_address, nrr_size, nrr_kind, enforce_nrr_kind));
/* Set NRR info. */
context->SetNrrInfoInUse(nrr_info, true);

View File

@@ -35,7 +35,7 @@ namespace ams::ro::impl {
void UnregisterProcess(size_t context_id);
/* Service implementations. */
Result RegisterModuleInfo(size_t context_id, Handle process_h, u64 nrr_address, u64 nrr_size, ModuleType expected_type, bool enforce_type);
Result RegisterModuleInfo(size_t context_id, Handle process_h, u64 nrr_address, u64 nrr_size, NrrKind nrr_kind, bool enforce_nrr_kind);
Result UnregisterModuleInfo(size_t context_id, u64 nrr_address);
Result MapManualLoadModuleMemory(u64 *out_address, size_t context_id, u64 nro_address, u64 nro_size, u64 bss_address, u64 bss_size);
Result UnmapManualLoadModuleMemory(size_t context_id, u64 nro_address);

View File

@@ -95,11 +95,11 @@ namespace {
constexpr size_t DebugMonitorMaxSessions = 2;
/* NOTE: Official code passes 32 for ldr:ro max sessions. We will pass 2, because that's the actual limit. */
constexpr sm::ServiceName ForSelfServiceName = sm::ServiceName::Encode("ldr:ro");
constexpr size_t ForSelfMaxSessions = 2;
constexpr sm::ServiceName UserServiceName = sm::ServiceName::Encode("ldr:ro");
constexpr size_t UserMaxSessions = 2;
constexpr sm::ServiceName ForOthersServiceName = sm::ServiceName::Encode("ro:1");
constexpr size_t ForOthersMaxSessions = 2;
constexpr sm::ServiceName JitPluginServiceName = sm::ServiceName::Encode("ro:1");
constexpr size_t JitPluginMaxSessions = 2;
}
@@ -120,9 +120,9 @@ int main(int argc, char **argv)
/* Create services. */
R_ABORT_UNLESS((g_server_manager.RegisterServer<ro::impl::IDebugMonitorInterface, ro::DebugMonitorService>(DebugMonitorServiceName, DebugMonitorMaxSessions)));
R_ABORT_UNLESS((g_server_manager.RegisterServer<ro::impl::IRoInterface, ro::RoServiceForSelf>(ForSelfServiceName, ForSelfMaxSessions)));
R_ABORT_UNLESS((g_server_manager.RegisterServer<ro::impl::IRoInterface, ro::RoUserService>(UserServiceName, UserMaxSessions)));
if (hos::GetVersion() >= hos::Version_7_0_0) {
R_ABORT_UNLESS((g_server_manager.RegisterServer<ro::impl::IRoInterface, ro::RoServiceForOthers>(ForOthersServiceName, ForOthersMaxSessions)));
R_ABORT_UNLESS((g_server_manager.RegisterServer<ro::impl::IRoInterface, ro::RoJitPluginService>(JitPluginServiceName, JitPluginMaxSessions)));
}
/* Loop forever, servicing our services. */

View File

@@ -27,7 +27,7 @@ namespace ams::ro {
impl::SetDevelopmentFunctionEnabled(is_development_function_enabled);
}
RoService::RoService(ModuleType t) : context_id(impl::InvalidContextId), type(t) {
RoService::RoService(NrrKind k) : context_id(impl::InvalidContextId), nrr_kind(k) {
/* ... */
}
@@ -47,7 +47,7 @@ namespace ams::ro {
Result RoService::RegisterModuleInfo(const sf::ClientProcessId &client_pid, u64 nrr_address, u64 nrr_size) {
R_TRY(impl::ValidateProcess(this->context_id, client_pid.GetValue()));
return impl::RegisterModuleInfo(this->context_id, svc::InvalidHandle, nrr_address, nrr_size, ModuleType::ForSelf, true);
return impl::RegisterModuleInfo(this->context_id, svc::InvalidHandle, nrr_address, nrr_size, NrrKind_User, true);
}
Result RoService::UnregisterModuleInfo(const sf::ClientProcessId &client_pid, u64 nrr_address) {
@@ -59,9 +59,9 @@ namespace ams::ro {
return impl::RegisterProcess(std::addressof(this->context_id), process_h.GetValue(), client_pid.GetValue());
}
Result RoService::RegisterModuleInfoEx(const sf::ClientProcessId &client_pid, u64 nrr_address, u64 nrr_size, sf::CopyHandle process_h) {
Result RoService::RegisterProcessModuleInfo(const sf::ClientProcessId &client_pid, u64 nrr_address, u64 nrr_size, sf::CopyHandle process_h) {
R_TRY(impl::ValidateProcess(this->context_id, client_pid.GetValue()));
return impl::RegisterModuleInfo(this->context_id, process_h.GetValue(), nrr_address, nrr_size, this->type, this->type == ModuleType::ForOthers);
return impl::RegisterModuleInfo(this->context_id, process_h.GetValue(), nrr_address, nrr_size, this->nrr_kind, this->nrr_kind == NrrKind_JitPlugin);
}
}

View File

@@ -26,9 +26,9 @@ namespace ams::ro {
class RoService {
private:
size_t context_id;
ModuleType type;
NrrKind nrr_kind;
protected:
explicit RoService(ModuleType t);
explicit RoService(NrrKind k);
public:
virtual ~RoService();
public:
@@ -38,19 +38,18 @@ namespace ams::ro {
Result RegisterModuleInfo(const sf::ClientProcessId &client_pid, u64 nrr_address, u64 nrr_size);
Result UnregisterModuleInfo(const sf::ClientProcessId &client_pid, u64 nrr_address);
Result RegisterProcessHandle(const sf::ClientProcessId &client_pid, sf::CopyHandle process_h);
Result RegisterModuleInfoEx(const sf::ClientProcessId &client_pid, u64 nrr_address, u64 nrr_size, sf::CopyHandle process_h);
Result RegisterProcessModuleInfo(const sf::ClientProcessId &client_pid, u64 nrr_address, u64 nrr_size, sf::CopyHandle process_h);
};
static_assert(ro::impl::IsIRoInterface<RoService>);
class RoServiceForSelf final : public RoService {
class RoUserService final : public RoService {
public:
RoServiceForSelf() : RoService(ro::ModuleType::ForSelf) { /* ... */ }
RoUserService() : RoService(NrrKind_User) { /* ... */ }
};
/* TODO: This is really JitPlugin... */
class RoServiceForOthers final : public RoService {
class RoJitPluginService final : public RoService {
public:
RoServiceForOthers() : RoService(ro::ModuleType::ForOthers) { /* ... */ }
RoJitPluginService() : RoService(NrrKind_JitPlugin) { /* ... */ }
};
}