diff options
| author | 2020-04-17 16:33:08 -0400 | |
|---|---|---|
| committer | 2020-04-17 16:33:08 -0400 | |
| commit | b8f5c71f2d7f819821acf036175cce65ab1ae12c (patch) | |
| tree | 151d7ed4e47536dc0e149a7117387b6a502d7da6 /src/core/hle/kernel/process.cpp | |
| parent | Merge pull request #3682 from lioncash/uam (diff) | |
| parent | core: hle: Address various feedback & code cleanup. (diff) | |
| download | yuzu-b8f5c71f2d7f819821acf036175cce65ab1ae12c.tar.gz yuzu-b8f5c71f2d7f819821acf036175cce65ab1ae12c.tar.xz yuzu-b8f5c71f2d7f819821acf036175cce65ab1ae12c.zip | |
Merge pull request #3666 from bunnei/new-vmm
Implement a new virtual memory manager
Diffstat (limited to 'src/core/hle/kernel/process.cpp')
| -rw-r--r-- | src/core/hle/kernel/process.cpp | 200 |
1 files changed, 133 insertions, 67 deletions
diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp index edc414d69..36724569f 100644 --- a/src/core/hle/kernel/process.cpp +++ b/src/core/hle/kernel/process.cpp | |||
| @@ -10,15 +10,18 @@ | |||
| 10 | #include "common/assert.h" | 10 | #include "common/assert.h" |
| 11 | #include "common/logging/log.h" | 11 | #include "common/logging/log.h" |
| 12 | #include "core/core.h" | 12 | #include "core/core.h" |
| 13 | #include "core/device_memory.h" | ||
| 13 | #include "core/file_sys/program_metadata.h" | 14 | #include "core/file_sys/program_metadata.h" |
| 14 | #include "core/hle/kernel/code_set.h" | 15 | #include "core/hle/kernel/code_set.h" |
| 15 | #include "core/hle/kernel/errors.h" | 16 | #include "core/hle/kernel/errors.h" |
| 16 | #include "core/hle/kernel/kernel.h" | 17 | #include "core/hle/kernel/kernel.h" |
| 18 | #include "core/hle/kernel/memory/memory_block_manager.h" | ||
| 19 | #include "core/hle/kernel/memory/page_table.h" | ||
| 20 | #include "core/hle/kernel/memory/slab_heap.h" | ||
| 17 | #include "core/hle/kernel/process.h" | 21 | #include "core/hle/kernel/process.h" |
| 18 | #include "core/hle/kernel/resource_limit.h" | 22 | #include "core/hle/kernel/resource_limit.h" |
| 19 | #include "core/hle/kernel/scheduler.h" | 23 | #include "core/hle/kernel/scheduler.h" |
| 20 | #include "core/hle/kernel/thread.h" | 24 | #include "core/hle/kernel/thread.h" |
| 21 | #include "core/hle/kernel/vm_manager.h" | ||
| 22 | #include "core/memory.h" | 25 | #include "core/memory.h" |
| 23 | #include "core/settings.h" | 26 | #include "core/settings.h" |
| 24 | 27 | ||
| @@ -31,10 +34,8 @@ namespace { | |||
| 31 | * @param kernel The kernel instance to create the main thread under. | 34 | * @param kernel The kernel instance to create the main thread under. |
| 32 | * @param priority The priority to give the main thread | 35 | * @param priority The priority to give the main thread |
| 33 | */ | 36 | */ |
| 34 | void SetupMainThread(Process& owner_process, KernelCore& kernel, u32 priority) { | 37 | void SetupMainThread(Process& owner_process, KernelCore& kernel, u32 priority, VAddr stack_top) { |
| 35 | const auto& vm_manager = owner_process.VMManager(); | 38 | const VAddr entry_point = owner_process.PageTable().GetCodeRegionStart(); |
| 36 | const VAddr entry_point = vm_manager.GetCodeRegionBaseAddress(); | ||
| 37 | const VAddr stack_top = vm_manager.GetTLSIORegionEndAddress(); | ||
| 38 | auto thread_res = Thread::Create(kernel, "main", entry_point, priority, 0, | 39 | auto thread_res = Thread::Create(kernel, "main", entry_point, priority, 0, |
| 39 | owner_process.GetIdealCore(), stack_top, owner_process); | 40 | owner_process.GetIdealCore(), stack_top, owner_process); |
| 40 | 41 | ||
| @@ -42,6 +43,8 @@ void SetupMainThread(Process& owner_process, KernelCore& kernel, u32 priority) { | |||
| 42 | 43 | ||
| 43 | // Register 1 must be a handle to the main thread | 44 | // Register 1 must be a handle to the main thread |
| 44 | const Handle thread_handle = owner_process.GetHandleTable().Create(thread).Unwrap(); | 45 | const Handle thread_handle = owner_process.GetHandleTable().Create(thread).Unwrap(); |
| 46 | thread->GetContext32().cpu_registers[0] = 0; | ||
| 47 | thread->GetContext64().cpu_registers[0] = 0; | ||
| 45 | thread->GetContext32().cpu_registers[1] = thread_handle; | 48 | thread->GetContext32().cpu_registers[1] = thread_handle; |
| 46 | thread->GetContext64().cpu_registers[1] = thread_handle; | 49 | thread->GetContext64().cpu_registers[1] = thread_handle; |
| 47 | 50 | ||
| @@ -57,7 +60,8 @@ void SetupMainThread(Process& owner_process, KernelCore& kernel, u32 priority) { | |||
| 57 | // (whichever page happens to have an available slot). | 60 | // (whichever page happens to have an available slot). |
| 58 | class TLSPage { | 61 | class TLSPage { |
| 59 | public: | 62 | public: |
| 60 | static constexpr std::size_t num_slot_entries = Memory::PAGE_SIZE / Memory::TLS_ENTRY_SIZE; | 63 | static constexpr std::size_t num_slot_entries = |
| 64 | Core::Memory::PAGE_SIZE / Core::Memory::TLS_ENTRY_SIZE; | ||
| 61 | 65 | ||
| 62 | explicit TLSPage(VAddr address) : base_address{address} {} | 66 | explicit TLSPage(VAddr address) : base_address{address} {} |
| 63 | 67 | ||
| @@ -76,7 +80,7 @@ public: | |||
| 76 | } | 80 | } |
| 77 | 81 | ||
| 78 | is_slot_used[i] = true; | 82 | is_slot_used[i] = true; |
| 79 | return base_address + (i * Memory::TLS_ENTRY_SIZE); | 83 | return base_address + (i * Core::Memory::TLS_ENTRY_SIZE); |
| 80 | } | 84 | } |
| 81 | 85 | ||
| 82 | return std::nullopt; | 86 | return std::nullopt; |
| @@ -86,15 +90,15 @@ public: | |||
| 86 | // Ensure that all given addresses are consistent with how TLS pages | 90 | // Ensure that all given addresses are consistent with how TLS pages |
| 87 | // are intended to be used when releasing slots. | 91 | // are intended to be used when releasing slots. |
| 88 | ASSERT(IsWithinPage(address)); | 92 | ASSERT(IsWithinPage(address)); |
| 89 | ASSERT((address % Memory::TLS_ENTRY_SIZE) == 0); | 93 | ASSERT((address % Core::Memory::TLS_ENTRY_SIZE) == 0); |
| 90 | 94 | ||
| 91 | const std::size_t index = (address - base_address) / Memory::TLS_ENTRY_SIZE; | 95 | const std::size_t index = (address - base_address) / Core::Memory::TLS_ENTRY_SIZE; |
| 92 | is_slot_used[index] = false; | 96 | is_slot_used[index] = false; |
| 93 | } | 97 | } |
| 94 | 98 | ||
| 95 | private: | 99 | private: |
| 96 | bool IsWithinPage(VAddr address) const { | 100 | bool IsWithinPage(VAddr address) const { |
| 97 | return base_address <= address && address < base_address + Memory::PAGE_SIZE; | 101 | return base_address <= address && address < base_address + Core::Memory::PAGE_SIZE; |
| 98 | } | 102 | } |
| 99 | 103 | ||
| 100 | VAddr base_address; | 104 | VAddr base_address; |
| @@ -106,7 +110,7 @@ std::shared_ptr<Process> Process::Create(Core::System& system, std::string name, | |||
| 106 | 110 | ||
| 107 | std::shared_ptr<Process> process = std::make_shared<Process>(system); | 111 | std::shared_ptr<Process> process = std::make_shared<Process>(system); |
| 108 | process->name = std::move(name); | 112 | process->name = std::move(name); |
| 109 | process->resource_limit = kernel.GetSystemResourceLimit(); | 113 | process->resource_limit = ResourceLimit::Create(kernel); |
| 110 | process->status = ProcessStatus::Created; | 114 | process->status = ProcessStatus::Created; |
| 111 | process->program_id = 0; | 115 | process->program_id = 0; |
| 112 | process->process_id = type == ProcessType::KernelInternal ? kernel.CreateNewKernelProcessID() | 116 | process->process_id = type == ProcessType::KernelInternal ? kernel.CreateNewKernelProcessID() |
| @@ -127,7 +131,14 @@ std::shared_ptr<ResourceLimit> Process::GetResourceLimit() const { | |||
| 127 | } | 131 | } |
| 128 | 132 | ||
| 129 | u64 Process::GetTotalPhysicalMemoryAvailable() const { | 133 | u64 Process::GetTotalPhysicalMemoryAvailable() const { |
| 130 | return vm_manager.GetTotalPhysicalMemoryAvailable(); | 134 | const u64 capacity{resource_limit->GetCurrentResourceValue(ResourceType::PhysicalMemory) + |
| 135 | page_table->GetTotalHeapSize() + image_size + main_thread_stack_size}; | ||
| 136 | |||
| 137 | if (capacity < memory_usage_capacity) { | ||
| 138 | return capacity; | ||
| 139 | } | ||
| 140 | |||
| 141 | return memory_usage_capacity; | ||
| 131 | } | 142 | } |
| 132 | 143 | ||
| 133 | u64 Process::GetTotalPhysicalMemoryAvailableWithoutSystemResource() const { | 144 | u64 Process::GetTotalPhysicalMemoryAvailableWithoutSystemResource() const { |
| @@ -135,8 +146,7 @@ u64 Process::GetTotalPhysicalMemoryAvailableWithoutSystemResource() const { | |||
| 135 | } | 146 | } |
| 136 | 147 | ||
| 137 | u64 Process::GetTotalPhysicalMemoryUsed() const { | 148 | u64 Process::GetTotalPhysicalMemoryUsed() const { |
| 138 | return vm_manager.GetCurrentHeapSize() + main_thread_stack_size + code_memory_size + | 149 | return image_size + main_thread_stack_size + page_table->GetTotalHeapSize(); |
| 139 | GetSystemResourceUsage(); | ||
| 140 | } | 150 | } |
| 141 | 151 | ||
| 142 | u64 Process::GetTotalPhysicalMemoryUsedWithoutSystemResource() const { | 152 | u64 Process::GetTotalPhysicalMemoryUsedWithoutSystemResource() const { |
| @@ -209,33 +219,82 @@ ResultCode Process::ClearSignalState() { | |||
| 209 | return RESULT_SUCCESS; | 219 | return RESULT_SUCCESS; |
| 210 | } | 220 | } |
| 211 | 221 | ||
| 212 | ResultCode Process::LoadFromMetadata(const FileSys::ProgramMetadata& metadata) { | 222 | ResultCode Process::LoadFromMetadata(const FileSys::ProgramMetadata& metadata, |
| 223 | std::size_t code_size) { | ||
| 213 | program_id = metadata.GetTitleID(); | 224 | program_id = metadata.GetTitleID(); |
| 214 | ideal_core = metadata.GetMainThreadCore(); | 225 | ideal_core = metadata.GetMainThreadCore(); |
| 215 | is_64bit_process = metadata.Is64BitProgram(); | 226 | is_64bit_process = metadata.Is64BitProgram(); |
| 216 | system_resource_size = metadata.GetSystemResourceSize(); | 227 | system_resource_size = metadata.GetSystemResourceSize(); |
| 228 | image_size = code_size; | ||
| 229 | |||
| 230 | // Initialize proces address space | ||
| 231 | if (const ResultCode result{ | ||
| 232 | page_table->InitializeForProcess(metadata.GetAddressSpaceType(), false, 0x8000000, | ||
| 233 | code_size, Memory::MemoryManager::Pool::Application)}; | ||
| 234 | result.IsError()) { | ||
| 235 | return result; | ||
| 236 | } | ||
| 217 | 237 | ||
| 218 | vm_manager.Reset(metadata.GetAddressSpaceType()); | 238 | // Map process code region |
| 239 | if (const ResultCode result{page_table->MapProcessCode( | ||
| 240 | page_table->GetCodeRegionStart(), code_size / Memory::PageSize, | ||
| 241 | Memory::MemoryState::Code, Memory::MemoryPermission::None)}; | ||
| 242 | result.IsError()) { | ||
| 243 | return result; | ||
| 244 | } | ||
| 219 | 245 | ||
| 220 | const auto& caps = metadata.GetKernelCapabilities(); | 246 | // Initialize process capabilities |
| 221 | const auto capability_init_result = | 247 | const auto& caps{metadata.GetKernelCapabilities()}; |
| 222 | capabilities.InitializeForUserProcess(caps.data(), caps.size(), vm_manager); | 248 | if (const ResultCode result{ |
| 223 | if (capability_init_result.IsError()) { | 249 | capabilities.InitializeForUserProcess(caps.data(), caps.size(), *page_table)}; |
| 224 | return capability_init_result; | 250 | result.IsError()) { |
| 251 | return result; | ||
| 225 | } | 252 | } |
| 226 | 253 | ||
| 254 | // Set memory usage capacity | ||
| 255 | switch (metadata.GetAddressSpaceType()) { | ||
| 256 | case FileSys::ProgramAddressSpaceType::Is32Bit: | ||
| 257 | case FileSys::ProgramAddressSpaceType::Is36Bit: | ||
| 258 | case FileSys::ProgramAddressSpaceType::Is39Bit: | ||
| 259 | memory_usage_capacity = page_table->GetHeapRegionEnd() - page_table->GetHeapRegionStart(); | ||
| 260 | break; | ||
| 261 | |||
| 262 | case FileSys::ProgramAddressSpaceType::Is32BitNoMap: | ||
| 263 | memory_usage_capacity = page_table->GetHeapRegionEnd() - page_table->GetHeapRegionStart() + | ||
| 264 | page_table->GetAliasRegionEnd() - page_table->GetAliasRegionStart(); | ||
| 265 | break; | ||
| 266 | |||
| 267 | default: | ||
| 268 | UNREACHABLE(); | ||
| 269 | } | ||
| 270 | |||
| 271 | // Set initial resource limits | ||
| 272 | resource_limit->SetLimitValue( | ||
| 273 | ResourceType::PhysicalMemory, | ||
| 274 | kernel.MemoryManager().GetSize(Memory::MemoryManager::Pool::Application)); | ||
| 275 | resource_limit->SetLimitValue(ResourceType::Threads, 608); | ||
| 276 | resource_limit->SetLimitValue(ResourceType::Events, 700); | ||
| 277 | resource_limit->SetLimitValue(ResourceType::TransferMemory, 128); | ||
| 278 | resource_limit->SetLimitValue(ResourceType::Sessions, 894); | ||
| 279 | ASSERT(resource_limit->Reserve(ResourceType::PhysicalMemory, code_size)); | ||
| 280 | |||
| 281 | // Create TLS region | ||
| 282 | tls_region_address = CreateTLSRegion(); | ||
| 283 | |||
| 227 | return handle_table.SetSize(capabilities.GetHandleTableSize()); | 284 | return handle_table.SetSize(capabilities.GetHandleTableSize()); |
| 228 | } | 285 | } |
| 229 | 286 | ||
| 230 | void Process::Run(s32 main_thread_priority, u64 stack_size) { | 287 | void Process::Run(s32 main_thread_priority, u64 stack_size) { |
| 231 | AllocateMainThreadStack(stack_size); | 288 | AllocateMainThreadStack(stack_size); |
| 232 | tls_region_address = CreateTLSRegion(); | ||
| 233 | 289 | ||
| 234 | vm_manager.LogLayout(); | 290 | const std::size_t heap_capacity{memory_usage_capacity - main_thread_stack_size - image_size}; |
| 291 | ASSERT(!page_table->SetHeapCapacity(heap_capacity).IsError()); | ||
| 235 | 292 | ||
| 236 | ChangeStatus(ProcessStatus::Running); | 293 | ChangeStatus(ProcessStatus::Running); |
| 237 | 294 | ||
| 238 | SetupMainThread(*this, kernel, main_thread_priority); | 295 | SetupMainThread(*this, kernel, main_thread_priority, main_thread_stack_top); |
| 296 | resource_limit->Reserve(ResourceType::Threads, 1); | ||
| 297 | resource_limit->Reserve(ResourceType::PhysicalMemory, main_thread_stack_size); | ||
| 239 | } | 298 | } |
| 240 | 299 | ||
| 241 | void Process::PrepareForTermination() { | 300 | void Process::PrepareForTermination() { |
| @@ -279,32 +338,37 @@ static auto FindTLSPageWithAvailableSlots(std::vector<TLSPage>& tls_pages) { | |||
| 279 | } | 338 | } |
| 280 | 339 | ||
| 281 | VAddr Process::CreateTLSRegion() { | 340 | VAddr Process::CreateTLSRegion() { |
| 282 | auto tls_page_iter = FindTLSPageWithAvailableSlots(tls_pages); | 341 | if (auto tls_page_iter{FindTLSPageWithAvailableSlots(tls_pages)}; |
| 342 | tls_page_iter != tls_pages.cend()) { | ||
| 343 | return *tls_page_iter->ReserveSlot(); | ||
| 344 | } | ||
| 283 | 345 | ||
| 284 | if (tls_page_iter == tls_pages.cend()) { | 346 | Memory::Page* const tls_page_ptr{kernel.GetUserSlabHeapPages().Allocate()}; |
| 285 | const auto region_address = | 347 | ASSERT(tls_page_ptr); |
| 286 | vm_manager.FindFreeRegion(vm_manager.GetTLSIORegionBaseAddress(), | ||
| 287 | vm_manager.GetTLSIORegionEndAddress(), Memory::PAGE_SIZE); | ||
| 288 | ASSERT(region_address.Succeeded()); | ||
| 289 | 348 | ||
| 290 | const auto map_result = vm_manager.MapMemoryBlock( | 349 | const VAddr start{page_table->GetKernelMapRegionStart()}; |
| 291 | *region_address, std::make_shared<PhysicalMemory>(Memory::PAGE_SIZE), 0, | 350 | const VAddr size{page_table->GetKernelMapRegionEnd() - start}; |
| 292 | Memory::PAGE_SIZE, MemoryState::ThreadLocal); | 351 | const PAddr tls_map_addr{system.DeviceMemory().GetPhysicalAddr(tls_page_ptr)}; |
| 293 | ASSERT(map_result.Succeeded()); | 352 | const VAddr tls_page_addr{ |
| 353 | page_table | ||
| 354 | ->AllocateAndMapMemory(1, Memory::PageSize, true, start, size / Memory::PageSize, | ||
| 355 | Memory::MemoryState::ThreadLocal, | ||
| 356 | Memory::MemoryPermission::ReadAndWrite, tls_map_addr) | ||
| 357 | .ValueOr(0)}; | ||
| 294 | 358 | ||
| 295 | tls_pages.emplace_back(*region_address); | 359 | ASSERT(tls_page_addr); |
| 296 | 360 | ||
| 297 | const auto reserve_result = tls_pages.back().ReserveSlot(); | 361 | std::memset(tls_page_ptr, 0, Memory::PageSize); |
| 298 | ASSERT(reserve_result.has_value()); | 362 | tls_pages.emplace_back(tls_page_addr); |
| 299 | 363 | ||
| 300 | return *reserve_result; | 364 | const auto reserve_result{tls_pages.back().ReserveSlot()}; |
| 301 | } | 365 | ASSERT(reserve_result.has_value()); |
| 302 | 366 | ||
| 303 | return *tls_page_iter->ReserveSlot(); | 367 | return *reserve_result; |
| 304 | } | 368 | } |
| 305 | 369 | ||
| 306 | void Process::FreeTLSRegion(VAddr tls_address) { | 370 | void Process::FreeTLSRegion(VAddr tls_address) { |
| 307 | const VAddr aligned_address = Common::AlignDown(tls_address, Memory::PAGE_SIZE); | 371 | const VAddr aligned_address = Common::AlignDown(tls_address, Core::Memory::PAGE_SIZE); |
| 308 | auto iter = | 372 | auto iter = |
| 309 | std::find_if(tls_pages.begin(), tls_pages.end(), [aligned_address](const auto& page) { | 373 | std::find_if(tls_pages.begin(), tls_pages.end(), [aligned_address](const auto& page) { |
| 310 | return page.GetBaseAddress() == aligned_address; | 374 | return page.GetBaseAddress() == aligned_address; |
| @@ -317,28 +381,22 @@ void Process::FreeTLSRegion(VAddr tls_address) { | |||
| 317 | iter->ReleaseSlot(tls_address); | 381 | iter->ReleaseSlot(tls_address); |
| 318 | } | 382 | } |
| 319 | 383 | ||
| 320 | void Process::LoadModule(CodeSet module_, VAddr base_addr) { | 384 | void Process::LoadModule(CodeSet code_set, VAddr base_addr) { |
| 321 | code_memory_size += module_.memory.size(); | 385 | const auto ReprotectSegment = [&](const CodeSet::Segment& segment, |
| 322 | 386 | Memory::MemoryPermission permission) { | |
| 323 | const auto memory = std::make_shared<PhysicalMemory>(std::move(module_.memory)); | 387 | page_table->SetCodeMemoryPermission(segment.addr + base_addr, segment.size, permission); |
| 324 | |||
| 325 | const auto MapSegment = [&](const CodeSet::Segment& segment, VMAPermission permissions, | ||
| 326 | MemoryState memory_state) { | ||
| 327 | const auto vma = vm_manager | ||
| 328 | .MapMemoryBlock(segment.addr + base_addr, memory, segment.offset, | ||
| 329 | segment.size, memory_state) | ||
| 330 | .Unwrap(); | ||
| 331 | vm_manager.Reprotect(vma, permissions); | ||
| 332 | }; | 388 | }; |
| 333 | 389 | ||
| 334 | // Map CodeSet segments | 390 | system.Memory().WriteBlock(*this, base_addr, code_set.memory.data(), code_set.memory.size()); |
| 335 | MapSegment(module_.CodeSegment(), VMAPermission::ReadExecute, MemoryState::Code); | 391 | |
| 336 | MapSegment(module_.RODataSegment(), VMAPermission::Read, MemoryState::CodeData); | 392 | ReprotectSegment(code_set.CodeSegment(), Memory::MemoryPermission::ReadAndExecute); |
| 337 | MapSegment(module_.DataSegment(), VMAPermission::ReadWrite, MemoryState::CodeData); | 393 | ReprotectSegment(code_set.RODataSegment(), Memory::MemoryPermission::Read); |
| 394 | ReprotectSegment(code_set.DataSegment(), Memory::MemoryPermission::ReadAndWrite); | ||
| 338 | } | 395 | } |
| 339 | 396 | ||
| 340 | Process::Process(Core::System& system) | 397 | Process::Process(Core::System& system) |
| 341 | : SynchronizationObject{system.Kernel()}, vm_manager{system}, | 398 | : SynchronizationObject{system.Kernel()}, page_table{std::make_unique<Memory::PageTable>( |
| 399 | system)}, | ||
| 342 | address_arbiter{system}, mutex{system}, system{system} {} | 400 | address_arbiter{system}, mutex{system}, system{system} {} |
| 343 | 401 | ||
| 344 | Process::~Process() = default; | 402 | Process::~Process() = default; |
| @@ -361,16 +419,24 @@ void Process::ChangeStatus(ProcessStatus new_status) { | |||
| 361 | Signal(); | 419 | Signal(); |
| 362 | } | 420 | } |
| 363 | 421 | ||
| 364 | void Process::AllocateMainThreadStack(u64 stack_size) { | 422 | ResultCode Process::AllocateMainThreadStack(std::size_t stack_size) { |
| 423 | ASSERT(stack_size); | ||
| 424 | |||
| 365 | // The kernel always ensures that the given stack size is page aligned. | 425 | // The kernel always ensures that the given stack size is page aligned. |
| 366 | main_thread_stack_size = Common::AlignUp(stack_size, Memory::PAGE_SIZE); | 426 | main_thread_stack_size = Common::AlignUp(stack_size, Memory::PageSize); |
| 367 | 427 | ||
| 368 | // Allocate and map the main thread stack | 428 | const VAddr start{page_table->GetStackRegionStart()}; |
| 369 | const VAddr mapping_address = vm_manager.GetTLSIORegionEndAddress() - main_thread_stack_size; | 429 | const std::size_t size{page_table->GetStackRegionEnd() - start}; |
| 370 | vm_manager | 430 | |
| 371 | .MapMemoryBlock(mapping_address, std::make_shared<PhysicalMemory>(main_thread_stack_size), | 431 | CASCADE_RESULT(main_thread_stack_top, |
| 372 | 0, main_thread_stack_size, MemoryState::Stack) | 432 | page_table->AllocateAndMapMemory( |
| 373 | .Unwrap(); | 433 | main_thread_stack_size / Memory::PageSize, Memory::PageSize, false, start, |
| 434 | size / Memory::PageSize, Memory::MemoryState::Stack, | ||
| 435 | Memory::MemoryPermission::ReadAndWrite)); | ||
| 436 | |||
| 437 | main_thread_stack_top += main_thread_stack_size; | ||
| 438 | |||
| 439 | return RESULT_SUCCESS; | ||
| 374 | } | 440 | } |
| 375 | 441 | ||
| 376 | } // namespace Kernel | 442 | } // namespace Kernel |