Merge pull request #1953 from lioncash/mem

kernel/process: Remove most allocation functions from Process' interface
This commit is contained in:
bunnei 2018-12-27 19:57:51 -05:00 committed by GitHub
commit 357bc956ae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 49 deletions

View file

@ -198,22 +198,6 @@ void Process::LoadModule(CodeSet module_, VAddr base_addr) {
Core::System::GetInstance().ArmInterface(3).ClearInstructionCache(); Core::System::GetInstance().ArmInterface(3).ClearInstructionCache();
} }
ResultVal<VAddr> Process::HeapAllocate(VAddr target, u64 size, VMAPermission perms) {
return vm_manager.HeapAllocate(target, size, perms);
}
ResultCode Process::HeapFree(VAddr target, u32 size) {
return vm_manager.HeapFree(target, size);
}
ResultCode Process::MirrorMemory(VAddr dst_addr, VAddr src_addr, u64 size, MemoryState state) {
return vm_manager.MirrorMemory(dst_addr, src_addr, size, state);
}
ResultCode Process::UnmapMemory(VAddr dst_addr, VAddr /*src_addr*/, u64 size) {
return vm_manager.UnmapRange(dst_addr, size);
}
Kernel::Process::Process(KernelCore& kernel) : WaitObject{kernel} {} Kernel::Process::Process(KernelCore& kernel) : WaitObject{kernel} {}
Kernel::Process::~Process() {} Kernel::Process::~Process() {}

View file

@ -242,7 +242,7 @@ public:
void LoadModule(CodeSet module_, VAddr base_addr); void LoadModule(CodeSet module_, VAddr base_addr);
/////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////
// Memory Management // Thread-local storage management
// Marks the next available region as used and returns the address of the slot. // Marks the next available region as used and returns the address of the slot.
VAddr MarkNextAvailableTLSSlotAsUsed(Thread& thread); VAddr MarkNextAvailableTLSSlotAsUsed(Thread& thread);
@ -250,13 +250,6 @@ public:
// Frees a used TLS slot identified by the given address // Frees a used TLS slot identified by the given address
void FreeTLSSlot(VAddr tls_address); void FreeTLSSlot(VAddr tls_address);
ResultVal<VAddr> HeapAllocate(VAddr target, u64 size, VMAPermission perms);
ResultCode HeapFree(VAddr target, u32 size);
ResultCode MirrorMemory(VAddr dst_addr, VAddr src_addr, u64 size, MemoryState state);
ResultCode UnmapMemory(VAddr dst_addr, VAddr src_addr, u64 size);
private: private:
explicit Process(KernelCore& kernel); explicit Process(KernelCore& kernel);
~Process() override; ~Process() override;

View file

@ -190,10 +190,16 @@ static ResultCode SetHeapSize(VAddr* heap_addr, u64 heap_size) {
return ERR_INVALID_SIZE; return ERR_INVALID_SIZE;
} }
auto& process = *Core::CurrentProcess(); auto& vm_manager = Core::CurrentProcess()->VMManager();
const VAddr heap_base = process.VMManager().GetHeapRegionBaseAddress(); const VAddr heap_base = vm_manager.GetHeapRegionBaseAddress();
CASCADE_RESULT(*heap_addr, const auto alloc_result =
process.HeapAllocate(heap_base, heap_size, VMAPermission::ReadWrite)); vm_manager.HeapAllocate(heap_base, heap_size, VMAPermission::ReadWrite);
if (alloc_result.Failed()) {
return alloc_result.Code();
}
*heap_addr = *alloc_result;
return RESULT_SUCCESS; return RESULT_SUCCESS;
} }
@ -307,15 +313,14 @@ static ResultCode MapMemory(VAddr dst_addr, VAddr src_addr, u64 size) {
LOG_TRACE(Kernel_SVC, "called, dst_addr=0x{:X}, src_addr=0x{:X}, size=0x{:X}", dst_addr, LOG_TRACE(Kernel_SVC, "called, dst_addr=0x{:X}, src_addr=0x{:X}, size=0x{:X}", dst_addr,
src_addr, size); src_addr, size);
auto* const current_process = Core::CurrentProcess(); auto& vm_manager = Core::CurrentProcess()->VMManager();
const auto& vm_manager = current_process->VMManager();
const auto result = MapUnmapMemorySanityChecks(vm_manager, dst_addr, src_addr, size); const auto result = MapUnmapMemorySanityChecks(vm_manager, dst_addr, src_addr, size);
if (result != RESULT_SUCCESS) {
if (result.IsError()) {
return result; return result;
} }
return current_process->MirrorMemory(dst_addr, src_addr, size, MemoryState::Stack); return vm_manager.MirrorMemory(dst_addr, src_addr, size, MemoryState::Stack);
} }
/// Unmaps a region that was previously mapped with svcMapMemory /// Unmaps a region that was previously mapped with svcMapMemory
@ -323,15 +328,14 @@ static ResultCode UnmapMemory(VAddr dst_addr, VAddr src_addr, u64 size) {
LOG_TRACE(Kernel_SVC, "called, dst_addr=0x{:X}, src_addr=0x{:X}, size=0x{:X}", dst_addr, LOG_TRACE(Kernel_SVC, "called, dst_addr=0x{:X}, src_addr=0x{:X}, size=0x{:X}", dst_addr,
src_addr, size); src_addr, size);
auto* const current_process = Core::CurrentProcess(); auto& vm_manager = Core::CurrentProcess()->VMManager();
const auto& vm_manager = current_process->VMManager();
const auto result = MapUnmapMemorySanityChecks(vm_manager, dst_addr, src_addr, size); const auto result = MapUnmapMemorySanityChecks(vm_manager, dst_addr, src_addr, size);
if (result != RESULT_SUCCESS) {
if (result.IsError()) {
return result; return result;
} }
return current_process->UnmapMemory(dst_addr, src_addr, size); return vm_manager.UnmapRange(dst_addr, size);
} }
/// Connect to an OS service given the port name, returns the handle to the port to out /// Connect to an OS service given the port name, returns the handle to the port to out

View file

@ -318,14 +318,18 @@ public:
return; return;
} }
ASSERT(process->MirrorMemory(*map_address, nro_addr, nro_size, ASSERT(vm_manager
Kernel::MemoryState::ModuleCodeStatic) == RESULT_SUCCESS); .MirrorMemory(*map_address, nro_addr, nro_size,
ASSERT(process->UnmapMemory(nro_addr, 0, nro_size) == RESULT_SUCCESS); Kernel::MemoryState::ModuleCodeStatic)
.IsSuccess());
ASSERT(vm_manager.UnmapRange(nro_addr, nro_size).IsSuccess());
if (bss_size > 0) { if (bss_size > 0) {
ASSERT(process->MirrorMemory(*map_address + nro_size, bss_addr, bss_size, ASSERT(vm_manager
Kernel::MemoryState::ModuleCodeStatic) == RESULT_SUCCESS); .MirrorMemory(*map_address + nro_size, bss_addr, bss_size,
ASSERT(process->UnmapMemory(bss_addr, 0, bss_size) == RESULT_SUCCESS); Kernel::MemoryState::ModuleCodeStatic)
.IsSuccess());
ASSERT(vm_manager.UnmapRange(bss_addr, bss_size).IsSuccess());
} }
vm_manager.ReprotectRange(*map_address, header.text_size, vm_manager.ReprotectRange(*map_address, header.text_size,
@ -380,13 +384,14 @@ public:
return; return;
} }
auto* process = Core::CurrentProcess(); auto& vm_manager = Core::CurrentProcess()->VMManager();
auto& vm_manager = process->VMManager();
const auto& nro_size = iter->second.size; const auto& nro_size = iter->second.size;
ASSERT(process->MirrorMemory(heap_addr, mapped_addr, nro_size, ASSERT(vm_manager
Kernel::MemoryState::ModuleCodeStatic) == RESULT_SUCCESS); .MirrorMemory(heap_addr, mapped_addr, nro_size,
ASSERT(process->UnmapMemory(mapped_addr, 0, nro_size) == RESULT_SUCCESS); Kernel::MemoryState::ModuleCodeStatic)
.IsSuccess());
ASSERT(vm_manager.UnmapRange(mapped_addr, nro_size).IsSuccess());
Core::System::GetInstance().InvalidateCpuInstructionCaches(); Core::System::GetInstance().InvalidateCpuInstructionCaches();