summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/process.cpp
diff options
context:
space:
mode:
authorGravatar Lioncash2018-09-24 20:01:45 -0400
committerGravatar Lioncash2018-09-24 22:16:03 -0400
commit83377113bfe7791483a1b67e06dd0f51620c04ec (patch)
treed766a2d2f20d247e8663c1a76d5c41fcf7f643d4 /src/core/hle/kernel/process.cpp
parentsvc: Report correct memory-related values within some of the cases in svcGetI... (diff)
downloadyuzu-83377113bfe7791483a1b67e06dd0f51620c04ec.tar.gz
yuzu-83377113bfe7791483a1b67e06dd0f51620c04ec.tar.xz
yuzu-83377113bfe7791483a1b67e06dd0f51620c04ec.zip
memory: Dehardcode the use of fixed memory range constants
The locations of these can actually vary depending on the address space layout, so we shouldn't be using these when determining where to map memory or be using them as offsets for calculations. This keeps all the memory ranges flexible and malleable based off of the virtual memory manager instance state.
Diffstat (limited to 'src/core/hle/kernel/process.cpp')
-rw-r--r--src/core/hle/kernel/process.cpp20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp
index f337f626f..a8e3098ca 100644
--- a/src/core/hle/kernel/process.cpp
+++ b/src/core/hle/kernel/process.cpp
@@ -127,7 +127,7 @@ void Process::Run(VAddr entry_point, s32 main_thread_priority, u32 stack_size) {
127 // TODO(bunnei): This is heap area that should be allocated by the kernel and not mapped as part 127 // TODO(bunnei): This is heap area that should be allocated by the kernel and not mapped as part
128 // of the user address space. 128 // of the user address space.
129 vm_manager 129 vm_manager
130 .MapMemoryBlock(Memory::STACK_AREA_VADDR_END - stack_size, 130 .MapMemoryBlock(vm_manager.GetTLSIORegionEndAddress() - stack_size,
131 std::make_shared<std::vector<u8>>(stack_size, 0), 0, stack_size, 131 std::make_shared<std::vector<u8>>(stack_size, 0), 0, stack_size,
132 MemoryState::Mapped) 132 MemoryState::Mapped)
133 .Unwrap(); 133 .Unwrap();
@@ -193,6 +193,7 @@ static std::tuple<std::size_t, std::size_t, bool> FindFreeThreadLocalSlot(
193 193
194VAddr Process::MarkNextAvailableTLSSlotAsUsed(Thread& thread) { 194VAddr Process::MarkNextAvailableTLSSlotAsUsed(Thread& thread) {
195 auto [available_page, available_slot, needs_allocation] = FindFreeThreadLocalSlot(tls_slots); 195 auto [available_page, available_slot, needs_allocation] = FindFreeThreadLocalSlot(tls_slots);
196 const VAddr tls_begin = vm_manager.GetTLSIORegionBaseAddress();
196 197
197 if (needs_allocation) { 198 if (needs_allocation) {
198 tls_slots.emplace_back(0); // The page is completely available at the start 199 tls_slots.emplace_back(0); // The page is completely available at the start
@@ -205,18 +206,17 @@ VAddr Process::MarkNextAvailableTLSSlotAsUsed(Thread& thread) {
205 206
206 vm_manager.RefreshMemoryBlockMappings(tls_memory.get()); 207 vm_manager.RefreshMemoryBlockMappings(tls_memory.get());
207 208
208 vm_manager.MapMemoryBlock(Memory::TLS_AREA_VADDR + available_page * Memory::PAGE_SIZE, 209 vm_manager.MapMemoryBlock(tls_begin + available_page * Memory::PAGE_SIZE, tls_memory, 0,
209 tls_memory, 0, Memory::PAGE_SIZE, MemoryState::ThreadLocal); 210 Memory::PAGE_SIZE, MemoryState::ThreadLocal);
210 } 211 }
211 212
212 tls_slots[available_page].set(available_slot); 213 tls_slots[available_page].set(available_slot);
213 214
214 return Memory::TLS_AREA_VADDR + available_page * Memory::PAGE_SIZE + 215 return tls_begin + available_page * Memory::PAGE_SIZE + available_slot * Memory::TLS_ENTRY_SIZE;
215 available_slot * Memory::TLS_ENTRY_SIZE;
216} 216}
217 217
218void Process::FreeTLSSlot(VAddr tls_address) { 218void Process::FreeTLSSlot(VAddr tls_address) {
219 const VAddr tls_base = tls_address - Memory::TLS_AREA_VADDR; 219 const VAddr tls_base = tls_address - vm_manager.GetTLSIORegionBaseAddress();
220 const VAddr tls_page = tls_base / Memory::PAGE_SIZE; 220 const VAddr tls_page = tls_base / Memory::PAGE_SIZE;
221 const VAddr tls_slot = (tls_base % Memory::PAGE_SIZE) / Memory::TLS_ENTRY_SIZE; 221 const VAddr tls_slot = (tls_base % Memory::PAGE_SIZE) / Memory::TLS_ENTRY_SIZE;
222 222
@@ -240,8 +240,8 @@ void Process::LoadModule(SharedPtr<CodeSet> module_, VAddr base_addr) {
240} 240}
241 241
242ResultVal<VAddr> Process::HeapAllocate(VAddr target, u64 size, VMAPermission perms) { 242ResultVal<VAddr> Process::HeapAllocate(VAddr target, u64 size, VMAPermission perms) {
243 if (target < Memory::HEAP_VADDR || target + size > Memory::HEAP_VADDR_END || 243 if (target < vm_manager.GetHeapRegionBaseAddress() ||
244 target + size < target) { 244 target + size > vm_manager.GetHeapRegionEndAddress() || target + size < target) {
245 return ERR_INVALID_ADDRESS; 245 return ERR_INVALID_ADDRESS;
246 } 246 }
247 247
@@ -276,8 +276,8 @@ ResultVal<VAddr> Process::HeapAllocate(VAddr target, u64 size, VMAPermission per
276} 276}
277 277
278ResultCode Process::HeapFree(VAddr target, u32 size) { 278ResultCode Process::HeapFree(VAddr target, u32 size) {
279 if (target < Memory::HEAP_VADDR || target + size > Memory::HEAP_VADDR_END || 279 if (target < vm_manager.GetHeapRegionBaseAddress() ||
280 target + size < target) { 280 target + size > vm_manager.GetHeapRegionEndAddress() || target + size < target) {
281 return ERR_INVALID_ADDRESS; 281 return ERR_INVALID_ADDRESS;
282 } 282 }
283 283