From 7c380a6612f00e4a7ed02364dc2b3769e8edc8f8 Mon Sep 17 00:00:00 2001 From: carpintero-de-c <175505615+carpintero-de-c@users.noreply.github.com> Date: Sun, 14 Jul 2024 03:55:58 +0530 Subject: Replace gettimeofday with clock_gettime (#2159) --- src/afl-common.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'src/afl-common.c') diff --git a/src/afl-common.c b/src/afl-common.c index efdb5d60..62432158 100644 --- a/src/afl-common.c +++ b/src/afl-common.c @@ -976,12 +976,11 @@ void read_bitmap(u8 *fname, u8 *map, size_t len) { inline u64 get_cur_time(void) { - struct timeval tv; - struct timezone tz; + struct timespec spec; - gettimeofday(&tv, &tz); + clock_gettime(CLOCK_REALTIME, &spec); - return (tv.tv_sec * 1000ULL) + (tv.tv_usec / 1000); + return (spec.tv_sec * 1000ULL) + (spec.tv_nsec / 1000000ULL); } @@ -989,19 +988,17 @@ inline u64 get_cur_time(void) { inline u64 get_cur_time_us(void) { - struct timeval tv; - struct timezone tz; + struct timespec spec; - gettimeofday(&tv, &tz); + clock_gettime(CLOCK_REALTIME, &spec); - return (tv.tv_sec * 1000000ULL) + tv.tv_usec; + return (spec.tv_sec * 1000000ULL) + (spec.tv_nsec / 1000ULL); } /* Describe integer. The buf should be at least 6 bytes to fit all ints we randomly see. Will return buf for convenience. */ - u8 *stringify_int(u8 *buf, size_t len, u64 val) { \ #define CHK_FORMAT(_divisor, _limit_mult, _fmt, _cast) \ -- cgit v1.2.3 From ccb952dde8dbf2165a0d84308e558cd68679fb13 Mon Sep 17 00:00:00 2001 From: vanhauser-thc Date: Sun, 14 Jul 2024 10:18:23 +0200 Subject: Revert "Replace gettimeofday with clock_gettime (#2159)" This reverts commit 7c380a6612f00e4a7ed02364dc2b3769e8edc8f8. --- src/afl-common.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/afl-common.c') diff --git a/src/afl-common.c b/src/afl-common.c index 62432158..efdb5d60 100644 --- a/src/afl-common.c +++ b/src/afl-common.c @@ -976,11 +976,12 @@ void read_bitmap(u8 *fname, u8 *map, size_t len) { inline u64 get_cur_time(void) { - struct timespec spec; + struct timeval tv; + struct timezone tz; - clock_gettime(CLOCK_REALTIME, &spec); + gettimeofday(&tv, &tz); - return (spec.tv_sec * 1000ULL) + (spec.tv_nsec / 1000000ULL); + return (tv.tv_sec * 1000ULL) + (tv.tv_usec / 1000); } @@ -988,17 +989,19 @@ inline u64 get_cur_time(void) { inline u64 get_cur_time_us(void) { - struct timespec spec; + struct timeval tv; + struct timezone tz; - clock_gettime(CLOCK_REALTIME, &spec); + gettimeofday(&tv, &tz); - return (spec.tv_sec * 1000000ULL) + (spec.tv_nsec / 1000ULL); + return (tv.tv_sec * 1000000ULL) + tv.tv_usec; } /* Describe integer. The buf should be at least 6 bytes to fit all ints we randomly see. Will return buf for convenience. */ + u8 *stringify_int(u8 *buf, size_t len, u64 val) { \ #define CHK_FORMAT(_divisor, _limit_mult, _fmt, _cast) \ -- cgit v1.2.3 From 69a596c0898e3ae295c4f606857ed2ca6d8d0605 Mon Sep 17 00:00:00 2001 From: vanhauser-thc Date: Sun, 14 Jul 2024 10:20:53 +0200 Subject: ensure this does not happen again --- src/afl-common.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/afl-common.c') diff --git a/src/afl-common.c b/src/afl-common.c index efdb5d60..04a984cb 100644 --- a/src/afl-common.c +++ b/src/afl-common.c @@ -979,6 +979,7 @@ inline u64 get_cur_time(void) { struct timeval tv; struct timezone tz; + // TO NOT REPLACE WITH clock_gettime!!! gettimeofday(&tv, &tz); return (tv.tv_sec * 1000ULL) + (tv.tv_usec / 1000); @@ -992,6 +993,7 @@ inline u64 get_cur_time_us(void) { struct timeval tv; struct timezone tz; + // TO NOT REPLACE WITH clock_gettime!!! gettimeofday(&tv, &tz); return (tv.tv_sec * 1000000ULL) + tv.tv_usec; -- cgit v1.2.3