summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/process.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hle/kernel/process.cpp')
-rw-r--r--src/core/hle/kernel/process.cpp33
1 files changed, 31 insertions, 2 deletions
diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp
index 06a673b9b..c5aa19afa 100644
--- a/src/core/hle/kernel/process.cpp
+++ b/src/core/hle/kernel/process.cpp
@@ -20,6 +20,35 @@
20#include "core/settings.h" 20#include "core/settings.h"
21 21
22namespace Kernel { 22namespace Kernel {
23namespace {
24/**
25 * Sets up the primary application thread
26 *
27 * @param owner_process The parent process for the main thread
28 * @param kernel The kernel instance to create the main thread under.
29 * @param entry_point The address at which the thread should start execution
30 * @param priority The priority to give the main thread
31 */
32void SetupMainThread(Process& owner_process, KernelCore& kernel, VAddr entry_point, u32 priority) {
33 // Setup page table so we can write to memory
34 SetCurrentPageTable(&owner_process.VMManager().page_table);
35
36 // Initialize new "main" thread
37 const VAddr stack_top = owner_process.VMManager().GetTLSIORegionEndAddress();
38 auto thread_res = Thread::Create(kernel, "main", entry_point, priority, 0,
39 owner_process.GetIdealCore(), stack_top, owner_process);
40
41 SharedPtr<Thread> thread = std::move(thread_res).Unwrap();
42
43 // Register 1 must be a handle to the main thread
44 const Handle guest_handle = owner_process.GetHandleTable().Create(thread).Unwrap();
45 thread->SetGuestHandle(guest_handle);
46 thread->GetContext().cpu_registers[1] = guest_handle;
47
48 // Threads by default are dormant, wake up the main thread so it runs when the scheduler fires
49 thread->ResumeFromWait();
50}
51} // Anonymous namespace
23 52
24CodeSet::CodeSet() = default; 53CodeSet::CodeSet() = default;
25CodeSet::~CodeSet() = default; 54CodeSet::~CodeSet() = default;
@@ -64,7 +93,7 @@ ResultCode Process::ClearSignalState() {
64 93
65ResultCode Process::LoadFromMetadata(const FileSys::ProgramMetadata& metadata) { 94ResultCode Process::LoadFromMetadata(const FileSys::ProgramMetadata& metadata) {
66 program_id = metadata.GetTitleID(); 95 program_id = metadata.GetTitleID();
67 ideal_processor = metadata.GetMainThreadCore(); 96 ideal_core = metadata.GetMainThreadCore();
68 is_64bit_process = metadata.Is64BitProgram(); 97 is_64bit_process = metadata.Is64BitProgram();
69 98
70 vm_manager.Reset(metadata.GetAddressSpaceType()); 99 vm_manager.Reset(metadata.GetAddressSpaceType());
@@ -86,7 +115,7 @@ void Process::Run(VAddr entry_point, s32 main_thread_priority, u32 stack_size) {
86 vm_manager.LogLayout(); 115 vm_manager.LogLayout();
87 ChangeStatus(ProcessStatus::Running); 116 ChangeStatus(ProcessStatus::Running);
88 117
89 Kernel::SetupMainThread(kernel, entry_point, main_thread_priority, *this); 118 SetupMainThread(*this, kernel, entry_point, main_thread_priority);
90} 119}
91 120
92void Process::PrepareForTermination() { 121void Process::PrepareForTermination() {