diff options
| author | 2018-09-29 10:54:39 -0400 | |
|---|---|---|
| committer | 2018-09-29 10:54:39 -0400 | |
| commit | f7b69d61f2a871e8afcd9819b014e873f6e0b80d (patch) | |
| tree | ab6fa797e0a0edd41cc84138ac56aaba0c5238fe /src/core/hle/kernel/process.cpp | |
| parent | Merge pull request #1360 from FearlessTobi/port-3979 (diff) | |
| parent | memory: Dehardcode the use of fixed memory range constants (diff) | |
| download | yuzu-f7b69d61f2a871e8afcd9819b014e873f6e0b80d.tar.gz yuzu-f7b69d61f2a871e8afcd9819b014e873f6e0b80d.tar.xz yuzu-f7b69d61f2a871e8afcd9819b014e873f6e0b80d.zip | |
Merge pull request #1395 from lioncash/vm
process/vm_manager: Initial modifications to load NPDM metadata
Diffstat (limited to 'src/core/hle/kernel/process.cpp')
| -rw-r--r-- | src/core/hle/kernel/process.cpp | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp index 121f741fd..a8e3098ca 100644 --- a/src/core/hle/kernel/process.cpp +++ b/src/core/hle/kernel/process.cpp | |||
| @@ -8,6 +8,7 @@ | |||
| 8 | #include "common/common_funcs.h" | 8 | #include "common/common_funcs.h" |
| 9 | #include "common/logging/log.h" | 9 | #include "common/logging/log.h" |
| 10 | #include "core/core.h" | 10 | #include "core/core.h" |
| 11 | #include "core/file_sys/program_metadata.h" | ||
| 11 | #include "core/hle/kernel/errors.h" | 12 | #include "core/hle/kernel/errors.h" |
| 12 | #include "core/hle/kernel/kernel.h" | 13 | #include "core/hle/kernel/kernel.h" |
| 13 | #include "core/hle/kernel/process.h" | 14 | #include "core/hle/kernel/process.h" |
| @@ -34,14 +35,21 @@ SharedPtr<Process> Process::Create(KernelCore& kernel, std::string&& name) { | |||
| 34 | process->name = std::move(name); | 35 | process->name = std::move(name); |
| 35 | process->flags.raw = 0; | 36 | process->flags.raw = 0; |
| 36 | process->flags.memory_region.Assign(MemoryRegion::APPLICATION); | 37 | process->flags.memory_region.Assign(MemoryRegion::APPLICATION); |
| 38 | process->resource_limit = kernel.ResourceLimitForCategory(ResourceLimitCategory::APPLICATION); | ||
| 37 | process->status = ProcessStatus::Created; | 39 | process->status = ProcessStatus::Created; |
| 38 | process->program_id = 0; | 40 | process->program_id = 0; |
| 39 | process->process_id = kernel.CreateNewProcessID(); | 41 | process->process_id = kernel.CreateNewProcessID(); |
| 42 | process->svc_access_mask.set(); | ||
| 40 | 43 | ||
| 41 | kernel.AppendNewProcess(process); | 44 | kernel.AppendNewProcess(process); |
| 42 | return process; | 45 | return process; |
| 43 | } | 46 | } |
| 44 | 47 | ||
| 48 | void Process::LoadFromMetadata(const FileSys::ProgramMetadata& metadata) { | ||
| 49 | program_id = metadata.GetTitleID(); | ||
| 50 | vm_manager.Reset(metadata.GetAddressSpaceType()); | ||
| 51 | } | ||
| 52 | |||
| 45 | void Process::ParseKernelCaps(const u32* kernel_caps, std::size_t len) { | 53 | void Process::ParseKernelCaps(const u32* kernel_caps, std::size_t len) { |
| 46 | for (std::size_t i = 0; i < len; ++i) { | 54 | for (std::size_t i = 0; i < len; ++i) { |
| 47 | u32 descriptor = kernel_caps[i]; | 55 | u32 descriptor = kernel_caps[i]; |
| @@ -119,7 +127,7 @@ void Process::Run(VAddr entry_point, s32 main_thread_priority, u32 stack_size) { | |||
| 119 | // 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 |
| 120 | // of the user address space. | 128 | // of the user address space. |
| 121 | vm_manager | 129 | vm_manager |
| 122 | .MapMemoryBlock(Memory::STACK_AREA_VADDR_END - stack_size, | 130 | .MapMemoryBlock(vm_manager.GetTLSIORegionEndAddress() - stack_size, |
| 123 | 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, |
| 124 | MemoryState::Mapped) | 132 | MemoryState::Mapped) |
| 125 | .Unwrap(); | 133 | .Unwrap(); |
| @@ -185,6 +193,7 @@ static std::tuple<std::size_t, std::size_t, bool> FindFreeThreadLocalSlot( | |||
| 185 | 193 | ||
| 186 | VAddr Process::MarkNextAvailableTLSSlotAsUsed(Thread& thread) { | 194 | VAddr Process::MarkNextAvailableTLSSlotAsUsed(Thread& thread) { |
| 187 | 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(); | ||
| 188 | 197 | ||
| 189 | if (needs_allocation) { | 198 | if (needs_allocation) { |
| 190 | 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 |
| @@ -197,18 +206,17 @@ VAddr Process::MarkNextAvailableTLSSlotAsUsed(Thread& thread) { | |||
| 197 | 206 | ||
| 198 | vm_manager.RefreshMemoryBlockMappings(tls_memory.get()); | 207 | vm_manager.RefreshMemoryBlockMappings(tls_memory.get()); |
| 199 | 208 | ||
| 200 | 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, |
| 201 | tls_memory, 0, Memory::PAGE_SIZE, MemoryState::ThreadLocal); | 210 | Memory::PAGE_SIZE, MemoryState::ThreadLocal); |
| 202 | } | 211 | } |
| 203 | 212 | ||
| 204 | tls_slots[available_page].set(available_slot); | 213 | tls_slots[available_page].set(available_slot); |
| 205 | 214 | ||
| 206 | 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; |
| 207 | available_slot * Memory::TLS_ENTRY_SIZE; | ||
| 208 | } | 216 | } |
| 209 | 217 | ||
| 210 | void Process::FreeTLSSlot(VAddr tls_address) { | 218 | void Process::FreeTLSSlot(VAddr tls_address) { |
| 211 | const VAddr tls_base = tls_address - Memory::TLS_AREA_VADDR; | 219 | const VAddr tls_base = tls_address - vm_manager.GetTLSIORegionBaseAddress(); |
| 212 | const VAddr tls_page = tls_base / Memory::PAGE_SIZE; | 220 | const VAddr tls_page = tls_base / Memory::PAGE_SIZE; |
| 213 | 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; |
| 214 | 222 | ||
| @@ -232,8 +240,8 @@ void Process::LoadModule(SharedPtr<CodeSet> module_, VAddr base_addr) { | |||
| 232 | } | 240 | } |
| 233 | 241 | ||
| 234 | ResultVal<VAddr> Process::HeapAllocate(VAddr target, u64 size, VMAPermission perms) { | 242 | ResultVal<VAddr> Process::HeapAllocate(VAddr target, u64 size, VMAPermission perms) { |
| 235 | if (target < Memory::HEAP_VADDR || target + size > Memory::HEAP_VADDR_END || | 243 | if (target < vm_manager.GetHeapRegionBaseAddress() || |
| 236 | target + size < target) { | 244 | target + size > vm_manager.GetHeapRegionEndAddress() || target + size < target) { |
| 237 | return ERR_INVALID_ADDRESS; | 245 | return ERR_INVALID_ADDRESS; |
| 238 | } | 246 | } |
| 239 | 247 | ||
| @@ -268,8 +276,8 @@ ResultVal<VAddr> Process::HeapAllocate(VAddr target, u64 size, VMAPermission per | |||
| 268 | } | 276 | } |
| 269 | 277 | ||
| 270 | ResultCode Process::HeapFree(VAddr target, u32 size) { | 278 | ResultCode Process::HeapFree(VAddr target, u32 size) { |
| 271 | if (target < Memory::HEAP_VADDR || target + size > Memory::HEAP_VADDR_END || | 279 | if (target < vm_manager.GetHeapRegionBaseAddress() || |
| 272 | target + size < target) { | 280 | target + size > vm_manager.GetHeapRegionEndAddress() || target + size < target) { |
| 273 | return ERR_INVALID_ADDRESS; | 281 | return ERR_INVALID_ADDRESS; |
| 274 | } | 282 | } |
| 275 | 283 | ||