summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Lioncash2018-12-27 18:31:31 -0500
committerGravatar Lioncash2018-12-27 19:08:47 -0500
commitfbeaa330a35f93857c249aa5f69dfee6b09eefe0 (patch)
treecc9223890f85e66ba61d1b8fe1acfbbb55822f15 /src
parentMerge pull request #1951 from Tinob/master (diff)
downloadyuzu-fbeaa330a35f93857c249aa5f69dfee6b09eefe0.tar.gz
yuzu-fbeaa330a35f93857c249aa5f69dfee6b09eefe0.tar.xz
yuzu-fbeaa330a35f93857c249aa5f69dfee6b09eefe0.zip
kernel/process: Remove most allocation functions from Process' interface
In all cases that these functions are needed, the VMManager can just be retrieved and used instead of providing the same functions in Process' interface. This also makes it a little nicer dependency-wise, since it gets rid of cases where the VMManager interface was being used, and then switched over to using the interface for a Process instance. Instead, it makes all accesses uniform and uses the VMManager instance for all necessary tasks. All the basic memory mapping functions did was forward to the Process' VMManager instance anyways.
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/kernel/process.cpp16
-rw-r--r--src/core/hle/kernel/process.h9
-rw-r--r--src/core/hle/kernel/svc.cpp32
-rw-r--r--src/core/hle/service/ldr/ldr.cpp27
4 files changed, 35 insertions, 49 deletions
diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp
index 4f209a979..06a673b9b 100644
--- a/src/core/hle/kernel/process.cpp
+++ b/src/core/hle/kernel/process.cpp
@@ -198,22 +198,6 @@ void Process::LoadModule(CodeSet module_, VAddr base_addr) {
198 Core::System::GetInstance().ArmInterface(3).ClearInstructionCache(); 198 Core::System::GetInstance().ArmInterface(3).ClearInstructionCache();
199} 199}
200 200
201ResultVal<VAddr> Process::HeapAllocate(VAddr target, u64 size, VMAPermission perms) {
202 return vm_manager.HeapAllocate(target, size, perms);
203}
204
205ResultCode Process::HeapFree(VAddr target, u32 size) {
206 return vm_manager.HeapFree(target, size);
207}
208
209ResultCode Process::MirrorMemory(VAddr dst_addr, VAddr src_addr, u64 size, MemoryState state) {
210 return vm_manager.MirrorMemory(dst_addr, src_addr, size, state);
211}
212
213ResultCode Process::UnmapMemory(VAddr dst_addr, VAddr /*src_addr*/, u64 size) {
214 return vm_manager.UnmapRange(dst_addr, size);
215}
216
217Kernel::Process::Process(KernelCore& kernel) : WaitObject{kernel} {} 201Kernel::Process::Process(KernelCore& kernel) : WaitObject{kernel} {}
218Kernel::Process::~Process() {} 202Kernel::Process::~Process() {}
219 203
diff --git a/src/core/hle/kernel/process.h b/src/core/hle/kernel/process.h
index 2c0b20f9e..ac6956266 100644
--- a/src/core/hle/kernel/process.h
+++ b/src/core/hle/kernel/process.h
@@ -242,7 +242,7 @@ public:
242 void LoadModule(CodeSet module_, VAddr base_addr); 242 void LoadModule(CodeSet module_, VAddr base_addr);
243 243
244 /////////////////////////////////////////////////////////////////////////////////////////////// 244 ///////////////////////////////////////////////////////////////////////////////////////////////
245 // Memory Management 245 // Thread-local storage management
246 246
247 // Marks the next available region as used and returns the address of the slot. 247 // Marks the next available region as used and returns the address of the slot.
248 VAddr MarkNextAvailableTLSSlotAsUsed(Thread& thread); 248 VAddr MarkNextAvailableTLSSlotAsUsed(Thread& thread);
@@ -250,13 +250,6 @@ public:
250 // Frees a used TLS slot identified by the given address 250 // Frees a used TLS slot identified by the given address
251 void FreeTLSSlot(VAddr tls_address); 251 void FreeTLSSlot(VAddr tls_address);
252 252
253 ResultVal<VAddr> HeapAllocate(VAddr target, u64 size, VMAPermission perms);
254 ResultCode HeapFree(VAddr target, u32 size);
255
256 ResultCode MirrorMemory(VAddr dst_addr, VAddr src_addr, u64 size, MemoryState state);
257
258 ResultCode UnmapMemory(VAddr dst_addr, VAddr src_addr, u64 size);
259
260private: 253private:
261 explicit Process(KernelCore& kernel); 254 explicit Process(KernelCore& kernel);
262 ~Process() override; 255 ~Process() override;
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp
index 2e80b48c2..b955f9839 100644
--- a/src/core/hle/kernel/svc.cpp
+++ b/src/core/hle/kernel/svc.cpp
@@ -190,10 +190,16 @@ static ResultCode SetHeapSize(VAddr* heap_addr, u64 heap_size) {
190 return ERR_INVALID_SIZE; 190 return ERR_INVALID_SIZE;
191 } 191 }
192 192
193 auto& process = *Core::CurrentProcess(); 193 auto& vm_manager = Core::CurrentProcess()->VMManager();
194 const VAddr heap_base = process.VMManager().GetHeapRegionBaseAddress(); 194 const VAddr heap_base = vm_manager.GetHeapRegionBaseAddress();
195 CASCADE_RESULT(*heap_addr, 195 const auto alloc_result =
196 process.HeapAllocate(heap_base, heap_size, VMAPermission::ReadWrite)); 196 vm_manager.HeapAllocate(heap_base, heap_size, VMAPermission::ReadWrite);
197
198 if (alloc_result.Failed()) {
199 return alloc_result.Code();
200 }
201
202 *heap_addr = *alloc_result;
197 return RESULT_SUCCESS; 203 return RESULT_SUCCESS;
198} 204}
199 205
@@ -307,15 +313,14 @@ static ResultCode MapMemory(VAddr dst_addr, VAddr src_addr, u64 size) {
307 LOG_TRACE(Kernel_SVC, "called, dst_addr=0x{:X}, src_addr=0x{:X}, size=0x{:X}", dst_addr, 313 LOG_TRACE(Kernel_SVC, "called, dst_addr=0x{:X}, src_addr=0x{:X}, size=0x{:X}", dst_addr,
308 src_addr, size); 314 src_addr, size);
309 315
310 auto* const current_process = Core::CurrentProcess(); 316 auto& vm_manager = Core::CurrentProcess()->VMManager();
311 const auto& vm_manager = current_process->VMManager();
312
313 const auto result = MapUnmapMemorySanityChecks(vm_manager, dst_addr, src_addr, size); 317 const auto result = MapUnmapMemorySanityChecks(vm_manager, dst_addr, src_addr, size);
314 if (result != RESULT_SUCCESS) { 318
319 if (result.IsError()) {
315 return result; 320 return result;
316 } 321 }
317 322
318 return current_process->MirrorMemory(dst_addr, src_addr, size, MemoryState::Stack); 323 return vm_manager.MirrorMemory(dst_addr, src_addr, size, MemoryState::Stack);
319} 324}
320 325
321/// Unmaps a region that was previously mapped with svcMapMemory 326/// Unmaps a region that was previously mapped with svcMapMemory
@@ -323,15 +328,14 @@ static ResultCode UnmapMemory(VAddr dst_addr, VAddr src_addr, u64 size) {
323 LOG_TRACE(Kernel_SVC, "called, dst_addr=0x{:X}, src_addr=0x{:X}, size=0x{:X}", dst_addr, 328 LOG_TRACE(Kernel_SVC, "called, dst_addr=0x{:X}, src_addr=0x{:X}, size=0x{:X}", dst_addr,
324 src_addr, size); 329 src_addr, size);
325 330
326 auto* const current_process = Core::CurrentProcess(); 331 auto& vm_manager = Core::CurrentProcess()->VMManager();
327 const auto& vm_manager = current_process->VMManager();
328
329 const auto result = MapUnmapMemorySanityChecks(vm_manager, dst_addr, src_addr, size); 332 const auto result = MapUnmapMemorySanityChecks(vm_manager, dst_addr, src_addr, size);
330 if (result != RESULT_SUCCESS) { 333
334 if (result.IsError()) {
331 return result; 335 return result;
332 } 336 }
333 337
334 return current_process->UnmapMemory(dst_addr, src_addr, size); 338 return vm_manager.UnmapRange(dst_addr, size);
335} 339}
336 340
337/// Connect to an OS service given the port name, returns the handle to the port to out 341/// Connect to an OS service given the port name, returns the handle to the port to out
diff --git a/src/core/hle/service/ldr/ldr.cpp b/src/core/hle/service/ldr/ldr.cpp
index 13bcefe07..9df7ac50f 100644
--- a/src/core/hle/service/ldr/ldr.cpp
+++ b/src/core/hle/service/ldr/ldr.cpp
@@ -318,14 +318,18 @@ public:
318 return; 318 return;
319 } 319 }
320 320
321 ASSERT(process->MirrorMemory(*map_address, nro_addr, nro_size, 321 ASSERT(vm_manager
322 Kernel::MemoryState::ModuleCodeStatic) == RESULT_SUCCESS); 322 .MirrorMemory(*map_address, nro_addr, nro_size,
323 ASSERT(process->UnmapMemory(nro_addr, 0, nro_size) == RESULT_SUCCESS); 323 Kernel::MemoryState::ModuleCodeStatic)
324 .IsSuccess());
325 ASSERT(vm_manager.UnmapRange(nro_addr, nro_size).IsSuccess());
324 326
325 if (bss_size > 0) { 327 if (bss_size > 0) {
326 ASSERT(process->MirrorMemory(*map_address + nro_size, bss_addr, bss_size, 328 ASSERT(vm_manager
327 Kernel::MemoryState::ModuleCodeStatic) == RESULT_SUCCESS); 329 .MirrorMemory(*map_address + nro_size, bss_addr, bss_size,
328 ASSERT(process->UnmapMemory(bss_addr, 0, bss_size) == RESULT_SUCCESS); 330 Kernel::MemoryState::ModuleCodeStatic)
331 .IsSuccess());
332 ASSERT(vm_manager.UnmapRange(bss_addr, bss_size).IsSuccess());
329 } 333 }
330 334
331 vm_manager.ReprotectRange(*map_address, header.text_size, 335 vm_manager.ReprotectRange(*map_address, header.text_size,
@@ -380,13 +384,14 @@ public:
380 return; 384 return;
381 } 385 }
382 386
383 auto* process = Core::CurrentProcess(); 387 auto& vm_manager = Core::CurrentProcess()->VMManager();
384 auto& vm_manager = process->VMManager();
385 const auto& nro_size = iter->second.size; 388 const auto& nro_size = iter->second.size;
386 389
387 ASSERT(process->MirrorMemory(heap_addr, mapped_addr, nro_size, 390 ASSERT(vm_manager
388 Kernel::MemoryState::ModuleCodeStatic) == RESULT_SUCCESS); 391 .MirrorMemory(heap_addr, mapped_addr, nro_size,
389 ASSERT(process->UnmapMemory(mapped_addr, 0, nro_size) == RESULT_SUCCESS); 392 Kernel::MemoryState::ModuleCodeStatic)
393 .IsSuccess());
394 ASSERT(vm_manager.UnmapRange(mapped_addr, nro_size).IsSuccess());
390 395
391 Core::System::GetInstance().InvalidateCpuInstructionCaches(); 396 Core::System::GetInstance().InvalidateCpuInstructionCaches();
392 397