23 #ifdef STATS_HAS_HIGHRES_TIMER 24 static INT64 gStatCallTimeNs;
41 #define __stats_case(x) case x: return &(#x[5]) 114 return "<err_counter>";
131 #ifndef STATS_HAS_HIGHRES_TIMER 134 clock_gettime(CLOCK_MONOTONIC, Time);
153 #ifdef STATS_HAS_HIGHRES_TIMER 154 if (
__likely(End->tv_nsec > Start->tv_nsec))
156 Result->tv_sec = End->tv_sec - Start->tv_sec;
157 Result->tv_nsec = End->tv_nsec - Start->tv_nsec;
161 Result->tv_sec = End->tv_sec - Start->tv_sec - 1;
162 Result->tv_nsec =
NSEC_PER_SEC + End->tv_nsec - Start->tv_nsec;
165 *Result = *End - *Start;
180 #ifdef STATS_HAS_HIGHRES_TIMER 183 if (gCounters[i].StartEventId ==
gEventId)
185 gCounters[i].StatCalls++;
204 #ifdef STATS_HAS_HIGHRES_TIMER 205 Time->tv_sec += Adder->tv_sec;
206 Time->tv_nsec += Adder->tv_nsec;
227 LOG(
"[STATS] Introspection stats (totaling %lld events):\n",
gEventId);
240 #if defined(STATS_DISABLE_TIMER) 243 #elif defined(STATS_HAS_HIGHRES_TIMER) 244 double t = (double)(pCounter->Total.tv_sec *
NSEC_PER_SEC +
245 pCounter->Total.tv_nsec) / (double)pCounter->
TotalCount;
254 snprintf(line,
sizeof(line),
255 "%25s: %8lld times - %4lu.%09lu (total) %4lld.%09lld (per exit) %4lld.%09lld (max)\n",
257 pCounter->Total.tv_sec, pCounter->Total.tv_nsec,
261 snprintf(line,
sizeof(line),
262 "%25s: %20llu CPU ticks %12llu times - %4.6f (total) %4.12f (per exit) %4.12f (max)\n",
289 #ifndef STATS_DISABLE_TIMER 291 pCounter->StartEventId = 0;
293 memset(&pCounter->Start, 0,
sizeof(pCounter->Start));
313 #ifndef STATS_DISABLE_TIMER 338 pCounter = &gCounters[StatId];
346 pCounter->StatCalls = 0;
375 if (pCounter->StartEventId !=
gEventId)
377 if (pCounter->StartEventId != 0)
379 ERROR(
"[ERROR] StartCount on event id %lld and stop on %lld for counter %d\n",
380 pCounter->StartEventId,
gEventId, StatId);
390 DiffTime(&end, &pCounter->Start, &total);
392 #ifndef STATS_HAS_HIGHRES_TIMER 394 if (total > pCounter->Max)
396 pCounter->Max = total;
402 QWORD statCallNs = pCounter->StatCalls * gStatCallTimeNs;
405 if (totalNs > statCallNs)
413 total.tv_nsec -= pCounter->StatCalls * gStatCallTimeNs;
418 if (totalNs > pCounter->Max)
420 pCounter->Max = totalNs;
423 #endif // STATS_HAS_HIGHRES_TIMER 427 pCounter->StartEventId = 0;
440 gCounters[StatId].StartEventId = 0;
441 gCounters[StatId].StatCalls = 0;
444 #endif // STATS_DISABLE_TIMER 457 #ifdef STATS_HAS_HIGHRES_TIMER 458 const DWORD calibrationCalls = 10000;
463 for (
DWORD i = 0; i < calibrationCalls; i++)
472 gStatCallTimeNs = (end.tv_nsec - start.tv_nsec) / calibrationCalls;
475 gStatCallTimeNs -= (gStatCallTimeNs / 10);
477 LOG(
"[DEBUG] Calibrated clock_gettime timer to %lld nanoseconds\n", gStatCallTimeNs);
Measures kernel mode exceptions checks.
void IntStatStop(STAT_ID StatId)
Stops a stat measurement.
STAT_COUNTER gCounters[statsMaxCounter]
The list of counters.
Measures IntWinHandleException invocations done for DEP violations.
Measures the integrity checks on the process security descriptor.
Measures the security descriptor DPI protection information gathering.
#define NSEC_TO_SEC(nsec)
Measures the pivoted stack DPI protection information gathering.
Measures CR violation exits.
Measures the debug flag DPI protection information gathering.
Measures page table writes emulation.
Measures user mode exceptions checks.
Measures page table writes.
Measures page tables integrity checks.
static __pure const char * IntStatGetName(STAT_ID StatId)
Returns the name of a STAT_ID.
Measures the instruction search done for the page table filtering agent.
Measures XCR violation exits.
Measures all EPT violations.
Measures reads done from the kernel EAT.
Measures the IntWinProcHandleCopyMemory detour handler.
Measures page table writes done by the VAS monitor.
Measures the checks done on SharedUserData.
Measures all the page table writes.
Measures the stolen token flag DPI protection information gathering.
Writes done from kernel mode over user mode.
Measures the DTR violation exits.
QWORD gEventId
The ID of the current event.
Measures the cases in which the stack trace mechanism encounters a JMP after a CALL.
Measures the thread start DPI protection information gathering.
static void AddToTime(TIMESPEC *Time, TIMESPEC const *Adder)
Adds two time values.
QWORD IntroActiveEventId
The event ID on which introcore became active.
Measures the process creation checks.
Measures the heap spray DPI protection information gathering.
Measures the EPT violations for which the instruction does a read and a write.
void IntStatsResetAll(void)
Resets all the stats.
Measures the execution handling on SharedUserData page.
Measures page table entries writes.
Measures event injections.
void IntStatsInit(void)
Initialization routine.
Measures the handling of VMCALL exits.
Measures the hook commits.
Measures the execution of EPT violation handlers.
Measures the INT3 exits generated by the page table filtering mechanism.
void IntStatDiscard(STAT_ID StatId)
Discards the current measurement for a stat counter.
Measures EPT violations generated while the guest was in kernel mode.
Measures the IntWinVadHandleCommit detour handler.
Measures the deletion of HOOK_REGION_DESCRIPTOR objects.
Measures the stack trace mechanism for 32-bit execution contexts.
void IntStatsDumpAll(void)
Prints all the non-zero stats.
Measures the handling of memory reads in which a write protection policy exists.
Measures the decoding of instructions that generate EPT violations.
void IntStatsReset(STAT_ID StatId)
Resets a stat.
Measures the checks to see if the token has been changed when a token swap occurs.
Measures EPT violations generated while the guest was in user mode.
Measures the INT3 events.
Measures page table writes that are actually relevant for Introcore.
static void DiffTime(TIMESPEC const *End, TIMESPEC const *Start, TIMESPEC *Result)
Computes the delta between two time values.
Measures the checks to see if the token has been changed when a write occurs over the token...
static void IncStatsCallsCount(void)
Computes the time GetTime was called for each counter that was started before this one and on this ev...
Measures the timer events.
Measures the VMCALL exists generated by the page table filtering agent.
QWORD TotalCount
The total number of times an event was measured.
static uint64_t __rdtsc(void)
Measures IntWinProcHandleCopyMemory invocations done for memory reads.
Measures the self map entry validation.
The number of valid stats IDs. Not a valid ID. Must always be the last entry in the enum...
Measures the instruction search done for the SWAPGS protection.
Measures MSR violation exits.
GUEST_STATE gGuest
The current guest state.
Measures write EPT violations.
enum _STAT_ID STAT_ID
Stat IDs.
Measures the handling of memory reads in which a read protection policy exists.
void IntStatStart(STAT_ID StatId)
Starts a stat measurement.
QWORD TscSpeed
Number of ticks/second of this given guest. Should be the same as the global (physical) one...
Measures the look-up of EPT violation handlers.
Measures the information gathering for the DPI mechanism.
Measures exits on NtSetInformationProcess.
static void GetTime(TIMESPEC *Time)
Returns the current time.
Measures module load violation handling.
Measures user mode crash handlers.
Measures execute EPT violations.
Measures glob-match exceptions.
Measures read EPT violations.
Measures the deletion of HOOK_GVA objects.
Measures the token privileges DPI protection information gathering.