HyperDbg/hyperdbg/include/platform/kernel/code/PlatformCpu.c
Max Raulea 953af9388a PlatformCPU Linux Implementation
Filled in the stubs for the windows functions:
KeQueryActiveProcessorCount(0) and KeGetCurrentProcessorNumberEx(NULL).
KeQueryActiveProcessorCount(0) maps one to one to num_online_cpus()
KeGetCurrentProcessorNumberEx(NULL) maps to raw_smp_processor_id(),
however this can also be smp_processor_id(), we have to decide based on
preemption, the latter checks for preemption and throws a warning if it
is executed in preemptible code. (I dont know the kernel code well
enough so this may need some discussion)
2026-08-01 16:54:08 +02:00

62 lines
1 KiB
C

/**
* @file PlatformCpu.c
* @author Sina Karvandi (sina@hyperdbg.org)
* @brief Implementation of cross platform APIs for CPU and processor queries
* @details
* @version 0.19
* @date 2026-05-09
*
* @copyright This project is released under the GNU Public License v3.
*
*/
#include "pch.h"
#if defined(__linux__)
# include "../header/PlatformCpu.h"
#endif // defined(__linux__)
/**
* @brief Get the count of active logical processors
*
* @return ULONG
*/
ULONG
PlatformCpuGetActiveProcessorCount(VOID)
{
#if defined(_WIN32) || defined(_WIN64)
return KeQueryActiveProcessorCount(0);
#elif defined(__linux__)
return num_online_cpus();
#else
# error "Unsupported platform"
#endif
}
/**
* @brief Get the current logical processor number
*
* @return ULONG
*/
ULONG
PlatformCpuGetCurrentProcessorNumber(VOID)
{
#if defined(_WIN32) || defined(_WIN64)
return KeGetCurrentProcessorNumberEx(NULL);
#elif defined(__linux__)
return raw_smp_processor_id();
#else
# error "Unsupported platform"
#endif
}