diff options
Diffstat (limited to '')
| -rw-r--r-- | src/core/hle/kernel/process.cpp | 2 | ||||
| -rw-r--r-- | src/core/hle/kernel/thread.cpp | 17 | ||||
| -rw-r--r-- | src/core/hle/kernel/thread.h | 15 | ||||
| -rw-r--r-- | src/core/hle/svc.cpp | 5 |
4 files changed, 22 insertions, 17 deletions
diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp index 522ad2333..cf3163e0f 100644 --- a/src/core/hle/kernel/process.cpp +++ b/src/core/hle/kernel/process.cpp | |||
| @@ -147,7 +147,7 @@ void Process::Run(s32 main_thread_priority, u32 stack_size) { | |||
| 147 | } | 147 | } |
| 148 | 148 | ||
| 149 | vm_manager.LogLayout(Log::Level::Debug); | 149 | vm_manager.LogLayout(Log::Level::Debug); |
| 150 | Kernel::SetupMainThread(codeset->entrypoint, main_thread_priority); | 150 | Kernel::SetupMainThread(codeset->entrypoint, main_thread_priority, this); |
| 151 | } | 151 | } |
| 152 | 152 | ||
| 153 | VAddr Process::GetLinearHeapAreaAddress() const { | 153 | VAddr Process::GetLinearHeapAreaAddress() const { |
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index 61378211f..1033f8552 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp | |||
| @@ -361,7 +361,8 @@ static void ResetThreadContext(ARM_Interface::ThreadContext& context, u32 stack_ | |||
| 361 | } | 361 | } |
| 362 | 362 | ||
| 363 | ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point, u32 priority, | 363 | ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point, u32 priority, |
| 364 | u32 arg, s32 processor_id, VAddr stack_top) { | 364 | u32 arg, s32 processor_id, VAddr stack_top, |
| 365 | SharedPtr<Process> owner_process) { | ||
| 365 | // Check if priority is in ranged. Lowest priority -> highest priority id. | 366 | // Check if priority is in ranged. Lowest priority -> highest priority id. |
| 366 | if (priority > THREADPRIO_LOWEST) { | 367 | if (priority > THREADPRIO_LOWEST) { |
| 367 | LOG_ERROR(Kernel_SVC, "Invalid thread priority: %d", priority); | 368 | LOG_ERROR(Kernel_SVC, "Invalid thread priority: %d", priority); |
| @@ -375,7 +376,7 @@ ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point, | |||
| 375 | 376 | ||
| 376 | // TODO(yuriks): Other checks, returning 0xD9001BEA | 377 | // TODO(yuriks): Other checks, returning 0xD9001BEA |
| 377 | 378 | ||
| 378 | if (!Memory::IsValidVirtualAddress(entry_point)) { | 379 | if (!Memory::IsValidVirtualAddress(*owner_process, entry_point)) { |
| 379 | LOG_ERROR(Kernel_SVC, "(name=%s): invalid entry %08x", name.c_str(), entry_point); | 380 | LOG_ERROR(Kernel_SVC, "(name=%s): invalid entry %08x", name.c_str(), entry_point); |
| 380 | // TODO: Verify error | 381 | // TODO: Verify error |
| 381 | return ResultCode(ErrorDescription::InvalidAddress, ErrorModule::Kernel, | 382 | return ResultCode(ErrorDescription::InvalidAddress, ErrorModule::Kernel, |
| @@ -399,10 +400,10 @@ ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point, | |||
| 399 | thread->wait_address = 0; | 400 | thread->wait_address = 0; |
| 400 | thread->name = std::move(name); | 401 | thread->name = std::move(name); |
| 401 | thread->callback_handle = wakeup_callback_handle_table.Create(thread).Unwrap(); | 402 | thread->callback_handle = wakeup_callback_handle_table.Create(thread).Unwrap(); |
| 402 | thread->owner_process = g_current_process; | 403 | thread->owner_process = owner_process; |
| 403 | 404 | ||
| 404 | // Find the next available TLS index, and mark it as used | 405 | // Find the next available TLS index, and mark it as used |
| 405 | auto& tls_slots = Kernel::g_current_process->tls_slots; | 406 | auto& tls_slots = owner_process->tls_slots; |
| 406 | bool needs_allocation = true; | 407 | bool needs_allocation = true; |
| 407 | u32 available_page; // Which allocated page has free space | 408 | u32 available_page; // Which allocated page has free space |
| 408 | u32 available_slot; // Which slot within the page is free | 409 | u32 available_slot; // Which slot within the page is free |
| @@ -426,13 +427,13 @@ ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point, | |||
| 426 | // Allocate some memory from the end of the linear heap for this region. | 427 | // Allocate some memory from the end of the linear heap for this region. |
| 427 | linheap_memory->insert(linheap_memory->end(), Memory::PAGE_SIZE, 0); | 428 | linheap_memory->insert(linheap_memory->end(), Memory::PAGE_SIZE, 0); |
| 428 | memory_region->used += Memory::PAGE_SIZE; | 429 | memory_region->used += Memory::PAGE_SIZE; |
| 429 | Kernel::g_current_process->linear_heap_used += Memory::PAGE_SIZE; | 430 | owner_process->linear_heap_used += Memory::PAGE_SIZE; |
| 430 | 431 | ||
| 431 | tls_slots.emplace_back(0); // The page is completely available at the start | 432 | tls_slots.emplace_back(0); // The page is completely available at the start |
| 432 | available_page = tls_slots.size() - 1; | 433 | available_page = tls_slots.size() - 1; |
| 433 | available_slot = 0; // Use the first slot in the new page | 434 | available_slot = 0; // Use the first slot in the new page |
| 434 | 435 | ||
| 435 | auto& vm_manager = Kernel::g_current_process->vm_manager; | 436 | auto& vm_manager = owner_process->vm_manager; |
| 436 | vm_manager.RefreshMemoryBlockMappings(linheap_memory.get()); | 437 | vm_manager.RefreshMemoryBlockMappings(linheap_memory.get()); |
| 437 | 438 | ||
| 438 | // Map the page to the current process' address space. | 439 | // Map the page to the current process' address space. |
| @@ -486,10 +487,10 @@ void Thread::BoostPriority(s32 priority) { | |||
| 486 | current_priority = priority; | 487 | current_priority = priority; |
| 487 | } | 488 | } |
| 488 | 489 | ||
| 489 | SharedPtr<Thread> SetupMainThread(u32 entry_point, s32 priority) { | 490 | SharedPtr<Thread> SetupMainThread(u32 entry_point, s32 priority, SharedPtr<Process> owner_process) { |
| 490 | // Initialize new "main" thread | 491 | // Initialize new "main" thread |
| 491 | auto thread_res = Thread::Create("main", entry_point, priority, 0, THREADPROCESSORID_0, | 492 | auto thread_res = Thread::Create("main", entry_point, priority, 0, THREADPROCESSORID_0, |
| 492 | Memory::HEAP_VADDR_END); | 493 | Memory::HEAP_VADDR_END, owner_process); |
| 493 | 494 | ||
| 494 | SharedPtr<Thread> thread = std::move(thread_res).Unwrap(); | 495 | SharedPtr<Thread> thread = std::move(thread_res).Unwrap(); |
| 495 | 496 | ||
diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h index 6a3566f15..ddc0d15c5 100644 --- a/src/core/hle/kernel/thread.h +++ b/src/core/hle/kernel/thread.h | |||
| @@ -56,10 +56,12 @@ public: | |||
| 56 | * @param arg User data to pass to the thread | 56 | * @param arg User data to pass to the thread |
| 57 | * @param processor_id The ID(s) of the processors on which the thread is desired to be run | 57 | * @param processor_id The ID(s) of the processors on which the thread is desired to be run |
| 58 | * @param stack_top The address of the thread's stack top | 58 | * @param stack_top The address of the thread's stack top |
| 59 | * @param owner_process The parent process for the thread | ||
| 59 | * @return A shared pointer to the newly created thread | 60 | * @return A shared pointer to the newly created thread |
| 60 | */ | 61 | */ |
| 61 | static ResultVal<SharedPtr<Thread>> Create(std::string name, VAddr entry_point, u32 priority, | 62 | static ResultVal<SharedPtr<Thread>> Create(std::string name, VAddr entry_point, u32 priority, |
| 62 | u32 arg, s32 processor_id, VAddr stack_top); | 63 | u32 arg, s32 processor_id, VAddr stack_top, |
| 64 | SharedPtr<Process> owner_process); | ||
| 63 | 65 | ||
| 64 | std::string GetName() const override { | 66 | std::string GetName() const override { |
| 65 | return name; | 67 | return name; |
| @@ -116,9 +118,9 @@ public: | |||
| 116 | void ResumeFromWait(); | 118 | void ResumeFromWait(); |
| 117 | 119 | ||
| 118 | /** | 120 | /** |
| 119 | * Schedules an event to wake up the specified thread after the specified delay | 121 | * Schedules an event to wake up the specified thread after the specified delay |
| 120 | * @param nanoseconds The time this thread will be allowed to sleep for | 122 | * @param nanoseconds The time this thread will be allowed to sleep for |
| 121 | */ | 123 | */ |
| 122 | void WakeAfterDelay(s64 nanoseconds); | 124 | void WakeAfterDelay(s64 nanoseconds); |
| 123 | 125 | ||
| 124 | /** | 126 | /** |
| @@ -214,9 +216,10 @@ private: | |||
| 214 | * Sets up the primary application thread | 216 | * Sets up the primary application thread |
| 215 | * @param entry_point The address at which the thread should start execution | 217 | * @param entry_point The address at which the thread should start execution |
| 216 | * @param priority The priority to give the main thread | 218 | * @param priority The priority to give the main thread |
| 219 | * @param owner_process The parent process for the main thread | ||
| 217 | * @return A shared pointer to the main thread | 220 | * @return A shared pointer to the main thread |
| 218 | */ | 221 | */ |
| 219 | SharedPtr<Thread> SetupMainThread(u32 entry_point, s32 priority); | 222 | SharedPtr<Thread> SetupMainThread(u32 entry_point, s32 priority, SharedPtr<Process> owner_process); |
| 220 | 223 | ||
| 221 | /** | 224 | /** |
| 222 | * Returns whether there are any threads that are ready to run. | 225 | * Returns whether there are any threads that are ready to run. |
| @@ -276,4 +279,4 @@ void ThreadingShutdown(); | |||
| 276 | */ | 279 | */ |
| 277 | const std::vector<SharedPtr<Thread>>& GetThreadList(); | 280 | const std::vector<SharedPtr<Thread>>& GetThreadList(); |
| 278 | 281 | ||
| 279 | } // namespace | 282 | } // namespace Kernel |
diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index dfc36748c..05c6897bf 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp | |||
| @@ -656,8 +656,9 @@ static ResultCode CreateThread(Kernel::Handle* out_handle, u32 priority, u32 ent | |||
| 656 | "Newly created thread must run in the SysCore (Core1), unimplemented."); | 656 | "Newly created thread must run in the SysCore (Core1), unimplemented."); |
| 657 | } | 657 | } |
| 658 | 658 | ||
| 659 | CASCADE_RESULT(SharedPtr<Thread> thread, Kernel::Thread::Create(name, entry_point, priority, | 659 | CASCADE_RESULT(SharedPtr<Thread> thread, |
| 660 | arg, processor_id, stack_top)); | 660 | Kernel::Thread::Create(name, entry_point, priority, arg, processor_id, stack_top, |
| 661 | Kernel::g_current_process)); | ||
| 661 | 662 | ||
| 662 | thread->context.fpscr = | 663 | thread->context.fpscr = |
| 663 | FPSCR_DEFAULT_NAN | FPSCR_FLUSH_TO_ZERO | FPSCR_ROUND_TOZERO; // 0x03C00000 | 664 | FPSCR_DEFAULT_NAN | FPSCR_FLUSH_TO_ZERO | FPSCR_ROUND_TOZERO; // 0x03C00000 |