diff options
Diffstat (limited to 'src/core/hle/kernel/process.cpp')
| -rw-r--r-- | src/core/hle/kernel/process.cpp | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp index 4f209a979..81a23dfbf 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 | ||
| 22 | namespace Kernel { | 22 | namespace Kernel { |
| 23 | namespace { | ||
| 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 | */ | ||
| 32 | void 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, THREADPROCESSORID_0, | ||
| 39 | 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 | ||
| 24 | CodeSet::CodeSet() = default; | 53 | CodeSet::CodeSet() = default; |
| 25 | CodeSet::~CodeSet() = default; | 54 | CodeSet::~CodeSet() = default; |
| @@ -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 | ||
| 92 | void Process::PrepareForTermination() { | 121 | void Process::PrepareForTermination() { |