From dbe59fd0411356a4829a8dcd5c32238eb506721c Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Thu, 17 Sep 2020 08:25:27 -0700 Subject: [PATCH] kern: fix KCodeMemory SVCs when Owner process != Generator process --- libraries/libmesosphere/source/kern_k_code_memory.cpp | 4 ++-- libraries/libmesosphere/source/svc/kern_svc_code_memory.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/libmesosphere/source/kern_k_code_memory.cpp b/libraries/libmesosphere/source/kern_k_code_memory.cpp index 57931326d..3dcd101b4 100644 --- a/libraries/libmesosphere/source/kern_k_code_memory.cpp +++ b/libraries/libmesosphere/source/kern_k_code_memory.cpp @@ -133,7 +133,7 @@ namespace ams::kern { } /* Map the memory. */ - R_TRY(GetCurrentProcess().GetPageTable().MapPageGroup(address, GetReference(this->page_group), KMemoryState_GeneratedCode, k_perm)); + R_TRY(this->owner->GetPageTable().MapPageGroup(address, GetReference(this->page_group), KMemoryState_GeneratedCode, k_perm)); /* Mark ourselves as mapped. */ this->is_owner_mapped = true; @@ -151,7 +151,7 @@ namespace ams::kern { KScopedLightLock lk(this->lock); /* Unmap the memory. */ - R_TRY(GetCurrentProcess().GetPageTable().UnmapPageGroup(address, GetReference(this->page_group), KMemoryState_GeneratedCode)); + R_TRY(this->owner->GetPageTable().UnmapPageGroup(address, GetReference(this->page_group), KMemoryState_GeneratedCode)); /* Mark ourselves as unmapped. */ MESOSPHERE_ASSERT(this->is_owner_mapped); diff --git a/libraries/libmesosphere/source/svc/kern_svc_code_memory.cpp b/libraries/libmesosphere/source/svc/kern_svc_code_memory.cpp index f217950da..2ab4b878c 100644 --- a/libraries/libmesosphere/source/svc/kern_svc_code_memory.cpp +++ b/libraries/libmesosphere/source/svc/kern_svc_code_memory.cpp @@ -110,7 +110,7 @@ namespace ams::kern::svc { case ams::svc::CodeMemoryOperation_MapToOwner: { /* Check that the region is in range. */ - R_UNLESS(GetCurrentProcess().GetPageTable().CanContain(address, size, KMemoryState_GeneratedCode), svc::ResultInvalidMemoryRegion()); + R_UNLESS(code_mem->GetOwner()->GetPageTable().CanContain(address, size, KMemoryState_GeneratedCode), svc::ResultInvalidMemoryRegion()); /* Check the memory permission. */ R_UNLESS(IsValidMapToOwnerCodeMemoryPermission(perm), svc::ResultInvalidNewMemoryPermission()); @@ -122,7 +122,7 @@ namespace ams::kern::svc { case ams::svc::CodeMemoryOperation_UnmapFromOwner: { /* Check that the region is in range. */ - R_UNLESS(GetCurrentProcess().GetPageTable().CanContain(address, size, KMemoryState_GeneratedCode), svc::ResultInvalidMemoryRegion()); + R_UNLESS(code_mem->GetOwner()->GetPageTable().CanContain(address, size, KMemoryState_GeneratedCode), svc::ResultInvalidMemoryRegion()); /* Check the memory permission. */ R_UNLESS(IsValidUnmapFromOwnerCodeMemoryPermission(perm), svc::ResultInvalidNewMemoryPermission());