mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2025-01-03 11:11:14 +00:00
ro: rename ModuleType to reflect reality
This commit is contained in:
parent
1cccb6efc4
commit
b7d99b732a
10 changed files with 39 additions and 39 deletions
|
@ -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, 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, 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, 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)
|
AMS_SF_DEFINE_INTERFACE(IRoInterface, AMS_RO_I_RO_INTERFACE_INTERFACE_INFO)
|
||||||
|
|
||||||
|
|
|
@ -20,10 +20,11 @@
|
||||||
|
|
||||||
namespace ams::ro {
|
namespace ams::ro {
|
||||||
|
|
||||||
enum class ModuleType : u8 {
|
enum NrrKind : u8 {
|
||||||
ForSelf = 0,
|
NrrKind_User = 0,
|
||||||
ForOthers = 1,
|
NrrKind_JitPlugin = 1,
|
||||||
Count
|
|
||||||
|
NrrKind_Count,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ModuleId {
|
struct ModuleId {
|
||||||
|
@ -54,7 +55,7 @@ namespace ams::ro {
|
||||||
u8 signature[0x100];
|
u8 signature[0x100];
|
||||||
ncm::ProgramId program_id;
|
ncm::ProgramId program_id;
|
||||||
u32 size;
|
u32 size;
|
||||||
u8 type; /* 7.0.0+ */
|
u8 nrr_kind; /* 7.0.0+ */
|
||||||
u8 reserved_33D[3];
|
u8 reserved_33D[3];
|
||||||
u32 hashes_offset;
|
u32 hashes_offset;
|
||||||
u32 num_hashes;
|
u32 num_hashes;
|
||||||
|
@ -68,10 +69,10 @@ namespace ams::ro {
|
||||||
return (static_cast<u64>(this->program_id) & this->certification.program_id_mask) == this->certification.program_id_pattern;
|
return (static_cast<u64>(this->program_id) & this->certification.program_id_mask) == this->certification.program_id_pattern;
|
||||||
}
|
}
|
||||||
|
|
||||||
ModuleType GetType() const {
|
NrrKind GetNrrKind() const {
|
||||||
const ModuleType type = static_cast<ModuleType>(this->type);
|
const NrrKind kind = static_cast<NrrKind>(this->nrr_kind);
|
||||||
AMS_ABORT_UNLESS(type < ModuleType::Count);
|
AMS_ABORT_UNLESS(kind < NrrKind_Count);
|
||||||
return type;
|
return kind;
|
||||||
}
|
}
|
||||||
|
|
||||||
ncm::ProgramId GetProgramId() const {
|
ncm::ProgramId GetProgramId() const {
|
||||||
|
|
|
@ -30,7 +30,7 @@ namespace ams::ro {
|
||||||
R_DEFINE_ERROR_RESULT(TooManyNro, 7);
|
R_DEFINE_ERROR_RESULT(TooManyNro, 7);
|
||||||
R_DEFINE_ERROR_RESULT(TooManyNrr, 8);
|
R_DEFINE_ERROR_RESULT(TooManyNrr, 8);
|
||||||
R_DEFINE_ERROR_RESULT(NotAuthorized, 9);
|
R_DEFINE_ERROR_RESULT(NotAuthorized, 9);
|
||||||
R_DEFINE_ERROR_RESULT(InvalidNrrType, 10);
|
R_DEFINE_ERROR_RESULT(InvalidNrrKind, 10);
|
||||||
|
|
||||||
R_DEFINE_ERROR_RESULT(InternalError, 1023);
|
R_DEFINE_ERROR_RESULT(InternalError, 1023);
|
||||||
|
|
||||||
|
|
|
@ -157,7 +157,7 @@ namespace ams::ro::impl {
|
||||||
return ResultSuccess();
|
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. */
|
/* Check magic. */
|
||||||
R_UNLESS(header->IsMagicValid(), ResultInvalidNrr());
|
R_UNLESS(header->IsMagicValid(), ResultInvalidNrr());
|
||||||
|
|
||||||
|
@ -182,9 +182,9 @@ namespace ams::ro::impl {
|
||||||
/* Check program id. */
|
/* Check program id. */
|
||||||
R_UNLESS(header->GetProgramId() == program_id, ResultInvalidNrr());
|
R_UNLESS(header->GetProgramId() == program_id, ResultInvalidNrr());
|
||||||
|
|
||||||
/* Check type. */
|
/* Check nrr kind. */
|
||||||
if (hos::GetVersion() >= hos::Version_7_0_0 && enforce_type) {
|
if (hos::GetVersion() >= hos::Version_7_0_0 && enforce_nrr_kind) {
|
||||||
R_UNLESS(header->GetType() == expected_type, ResultInvalidNrrType());
|
R_UNLESS(header->GetNrrKind() == nrr_kind, ResultInvalidNrrKind());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,7 +194,7 @@ namespace ams::ro::impl {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Utilities for working with NRRs. */
|
/* 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{});
|
map::MappedCodeMemory nrr_mcm(ResultInternalError{});
|
||||||
|
|
||||||
/* First, map the NRR. */
|
/* First, map the NRR. */
|
||||||
|
@ -209,7 +209,7 @@ namespace ams::ro::impl {
|
||||||
R_TRY(nrr_map.GetResult());
|
R_TRY(nrr_map.GetResult());
|
||||||
|
|
||||||
NrrHeader *nrr_header = reinterpret_cast<NrrHeader *>(map_address);
|
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. */
|
/* Invalidation here actually prevents them from unmapping at scope exit. */
|
||||||
nrr_map.Invalidate();
|
nrr_map.Invalidate();
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
namespace ams::ro::impl {
|
namespace ams::ro::impl {
|
||||||
|
|
||||||
/* Utilities for working with NRRs. */
|
/* 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);
|
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);
|
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);
|
||||||
|
|
|
@ -413,7 +413,7 @@ namespace ams::ro::impl {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Service implementations. */
|
/* 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. */
|
/* Get context. */
|
||||||
ProcessContext *context = GetContextById(context_id);
|
ProcessContext *context = GetContextById(context_id);
|
||||||
AMS_ABORT_UNLESS(context != nullptr);
|
AMS_ABORT_UNLESS(context != nullptr);
|
||||||
|
@ -435,7 +435,7 @@ namespace ams::ro::impl {
|
||||||
/* Map. */
|
/* Map. */
|
||||||
NrrHeader *header = nullptr;
|
NrrHeader *header = nullptr;
|
||||||
u64 mapped_code_address = 0;
|
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. */
|
/* Set NRR info. */
|
||||||
context->SetNrrInfoInUse(nrr_info, true);
|
context->SetNrrInfoInUse(nrr_info, true);
|
||||||
|
|
|
@ -35,7 +35,7 @@ namespace ams::ro::impl {
|
||||||
void UnregisterProcess(size_t context_id);
|
void UnregisterProcess(size_t context_id);
|
||||||
|
|
||||||
/* Service implementations. */
|
/* 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 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 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);
|
Result UnmapManualLoadModuleMemory(size_t context_id, u64 nro_address);
|
||||||
|
|
|
@ -95,11 +95,11 @@ namespace {
|
||||||
constexpr size_t DebugMonitorMaxSessions = 2;
|
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. */
|
/* 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 sm::ServiceName UserServiceName = sm::ServiceName::Encode("ldr:ro");
|
||||||
constexpr size_t ForSelfMaxSessions = 2;
|
constexpr size_t UserMaxSessions = 2;
|
||||||
|
|
||||||
constexpr sm::ServiceName ForOthersServiceName = sm::ServiceName::Encode("ro:1");
|
constexpr sm::ServiceName JitPluginServiceName = sm::ServiceName::Encode("ro:1");
|
||||||
constexpr size_t ForOthersMaxSessions = 2;
|
constexpr size_t JitPluginMaxSessions = 2;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,9 +120,9 @@ int main(int argc, char **argv)
|
||||||
/* Create services. */
|
/* 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::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) {
|
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. */
|
/* Loop forever, servicing our services. */
|
||||||
|
|
|
@ -27,7 +27,7 @@ namespace ams::ro {
|
||||||
impl::SetDevelopmentFunctionEnabled(is_development_function_enabled);
|
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) {
|
Result RoService::RegisterModuleInfo(const sf::ClientProcessId &client_pid, u64 nrr_address, u64 nrr_size) {
|
||||||
R_TRY(impl::ValidateProcess(this->context_id, client_pid.GetValue()));
|
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) {
|
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());
|
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()));
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,9 +26,9 @@ namespace ams::ro {
|
||||||
class RoService {
|
class RoService {
|
||||||
private:
|
private:
|
||||||
size_t context_id;
|
size_t context_id;
|
||||||
ModuleType type;
|
NrrKind nrr_kind;
|
||||||
protected:
|
protected:
|
||||||
explicit RoService(ModuleType t);
|
explicit RoService(NrrKind k);
|
||||||
public:
|
public:
|
||||||
virtual ~RoService();
|
virtual ~RoService();
|
||||||
public:
|
public:
|
||||||
|
@ -38,19 +38,18 @@ namespace ams::ro {
|
||||||
Result RegisterModuleInfo(const sf::ClientProcessId &client_pid, u64 nrr_address, u64 nrr_size);
|
Result RegisterModuleInfo(const sf::ClientProcessId &client_pid, u64 nrr_address, u64 nrr_size);
|
||||||
Result UnregisterModuleInfo(const sf::ClientProcessId &client_pid, u64 nrr_address);
|
Result UnregisterModuleInfo(const sf::ClientProcessId &client_pid, u64 nrr_address);
|
||||||
Result RegisterProcessHandle(const sf::ClientProcessId &client_pid, sf::CopyHandle process_h);
|
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>);
|
static_assert(ro::impl::IsIRoInterface<RoService>);
|
||||||
|
|
||||||
class RoServiceForSelf final : public RoService {
|
class RoUserService final : public RoService {
|
||||||
public:
|
public:
|
||||||
RoServiceForSelf() : RoService(ro::ModuleType::ForSelf) { /* ... */ }
|
RoUserService() : RoService(NrrKind_User) { /* ... */ }
|
||||||
};
|
};
|
||||||
|
|
||||||
/* TODO: This is really JitPlugin... */
|
class RoJitPluginService final : public RoService {
|
||||||
class RoServiceForOthers final : public RoService {
|
|
||||||
public:
|
public:
|
||||||
RoServiceForOthers() : RoService(ro::ModuleType::ForOthers) { /* ... */ }
|
RoJitPluginService() : RoService(NrrKind_JitPlugin) { /* ... */ }
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue