diff options
Diffstat (limited to 'src/core/hle/kernel/process.cpp')
| -rw-r--r-- | src/core/hle/kernel/process.cpp | 78 |
1 files changed, 2 insertions, 76 deletions
diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp index 0c0506085..5403ceef5 100644 --- a/src/core/hle/kernel/process.cpp +++ b/src/core/hle/kernel/process.cpp | |||
| @@ -8,7 +8,6 @@ | |||
| 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/hle/kernel/errors.h" | 10 | #include "core/hle/kernel/errors.h" |
| 11 | #include "core/hle/kernel/memory.h" | ||
| 12 | #include "core/hle/kernel/process.h" | 11 | #include "core/hle/kernel/process.h" |
| 13 | #include "core/hle/kernel/resource_limit.h" | 12 | #include "core/hle/kernel/resource_limit.h" |
| 14 | #include "core/hle/kernel/thread.h" | 13 | #include "core/hle/kernel/thread.h" |
| @@ -125,14 +124,6 @@ void Process::Run(VAddr entry_point, s32 main_thread_priority, u32 stack_size) { | |||
| 125 | std::make_shared<std::vector<u8>>(stack_size, 0), 0, stack_size, | 124 | std::make_shared<std::vector<u8>>(stack_size, 0), 0, stack_size, |
| 126 | MemoryState::Mapped) | 125 | MemoryState::Mapped) |
| 127 | .Unwrap(); | 126 | .Unwrap(); |
| 128 | misc_memory_used += stack_size; | ||
| 129 | memory_region->used += stack_size; | ||
| 130 | |||
| 131 | // Map special address mappings | ||
| 132 | MapSharedPages(vm_manager); | ||
| 133 | for (const auto& mapping : address_mappings) { | ||
| 134 | HandleSpecialMapping(vm_manager, mapping); | ||
| 135 | } | ||
| 136 | 127 | ||
| 137 | vm_manager.LogLayout(); | 128 | vm_manager.LogLayout(); |
| 138 | status = ProcessStatus::Running; | 129 | status = ProcessStatus::Running; |
| @@ -141,17 +132,13 @@ void Process::Run(VAddr entry_point, s32 main_thread_priority, u32 stack_size) { | |||
| 141 | } | 132 | } |
| 142 | 133 | ||
| 143 | void Process::LoadModule(SharedPtr<CodeSet> module_, VAddr base_addr) { | 134 | void Process::LoadModule(SharedPtr<CodeSet> module_, VAddr base_addr) { |
| 144 | memory_region = GetMemoryRegion(flags.memory_region); | 135 | const auto MapSegment = [&](CodeSet::Segment& segment, VMAPermission permissions, |
| 145 | 136 | MemoryState memory_state) { | |
| 146 | auto MapSegment = [&](CodeSet::Segment& segment, VMAPermission permissions, | ||
| 147 | MemoryState memory_state) { | ||
| 148 | auto vma = vm_manager | 137 | auto vma = vm_manager |
| 149 | .MapMemoryBlock(segment.addr + base_addr, module_->memory, segment.offset, | 138 | .MapMemoryBlock(segment.addr + base_addr, module_->memory, segment.offset, |
| 150 | segment.size, memory_state) | 139 | segment.size, memory_state) |
| 151 | .Unwrap(); | 140 | .Unwrap(); |
| 152 | vm_manager.Reprotect(vma, permissions); | 141 | vm_manager.Reprotect(vma, permissions); |
| 153 | misc_memory_used += segment.size; | ||
| 154 | memory_region->used += segment.size; | ||
| 155 | }; | 142 | }; |
| 156 | 143 | ||
| 157 | // Map CodeSet segments | 144 | // Map CodeSet segments |
| @@ -160,20 +147,6 @@ void Process::LoadModule(SharedPtr<CodeSet> module_, VAddr base_addr) { | |||
| 160 | MapSegment(module_->data, VMAPermission::ReadWrite, MemoryState::CodeMutable); | 147 | MapSegment(module_->data, VMAPermission::ReadWrite, MemoryState::CodeMutable); |
| 161 | } | 148 | } |
| 162 | 149 | ||
| 163 | VAddr Process::GetLinearHeapAreaAddress() const { | ||
| 164 | // Starting from system version 8.0.0 a new linear heap layout is supported to allow usage of | ||
| 165 | // the extra RAM in the n3DS. | ||
| 166 | return kernel_version < 0x22C ? Memory::LINEAR_HEAP_VADDR : Memory::NEW_LINEAR_HEAP_VADDR; | ||
| 167 | } | ||
| 168 | |||
| 169 | VAddr Process::GetLinearHeapBase() const { | ||
| 170 | return GetLinearHeapAreaAddress() + memory_region->base; | ||
| 171 | } | ||
| 172 | |||
| 173 | VAddr Process::GetLinearHeapLimit() const { | ||
| 174 | return GetLinearHeapBase() + memory_region->size; | ||
| 175 | } | ||
| 176 | |||
| 177 | ResultVal<VAddr> Process::HeapAllocate(VAddr target, u64 size, VMAPermission perms) { | 150 | ResultVal<VAddr> Process::HeapAllocate(VAddr target, u64 size, VMAPermission perms) { |
| 178 | if (target < Memory::HEAP_VADDR || target + size > Memory::HEAP_VADDR_END || | 151 | if (target < Memory::HEAP_VADDR || target + size > Memory::HEAP_VADDR_END || |
| 179 | target + size < target) { | 152 | target + size < target) { |
| @@ -206,7 +179,6 @@ ResultVal<VAddr> Process::HeapAllocate(VAddr target, u64 size, VMAPermission per | |||
| 206 | vm_manager.Reprotect(vma, perms); | 179 | vm_manager.Reprotect(vma, perms); |
| 207 | 180 | ||
| 208 | heap_used = size; | 181 | heap_used = size; |
| 209 | memory_region->used += size; | ||
| 210 | 182 | ||
| 211 | return MakeResult<VAddr>(heap_end - size); | 183 | return MakeResult<VAddr>(heap_end - size); |
| 212 | } | 184 | } |
| @@ -226,52 +198,6 @@ ResultCode Process::HeapFree(VAddr target, u32 size) { | |||
| 226 | return result; | 198 | return result; |
| 227 | 199 | ||
| 228 | heap_used -= size; | 200 | heap_used -= size; |
| 229 | memory_region->used -= size; | ||
| 230 | |||
| 231 | return RESULT_SUCCESS; | ||
| 232 | } | ||
| 233 | |||
| 234 | ResultVal<VAddr> Process::LinearAllocate(VAddr target, u32 size, VMAPermission perms) { | ||
| 235 | UNIMPLEMENTED(); | ||
| 236 | return {}; | ||
| 237 | } | ||
| 238 | |||
| 239 | ResultCode Process::LinearFree(VAddr target, u32 size) { | ||
| 240 | auto& linheap_memory = memory_region->linear_heap_memory; | ||
| 241 | |||
| 242 | if (target < GetLinearHeapBase() || target + size > GetLinearHeapLimit() || | ||
| 243 | target + size < target) { | ||
| 244 | |||
| 245 | return ERR_INVALID_ADDRESS; | ||
| 246 | } | ||
| 247 | |||
| 248 | if (size == 0) { | ||
| 249 | return RESULT_SUCCESS; | ||
| 250 | } | ||
| 251 | |||
| 252 | VAddr heap_end = GetLinearHeapBase() + (u32)linheap_memory->size(); | ||
| 253 | if (target + size > heap_end) { | ||
| 254 | return ERR_INVALID_ADDRESS_STATE; | ||
| 255 | } | ||
| 256 | |||
| 257 | ResultCode result = vm_manager.UnmapRange(target, size); | ||
| 258 | if (result.IsError()) | ||
| 259 | return result; | ||
| 260 | |||
| 261 | linear_heap_used -= size; | ||
| 262 | memory_region->used -= size; | ||
| 263 | |||
| 264 | if (target + size == heap_end) { | ||
| 265 | // End of linear heap has been freed, so check what's the last allocated block in it and | ||
| 266 | // reduce the size. | ||
| 267 | auto vma = vm_manager.FindVMA(target); | ||
| 268 | ASSERT(vma != vm_manager.vma_map.end()); | ||
| 269 | ASSERT(vma->second.type == VMAType::Free); | ||
| 270 | VAddr new_end = vma->second.base; | ||
| 271 | if (new_end >= GetLinearHeapBase()) { | ||
| 272 | linheap_memory->resize(new_end - GetLinearHeapBase()); | ||
| 273 | } | ||
| 274 | } | ||
| 275 | 201 | ||
| 276 | return RESULT_SUCCESS; | 202 | return RESULT_SUCCESS; |
| 277 | } | 203 | } |