diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/kernel/k_process.cpp | 11 | ||||
| -rw-r--r-- | src/core/hle/kernel/k_process.h | 3 | ||||
| -rw-r--r-- | src/core/hle/kernel/svc.cpp | 130 |
3 files changed, 64 insertions, 80 deletions
diff --git a/src/core/hle/kernel/k_process.cpp b/src/core/hle/kernel/k_process.cpp index d1dc62401..a1abf5d68 100644 --- a/src/core/hle/kernel/k_process.cpp +++ b/src/core/hle/kernel/k_process.cpp | |||
| @@ -285,6 +285,17 @@ void KProcess::UnregisterThread(KThread* thread) { | |||
| 285 | thread_list.remove(thread); | 285 | thread_list.remove(thread); |
| 286 | } | 286 | } |
| 287 | 287 | ||
| 288 | u64 KProcess::GetFreeThreadCount() const { | ||
| 289 | if (resource_limit != nullptr) { | ||
| 290 | const auto current_value = | ||
| 291 | resource_limit->GetCurrentValue(LimitableResource::ThreadCountMax); | ||
| 292 | const auto limit_value = resource_limit->GetLimitValue(LimitableResource::ThreadCountMax); | ||
| 293 | return limit_value - current_value; | ||
| 294 | } else { | ||
| 295 | return 0; | ||
| 296 | } | ||
| 297 | } | ||
| 298 | |||
| 288 | Result KProcess::Reset() { | 299 | Result KProcess::Reset() { |
| 289 | // Lock the process and the scheduler. | 300 | // Lock the process and the scheduler. |
| 290 | KScopedLightLock lk(state_lock); | 301 | KScopedLightLock lk(state_lock); |
diff --git a/src/core/hle/kernel/k_process.h b/src/core/hle/kernel/k_process.h index 2e0cc3d0b..09bf2f1d0 100644 --- a/src/core/hle/kernel/k_process.h +++ b/src/core/hle/kernel/k_process.h | |||
| @@ -304,6 +304,9 @@ public: | |||
| 304 | /// from this process' thread list. | 304 | /// from this process' thread list. |
| 305 | void UnregisterThread(KThread* thread); | 305 | void UnregisterThread(KThread* thread); |
| 306 | 306 | ||
| 307 | /// Retrieves the number of available threads for this process. | ||
| 308 | u64 GetFreeThreadCount() const; | ||
| 309 | |||
| 307 | /// Clears the signaled state of the process if and only if it's signaled. | 310 | /// Clears the signaled state of the process if and only if it's signaled. |
| 308 | /// | 311 | /// |
| 309 | /// @pre The process must not be already terminated. If this is called on a | 312 | /// @pre The process must not be already terminated. If this is called on a |
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index e520cab47..788ee2160 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp | |||
| @@ -784,63 +784,29 @@ static Result GetInfo(Core::System& system, u64* result, u64 info_id, Handle han | |||
| 784 | LOG_TRACE(Kernel_SVC, "called info_id=0x{:X}, info_sub_id=0x{:X}, handle=0x{:08X}", info_id, | 784 | LOG_TRACE(Kernel_SVC, "called info_id=0x{:X}, info_sub_id=0x{:X}, handle=0x{:08X}", info_id, |
| 785 | info_sub_id, handle); | 785 | info_sub_id, handle); |
| 786 | 786 | ||
| 787 | enum class GetInfoType : u64 { | 787 | const auto info_id_type = static_cast<InfoType>(info_id); |
| 788 | // 1.0.0+ | ||
| 789 | AllowedCPUCoreMask = 0, | ||
| 790 | AllowedThreadPriorityMask = 1, | ||
| 791 | MapRegionBaseAddr = 2, | ||
| 792 | MapRegionSize = 3, | ||
| 793 | HeapRegionBaseAddr = 4, | ||
| 794 | HeapRegionSize = 5, | ||
| 795 | TotalPhysicalMemoryAvailable = 6, | ||
| 796 | TotalPhysicalMemoryUsed = 7, | ||
| 797 | IsCurrentProcessBeingDebugged = 8, | ||
| 798 | RegisterResourceLimit = 9, | ||
| 799 | IdleTickCount = 10, | ||
| 800 | RandomEntropy = 11, | ||
| 801 | ThreadTickCount = 0xF0000002, | ||
| 802 | // 2.0.0+ | ||
| 803 | ASLRRegionBaseAddr = 12, | ||
| 804 | ASLRRegionSize = 13, | ||
| 805 | StackRegionBaseAddr = 14, | ||
| 806 | StackRegionSize = 15, | ||
| 807 | // 3.0.0+ | ||
| 808 | SystemResourceSize = 16, | ||
| 809 | SystemResourceUsage = 17, | ||
| 810 | TitleId = 18, | ||
| 811 | // 4.0.0+ | ||
| 812 | PrivilegedProcessId = 19, | ||
| 813 | // 5.0.0+ | ||
| 814 | UserExceptionContextAddr = 20, | ||
| 815 | // 6.0.0+ | ||
| 816 | TotalPhysicalMemoryAvailableWithoutSystemResource = 21, | ||
| 817 | TotalPhysicalMemoryUsedWithoutSystemResource = 22, | ||
| 818 | |||
| 819 | // Homebrew only | ||
| 820 | MesosphereCurrentProcess = 65001, | ||
| 821 | }; | ||
| 822 | |||
| 823 | const auto info_id_type = static_cast<GetInfoType>(info_id); | ||
| 824 | 788 | ||
| 825 | switch (info_id_type) { | 789 | switch (info_id_type) { |
| 826 | case GetInfoType::AllowedCPUCoreMask: | 790 | case InfoType::CoreMask: |
| 827 | case GetInfoType::AllowedThreadPriorityMask: | 791 | case InfoType::PriorityMask: |
| 828 | case GetInfoType::MapRegionBaseAddr: | 792 | case InfoType::AliasRegionAddress: |
| 829 | case GetInfoType::MapRegionSize: | 793 | case InfoType::AliasRegionSize: |
| 830 | case GetInfoType::HeapRegionBaseAddr: | 794 | case InfoType::HeapRegionAddress: |
| 831 | case GetInfoType::HeapRegionSize: | 795 | case InfoType::HeapRegionSize: |
| 832 | case GetInfoType::ASLRRegionBaseAddr: | 796 | case InfoType::AslrRegionAddress: |
| 833 | case GetInfoType::ASLRRegionSize: | 797 | case InfoType::AslrRegionSize: |
| 834 | case GetInfoType::StackRegionBaseAddr: | 798 | case InfoType::StackRegionAddress: |
| 835 | case GetInfoType::StackRegionSize: | 799 | case InfoType::StackRegionSize: |
| 836 | case GetInfoType::TotalPhysicalMemoryAvailable: | 800 | case InfoType::TotalMemorySize: |
| 837 | case GetInfoType::TotalPhysicalMemoryUsed: | 801 | case InfoType::UsedMemorySize: |
| 838 | case GetInfoType::SystemResourceSize: | 802 | case InfoType::SystemResourceSizeTotal: |
| 839 | case GetInfoType::SystemResourceUsage: | 803 | case InfoType::SystemResourceSizeUsed: |
| 840 | case GetInfoType::TitleId: | 804 | case InfoType::ProgramId: |
| 841 | case GetInfoType::UserExceptionContextAddr: | 805 | case InfoType::UserExceptionContextAddress: |
| 842 | case GetInfoType::TotalPhysicalMemoryAvailableWithoutSystemResource: | 806 | case InfoType::TotalNonSystemMemorySize: |
| 843 | case GetInfoType::TotalPhysicalMemoryUsedWithoutSystemResource: { | 807 | case InfoType::UsedNonSystemMemorySize: |
| 808 | case InfoType::IsApplication: | ||
| 809 | case InfoType::FreeThreadCount: { | ||
| 844 | if (info_sub_id != 0) { | 810 | if (info_sub_id != 0) { |
| 845 | LOG_ERROR(Kernel_SVC, "Info sub id is non zero! info_id={}, info_sub_id={}", info_id, | 811 | LOG_ERROR(Kernel_SVC, "Info sub id is non zero! info_id={}, info_sub_id={}", info_id, |
| 846 | info_sub_id); | 812 | info_sub_id); |
| @@ -856,79 +822,83 @@ static Result GetInfo(Core::System& system, u64* result, u64 info_id, Handle han | |||
| 856 | } | 822 | } |
| 857 | 823 | ||
| 858 | switch (info_id_type) { | 824 | switch (info_id_type) { |
| 859 | case GetInfoType::AllowedCPUCoreMask: | 825 | case InfoType::CoreMask: |
| 860 | *result = process->GetCoreMask(); | 826 | *result = process->GetCoreMask(); |
| 861 | return ResultSuccess; | 827 | return ResultSuccess; |
| 862 | 828 | ||
| 863 | case GetInfoType::AllowedThreadPriorityMask: | 829 | case InfoType::PriorityMask: |
| 864 | *result = process->GetPriorityMask(); | 830 | *result = process->GetPriorityMask(); |
| 865 | return ResultSuccess; | 831 | return ResultSuccess; |
| 866 | 832 | ||
| 867 | case GetInfoType::MapRegionBaseAddr: | 833 | case InfoType::AliasRegionAddress: |
| 868 | *result = process->PageTable().GetAliasRegionStart(); | 834 | *result = process->PageTable().GetAliasRegionStart(); |
| 869 | return ResultSuccess; | 835 | return ResultSuccess; |
| 870 | 836 | ||
| 871 | case GetInfoType::MapRegionSize: | 837 | case InfoType::AliasRegionSize: |
| 872 | *result = process->PageTable().GetAliasRegionSize(); | 838 | *result = process->PageTable().GetAliasRegionSize(); |
| 873 | return ResultSuccess; | 839 | return ResultSuccess; |
| 874 | 840 | ||
| 875 | case GetInfoType::HeapRegionBaseAddr: | 841 | case InfoType::HeapRegionAddress: |
| 876 | *result = process->PageTable().GetHeapRegionStart(); | 842 | *result = process->PageTable().GetHeapRegionStart(); |
| 877 | return ResultSuccess; | 843 | return ResultSuccess; |
| 878 | 844 | ||
| 879 | case GetInfoType::HeapRegionSize: | 845 | case InfoType::HeapRegionSize: |
| 880 | *result = process->PageTable().GetHeapRegionSize(); | 846 | *result = process->PageTable().GetHeapRegionSize(); |
| 881 | return ResultSuccess; | 847 | return ResultSuccess; |
| 882 | 848 | ||
| 883 | case GetInfoType::ASLRRegionBaseAddr: | 849 | case InfoType::AslrRegionAddress: |
| 884 | *result = process->PageTable().GetAliasCodeRegionStart(); | 850 | *result = process->PageTable().GetAliasCodeRegionStart(); |
| 885 | return ResultSuccess; | 851 | return ResultSuccess; |
| 886 | 852 | ||
| 887 | case GetInfoType::ASLRRegionSize: | 853 | case InfoType::AslrRegionSize: |
| 888 | *result = process->PageTable().GetAliasCodeRegionSize(); | 854 | *result = process->PageTable().GetAliasCodeRegionSize(); |
| 889 | return ResultSuccess; | 855 | return ResultSuccess; |
| 890 | 856 | ||
| 891 | case GetInfoType::StackRegionBaseAddr: | 857 | case InfoType::StackRegionAddress: |
| 892 | *result = process->PageTable().GetStackRegionStart(); | 858 | *result = process->PageTable().GetStackRegionStart(); |
| 893 | return ResultSuccess; | 859 | return ResultSuccess; |
| 894 | 860 | ||
| 895 | case GetInfoType::StackRegionSize: | 861 | case InfoType::StackRegionSize: |
| 896 | *result = process->PageTable().GetStackRegionSize(); | 862 | *result = process->PageTable().GetStackRegionSize(); |
| 897 | return ResultSuccess; | 863 | return ResultSuccess; |
| 898 | 864 | ||
| 899 | case GetInfoType::TotalPhysicalMemoryAvailable: | 865 | case InfoType::TotalMemorySize: |
| 900 | *result = process->GetTotalPhysicalMemoryAvailable(); | 866 | *result = process->GetTotalPhysicalMemoryAvailable(); |
| 901 | return ResultSuccess; | 867 | return ResultSuccess; |
| 902 | 868 | ||
| 903 | case GetInfoType::TotalPhysicalMemoryUsed: | 869 | case InfoType::UsedMemorySize: |
| 904 | *result = process->GetTotalPhysicalMemoryUsed(); | 870 | *result = process->GetTotalPhysicalMemoryUsed(); |
| 905 | return ResultSuccess; | 871 | return ResultSuccess; |
| 906 | 872 | ||
| 907 | case GetInfoType::SystemResourceSize: | 873 | case InfoType::SystemResourceSizeTotal: |
| 908 | *result = process->GetSystemResourceSize(); | 874 | *result = process->GetSystemResourceSize(); |
| 909 | return ResultSuccess; | 875 | return ResultSuccess; |
| 910 | 876 | ||
| 911 | case GetInfoType::SystemResourceUsage: | 877 | case InfoType::SystemResourceSizeUsed: |
| 912 | LOG_WARNING(Kernel_SVC, "(STUBBED) Attempted to query system resource usage"); | 878 | LOG_WARNING(Kernel_SVC, "(STUBBED) Attempted to query system resource usage"); |
| 913 | *result = process->GetSystemResourceUsage(); | 879 | *result = process->GetSystemResourceUsage(); |
| 914 | return ResultSuccess; | 880 | return ResultSuccess; |
| 915 | 881 | ||
| 916 | case GetInfoType::TitleId: | 882 | case InfoType::ProgramId: |
| 917 | *result = process->GetProgramID(); | 883 | *result = process->GetProgramID(); |
| 918 | return ResultSuccess; | 884 | return ResultSuccess; |
| 919 | 885 | ||
| 920 | case GetInfoType::UserExceptionContextAddr: | 886 | case InfoType::UserExceptionContextAddress: |
| 921 | *result = process->GetProcessLocalRegionAddress(); | 887 | *result = process->GetProcessLocalRegionAddress(); |
| 922 | return ResultSuccess; | 888 | return ResultSuccess; |
| 923 | 889 | ||
| 924 | case GetInfoType::TotalPhysicalMemoryAvailableWithoutSystemResource: | 890 | case InfoType::TotalNonSystemMemorySize: |
| 925 | *result = process->GetTotalPhysicalMemoryAvailableWithoutSystemResource(); | 891 | *result = process->GetTotalPhysicalMemoryAvailableWithoutSystemResource(); |
| 926 | return ResultSuccess; | 892 | return ResultSuccess; |
| 927 | 893 | ||
| 928 | case GetInfoType::TotalPhysicalMemoryUsedWithoutSystemResource: | 894 | case InfoType::UsedNonSystemMemorySize: |
| 929 | *result = process->GetTotalPhysicalMemoryUsedWithoutSystemResource(); | 895 | *result = process->GetTotalPhysicalMemoryUsedWithoutSystemResource(); |
| 930 | return ResultSuccess; | 896 | return ResultSuccess; |
| 931 | 897 | ||
| 898 | case InfoType::FreeThreadCount: | ||
| 899 | *result = process->GetFreeThreadCount(); | ||
| 900 | return ResultSuccess; | ||
| 901 | |||
| 932 | default: | 902 | default: |
| 933 | break; | 903 | break; |
| 934 | } | 904 | } |
| @@ -937,11 +907,11 @@ static Result GetInfo(Core::System& system, u64* result, u64 info_id, Handle han | |||
| 937 | return ResultInvalidEnumValue; | 907 | return ResultInvalidEnumValue; |
| 938 | } | 908 | } |
| 939 | 909 | ||
| 940 | case GetInfoType::IsCurrentProcessBeingDebugged: | 910 | case InfoType::DebuggerAttached: |
| 941 | *result = 0; | 911 | *result = 0; |
| 942 | return ResultSuccess; | 912 | return ResultSuccess; |
| 943 | 913 | ||
| 944 | case GetInfoType::RegisterResourceLimit: { | 914 | case InfoType::ResourceLimit: { |
| 945 | if (handle != 0) { | 915 | if (handle != 0) { |
| 946 | LOG_ERROR(Kernel, "Handle is non zero! handle={:08X}", handle); | 916 | LOG_ERROR(Kernel, "Handle is non zero! handle={:08X}", handle); |
| 947 | return ResultInvalidHandle; | 917 | return ResultInvalidHandle; |
| @@ -969,7 +939,7 @@ static Result GetInfo(Core::System& system, u64* result, u64 info_id, Handle han | |||
| 969 | return ResultSuccess; | 939 | return ResultSuccess; |
| 970 | } | 940 | } |
| 971 | 941 | ||
| 972 | case GetInfoType::RandomEntropy: | 942 | case InfoType::RandomEntropy: |
| 973 | if (handle != 0) { | 943 | if (handle != 0) { |
| 974 | LOG_ERROR(Kernel_SVC, "Process Handle is non zero, expected 0 result but got {:016X}", | 944 | LOG_ERROR(Kernel_SVC, "Process Handle is non zero, expected 0 result but got {:016X}", |
| 975 | handle); | 945 | handle); |
| @@ -985,13 +955,13 @@ static Result GetInfo(Core::System& system, u64* result, u64 info_id, Handle han | |||
| 985 | *result = system.Kernel().CurrentProcess()->GetRandomEntropy(info_sub_id); | 955 | *result = system.Kernel().CurrentProcess()->GetRandomEntropy(info_sub_id); |
| 986 | return ResultSuccess; | 956 | return ResultSuccess; |
| 987 | 957 | ||
| 988 | case GetInfoType::PrivilegedProcessId: | 958 | case InfoType::InitialProcessIdRange: |
| 989 | LOG_WARNING(Kernel_SVC, | 959 | LOG_WARNING(Kernel_SVC, |
| 990 | "(STUBBED) Attempted to query privileged process id bounds, returned 0"); | 960 | "(STUBBED) Attempted to query privileged process id bounds, returned 0"); |
| 991 | *result = 0; | 961 | *result = 0; |
| 992 | return ResultSuccess; | 962 | return ResultSuccess; |
| 993 | 963 | ||
| 994 | case GetInfoType::ThreadTickCount: { | 964 | case InfoType::ThreadTickCount: { |
| 995 | constexpr u64 num_cpus = 4; | 965 | constexpr u64 num_cpus = 4; |
| 996 | if (info_sub_id != 0xFFFFFFFFFFFFFFFF && info_sub_id >= num_cpus) { | 966 | if (info_sub_id != 0xFFFFFFFFFFFFFFFF && info_sub_id >= num_cpus) { |
| 997 | LOG_ERROR(Kernel_SVC, "Core count is out of range, expected {} but got {}", num_cpus, | 967 | LOG_ERROR(Kernel_SVC, "Core count is out of range, expected {} but got {}", num_cpus, |
| @@ -1026,7 +996,7 @@ static Result GetInfo(Core::System& system, u64* result, u64 info_id, Handle han | |||
| 1026 | *result = out_ticks; | 996 | *result = out_ticks; |
| 1027 | return ResultSuccess; | 997 | return ResultSuccess; |
| 1028 | } | 998 | } |
| 1029 | case GetInfoType::IdleTickCount: { | 999 | case InfoType::IdleTickCount: { |
| 1030 | // Verify the input handle is invalid. | 1000 | // Verify the input handle is invalid. |
| 1031 | R_UNLESS(handle == InvalidHandle, ResultInvalidHandle); | 1001 | R_UNLESS(handle == InvalidHandle, ResultInvalidHandle); |
| 1032 | 1002 | ||
| @@ -1040,7 +1010,7 @@ static Result GetInfo(Core::System& system, u64* result, u64 info_id, Handle han | |||
| 1040 | *result = system.Kernel().CurrentScheduler()->GetIdleThread()->GetCpuTime(); | 1010 | *result = system.Kernel().CurrentScheduler()->GetIdleThread()->GetCpuTime(); |
| 1041 | return ResultSuccess; | 1011 | return ResultSuccess; |
| 1042 | } | 1012 | } |
| 1043 | case GetInfoType::MesosphereCurrentProcess: { | 1013 | case InfoType::MesosphereCurrentProcess: { |
| 1044 | // Verify the input handle is invalid. | 1014 | // Verify the input handle is invalid. |
| 1045 | R_UNLESS(handle == InvalidHandle, ResultInvalidHandle); | 1015 | R_UNLESS(handle == InvalidHandle, ResultInvalidHandle); |
| 1046 | 1016 | ||