diff options
| author | 2019-03-20 15:03:52 -0400 | |
|---|---|---|
| committer | 2019-04-02 00:47:14 -0400 | |
| commit | cb2bce8006189d866fb468b497d1ddcf2fd99ccf (patch) | |
| tree | 3ec965e9a4c9ed69fda4cdfd859b88ad6b48bb66 | |
| parent | Merge pull request #2316 from ReinUsesLisp/fixup-process (diff) | |
| download | yuzu-cb2bce8006189d866fb468b497d1ddcf2fd99ccf.tar.gz yuzu-cb2bce8006189d866fb468b497d1ddcf2fd99ccf.tar.xz yuzu-cb2bce8006189d866fb468b497d1ddcf2fd99ccf.zip | |
kernel/svc: Implement svcGetProcessList
This service function simply copies out a specified number of kernel
process IDs, while simultaneously reporting the total number of
processes.
| -rw-r--r-- | src/core/hle/kernel/kernel.cpp | 4 | ||||
| -rw-r--r-- | src/core/hle/kernel/kernel.h | 3 | ||||
| -rw-r--r-- | src/core/hle/kernel/svc.cpp | 39 | ||||
| -rw-r--r-- | src/core/hle/kernel/svc_wrap.h | 8 |
4 files changed, 53 insertions, 1 deletions
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index 6baeb3494..ea1c13cdf 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp | |||
| @@ -191,6 +191,10 @@ const Process* KernelCore::CurrentProcess() const { | |||
| 191 | return impl->current_process; | 191 | return impl->current_process; |
| 192 | } | 192 | } |
| 193 | 193 | ||
| 194 | const std::vector<SharedPtr<Process>>& KernelCore::GetProcessList() const { | ||
| 195 | return impl->process_list; | ||
| 196 | } | ||
| 197 | |||
| 194 | void KernelCore::AddNamedPort(std::string name, SharedPtr<ClientPort> port) { | 198 | void KernelCore::AddNamedPort(std::string name, SharedPtr<ClientPort> port) { |
| 195 | impl->named_ports.emplace(std::move(name), std::move(port)); | 199 | impl->named_ports.emplace(std::move(name), std::move(port)); |
| 196 | } | 200 | } |
diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h index 03ea5b659..6b8738599 100644 --- a/src/core/hle/kernel/kernel.h +++ b/src/core/hle/kernel/kernel.h | |||
| @@ -72,6 +72,9 @@ public: | |||
| 72 | /// Retrieves a const pointer to the current process. | 72 | /// Retrieves a const pointer to the current process. |
| 73 | const Process* CurrentProcess() const; | 73 | const Process* CurrentProcess() const; |
| 74 | 74 | ||
| 75 | /// Retrieves the list of processes. | ||
| 76 | const std::vector<SharedPtr<Process>>& GetProcessList() const; | ||
| 77 | |||
| 75 | /// Adds a port to the named port table | 78 | /// Adds a port to the named port table |
| 76 | void AddNamedPort(std::string name, SharedPtr<ClientPort> port); | 79 | void AddNamedPort(std::string name, SharedPtr<ClientPort> port); |
| 77 | 80 | ||
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index 76a8b0191..3cd948bb5 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp | |||
| @@ -1983,6 +1983,43 @@ static ResultCode SetResourceLimitLimitValue(Handle resource_limit, u32 resource | |||
| 1983 | return RESULT_SUCCESS; | 1983 | return RESULT_SUCCESS; |
| 1984 | } | 1984 | } |
| 1985 | 1985 | ||
| 1986 | static ResultCode GetProcessList(u32* out_num_processes, VAddr out_process_ids, | ||
| 1987 | u32 out_process_ids_size) { | ||
| 1988 | LOG_DEBUG(Kernel_SVC, "called. out_process_ids=0x{:016X}, out_process_ids_size={}", | ||
| 1989 | out_process_ids, out_process_ids_size); | ||
| 1990 | |||
| 1991 | // If the supplied size is negative or greater than INT32_MAX / sizeof(u64), bail. | ||
| 1992 | if ((out_process_ids_size & 0xF0000000) != 0) { | ||
| 1993 | LOG_ERROR(Kernel_SVC, | ||
| 1994 | "Supplied size outside [0, 0x0FFFFFFF] range. out_process_ids_size={}", | ||
| 1995 | out_process_ids_size); | ||
| 1996 | return ERR_OUT_OF_RANGE; | ||
| 1997 | } | ||
| 1998 | |||
| 1999 | const auto& kernel = Core::System::GetInstance().Kernel(); | ||
| 2000 | const auto& vm_manager = kernel.CurrentProcess()->VMManager(); | ||
| 2001 | const auto total_copy_size = out_process_ids_size * sizeof(u64); | ||
| 2002 | |||
| 2003 | if (out_process_ids_size > 0 && | ||
| 2004 | !vm_manager.IsWithinAddressSpace(out_process_ids, total_copy_size)) { | ||
| 2005 | LOG_ERROR(Kernel_SVC, "Address range outside address space. begin=0x{:016X}, end=0x{:016X}", | ||
| 2006 | out_process_ids, out_process_ids + total_copy_size); | ||
| 2007 | return ERR_INVALID_ADDRESS_STATE; | ||
| 2008 | } | ||
| 2009 | |||
| 2010 | const auto& process_list = kernel.GetProcessList(); | ||
| 2011 | const auto num_processes = process_list.size(); | ||
| 2012 | const auto copy_amount = std::min(std::size_t{out_process_ids_size}, num_processes); | ||
| 2013 | |||
| 2014 | for (std::size_t i = 0; i < copy_amount; ++i) { | ||
| 2015 | Memory::Write64(out_process_ids, process_list[i]->GetProcessID()); | ||
| 2016 | out_process_ids += sizeof(u64); | ||
| 2017 | } | ||
| 2018 | |||
| 2019 | *out_num_processes = static_cast<u32>(num_processes); | ||
| 2020 | return RESULT_SUCCESS; | ||
| 2021 | } | ||
| 2022 | |||
| 1986 | namespace { | 2023 | namespace { |
| 1987 | struct FunctionDef { | 2024 | struct FunctionDef { |
| 1988 | using Func = void(); | 2025 | using Func = void(); |
| @@ -2095,7 +2132,7 @@ static const FunctionDef SVC_Table[] = { | |||
| 2095 | {0x62, nullptr, "TerminateDebugProcess"}, | 2132 | {0x62, nullptr, "TerminateDebugProcess"}, |
| 2096 | {0x63, nullptr, "GetDebugEvent"}, | 2133 | {0x63, nullptr, "GetDebugEvent"}, |
| 2097 | {0x64, nullptr, "ContinueDebugEvent"}, | 2134 | {0x64, nullptr, "ContinueDebugEvent"}, |
| 2098 | {0x65, nullptr, "GetProcessList"}, | 2135 | {0x65, SvcWrap<GetProcessList>, "GetProcessList"}, |
| 2099 | {0x66, nullptr, "GetThreadList"}, | 2136 | {0x66, nullptr, "GetThreadList"}, |
| 2100 | {0x67, nullptr, "GetDebugThreadContext"}, | 2137 | {0x67, nullptr, "GetDebugThreadContext"}, |
| 2101 | {0x68, nullptr, "SetDebugThreadContext"}, | 2138 | {0x68, nullptr, "SetDebugThreadContext"}, |
diff --git a/src/core/hle/kernel/svc_wrap.h b/src/core/hle/kernel/svc_wrap.h index 2a2c2c5ea..b3733680f 100644 --- a/src/core/hle/kernel/svc_wrap.h +++ b/src/core/hle/kernel/svc_wrap.h | |||
| @@ -78,6 +78,14 @@ void SvcWrap() { | |||
| 78 | FuncReturn(retval); | 78 | FuncReturn(retval); |
| 79 | } | 79 | } |
| 80 | 80 | ||
| 81 | template <ResultCode func(u32*, u64, u32)> | ||
| 82 | void SvcWrap() { | ||
| 83 | u32 param_1 = 0; | ||
| 84 | const u32 retval = func(¶m_1, Param(1), static_cast<u32>(Param(2))).raw; | ||
| 85 | Core::CurrentArmInterface().SetReg(1, param_1); | ||
| 86 | FuncReturn(retval); | ||
| 87 | } | ||
| 88 | |||
| 81 | template <ResultCode func(u64*, u32)> | 89 | template <ResultCode func(u64*, u32)> |
| 82 | void SvcWrap() { | 90 | void SvcWrap() { |
| 83 | u64 param_1 = 0; | 91 | u64 param_1 = 0; |