Skip to content

Commit

Permalink
[libFuzzer] Implement Timers for Windows.
Browse files Browse the repository at this point in the history
Implemented timeouts for Windows using TimerQueueTimers.
Timers are used to supervise the time of execution of the
callback function that is being fuzzed.

Differential Revision: https://reviews.llvm.org/D27237

llvm-svn: 289495
  • Loading branch information
Marcos Pividori committed Dec 12, 2016
1 parent 295f940 commit 681e904
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion llvm/lib/Fuzzer/FuzzerUtilWindows.cpp
Expand Up @@ -95,8 +95,39 @@ BOOL WINAPI TERMHandler(DWORD dwCtrlType) {
}
}

void CALLBACK AlarmHandler(PVOID, BOOLEAN) {
Fuzzer::StaticAlarmCallback();
}

class TimerQ {
HANDLE TimerQueue;
public:
TimerQ() : TimerQueue(NULL) {};
~TimerQ() {
if (TimerQueue)
DeleteTimerQueueEx(TimerQueue, NULL);
};
void SetTimer(int Seconds) {
if (!TimerQueue) {
TimerQueue = CreateTimerQueue();
if (!TimerQueue) {
Printf("libFuzzer: CreateTimerQueue failed.\n");
exit(1);
}
}
HANDLE Timer;
if (!CreateTimerQueueTimer(&Timer, TimerQueue, AlarmHandler, NULL,
Seconds*1000, Seconds*1000, 0)) {
Printf("libFuzzer: CreateTimerQueueTimer failed.\n");
exit(1);
}
};
};

static TimerQ Timer;

void SetTimer(int Seconds) {
// TODO: Complete this implementation.
Timer.SetTimer(Seconds);
return;
}

Expand Down

0 comments on commit 681e904

Please sign in to comment.