#include #include #include #include #include long SmartScheduleInterval = 20; /* ms */ long SmartScheduleTime = 0; static void SmartScheduleTimer(int sig) { SmartScheduleTime += SmartScheduleInterval; } void SmartScheduleStartTimer(void) { struct itimerval timer; timer.it_interval.tv_sec = 0; timer.it_interval.tv_usec = SmartScheduleInterval * 1000; timer.it_value.tv_sec = 0; timer.it_value.tv_usec = SmartScheduleInterval * 1000; setitimer(ITIMER_REAL, &timer, 0); } int main() { /* Set up the timer signal function */ struct sigaction act; act.sa_handler = SmartScheduleTimer; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGALRM); if (sigaction(SIGALRM, &act, 0) < 0) { perror("sigaction failed"); return -1; } HMODULE hMod = LoadLibraryEx("kernel32.dll", NULL, 0); assert(hMod); printf("hMod is %p\n", hMod); /* start timer */ SmartScheduleStartTimer(); /* Loop forever, spending most of our time inside ntdll */ int i = 0; while (1) { void *gpa = GetProcAddress(hMod, "GetProcAddress"); assert(gpa); i++; printf("iteration %d\n", i); } }