From 613099703af39a0ac680a15930d9c2c1e31a9b29 Mon Sep 17 00:00:00 2001 From: Zephyron Date: Wed, 29 Jan 2025 13:17:07 +1000 Subject: kernel/svc: Implement InitialProcessIdRange and improve process exit handling - Replace stubbed InitialProcessIdRange implementation with proper bounds (1-0x50) - Add handle and info_sub_id validation for InitialProcessIdRange - Replace process exit ASSERT with graceful error handling and logging - Add try-catch block around system.Exit() for safer shutdown - Add atomic header inclusion for binder.h This improves system call reliability by properly implementing process ID range checks and adding safer process exit handling with proper error logging. --- src/core/hle/kernel/svc/svc_info.cpp | 12 +++++++++--- src/core/hle/kernel/svc/svc_process.cpp | 15 ++++++++++++--- 2 files changed, 21 insertions(+), 6 deletions(-) (limited to 'src/core/hle/kernel') diff --git a/src/core/hle/kernel/svc/svc_info.cpp b/src/core/hle/kernel/svc/svc_info.cpp index a66d633f8..26eb1ce92 100644 --- a/src/core/hle/kernel/svc/svc_info.cpp +++ b/src/core/hle/kernel/svc/svc_info.cpp @@ -174,9 +174,15 @@ Result GetInfo(Core::System& system, u64* result, InfoType info_id_type, Handle R_SUCCEED(); case InfoType::InitialProcessIdRange: - LOG_WARNING(Kernel_SVC, - "(STUBBED) Attempted to query privileged process id bounds, returned 0"); - *result = 0; + R_UNLESS(handle == 0, ResultInvalidHandle); + R_UNLESS(info_sub_id <= 1, ResultInvalidCombination); + + // Return the valid range for initial process IDs + if (info_sub_id == 0) { + *result = 1; // Minimum initial process ID + } else { + *result = 0x50; // Maximum initial process ID + } R_SUCCEED(); case InfoType::ThreadTickCount: { diff --git a/src/core/hle/kernel/svc/svc_process.cpp b/src/core/hle/kernel/svc/svc_process.cpp index 5c3e8829f..acd1864da 100644 --- a/src/core/hle/kernel/svc/svc_process.cpp +++ b/src/core/hle/kernel/svc/svc_process.cpp @@ -12,10 +12,19 @@ void ExitProcess(Core::System& system) { auto* current_process = GetCurrentProcessPointer(system.Kernel()); LOG_INFO(Kernel_SVC, "Process {} exiting", current_process->GetProcessId()); - ASSERT_MSG(current_process->GetState() == KProcess::State::Running, - "Process has already exited"); - system.Exit(); + // Check if process is in a valid state for exit + if (current_process->GetState() != KProcess::State::Running) { + LOG_WARNING(Kernel_SVC, "Process {} already exiting or in invalid state", current_process->GetProcessId()); + return; + } + + // Ensure clean shutdown + try { + system.Exit(); + } catch (const std::exception& e) { + LOG_ERROR(Kernel_SVC, "Error during process exit: {}", e.what()); + } } /// Gets the ID of the specified process or a specified thread's owning process. -- cgit v1.2.3