summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar bunnei2019-07-18 13:53:04 -0400
committerGravatar GitHub2019-07-18 13:53:04 -0400
commit5d369112d9d467d4257e24ce57f3ebba824556f0 (patch)
treeff5dcc2c614dd7d257a0993b651a546e31c5ce9a
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 '')
-rw-r--r--src/core/hle/kernel/process.cpp29
-rw-r--r--src/core/hle/kernel/process.h11
-rw-r--r--src/core/hle/kernel/svc.cpp4
3 files changed, 30 insertions, 14 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
diff --git a/src/core/hle/kernel/process.h b/src/core/hle/kernel/process.h
index 3196014da..c2df451f3 100644
--- a/src/core/hle/kernel/process.h
+++ b/src/core/hle/kernel/process.h
@@ -135,6 +135,11 @@ public:
135 return mutex; 135 return mutex;
136 } 136 }
137 137
138 /// Gets the address to the process' dedicated TLS region.
139 VAddr GetTLSRegionAddress() const {
140 return tls_region_address;
141 }
142
138 /// Gets the current status of the process 143 /// Gets the current status of the process
139 ProcessStatus GetStatus() const { 144 ProcessStatus GetStatus() const {
140 return status; 145 return status;
@@ -296,6 +301,9 @@ private:
296 /// a process signal. 301 /// a process signal.
297 void ChangeStatus(ProcessStatus new_status); 302 void ChangeStatus(ProcessStatus new_status);
298 303
304 /// Allocates the main thread stack for the process, given the stack size in bytes.
305 void AllocateMainThreadStack(u64 stack_size);
306
299 /// Memory manager for this process. 307 /// Memory manager for this process.
300 Kernel::VMManager vm_manager; 308 Kernel::VMManager vm_manager;
301 309
@@ -358,6 +366,9 @@ private:
358 /// variable related facilities. 366 /// variable related facilities.
359 Mutex mutex; 367 Mutex mutex;
360 368
369 /// Address indicating the location of the process' dedicated TLS region.
370 VAddr tls_region_address = 0;
371
361 /// Random values for svcGetInfo RandomEntropy 372 /// Random values for svcGetInfo RandomEntropy
362 std::array<u64, RANDOM_ENTROPY_SIZE> random_entropy{}; 373 std::array<u64, RANDOM_ENTROPY_SIZE> random_entropy{};
363 374
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp
index 0687839ff..1fd1a732a 100644
--- a/src/core/hle/kernel/svc.cpp
+++ b/src/core/hle/kernel/svc.cpp
@@ -843,9 +843,7 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, u64 ha
843 return RESULT_SUCCESS; 843 return RESULT_SUCCESS;
844 844
845 case GetInfoType::UserExceptionContextAddr: 845 case GetInfoType::UserExceptionContextAddr:
846 LOG_WARNING(Kernel_SVC, 846 *result = process->GetTLSRegionAddress();
847 "(STUBBED) Attempted to query user exception context address, returned 0");
848 *result = 0;
849 return RESULT_SUCCESS; 847 return RESULT_SUCCESS;
850 848
851 case GetInfoType::TotalPhysicalMemoryAvailableWithoutSystemResource: 849 case GetInfoType::TotalPhysicalMemoryAvailableWithoutSystemResource: