diff options
| author | 2018-03-13 17:49:59 -0400 | |
|---|---|---|
| committer | 2018-03-14 18:42:19 -0400 | |
| commit | 7d6653268f68dea8bc39288e3a27bc499b7b8154 (patch) | |
| tree | 6330442e1dacc0d850ce09c35dcee7ddd3a2bc9d /src/core/hle/kernel/svc.cpp | |
| parent | Merge pull request #213 from Hexagon12/dynarmic-default (diff) | |
| download | yuzu-7d6653268f68dea8bc39288e3a27bc499b7b8154.tar.gz yuzu-7d6653268f68dea8bc39288e3a27bc499b7b8154.tar.xz yuzu-7d6653268f68dea8bc39288e3a27bc499b7b8154.zip | |
core: Move process creation out of global state.
Diffstat (limited to 'src/core/hle/kernel/svc.cpp')
| -rw-r--r-- | src/core/hle/kernel/svc.cpp | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index 1ab8cbd88..207583320 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp | |||
| @@ -8,6 +8,7 @@ | |||
| 8 | #include "common/logging/log.h" | 8 | #include "common/logging/log.h" |
| 9 | #include "common/microprofile.h" | 9 | #include "common/microprofile.h" |
| 10 | #include "common/string_util.h" | 10 | #include "common/string_util.h" |
| 11 | #include "core/core.h" | ||
| 11 | #include "core/core_timing.h" | 12 | #include "core/core_timing.h" |
| 12 | #include "core/hle/kernel/client_port.h" | 13 | #include "core/hle/kernel/client_port.h" |
| 13 | #include "core/hle/kernel/client_session.h" | 14 | #include "core/hle/kernel/client_session.h" |
| @@ -31,7 +32,7 @@ namespace Kernel { | |||
| 31 | /// Set the process heap to a given Size. It can both extend and shrink the heap. | 32 | /// Set the process heap to a given Size. It can both extend and shrink the heap. |
| 32 | static ResultCode SetHeapSize(VAddr* heap_addr, u64 heap_size) { | 33 | static ResultCode SetHeapSize(VAddr* heap_addr, u64 heap_size) { |
| 33 | LOG_TRACE(Kernel_SVC, "called, heap_size=0x%llx", heap_size); | 34 | LOG_TRACE(Kernel_SVC, "called, heap_size=0x%llx", heap_size); |
| 34 | auto& process = *g_current_process; | 35 | auto& process = *Core::CurrentProcess(); |
| 35 | CASCADE_RESULT(*heap_addr, | 36 | CASCADE_RESULT(*heap_addr, |
| 36 | process.HeapAllocate(Memory::HEAP_VADDR, heap_size, VMAPermission::ReadWrite)); | 37 | process.HeapAllocate(Memory::HEAP_VADDR, heap_size, VMAPermission::ReadWrite)); |
| 37 | return RESULT_SUCCESS; | 38 | return RESULT_SUCCESS; |
| @@ -46,14 +47,14 @@ static ResultCode SetMemoryAttribute(VAddr addr, u64 size, u32 state0, u32 state | |||
| 46 | static ResultCode MapMemory(VAddr dst_addr, VAddr src_addr, u64 size) { | 47 | static ResultCode MapMemory(VAddr dst_addr, VAddr src_addr, u64 size) { |
| 47 | LOG_TRACE(Kernel_SVC, "called, dst_addr=0x%llx, src_addr=0x%llx, size=0x%llx", dst_addr, | 48 | LOG_TRACE(Kernel_SVC, "called, dst_addr=0x%llx, src_addr=0x%llx, size=0x%llx", dst_addr, |
| 48 | src_addr, size); | 49 | src_addr, size); |
| 49 | return g_current_process->MirrorMemory(dst_addr, src_addr, size); | 50 | return Core::CurrentProcess()->MirrorMemory(dst_addr, src_addr, size); |
| 50 | } | 51 | } |
| 51 | 52 | ||
| 52 | /// Unmaps a region that was previously mapped with svcMapMemory | 53 | /// Unmaps a region that was previously mapped with svcMapMemory |
| 53 | static ResultCode UnmapMemory(VAddr dst_addr, VAddr src_addr, u64 size) { | 54 | static ResultCode UnmapMemory(VAddr dst_addr, VAddr src_addr, u64 size) { |
| 54 | LOG_TRACE(Kernel_SVC, "called, dst_addr=0x%llx, src_addr=0x%llx, size=0x%llx", dst_addr, | 55 | LOG_TRACE(Kernel_SVC, "called, dst_addr=0x%llx, src_addr=0x%llx, size=0x%llx", dst_addr, |
| 55 | src_addr, size); | 56 | src_addr, size); |
| 56 | return g_current_process->UnmapMemory(dst_addr, src_addr, size); | 57 | return Core::CurrentProcess()->UnmapMemory(dst_addr, src_addr, size); |
| 57 | } | 58 | } |
| 58 | 59 | ||
| 59 | /// Connect to an OS service given the port name, returns the handle to the port to out | 60 | /// Connect to an OS service given the port name, returns the handle to the port to out |
| @@ -306,14 +307,14 @@ static ResultCode GetInfo(u64* result, u64 info_id, u64 handle, u64 info_sub_id) | |||
| 306 | LOG_TRACE(Kernel_SVC, "called info_id=0x%X, info_sub_id=0x%X, handle=0x%08X", info_id, | 307 | LOG_TRACE(Kernel_SVC, "called info_id=0x%X, info_sub_id=0x%X, handle=0x%08X", info_id, |
| 307 | info_sub_id, handle); | 308 | info_sub_id, handle); |
| 308 | 309 | ||
| 309 | auto& vm_manager = g_current_process->vm_manager; | 310 | auto& vm_manager = Core::CurrentProcess()->vm_manager; |
| 310 | 311 | ||
| 311 | switch (static_cast<GetInfoType>(info_id)) { | 312 | switch (static_cast<GetInfoType>(info_id)) { |
| 312 | case GetInfoType::AllowedCpuIdBitmask: | 313 | case GetInfoType::AllowedCpuIdBitmask: |
| 313 | *result = g_current_process->allowed_processor_mask; | 314 | *result = Core::CurrentProcess()->allowed_processor_mask; |
| 314 | break; | 315 | break; |
| 315 | case GetInfoType::AllowedThreadPrioBitmask: | 316 | case GetInfoType::AllowedThreadPrioBitmask: |
| 316 | *result = g_current_process->allowed_thread_priority_mask; | 317 | *result = Core::CurrentProcess()->allowed_thread_priority_mask; |
| 317 | break; | 318 | break; |
| 318 | case GetInfoType::MapRegionBaseAddr: | 319 | case GetInfoType::MapRegionBaseAddr: |
| 319 | *result = vm_manager.GetMapRegionBaseAddr(); | 320 | *result = vm_manager.GetMapRegionBaseAddr(); |
| @@ -352,7 +353,7 @@ static ResultCode GetInfo(u64* result, u64 info_id, u64 handle, u64 info_sub_id) | |||
| 352 | *result = vm_manager.GetNewMapRegionSize(); | 353 | *result = vm_manager.GetNewMapRegionSize(); |
| 353 | break; | 354 | break; |
| 354 | case GetInfoType::IsVirtualAddressMemoryEnabled: | 355 | case GetInfoType::IsVirtualAddressMemoryEnabled: |
| 355 | *result = g_current_process->is_virtual_address_memory_enabled; | 356 | *result = Core::CurrentProcess()->is_virtual_address_memory_enabled; |
| 356 | break; | 357 | break; |
| 357 | case GetInfoType::TitleId: | 358 | case GetInfoType::TitleId: |
| 358 | LOG_WARNING(Kernel_SVC, "(STUBBED) Attempted to query titleid, returned 0"); | 359 | LOG_WARNING(Kernel_SVC, "(STUBBED) Attempted to query titleid, returned 0"); |
| @@ -392,7 +393,7 @@ static ResultCode SetThreadPriority(Handle handle, u32 priority) { | |||
| 392 | 393 | ||
| 393 | // Note: The kernel uses the current process's resource limit instead of | 394 | // Note: The kernel uses the current process's resource limit instead of |
| 394 | // the one from the thread owner's resource limit. | 395 | // the one from the thread owner's resource limit. |
| 395 | SharedPtr<ResourceLimit>& resource_limit = g_current_process->resource_limit; | 396 | SharedPtr<ResourceLimit>& resource_limit = Core::CurrentProcess()->resource_limit; |
| 396 | if (resource_limit->GetMaxResourceValue(ResourceTypes::PRIORITY) > priority) { | 397 | if (resource_limit->GetMaxResourceValue(ResourceTypes::PRIORITY) > priority) { |
| 397 | return ERR_NOT_AUTHORIZED; | 398 | return ERR_NOT_AUTHORIZED; |
| 398 | } | 399 | } |
| @@ -435,7 +436,7 @@ static ResultCode MapSharedMemory(Handle shared_memory_handle, VAddr addr, u64 s | |||
| 435 | case MemoryPermission::WriteExecute: | 436 | case MemoryPermission::WriteExecute: |
| 436 | case MemoryPermission::ReadWriteExecute: | 437 | case MemoryPermission::ReadWriteExecute: |
| 437 | case MemoryPermission::DontCare: | 438 | case MemoryPermission::DontCare: |
| 438 | return shared_memory->Map(g_current_process.get(), addr, permissions_type, | 439 | return shared_memory->Map(Core::CurrentProcess().get(), addr, permissions_type, |
| 439 | MemoryPermission::DontCare); | 440 | MemoryPermission::DontCare); |
| 440 | default: | 441 | default: |
| 441 | LOG_ERROR(Kernel_SVC, "unknown permissions=0x%08X", permissions); | 442 | LOG_ERROR(Kernel_SVC, "unknown permissions=0x%08X", permissions); |
| @@ -451,7 +452,7 @@ static ResultCode UnmapSharedMemory(Handle shared_memory_handle, VAddr addr, u64 | |||
| 451 | 452 | ||
| 452 | SharedPtr<SharedMemory> shared_memory = g_handle_table.Get<SharedMemory>(shared_memory_handle); | 453 | SharedPtr<SharedMemory> shared_memory = g_handle_table.Get<SharedMemory>(shared_memory_handle); |
| 453 | 454 | ||
| 454 | return shared_memory->Unmap(g_current_process.get(), addr); | 455 | return shared_memory->Unmap(Core::CurrentProcess().get(), addr); |
| 455 | } | 456 | } |
| 456 | 457 | ||
| 457 | /// Query process memory | 458 | /// Query process memory |
| @@ -463,7 +464,7 @@ static ResultCode QueryProcessMemory(MemoryInfo* memory_info, PageInfo* /*page_i | |||
| 463 | } | 464 | } |
| 464 | auto vma = process->vm_manager.FindVMA(addr); | 465 | auto vma = process->vm_manager.FindVMA(addr); |
| 465 | memory_info->attributes = 0; | 466 | memory_info->attributes = 0; |
| 466 | if (vma == g_current_process->vm_manager.vma_map.end()) { | 467 | if (vma == Core::CurrentProcess()->vm_manager.vma_map.end()) { |
| 467 | memory_info->base_address = 0; | 468 | memory_info->base_address = 0; |
| 468 | memory_info->permission = static_cast<u32>(VMAPermission::None); | 469 | memory_info->permission = static_cast<u32>(VMAPermission::None); |
| 469 | memory_info->size = 0; | 470 | memory_info->size = 0; |
| @@ -487,16 +488,17 @@ static ResultCode QueryMemory(MemoryInfo* memory_info, PageInfo* page_info, VAdd | |||
| 487 | 488 | ||
| 488 | /// Exits the current process | 489 | /// Exits the current process |
| 489 | static void ExitProcess() { | 490 | static void ExitProcess() { |
| 490 | LOG_INFO(Kernel_SVC, "Process %u exiting", g_current_process->process_id); | 491 | LOG_INFO(Kernel_SVC, "Process %u exiting", Core::CurrentProcess()->process_id); |
| 491 | 492 | ||
| 492 | ASSERT_MSG(g_current_process->status == ProcessStatus::Running, "Process has already exited"); | 493 | ASSERT_MSG(Core::CurrentProcess()->status == ProcessStatus::Running, |
| 494 | "Process has already exited"); | ||
| 493 | 495 | ||
| 494 | g_current_process->status = ProcessStatus::Exited; | 496 | Core::CurrentProcess()->status = ProcessStatus::Exited; |
| 495 | 497 | ||
| 496 | // Stop all the process threads that are currently waiting for objects. | 498 | // Stop all the process threads that are currently waiting for objects. |
| 497 | auto& thread_list = Core::System::GetInstance().Scheduler().GetThreadList(); | 499 | auto& thread_list = Core::System::GetInstance().Scheduler().GetThreadList(); |
| 498 | for (auto& thread : thread_list) { | 500 | for (auto& thread : thread_list) { |
| 499 | if (thread->owner_process != g_current_process) | 501 | if (thread->owner_process != Core::CurrentProcess()) |
| 500 | continue; | 502 | continue; |
| 501 | 503 | ||
| 502 | if (thread == GetCurrentThread()) | 504 | if (thread == GetCurrentThread()) |
| @@ -525,14 +527,14 @@ static ResultCode CreateThread(Handle* out_handle, VAddr entry_point, u64 arg, V | |||
| 525 | return ERR_OUT_OF_RANGE; | 527 | return ERR_OUT_OF_RANGE; |
| 526 | } | 528 | } |
| 527 | 529 | ||
| 528 | SharedPtr<ResourceLimit>& resource_limit = g_current_process->resource_limit; | 530 | SharedPtr<ResourceLimit>& resource_limit = Core::CurrentProcess()->resource_limit; |
| 529 | if (resource_limit->GetMaxResourceValue(ResourceTypes::PRIORITY) > priority) { | 531 | if (resource_limit->GetMaxResourceValue(ResourceTypes::PRIORITY) > priority) { |
| 530 | return ERR_NOT_AUTHORIZED; | 532 | return ERR_NOT_AUTHORIZED; |
| 531 | } | 533 | } |
| 532 | 534 | ||
| 533 | if (processor_id == THREADPROCESSORID_DEFAULT) { | 535 | if (processor_id == THREADPROCESSORID_DEFAULT) { |
| 534 | // Set the target CPU to the one specified in the process' exheader. | 536 | // Set the target CPU to the one specified in the process' exheader. |
| 535 | processor_id = g_current_process->ideal_processor; | 537 | processor_id = Core::CurrentProcess()->ideal_processor; |
| 536 | ASSERT(processor_id != THREADPROCESSORID_DEFAULT); | 538 | ASSERT(processor_id != THREADPROCESSORID_DEFAULT); |
| 537 | } | 539 | } |
| 538 | 540 | ||
| @@ -554,7 +556,7 @@ static ResultCode CreateThread(Handle* out_handle, VAddr entry_point, u64 arg, V | |||
| 554 | 556 | ||
| 555 | CASCADE_RESULT(SharedPtr<Thread> thread, | 557 | CASCADE_RESULT(SharedPtr<Thread> thread, |
| 556 | Thread::Create(name, entry_point, priority, arg, processor_id, stack_top, | 558 | Thread::Create(name, entry_point, priority, arg, processor_id, stack_top, |
| 557 | g_current_process)); | 559 | Core::CurrentProcess())); |
| 558 | CASCADE_RESULT(thread->guest_handle, g_handle_table.Create(thread)); | 560 | CASCADE_RESULT(thread->guest_handle, g_handle_table.Create(thread)); |
| 559 | *out_handle = thread->guest_handle; | 561 | *out_handle = thread->guest_handle; |
| 560 | 562 | ||