Skip to content

Commit 3b29a8a

Browse files
authored
[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` ![image](https://github.com/user-attachments/assets/19b4e073-16a5-4daa-95ed-2cf4830c042f)
1 parent aad2565 commit 3b29a8a

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

compiler-rt/lib/fuzzer/FuzzerUtilPosix.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,19 @@ bool ExecuteCommand(const Command &Cmd, std::string *CmdOutput) {
104104
}
105105

106106
void SetTimer(int Seconds) {
107-
struct itimerval T {
107+
timer_t TimerId;
108+
struct itimerspec T {
108109
{Seconds, 0}, { Seconds, 0 }
109110
};
110-
if (setitimer(ITIMER_REAL, &T, nullptr)) {
111-
Printf("libFuzzer: setitimer failed with %d\n", errno);
111+
SetSigaction(SIGALRM, AlarmHandler);
112+
if (timer_create(CLOCK_REALTIME, nullptr, &TimerId) == -1) {
113+
Printf("libFuzzer: timer_create failed with %d\n", errno);
114+
exit(1);
115+
}
116+
if (timer_settime(TimerId, 0, &T, nullptr) == -1) {
117+
Printf("libFuzzer: timer_settime failed with %d\n", errno);
112118
exit(1);
113119
}
114-
SetSigaction(SIGALRM, AlarmHandler);
115120
}
116121

117122
void SetSignalHandler(const FuzzingOptions& Options) {

0 commit comments

Comments
 (0)