Add enums for GetInfo/GetSystemInfo (#292)

This commit is contained in:
SciresM 2019-06-21 15:05:56 -07:00 committed by fincs
parent 9c887a13b4
commit e1a6a463c2
6 changed files with 75 additions and 15 deletions

View File

@ -144,6 +144,66 @@ typedef enum {
DebugThreadParam_CoreMask=4,
} DebugThreadParam;
/// GetInfo IDs.
typedef enum {
InfoType_CoreMask = 0, ///< Bitmask of allowed Core IDs.
InfoType_PriorityMask = 1, ///< Bitmask of allowed Thread Priorities.
InfoType_AliasRegionAddress = 2, ///< Base of the Alias memory region.
InfoType_AliasRegionSize = 3, ///< Size of the Alias memory region.
InfoType_HeapRegionAddress = 4, ///< Base of the Heap memory region.
InfoType_HeapRegionSize = 5, ///< Size of the Heap memory region.
InfoType_TotalMemorySize = 6, ///< Total amount of memory available for process.
InfoType_UsedMemorySize = 7, ///< Amount of memory currently used by process.
InfoType_DebuggerAttached = 8, ///< Whether current process is being debugged.
InfoType_ResourceLimit = 9, ///< Current process's resource limit handle.
InfoType_IdleTickCount = 10, ///< Number of idle ticks on CPU.
InfoType_RandomEntropy = 11, ///< 2.0.0+ Random entropy for current process.
InfoType_AslrRegionAddress = 12, ///< 2.0.0+ Base of the process's address space.
InfoType_AslrRegionSize = 13, ///< 2.0.0+ Size of the process's address space.
InfoType_StackRegionAddress = 14, ///< 2.0.0+ Base of the Stack memory region.
InfoType_StackRegionSize = 15, ///< 2.0.0+ Size of the Stack memory region.
InfoType_SystemResourceSizeTotal = 16, ///< 3.0.0+ Total memory allocated for process memory management.
InfoType_SystemResourceSizeUsed = 17, ///< 3.0.0+ Amount of memory currently used by process memory management.
InfoType_TitleId = 18, ///< 3.0.0+ Title ID for the process.
InfoType_InitialProcessIdRange = 19, ///< 4.0.0-4.1.0 Min/max initial process IDs.
InfoType_UserExceptionContextAddress = 20, ///< 5.0.0+ Address of the process's exception context (for break).
InfoType_TotalNonSystemMemorySize = 21, ///< 6.0.0+ Total amount of memory available for process, excluding that for process memory management.
InfoType_UsedNonSystemMemorySize = 22, ///< 6.0.0+ Amount of memory used by process, excluding that for process memory management.
InfoType_ThreadTickCount = 0xF0000002, ///< Number of ticks spent on thread.
} InfoType;
/// GetSystemInfo IDs.
typedef enum {
SystemInfoType_TotalPhysicalMemorySize = 0, ///< Total amount of DRAM available to system.
SystemInfoType_UsedPhysicalMemorySize = 1, ///< Current amount of DRAM used by system.
SystemInfoType_InitialProcessIdRange = 2, ///< Min/max initial process IDs.
} SystemInfoType;
/// GetInfo Idle/Thread Tick Count Sub IDs.
typedef enum {
TickCountInfo_Core0 = 0, ///< Tick count on core 0.
TickCountInfo_Core1 = 1, ///< Tick count on core 1.
TickCountInfo_Core2 = 2, ///< Tick count on core 2.
TickCountInfo_Core3 = 3, ///< Tick count on core 3.
TickCountInfo_Total = U64_MAX, ///< Tick count on all cores.
} TickCountInfo;
/// GetInfo InitialProcessIdRange Sub IDs.
typedef enum {
InitialProcessIdRangeInfo_Minimum = 0, ///< Lowest initial process ID.
InitialProcessIdRangeInfo_Maximum = 1, ///< Highest initial process ID.
} InitialProcessIdRangeInfo;
/// GetSystemInfo PhysicalMemory Sub IDs.
typedef enum {
PhysicalMemoryInfo_Application = 0, ///< Memory allocated for application usage.
PhysicalMemoryInfo_Applet = 1, ///< Memory allocated for applet usage.
PhysicalMemoryInfo_System = 2, ///< Memory allocated for system usage.
PhysicalMemoryInfo_SystemUnsafe = 3, ///< Memory allocated for unsafe system usage (accessible to devices).
} PhysicalMemoryInfo;
///@name Memory management
///@{

View File

@ -28,15 +28,15 @@ static void _CacheVersion(void)
u64 tmp;
g_Version = 1;
if (R_VALUE(svcGetInfo(&tmp, 12, INVALID_HANDLE, 0)) != KERNELRESULT(InvalidEnumValue))
if (R_VALUE(svcGetInfo(&tmp, InfoType_AslrRegionAddress, INVALID_HANDLE, 0)) != KERNELRESULT(InvalidEnumValue))
g_Version = 2;
if (R_VALUE(svcGetInfo(&tmp, 18, INVALID_HANDLE, 0)) != KERNELRESULT(InvalidEnumValue))
if (R_VALUE(svcGetInfo(&tmp, InfoType_TitleId, INVALID_HANDLE, 0)) != KERNELRESULT(InvalidEnumValue))
g_Version = 3;
if (R_VALUE(svcGetInfo(&tmp, 19, INVALID_HANDLE, 0)) != KERNELRESULT(InvalidEnumValue))
if (R_VALUE(svcGetInfo(&tmp, InfoType_InitialProcessIdRange, INVALID_HANDLE, 0)) != KERNELRESULT(InvalidEnumValue))
g_Version = 4;
if (R_VALUE(svcGetInfo(&tmp, 20, INVALID_HANDLE, 0)) != KERNELRESULT(InvalidEnumValue))
if (R_VALUE(svcGetInfo(&tmp, InfoType_UserExceptionContextAddress, INVALID_HANDLE, 0)) != KERNELRESULT(InvalidEnumValue))
g_Version = 5;
if (R_VALUE(svcGetInfo(&tmp, 21, INVALID_HANDLE, 0)) != KERNELRESULT(InvalidEnumValue))
if (R_VALUE(svcGetInfo(&tmp, InfoType_TotalNonSystemMemorySize, INVALID_HANDLE, 0)) != KERNELRESULT(InvalidEnumValue))
g_Version = 6;
__atomic_store_n(&g_VersionCached, true, __ATOMIC_SEQ_CST);
@ -88,7 +88,7 @@ int detectKernelVersion(void) {
bool detectDebugger(void) {
u64 tmp;
svcGetInfo(&tmp, 8, 0, 0);
svcGetInfo(&tmp, InfoType_DebuggerAttached, INVALID_HANDLE, 0);
return !!tmp;
}

View File

@ -136,7 +136,7 @@ static void _randomInit(void)
for (i=0; i<4; i++)
{
// Get process TRNG seeds from kernel.
if (R_FAILED(svcGetInfo(&seed[i], 11, 0, i)))
if (R_FAILED(svcGetInfo(&seed[i], InfoType_RandomEntropy, INVALID_HANDLE, i)))
fatalSimple(MAKERESULT(Module_Libnx, LibnxError_BadGetInfo_Rng));
}

View File

@ -45,7 +45,7 @@ static inline bool _InRegion(VirtualRegion* r, u64 addr) {
}
void virtmemSetup(void) {
if (R_FAILED(_GetRegionFromInfo(&g_AddressSpace, 12, 13))) {
if (R_FAILED(_GetRegionFromInfo(&g_AddressSpace, InfoType_AslrRegionAddress, InfoType_AslrRegionSize))) {
// 1.0.0 doesn't expose address space size so we have to do this dirty hack to detect it.
// Forgive me.
@ -74,16 +74,16 @@ void virtmemSetup(void) {
fatalSimple(MAKERESULT(Module_Libnx, LibnxError_WeirdKernel));
}
} else {
if (R_FAILED(_GetRegionFromInfo(&g_Region[REGION_STACK], 14, 15))) {
if (R_FAILED(_GetRegionFromInfo(&g_Region[REGION_STACK], InfoType_StackRegionAddress, InfoType_StackRegionSize))) {
fatalSimple(MAKERESULT(Module_Libnx, LibnxError_BadGetInfo_Stack));
}
}
if (R_FAILED(_GetRegionFromInfo(&g_Region[REGION_HEAP], 4, 5))) {
if (R_FAILED(_GetRegionFromInfo(&g_Region[REGION_HEAP], InfoType_HeapRegionAddress, InfoType_HeapRegionSize))) {
fatalSimple(MAKERESULT(Module_Libnx, LibnxError_BadGetInfo_Heap));
}
}
_GetRegionFromInfo(&g_Region[REGION_LEGACY_ALIAS], 2, 3);
_GetRegionFromInfo(&g_Region[REGION_LEGACY_ALIAS], InfoType_AliasRegionAddress, InfoType_AliasRegionSize);
}
void* virtmemReserve(size_t size) {

View File

@ -72,8 +72,8 @@ void __attribute__((weak)) __libnx_initheap(void)
}
else {
if (__nx_heap_size==0) {
svcGetInfo(&mem_available, 6, CUR_PROCESS_HANDLE, 0);
svcGetInfo(&mem_used, 7, CUR_PROCESS_HANDLE, 0);
svcGetInfo(&mem_available, InfoType_TotalMemorySize, CUR_PROCESS_HANDLE, 0);
svcGetInfo(&mem_used, InfoType_UsedMemorySize, CUR_PROCESS_HANDLE, 0);
if (mem_available > mem_used+0x200000)
size = (mem_available - mem_used - 0x200000) & ~0x1FFFFF;
if (size==0)

View File

@ -179,7 +179,7 @@ int __syscall_thread_create(struct __pthread_t **thread, void* (*func)(void*), v
*thread = NULL;
u64 core_mask = 0;
rc = svcGetInfo(&core_mask, 0, CUR_PROCESS_HANDLE, 0);
rc = svcGetInfo(&core_mask, InfoType_CoreMask, CUR_PROCESS_HANDLE, 0);
if (R_FAILED(rc))
return EPERM;