diff options
Diffstat (limited to 'src/core/hle/kernel/thread.cpp')
| -rw-r--r-- | src/core/hle/kernel/thread.cpp | 17 |
1 files changed, 9 insertions, 8 deletions
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 | ||