summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/process.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2019-07-18 13:53:04 -0400
committerGravatar GitHub2019-07-18 13:53:04 -0400
commit5d369112d9d467d4257e24ce57f3ebba824556f0 (patch)
treeff5dcc2c614dd7d257a0993b651a546e31c5ce9a /src/core/hle/kernel/process.cpp
parentMerge pull request #2738 from lioncash/shader-ir (diff)
parentkernel/process: Allocate the process' TLS region during initialization (diff)
downloadyuzu-5d369112d9d467d4257e24ce57f3ebba824556f0.tar.gz
yuzu-5d369112d9d467d4257e24ce57f3ebba824556f0.tar.xz
yuzu-5d369112d9d467d4257e24ce57f3ebba824556f0.zip
Merge pull request #2687 from lioncash/tls-process
kernel/process: Allocate the process' TLS region during initialization
Diffstat (limited to 'src/core/hle/kernel/process.cpp')
-rw-r--r--src/core/hle/kernel/process.cpp29
1 files changed, 18 insertions, 11 deletions
diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp
index db3ab14ce..92169a97b 100644
--- a/src/core/hle/kernel/process.cpp
+++ b/src/core/hle/kernel/process.cpp
@@ -184,19 +184,11 @@ ResultCode Process::LoadFromMetadata(const FileSys::ProgramMetadata& metadata) {
184} 184}
185 185
186void Process::Run(s32 main_thread_priority, u64 stack_size) { 186void Process::Run(s32 main_thread_priority, u64 stack_size) {
187 // The kernel always ensures that the given stack size is page aligned. 187 AllocateMainThreadStack(stack_size);
188 main_thread_stack_size = Common::AlignUp(stack_size, Memory::PAGE_SIZE); 188 tls_region_address = CreateTLSRegion();
189
190 // Allocate and map the main thread stack
191 // TODO(bunnei): This is heap area that should be allocated by the kernel and not mapped as part
192 // of the user address space.
193 const VAddr mapping_address = vm_manager.GetTLSIORegionEndAddress() - main_thread_stack_size;
194 vm_manager
195 .MapMemoryBlock(mapping_address, std::make_shared<std::vector<u8>>(main_thread_stack_size),
196 0, main_thread_stack_size, MemoryState::Stack)
197 .Unwrap();
198 189
199 vm_manager.LogLayout(); 190 vm_manager.LogLayout();
191
200 ChangeStatus(ProcessStatus::Running); 192 ChangeStatus(ProcessStatus::Running);
201 193
202 SetupMainThread(*this, kernel, main_thread_priority); 194 SetupMainThread(*this, kernel, main_thread_priority);
@@ -226,6 +218,9 @@ void Process::PrepareForTermination() {
226 stop_threads(system.Scheduler(2).GetThreadList()); 218 stop_threads(system.Scheduler(2).GetThreadList());
227 stop_threads(system.Scheduler(3).GetThreadList()); 219 stop_threads(system.Scheduler(3).GetThreadList());
228 220
221 FreeTLSRegion(tls_region_address);
222 tls_region_address = 0;
223
229 ChangeStatus(ProcessStatus::Exited); 224 ChangeStatus(ProcessStatus::Exited);
230} 225}
231 226
@@ -325,4 +320,16 @@ void Process::ChangeStatus(ProcessStatus new_status) {
325 WakeupAllWaitingThreads(); 320 WakeupAllWaitingThreads();
326} 321}
327 322
323void Process::AllocateMainThreadStack(u64 stack_size) {
324 // The kernel always ensures that the given stack size is page aligned.
325 main_thread_stack_size = Common::AlignUp(stack_size, Memory::PAGE_SIZE);
326
327 // Allocate and map the main thread stack
328 const VAddr mapping_address = vm_manager.GetTLSIORegionEndAddress() - main_thread_stack_size;
329 vm_manager
330 .MapMemoryBlock(mapping_address, std::make_shared<std::vector<u8>>(main_thread_stack_size),
331 0, main_thread_stack_size, MemoryState::Stack)
332 .Unwrap();
333}
334
328} // namespace Kernel 335} // namespace Kernel