im trying read rdtsc 1 nanosecond on kernel but the problem i cant read core 0 properly by those apis KeSetSystemGroupAffinityThread KeSetSystemAffinityThreadEx KeSetAffinityThread all those apis fail to read core 0 the only one that work for me was to create systemthread by using PsCreateSystemThread then read core 0 from ZwSetInformationThread may i ask why those apis fail to read core 0?
int64_t readcore()
{
KAFFINITY affinity = (1ULL);
return (int64_t)KeSetSystemAffinityThreadEx(affinity);
}
void readcore()
{
const ULONG numberOfProcessors = KeQueryActiveProcessorCountEx(ALL_PROCESSOR_GROUPS);
PROCESSOR_NUMBER processorNumber;
NTSTATUS status = KeGetProcessorNumberFromIndex(numberOfProcessors - 1, &processorNumber);
if (!NT_SUCCESS(status))
{
return;
}
GROUP_AFFINITY affinity, oldAffinity;
affinity.Group = processorNumber.Group;
affinity.Mask = 1ULL << processorNumber.Number;
affinity.Reserved[0] = affinity.Reserved[1] = affinity.Reserved[2] = 0;
KeSetSystemGroupAffinityThread(&affinity, &oldAffinity);
}
VOID switchToCPU(CCHAR cpu)
{
UNICODE_STRING ustrKeSetAffinityThread;
RtlInitUnicodeString(&ustrKeSetAffinityThread, L"KeSetAffinityThread");
KeSetAffinityThread = (_KeSetAffinityThread)MmGetSystemRoutineAddress(&ustrKeSetAffinityThread);
KeSetAffinityThread(KeGetCurrentThread(), 1 << cpu);
}