strat: use sf::NativeHandle for ipc templating

This commit is contained in:
Michael Scire
2021-10-05 00:11:36 -07:00
parent d97e97258e
commit 69777cf792
41 changed files with 447 additions and 454 deletions

View File

@@ -373,16 +373,12 @@ namespace ams::ro::impl {
}
/* Context utilities. */
Result RegisterProcess(size_t *out_context_id, os::NativeHandle process_handle, os::ProcessId process_id) {
/* Ensure we manage process handle correctly. */
auto handle_guard = SCOPE_GUARD { os::CloseNativeHandle(process_handle); };
Result RegisterProcess(size_t *out_context_id, sf::NativeHandle &&process_handle, os::ProcessId process_id) {
/* Validate process handle. */
{
os::ProcessId handle_pid = os::InvalidProcessId;
/* Validate handle is a valid process handle. */
R_UNLESS(R_SUCCEEDED(os::GetProcessId(&handle_pid, process_handle)), ResultInvalidProcess());
os::ProcessId handle_pid;
R_UNLESS(R_SUCCEEDED(os::GetProcessId(&handle_pid, process_handle.GetOsHandle())), ResultInvalidProcess());
/* Validate process id. */
R_UNLESS(handle_pid == process_id, ResultInvalidProcess());
@@ -392,8 +388,8 @@ namespace ams::ro::impl {
R_UNLESS(GetContextByProcessId(process_id) == nullptr, ResultInvalidSession());
/* Allocate a context to manage the process handle. */
handle_guard.Cancel();
*out_context_id = AllocateContext(process_handle, process_id);
*out_context_id = AllocateContext(process_handle.GetOsHandle(), process_id);
process_handle.Detach();
return ResultSuccess();
}
@@ -411,9 +407,6 @@ namespace ams::ro::impl {
/* Service implementations. */
Result RegisterModuleInfo(size_t context_id, os::NativeHandle process_handle, u64 nrr_address, u64 nrr_size, NrrKind nrr_kind, bool enforce_nrr_kind) {
/* Ensure we close the process handle when we're done with it. */
ON_SCOPE_EXIT { os::CloseNativeHandle(process_handle); };
/* Get context. */
ProcessContext *context = GetContextById(context_id);
AMS_ABORT_UNLESS(context != nullptr);

View File

@@ -30,7 +30,7 @@ namespace ams::ro::impl {
bool ShouldEaseNroRestriction();
/* Context utilities. */
Result RegisterProcess(size_t *out_context_id, os::NativeHandle process_handle, os::ProcessId process_id);
Result RegisterProcess(size_t *out_context_id, sf::NativeHandle &&process_handle, os::ProcessId process_id);
Result ValidateProcess(size_t context_id, os::ProcessId process_id);
void UnregisterProcess(size_t context_id);

View File

@@ -55,21 +55,17 @@ namespace ams::ro {
return impl::UnregisterModuleInfo(this->context_id, nrr_address);
}
Result RoService::RegisterProcessHandle(const sf::ClientProcessId &client_pid, sf::CopyHandle process_h) {
Result RoService::RegisterProcessHandle(const sf::ClientProcessId &client_pid, sf::CopyHandle &&process_h) {
/* Register the process. */
return impl::RegisterProcess(std::addressof(this->context_id), process_h.GetValue(), client_pid.GetValue());
return impl::RegisterProcess(std::addressof(this->context_id), std::move(process_h), client_pid.GetValue());
}
Result RoService::RegisterProcessModuleInfo(const sf::ClientProcessId &client_pid, u64 nrr_address, u64 nrr_size, sf::CopyHandle process_h) {
/* Validate the process, ensuring we manage the process handle correctly. */
{
auto handle_guard = SCOPE_GUARD { os::CloseNativeHandle(process_h.GetValue()); };
R_TRY(impl::ValidateProcess(this->context_id, client_pid.GetValue()));
handle_guard.Cancel();
}
Result RoService::RegisterProcessModuleInfo(const sf::ClientProcessId &client_pid, u64 nrr_address, u64 nrr_size, sf::CopyHandle &&process_h) {
/* Validate the process. */
R_TRY(impl::ValidateProcess(this->context_id, client_pid.GetValue()));
/* Register the module. */
return impl::RegisterModuleInfo(this->context_id, process_h.GetValue(), nrr_address, nrr_size, this->nrr_kind, this->nrr_kind == NrrKind_JitPlugin);
return impl::RegisterModuleInfo(this->context_id, process_h.GetOsHandle(), nrr_address, nrr_size, this->nrr_kind, this->nrr_kind == NrrKind_JitPlugin);
}
}

View File

@@ -37,8 +37,8 @@ namespace ams::ro {
Result UnmapManualLoadModuleMemory(const sf::ClientProcessId &client_pid, u64 nro_address);
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 RegisterProcessModuleInfo(const sf::ClientProcessId &client_pid, u64 nrr_address, u64 nrr_size, sf::CopyHandle process_h);
Result RegisterProcessHandle(const sf::ClientProcessId &client_pid, 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>);