From b7d99b732af2f4b8d07393412f750a047c702073 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Tue, 8 Sep 2020 15:05:15 -0700 Subject: [PATCH] ro: rename ModuleType to reflect reality --- .../stratosphere/ro/impl/ro_ro_interface.hpp | 2 +- .../include/stratosphere/ro/ro_types.hpp | 19 ++++++++++--------- .../include/vapours/results/ro_results.hpp | 2 +- stratosphere/ro/source/impl/ro_nrr_utils.cpp | 12 ++++++------ stratosphere/ro/source/impl/ro_nrr_utils.hpp | 2 +- .../ro/source/impl/ro_service_impl.cpp | 4 ++-- .../ro/source/impl/ro_service_impl.hpp | 2 +- stratosphere/ro/source/ro_main.cpp | 12 ++++++------ stratosphere/ro/source/ro_ro_service.cpp | 8 ++++---- stratosphere/ro/source/ro_ro_service.hpp | 15 +++++++-------- 10 files changed, 39 insertions(+), 39 deletions(-) diff --git a/libraries/libstratosphere/include/stratosphere/ro/impl/ro_ro_interface.hpp b/libraries/libstratosphere/include/stratosphere/ro/impl/ro_ro_interface.hpp index 624d1e5d8..185293c16 100644 --- a/libraries/libstratosphere/include/stratosphere/ro/impl/ro_ro_interface.hpp +++ b/libraries/libstratosphere/include/stratosphere/ro/impl/ro_ro_interface.hpp @@ -27,7 +27,7 @@ namespace ams::ro::impl { AMS_SF_METHOD_INFO(C, H, 2, Result, RegisterModuleInfo, (const sf::ClientProcessId &client_pid, u64 nrr_address, u64 nrr_size)) \ AMS_SF_METHOD_INFO(C, H, 3, Result, UnregisterModuleInfo, (const sf::ClientProcessId &client_pid, u64 nrr_address)) \ AMS_SF_METHOD_INFO(C, H, 4, Result, RegisterProcessHandle, (const sf::ClientProcessId &client_pid, sf::CopyHandle process_h)) \ - AMS_SF_METHOD_INFO(C, H, 10, Result, RegisterModuleInfoEx, (const sf::ClientProcessId &client_pid, u64 nrr_address, u64 nrr_size, sf::CopyHandle process_h), hos::Version_7_0_0) + AMS_SF_METHOD_INFO(C, H, 10, Result, RegisterProcessModuleInfo, (const sf::ClientProcessId &client_pid, u64 nrr_address, u64 nrr_size, sf::CopyHandle process_h), hos::Version_7_0_0) AMS_SF_DEFINE_INTERFACE(IRoInterface, AMS_RO_I_RO_INTERFACE_INTERFACE_INFO) diff --git a/libraries/libstratosphere/include/stratosphere/ro/ro_types.hpp b/libraries/libstratosphere/include/stratosphere/ro/ro_types.hpp index eafde873c..73aca6e33 100644 --- a/libraries/libstratosphere/include/stratosphere/ro/ro_types.hpp +++ b/libraries/libstratosphere/include/stratosphere/ro/ro_types.hpp @@ -20,10 +20,11 @@ namespace ams::ro { - enum class ModuleType : u8 { - ForSelf = 0, - ForOthers = 1, - Count + enum NrrKind : u8 { + NrrKind_User = 0, + NrrKind_JitPlugin = 1, + + NrrKind_Count, }; struct ModuleId { @@ -54,7 +55,7 @@ namespace ams::ro { u8 signature[0x100]; ncm::ProgramId program_id; u32 size; - u8 type; /* 7.0.0+ */ + u8 nrr_kind; /* 7.0.0+ */ u8 reserved_33D[3]; u32 hashes_offset; u32 num_hashes; @@ -68,10 +69,10 @@ namespace ams::ro { return (static_cast(this->program_id) & this->certification.program_id_mask) == this->certification.program_id_pattern; } - ModuleType GetType() const { - const ModuleType type = static_cast(this->type); - AMS_ABORT_UNLESS(type < ModuleType::Count); - return type; + NrrKind GetNrrKind() const { + const NrrKind kind = static_cast(this->nrr_kind); + AMS_ABORT_UNLESS(kind < NrrKind_Count); + return kind; } ncm::ProgramId GetProgramId() const { diff --git a/libraries/libvapours/include/vapours/results/ro_results.hpp b/libraries/libvapours/include/vapours/results/ro_results.hpp index fc4dbe16f..8614e400f 100644 --- a/libraries/libvapours/include/vapours/results/ro_results.hpp +++ b/libraries/libvapours/include/vapours/results/ro_results.hpp @@ -30,7 +30,7 @@ namespace ams::ro { R_DEFINE_ERROR_RESULT(TooManyNro, 7); R_DEFINE_ERROR_RESULT(TooManyNrr, 8); R_DEFINE_ERROR_RESULT(NotAuthorized, 9); - R_DEFINE_ERROR_RESULT(InvalidNrrType, 10); + R_DEFINE_ERROR_RESULT(InvalidNrrKind, 10); R_DEFINE_ERROR_RESULT(InternalError, 1023); diff --git a/stratosphere/ro/source/impl/ro_nrr_utils.cpp b/stratosphere/ro/source/impl/ro_nrr_utils.cpp index f4cbfc7a1..d8adf28db 100644 --- a/stratosphere/ro/source/impl/ro_nrr_utils.cpp +++ b/stratosphere/ro/source/impl/ro_nrr_utils.cpp @@ -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(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(); diff --git a/stratosphere/ro/source/impl/ro_nrr_utils.hpp b/stratosphere/ro/source/impl/ro_nrr_utils.hpp index 3a675ad8f..f0e208ee1 100644 --- a/stratosphere/ro/source/impl/ro_nrr_utils.hpp +++ b/stratosphere/ro/source/impl/ro_nrr_utils.hpp @@ -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); diff --git a/stratosphere/ro/source/impl/ro_service_impl.cpp b/stratosphere/ro/source/impl/ro_service_impl.cpp index 5568b0f43..c90c57418 100644 --- a/stratosphere/ro/source/impl/ro_service_impl.cpp +++ b/stratosphere/ro/source/impl/ro_service_impl.cpp @@ -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); diff --git a/stratosphere/ro/source/impl/ro_service_impl.hpp b/stratosphere/ro/source/impl/ro_service_impl.hpp index a8f45456d..32dbeb5cd 100644 --- a/stratosphere/ro/source/impl/ro_service_impl.hpp +++ b/stratosphere/ro/source/impl/ro_service_impl.hpp @@ -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); diff --git a/stratosphere/ro/source/ro_main.cpp b/stratosphere/ro/source/ro_main.cpp index f3de32bb9..a7d71adf8 100644 --- a/stratosphere/ro/source/ro_main.cpp +++ b/stratosphere/ro/source/ro_main.cpp @@ -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(DebugMonitorServiceName, DebugMonitorMaxSessions))); - R_ABORT_UNLESS((g_server_manager.RegisterServer(ForSelfServiceName, ForSelfMaxSessions))); + R_ABORT_UNLESS((g_server_manager.RegisterServer(UserServiceName, UserMaxSessions))); if (hos::GetVersion() >= hos::Version_7_0_0) { - R_ABORT_UNLESS((g_server_manager.RegisterServer(ForOthersServiceName, ForOthersMaxSessions))); + R_ABORT_UNLESS((g_server_manager.RegisterServer(JitPluginServiceName, JitPluginMaxSessions))); } /* Loop forever, servicing our services. */ diff --git a/stratosphere/ro/source/ro_ro_service.cpp b/stratosphere/ro/source/ro_ro_service.cpp index 47eb27b02..a00759557 100644 --- a/stratosphere/ro/source/ro_ro_service.cpp +++ b/stratosphere/ro/source/ro_ro_service.cpp @@ -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); } } diff --git a/stratosphere/ro/source/ro_ro_service.hpp b/stratosphere/ro/source/ro_ro_service.hpp index c3dd6d15b..8e1702568 100644 --- a/stratosphere/ro/source/ro_ro_service.hpp +++ b/stratosphere/ro/source/ro_ro_service.hpp @@ -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); - 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) { /* ... */ } }; }