aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Horizon/Sdk/OsTypes/OsProcessHandle.cs
blob: c835be2c9942d3f61e6dbf2949ba185221456b80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using Ryujinx.Horizon.Common;

namespace Ryujinx.Horizon.Sdk.OsTypes
{
    static partial class Os
    {
        private const int SelfProcessHandle = (0x1ffff << 15) | 1;

        public static int GetCurrentProcessHandle()
        {
            return SelfProcessHandle;
        }

        public static ulong GetCurrentProcessId()
        {
            return GetProcessId(GetCurrentProcessHandle());
        }

        private static ulong GetProcessId(int handle)
        {
            Result result = TryGetProcessId(handle, out ulong pid);

            result.AbortOnFailure();

            return pid;
        }

        private static Result TryGetProcessId(int handle, out ulong pid)
        {
            return HorizonStatic.Syscall.GetProcessId(out pid, handle);
        }
    }
}