2020-02-08 20:53:27 +01:00
|
|
|
/*
|
2021-10-04 21:59:10 +02:00
|
|
|
* Copyright (c) Atmosphère-NX
|
2020-02-08 20:53:27 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#include <mesosphere.hpp>
|
|
|
|
|
|
|
|
namespace ams::kern::svc {
|
|
|
|
|
|
|
|
/* ============================= Common ============================= */
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2021-02-05 23:59:03 +01:00
|
|
|
constexpr bool IsValidVirtualCoreId(int32_t core_id) {
|
|
|
|
return (0 <= core_id && core_id < static_cast<int32_t>(cpu::NumVirtualCores));
|
2020-07-22 08:03:17 +02:00
|
|
|
}
|
|
|
|
|
2020-07-10 05:11:41 +02:00
|
|
|
void ExitProcess() {
|
|
|
|
GetCurrentProcess().Exit();
|
|
|
|
MESOSPHERE_PANIC("Process survived call to exit");
|
|
|
|
}
|
|
|
|
|
2020-03-14 07:12:47 +01:00
|
|
|
Result GetProcessId(u64 *out_process_id, ams::svc::Handle handle) {
|
|
|
|
/* Get the object from the handle table. */
|
|
|
|
KScopedAutoObject obj = GetCurrentProcess().GetHandleTable().GetObject<KAutoObject>(handle);
|
|
|
|
R_UNLESS(obj.IsNotNull(), svc::ResultInvalidHandle());
|
|
|
|
|
|
|
|
/* Get the process from the object. */
|
2021-09-18 03:10:05 +02:00
|
|
|
if (KProcess *process = obj->DynamicCast<KProcess *>(); process != nullptr) {
|
2020-03-14 07:12:47 +01:00
|
|
|
/* The object is a process, so we can use it directly. */
|
2021-09-18 03:10:05 +02:00
|
|
|
|
|
|
|
/* Make sure the target process exists. */
|
|
|
|
R_UNLESS(process != nullptr, svc::ResultInvalidHandle());
|
|
|
|
|
|
|
|
/* Get the process id. */
|
|
|
|
*out_process_id = process->GetId();
|
2020-07-31 09:29:00 +02:00
|
|
|
} else if (KThread *t = obj->DynamicCast<KThread *>(); t != nullptr) {
|
2020-03-14 07:12:47 +01:00
|
|
|
/* The object is a thread, so we want to use its parent. */
|
2021-09-18 03:10:05 +02:00
|
|
|
KProcess *process = t->GetOwnerProcess();
|
|
|
|
|
|
|
|
/* Make sure the target process exists. */
|
|
|
|
R_UNLESS(process != nullptr, svc::ResultInvalidHandle());
|
|
|
|
|
|
|
|
/* Get the process id. */
|
|
|
|
*out_process_id = process->GetId();
|
2020-07-31 09:29:00 +02:00
|
|
|
} else if (KDebug *d = obj->DynamicCast<KDebug *>(); d != nullptr) {
|
2020-03-14 07:12:47 +01:00
|
|
|
/* The object is a debug, so we want to use the process it's attached to. */
|
2020-07-31 09:29:00 +02:00
|
|
|
|
2021-09-18 03:10:05 +02:00
|
|
|
/* Make sure the target process exists. */
|
|
|
|
R_UNLESS(d->IsAttached(), svc::ResultInvalidHandle());
|
|
|
|
R_UNLESS(d->OpenProcess(), svc::ResultInvalidHandle());
|
|
|
|
ON_SCOPE_EXIT { d->CloseProcess(); };
|
2020-03-14 07:12:47 +01:00
|
|
|
|
2021-09-18 03:10:05 +02:00
|
|
|
/* Get the process id. */
|
|
|
|
*out_process_id = d->GetProcessUnsafe()->GetProcessId();
|
|
|
|
}
|
2020-03-14 07:12:47 +01:00
|
|
|
|
2022-02-14 23:45:32 +01:00
|
|
|
R_SUCCEED();
|
2020-03-14 07:12:47 +01:00
|
|
|
}
|
|
|
|
|
2020-07-14 22:22:08 +02:00
|
|
|
Result GetProcessList(int32_t *out_num_processes, KUserPointer<uint64_t *> out_process_ids, int32_t max_out_count) {
|
|
|
|
/* Validate that the out count is valid. */
|
|
|
|
R_UNLESS((0 <= max_out_count && max_out_count <= static_cast<int32_t>(std::numeric_limits<int32_t>::max() / sizeof(u64))), svc::ResultOutOfRange());
|
2020-02-08 20:53:27 +01:00
|
|
|
|
2020-07-14 22:22:08 +02:00
|
|
|
/* Validate that the pointer is in range. */
|
|
|
|
if (max_out_count > 0) {
|
|
|
|
R_UNLESS(GetCurrentProcess().GetPageTable().Contains(KProcessAddress(out_process_ids.GetUnsafePointer()), max_out_count * sizeof(u64)), svc::ResultInvalidCurrentMemory());
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the process list. */
|
2022-02-14 23:45:32 +01:00
|
|
|
R_RETURN(KProcess::GetProcessList(out_num_processes, out_process_ids, max_out_count));
|
2020-07-14 22:22:08 +02:00
|
|
|
}
|
2020-02-08 20:53:27 +01:00
|
|
|
|
2020-07-22 03:54:08 +02:00
|
|
|
Result CreateProcess(ams::svc::Handle *out, const ams::svc::CreateProcessParameter ¶ms, KUserPointer<const uint32_t *> user_caps, int32_t num_caps) {
|
|
|
|
/* Validate the capabilities pointer. */
|
|
|
|
R_UNLESS(num_caps >= 0, svc::ResultInvalidPointer());
|
|
|
|
if (num_caps > 0) {
|
|
|
|
/* Check for overflow. */
|
|
|
|
R_UNLESS(((num_caps * sizeof(u32)) / sizeof(u32)) == static_cast<size_t>(num_caps), svc::ResultInvalidPointer());
|
|
|
|
|
|
|
|
/* Validate that the pointer is in range. */
|
|
|
|
R_UNLESS(GetCurrentProcess().GetPageTable().Contains(KProcessAddress(user_caps.GetUnsafePointer()), num_caps * sizeof(u32)), svc::ResultInvalidPointer());
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Validate that the parameter flags are valid. */
|
|
|
|
R_UNLESS((params.flags & ~ams::svc::CreateProcessFlag_All) == 0, svc::ResultInvalidEnumValue());
|
|
|
|
|
|
|
|
/* Validate that 64-bit process is okay. */
|
|
|
|
const bool is_64_bit = (params.flags & ams::svc::CreateProcessFlag_Is64Bit) != 0;
|
|
|
|
if constexpr (sizeof(void *) < sizeof(u64)) {
|
|
|
|
R_UNLESS(!is_64_bit, svc::ResultInvalidCombination());
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Decide on an address space map region. */
|
|
|
|
uintptr_t map_start, map_end;
|
|
|
|
size_t map_size;
|
|
|
|
switch (params.flags & ams::svc::CreateProcessFlag_AddressSpaceMask) {
|
|
|
|
case ams::svc::CreateProcessFlag_AddressSpace32Bit:
|
|
|
|
case ams::svc::CreateProcessFlag_AddressSpace32BitWithoutAlias:
|
|
|
|
{
|
|
|
|
map_start = KAddressSpaceInfo::GetAddressSpaceStart(32, KAddressSpaceInfo::Type_MapSmall);
|
|
|
|
map_size = KAddressSpaceInfo::GetAddressSpaceSize(32, KAddressSpaceInfo::Type_MapSmall);
|
|
|
|
map_end = map_start + map_size;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ams::svc::CreateProcessFlag_AddressSpace64BitDeprecated:
|
|
|
|
{
|
|
|
|
/* 64-bit address space requires 64-bit process. */
|
|
|
|
R_UNLESS(is_64_bit, svc::ResultInvalidCombination());
|
|
|
|
|
|
|
|
map_start = KAddressSpaceInfo::GetAddressSpaceStart(36, KAddressSpaceInfo::Type_MapSmall);
|
|
|
|
map_size = KAddressSpaceInfo::GetAddressSpaceSize(36, KAddressSpaceInfo::Type_MapSmall);
|
|
|
|
map_end = map_start + map_size;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ams::svc::CreateProcessFlag_AddressSpace64Bit:
|
|
|
|
{
|
|
|
|
/* 64-bit address space requires 64-bit process. */
|
|
|
|
R_UNLESS(is_64_bit, svc::ResultInvalidCombination());
|
|
|
|
|
|
|
|
map_start = KAddressSpaceInfo::GetAddressSpaceStart(39, KAddressSpaceInfo::Type_Map39Bit);
|
|
|
|
map_end = map_start + KAddressSpaceInfo::GetAddressSpaceSize(39, KAddressSpaceInfo::Type_Map39Bit);
|
|
|
|
|
|
|
|
map_size = KAddressSpaceInfo::GetAddressSpaceSize(39, KAddressSpaceInfo::Type_Heap);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2022-02-14 23:45:32 +01:00
|
|
|
R_THROW(svc::ResultInvalidEnumValue());
|
2020-07-22 03:54:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Validate the pool partition. */
|
2020-08-26 03:10:58 +02:00
|
|
|
if (GetTargetFirmware() >= TargetFirmware_5_0_0) {
|
|
|
|
switch (params.flags & ams::svc::CreateProcessFlag_PoolPartitionMask) {
|
|
|
|
case ams::svc::CreateProcessFlag_PoolPartitionApplication:
|
|
|
|
case ams::svc::CreateProcessFlag_PoolPartitionApplet:
|
|
|
|
case ams::svc::CreateProcessFlag_PoolPartitionSystem:
|
|
|
|
case ams::svc::CreateProcessFlag_PoolPartitionSystemNonSecure:
|
|
|
|
break;
|
|
|
|
default:
|
2022-02-14 23:45:32 +01:00
|
|
|
R_THROW(svc::ResultInvalidEnumValue());
|
2020-08-26 03:10:58 +02:00
|
|
|
}
|
2020-07-22 03:54:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check that the code address is aligned. */
|
|
|
|
R_UNLESS(util::IsAligned(params.code_address, KProcess::AslrAlignment), svc::ResultInvalidAddress());
|
|
|
|
|
|
|
|
/* Check that the number of code pages is >= 0. */
|
|
|
|
R_UNLESS(params.code_num_pages >= 0, svc::ResultInvalidSize());
|
|
|
|
|
|
|
|
/* Check that the number of extra resource pages is >= 0. */
|
|
|
|
R_UNLESS(params.system_resource_num_pages >= 0, svc::ResultInvalidSize());
|
|
|
|
|
|
|
|
/* Convert to sizes. */
|
|
|
|
const size_t code_num_pages = params.code_num_pages;
|
|
|
|
const size_t system_resource_num_pages = params.system_resource_num_pages;
|
|
|
|
const size_t total_pages = code_num_pages + system_resource_num_pages;
|
|
|
|
const size_t code_size = code_num_pages * PageSize;
|
|
|
|
const size_t system_resource_size = system_resource_num_pages * PageSize;
|
|
|
|
const size_t total_size = code_size + system_resource_size;
|
|
|
|
|
|
|
|
/* Check for overflow. */
|
|
|
|
R_UNLESS((code_size / PageSize) == code_num_pages, svc::ResultInvalidSize());
|
|
|
|
R_UNLESS((system_resource_size / PageSize) == system_resource_num_pages, svc::ResultInvalidSize());
|
|
|
|
R_UNLESS((code_num_pages + system_resource_num_pages) >= code_num_pages, svc::ResultOutOfMemory());
|
|
|
|
R_UNLESS((total_size / PageSize) == total_pages, svc::ResultInvalidSize());
|
|
|
|
|
|
|
|
/* Check that the number of pages is valid. */
|
|
|
|
R_UNLESS(code_num_pages < (map_size / PageSize), svc::ResultInvalidMemoryRegion());
|
|
|
|
|
|
|
|
/* Validate that the code falls within the map reigon. */
|
|
|
|
R_UNLESS(map_start <= params.code_address, svc::ResultInvalidMemoryRegion());
|
|
|
|
R_UNLESS(params.code_address < params.code_address + code_size, svc::ResultInvalidMemoryRegion());
|
|
|
|
R_UNLESS(params.code_address + code_size - 1 <= map_end - 1, svc::ResultInvalidMemoryRegion());
|
|
|
|
|
|
|
|
/* Check that the number of pages is valid for the kernel address space. */
|
2021-01-07 12:43:09 +01:00
|
|
|
R_UNLESS(code_num_pages < (kern::MainMemorySizeMax / PageSize), svc::ResultOutOfMemory());
|
|
|
|
R_UNLESS(system_resource_num_pages < (kern::MainMemorySizeMax / PageSize), svc::ResultOutOfMemory());
|
|
|
|
R_UNLESS(total_pages < (kern::MainMemorySizeMax / PageSize), svc::ResultOutOfMemory());
|
2020-07-22 03:54:08 +02:00
|
|
|
|
|
|
|
/* Check that optimized memory allocation is used only for applications. */
|
|
|
|
const bool optimize_allocs = (params.flags & ams::svc::CreateProcessFlag_OptimizeMemoryAllocation) != 0;
|
|
|
|
const bool is_application = (params.flags & ams::svc::CreateProcessFlag_IsApplication) != 0;
|
|
|
|
R_UNLESS(!optimize_allocs || is_application, svc::ResultBusy());
|
|
|
|
|
|
|
|
/* Get the current handle table. */
|
|
|
|
auto &handle_table = GetCurrentProcess().GetHandleTable();
|
|
|
|
|
|
|
|
/* Create the new process. */
|
|
|
|
KProcess *process = KProcess::Create();
|
|
|
|
R_UNLESS(process != nullptr, svc::ResultOutOfResource());
|
|
|
|
|
|
|
|
/* Ensure that the only reference to the process is in the handle table when we're done. */
|
|
|
|
ON_SCOPE_EXIT { process->Close(); };
|
|
|
|
|
|
|
|
/* Get the resource limit from the handle. */
|
|
|
|
KScopedAutoObject resource_limit = handle_table.GetObject<KResourceLimit>(params.reslimit);
|
|
|
|
R_UNLESS(resource_limit.IsNotNull() || params.reslimit == ams::svc::InvalidHandle, svc::ResultInvalidHandle());
|
|
|
|
|
|
|
|
/* Decide on a resource limit for the process. */
|
|
|
|
KResourceLimit *process_resource_limit = resource_limit.IsNotNull() ? resource_limit.GetPointerUnsafe() : std::addressof(Kernel::GetSystemResourceLimit());
|
|
|
|
|
|
|
|
/* Get the pool for the process. */
|
2021-11-07 02:19:34 +01:00
|
|
|
const auto pool = [](u32 flags) ALWAYS_INLINE_LAMBDA -> KMemoryManager::Pool {
|
2020-08-26 03:10:58 +02:00
|
|
|
if (GetTargetFirmware() >= TargetFirmware_5_0_0) {
|
|
|
|
switch (flags & ams::svc::CreateProcessFlag_PoolPartitionMask) {
|
|
|
|
case ams::svc::CreateProcessFlag_PoolPartitionApplication:
|
|
|
|
return KMemoryManager::Pool_Application;
|
|
|
|
case ams::svc::CreateProcessFlag_PoolPartitionApplet:
|
|
|
|
return KMemoryManager::Pool_Applet;
|
|
|
|
case ams::svc::CreateProcessFlag_PoolPartitionSystem:
|
|
|
|
return KMemoryManager::Pool_System;
|
|
|
|
case ams::svc::CreateProcessFlag_PoolPartitionSystemNonSecure:
|
|
|
|
default:
|
|
|
|
return KMemoryManager::Pool_SystemNonSecure;
|
|
|
|
}
|
|
|
|
} else if (GetTargetFirmware() >= TargetFirmware_4_0_0) {
|
|
|
|
if ((flags & ams::svc::CreateProcessFlag_DeprecatedUseSecureMemory) != 0) {
|
|
|
|
return KMemoryManager::Pool_Secure;
|
|
|
|
} else {
|
2020-08-26 08:28:39 +02:00
|
|
|
return static_cast<KMemoryManager::Pool>(KSystemControl::GetCreateProcessMemoryPool());
|
2020-08-26 03:10:58 +02:00
|
|
|
}
|
|
|
|
} else {
|
2020-08-26 08:28:39 +02:00
|
|
|
return static_cast<KMemoryManager::Pool>(KSystemControl::GetCreateProcessMemoryPool());
|
2020-08-26 03:10:58 +02:00
|
|
|
}
|
|
|
|
}(params.flags);
|
|
|
|
|
2020-07-22 03:54:08 +02:00
|
|
|
/* Initialize the process. */
|
|
|
|
R_TRY(process->Initialize(params, user_caps, num_caps, process_resource_limit, pool));
|
|
|
|
|
|
|
|
/* Register the process. */
|
2020-12-01 22:49:30 +01:00
|
|
|
KProcess::Register(process);
|
2020-07-22 03:54:08 +02:00
|
|
|
|
|
|
|
/* Add the process to the handle table. */
|
|
|
|
R_TRY(handle_table.Add(out, process));
|
|
|
|
|
2022-02-14 23:45:32 +01:00
|
|
|
R_SUCCEED();
|
2020-07-22 03:54:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
Result CreateProcess(ams::svc::Handle *out, KUserPointer<const T *> user_parameters, KUserPointer<const uint32_t *> user_caps, int32_t num_caps) {
|
|
|
|
/* Read the parameters from user space. */
|
|
|
|
T params;
|
|
|
|
R_TRY(user_parameters.CopyTo(std::addressof(params)));
|
|
|
|
|
|
|
|
/* Invoke the implementation. */
|
|
|
|
if constexpr (std::same_as<T, ams::svc::CreateProcessParameter>) {
|
2022-02-14 23:45:32 +01:00
|
|
|
R_RETURN(CreateProcess(out, params, user_caps, num_caps));
|
2020-07-22 03:54:08 +02:00
|
|
|
} else {
|
|
|
|
/* Convert the parameters. */
|
|
|
|
ams::svc::CreateProcessParameter converted_params;
|
|
|
|
static_assert(sizeof(T{}.name) == sizeof(ams::svc::CreateProcessParameter{}.name));
|
|
|
|
|
|
|
|
std::memcpy(converted_params.name, params.name, sizeof(converted_params.name));
|
|
|
|
converted_params.version = params.version;
|
|
|
|
converted_params.program_id = params.program_id;
|
|
|
|
converted_params.code_address = params.code_address;
|
|
|
|
converted_params.code_num_pages = params.code_num_pages;
|
|
|
|
converted_params.flags = params.flags;
|
|
|
|
converted_params.reslimit = params.reslimit;
|
|
|
|
converted_params.system_resource_num_pages = params.system_resource_num_pages;
|
|
|
|
|
|
|
|
/* Invoke. */
|
2022-02-14 23:45:32 +01:00
|
|
|
R_RETURN(CreateProcess(out, converted_params, user_caps, num_caps));
|
2020-07-22 03:54:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-22 08:03:17 +02:00
|
|
|
Result StartProcess(ams::svc::Handle process_handle, int32_t priority, int32_t core_id, uint64_t main_thread_stack_size) {
|
|
|
|
/* Validate stack size. */
|
|
|
|
R_UNLESS(main_thread_stack_size == static_cast<size_t>(main_thread_stack_size), svc::ResultOutOfMemory());
|
|
|
|
|
|
|
|
/* Get the target process. */
|
|
|
|
KScopedAutoObject process = GetCurrentProcess().GetHandleTable().GetObject<KProcess>(process_handle);
|
|
|
|
R_UNLESS(process.IsNotNull(), svc::ResultInvalidHandle());
|
|
|
|
|
|
|
|
/* Validate the core id. */
|
2021-02-05 23:59:03 +01:00
|
|
|
R_UNLESS(IsValidVirtualCoreId(core_id), svc::ResultInvalidCoreId());
|
2020-07-22 08:03:17 +02:00
|
|
|
R_UNLESS(((1ul << core_id) & process->GetCoreMask()) != 0, svc::ResultInvalidCoreId());
|
|
|
|
|
|
|
|
/* Validate the priority. */
|
|
|
|
R_UNLESS(ams::svc::HighestThreadPriority <= priority && priority <= ams::svc::LowestThreadPriority, svc::ResultInvalidPriority());
|
|
|
|
R_UNLESS(process->CheckThreadPriority(priority), svc::ResultInvalidPriority());
|
|
|
|
|
|
|
|
/* Set the process's ideal processor. */
|
|
|
|
process->SetIdealCoreId(core_id);
|
|
|
|
|
|
|
|
/* Run the process. */
|
2022-02-14 23:45:32 +01:00
|
|
|
R_RETURN(process->Run(priority, static_cast<size_t>(main_thread_stack_size)));
|
2020-07-22 08:03:17 +02:00
|
|
|
}
|
|
|
|
|
2020-07-22 20:15:45 +02:00
|
|
|
Result TerminateProcess(ams::svc::Handle process_handle) {
|
|
|
|
/* Get the target process. */
|
|
|
|
KProcess *process = GetCurrentProcess().GetHandleTable().GetObject<KProcess>(process_handle).ReleasePointerUnsafe();
|
|
|
|
R_UNLESS(process != nullptr, svc::ResultInvalidHandle());
|
|
|
|
|
|
|
|
if (process != GetCurrentProcessPointer()) {
|
|
|
|
/* We're terminating another process. Close our reference after terminating the process. */
|
|
|
|
ON_SCOPE_EXIT { process->Close(); };
|
|
|
|
|
|
|
|
/* Terminate the process. */
|
|
|
|
R_TRY(process->Terminate());
|
|
|
|
} else {
|
|
|
|
/* We're terminating ourselves. Close our reference immediately. */
|
|
|
|
process->Close();
|
|
|
|
|
|
|
|
/* Exit. */
|
|
|
|
ExitProcess();
|
|
|
|
}
|
|
|
|
|
2022-02-14 23:45:32 +01:00
|
|
|
R_SUCCEED();
|
2020-07-22 20:15:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Result GetProcessInfo(int64_t *out, ams::svc::Handle process_handle, ams::svc::ProcessInfoType info_type) {
|
|
|
|
/* Get the target process. */
|
|
|
|
KScopedAutoObject process = GetCurrentProcess().GetHandleTable().GetObject<KProcess>(process_handle);
|
|
|
|
R_UNLESS(process.IsNotNull(), svc::ResultInvalidHandle());
|
|
|
|
|
|
|
|
/* Get the info. */
|
|
|
|
switch (info_type) {
|
|
|
|
case ams::svc::ProcessInfoType_ProcessState:
|
|
|
|
{
|
|
|
|
/* Get the process's state. */
|
|
|
|
KProcess::State state;
|
|
|
|
{
|
|
|
|
KScopedLightLock proc_lk(process->GetStateLock());
|
|
|
|
KScopedSchedulerLock sl;
|
|
|
|
|
|
|
|
state = process->GetState();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Convert to svc state. */
|
|
|
|
switch (state) {
|
|
|
|
case KProcess::State_Created: *out = ams::svc::ProcessState_Created; break;
|
|
|
|
case KProcess::State_CreatedAttached: *out = ams::svc::ProcessState_CreatedAttached; break;
|
|
|
|
case KProcess::State_Running: *out = ams::svc::ProcessState_Running; break;
|
|
|
|
case KProcess::State_Crashed: *out = ams::svc::ProcessState_Crashed; break;
|
|
|
|
case KProcess::State_RunningAttached: *out = ams::svc::ProcessState_RunningAttached; break;
|
|
|
|
case KProcess::State_Terminating: *out = ams::svc::ProcessState_Terminating; break;
|
|
|
|
case KProcess::State_Terminated: *out = ams::svc::ProcessState_Terminated; break;
|
|
|
|
case KProcess::State_DebugBreak: *out = ams::svc::ProcessState_DebugBreak; break;
|
|
|
|
MESOSPHERE_UNREACHABLE_DEFAULT_CASE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2022-02-14 23:45:32 +01:00
|
|
|
R_THROW(svc::ResultInvalidEnumValue());
|
2020-07-22 20:15:45 +02:00
|
|
|
}
|
|
|
|
|
2022-02-14 23:45:32 +01:00
|
|
|
R_SUCCEED();
|
2020-07-22 20:15:45 +02:00
|
|
|
}
|
|
|
|
|
2020-02-08 20:53:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ============================= 64 ABI ============================= */
|
|
|
|
|
|
|
|
void ExitProcess64() {
|
2020-07-10 05:11:41 +02:00
|
|
|
return ExitProcess();
|
2020-02-08 20:53:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Result GetProcessId64(uint64_t *out_process_id, ams::svc::Handle process_handle) {
|
2022-02-14 23:45:32 +01:00
|
|
|
R_RETURN(GetProcessId(out_process_id, process_handle));
|
2020-02-08 20:53:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Result GetProcessList64(int32_t *out_num_processes, KUserPointer<uint64_t *> out_process_ids, int32_t max_out_count) {
|
2022-02-14 23:45:32 +01:00
|
|
|
R_RETURN(GetProcessList(out_num_processes, out_process_ids, max_out_count));
|
2020-02-08 20:53:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Result CreateProcess64(ams::svc::Handle *out_handle, KUserPointer<const ams::svc::lp64::CreateProcessParameter *> parameters, KUserPointer<const uint32_t *> caps, int32_t num_caps) {
|
2022-02-14 23:45:32 +01:00
|
|
|
R_RETURN(CreateProcess(out_handle, parameters, caps, num_caps));
|
2020-02-08 20:53:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Result StartProcess64(ams::svc::Handle process_handle, int32_t priority, int32_t core_id, uint64_t main_thread_stack_size) {
|
2022-02-14 23:45:32 +01:00
|
|
|
R_RETURN(StartProcess(process_handle, priority, core_id, main_thread_stack_size));
|
2020-02-08 20:53:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Result TerminateProcess64(ams::svc::Handle process_handle) {
|
2022-02-14 23:45:32 +01:00
|
|
|
R_RETURN(TerminateProcess(process_handle));
|
2020-02-08 20:53:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Result GetProcessInfo64(int64_t *out_info, ams::svc::Handle process_handle, ams::svc::ProcessInfoType info_type) {
|
2022-02-14 23:45:32 +01:00
|
|
|
R_RETURN(GetProcessInfo(out_info, process_handle, info_type));
|
2020-02-08 20:53:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ============================= 64From32 ABI ============================= */
|
|
|
|
|
|
|
|
void ExitProcess64From32() {
|
2020-07-10 05:11:41 +02:00
|
|
|
return ExitProcess();
|
2020-02-08 20:53:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Result GetProcessId64From32(uint64_t *out_process_id, ams::svc::Handle process_handle) {
|
2022-02-14 23:45:32 +01:00
|
|
|
R_RETURN(GetProcessId(out_process_id, process_handle));
|
2020-02-08 20:53:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Result GetProcessList64From32(int32_t *out_num_processes, KUserPointer<uint64_t *> out_process_ids, int32_t max_out_count) {
|
2022-02-14 23:45:32 +01:00
|
|
|
R_RETURN(GetProcessList(out_num_processes, out_process_ids, max_out_count));
|
2020-02-08 20:53:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Result CreateProcess64From32(ams::svc::Handle *out_handle, KUserPointer<const ams::svc::ilp32::CreateProcessParameter *> parameters, KUserPointer<const uint32_t *> caps, int32_t num_caps) {
|
2022-02-14 23:45:32 +01:00
|
|
|
R_RETURN(CreateProcess(out_handle, parameters, caps, num_caps));
|
2020-02-08 20:53:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Result StartProcess64From32(ams::svc::Handle process_handle, int32_t priority, int32_t core_id, uint64_t main_thread_stack_size) {
|
2022-02-14 23:45:32 +01:00
|
|
|
R_RETURN(StartProcess(process_handle, priority, core_id, main_thread_stack_size));
|
2020-02-08 20:53:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Result TerminateProcess64From32(ams::svc::Handle process_handle) {
|
2022-02-14 23:45:32 +01:00
|
|
|
R_RETURN(TerminateProcess(process_handle));
|
2020-02-08 20:53:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Result GetProcessInfo64From32(int64_t *out_info, ams::svc::Handle process_handle, ams::svc::ProcessInfoType info_type) {
|
2022-02-14 23:45:32 +01:00
|
|
|
R_RETURN(GetProcessInfo(out_info, process_handle, info_type));
|
2020-02-08 20:53:27 +01:00
|
|
|
}
|
|
|
|
|
2020-02-08 20:56:13 +01:00
|
|
|
}
|