summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/process.cpp
diff options
context:
space:
mode:
authorGravatar Lioncash2019-07-07 04:13:56 -0400
committerGravatar Lioncash2019-07-07 14:08:25 -0400
commiteb6f55d880f2c749d651290a3d1b6e8682563a67 (patch)
treec4d11cac3ddc8f0717734aa650abb7553759a65b /src/core/hle/kernel/process.cpp
parentMerge pull request #2674 from lioncash/reporter (diff)
downloadyuzu-eb6f55d880f2c749d651290a3d1b6e8682563a67.tar.gz
yuzu-eb6f55d880f2c749d651290a3d1b6e8682563a67.tar.xz
yuzu-eb6f55d880f2c749d651290a3d1b6e8682563a67.zip
kernel/process: Move main thread stack allocation to its own function
Keeps this particular set of behavior isolated to its own function.
Diffstat (limited to 'src/core/hle/kernel/process.cpp')
-rw-r--r--src/core/hle/kernel/process.cpp26
1 files changed, 14 insertions, 12 deletions
diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp
index f45ef05f6..90d579b5c 100644
--- a/src/core/hle/kernel/process.cpp
+++ b/src/core/hle/kernel/process.cpp
@@ -186,19 +186,9 @@ ResultCode Process::LoadFromMetadata(const FileSys::ProgramMetadata& metadata) {
186} 186}
187 187
188void Process::Run(s32 main_thread_priority, u64 stack_size) { 188void Process::Run(s32 main_thread_priority, u64 stack_size) {
189 // The kernel always ensures that the given stack size is page aligned. 189 AllocateMainThreadStack(stack_size);
190 main_thread_stack_size = Common::AlignUp(stack_size, Memory::PAGE_SIZE);
191
192 // Allocate and map the main thread stack
193 // TODO(bunnei): This is heap area that should be allocated by the kernel and not mapped as part
194 // of the user address space.
195 const VAddr mapping_address = vm_manager.GetTLSIORegionEndAddress() - main_thread_stack_size;
196 vm_manager
197 .MapMemoryBlock(mapping_address, std::make_shared<std::vector<u8>>(main_thread_stack_size),
198 0, main_thread_stack_size, MemoryState::Stack)
199 .Unwrap();
200
201 vm_manager.LogLayout(); 190 vm_manager.LogLayout();
191
202 ChangeStatus(ProcessStatus::Running); 192 ChangeStatus(ProcessStatus::Running);
203 193
204 SetupMainThread(*this, kernel, main_thread_priority); 194 SetupMainThread(*this, kernel, main_thread_priority);
@@ -327,4 +317,16 @@ void Process::ChangeStatus(ProcessStatus new_status) {
327 WakeupAllWaitingThreads(); 317 WakeupAllWaitingThreads();
328} 318}
329 319
320void Process::AllocateMainThreadStack(u64 stack_size) {
321 // The kernel always ensures that the given stack size is page aligned.
322 main_thread_stack_size = Common::AlignUp(stack_size, Memory::PAGE_SIZE);
323
324 // Allocate and map the main thread stack
325 const VAddr mapping_address = vm_manager.GetTLSIORegionEndAddress() - main_thread_stack_size;
326 vm_manager
327 .MapMemoryBlock(mapping_address, std::make_shared<std::vector<u8>>(main_thread_stack_size),
328 0, main_thread_stack_size, MemoryState::Stack)
329 .Unwrap();
330}
331
330} // namespace Kernel 332} // namespace Kernel