mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-25 20:56:06 +00:00
[libfuzzer] use timer_create() instead of setitimer() for linux (#110274)
SetTimer() now uses setitimer() to sending SIGALRM every ` UnitTimeoutSec/2 + 1` s Set UnitTimeoutSec with the `-timeout=` option "POSIX.1-2008 marks getitimer() and setitimer() obsolete" and also has some issues regarding accuracy of the timers under load . See https://linux.die.net/man/2/setitimer. I propose using timer_create() and sigaction() ,See http://man7.org/linux/man-pages/man2/timer_create.2.html # test result on my x86_64 linux `make check-fuzzer` 
This commit is contained in:
parent
aad256598d
commit
3b29a8a008
@ -104,14 +104,19 @@ bool ExecuteCommand(const Command &Cmd, std::string *CmdOutput) {
|
||||
}
|
||||
|
||||
void SetTimer(int Seconds) {
|
||||
struct itimerval T {
|
||||
timer_t TimerId;
|
||||
struct itimerspec T {
|
||||
{Seconds, 0}, { Seconds, 0 }
|
||||
};
|
||||
if (setitimer(ITIMER_REAL, &T, nullptr)) {
|
||||
Printf("libFuzzer: setitimer failed with %d\n", errno);
|
||||
SetSigaction(SIGALRM, AlarmHandler);
|
||||
if (timer_create(CLOCK_REALTIME, nullptr, &TimerId) == -1) {
|
||||
Printf("libFuzzer: timer_create failed with %d\n", errno);
|
||||
exit(1);
|
||||
}
|
||||
if (timer_settime(TimerId, 0, &T, nullptr) == -1) {
|
||||
Printf("libFuzzer: timer_settime failed with %d\n", errno);
|
||||
exit(1);
|
||||
}
|
||||
SetSigaction(SIGALRM, AlarmHandler);
|
||||
}
|
||||
|
||||
void SetSignalHandler(const FuzzingOptions& Options) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user