diff options
Diffstat (limited to 'include/common.h')
-rw-r--r-- | include/common.h | 64 |
1 files changed, 51 insertions, 13 deletions
diff --git a/include/common.h b/include/common.h index 28c11049..8dd66355 100644 --- a/include/common.h +++ b/include/common.h @@ -27,10 +27,17 @@ #ifndef __AFLCOMMON_H #define __AFLCOMMON_H +#include <stdio.h> +#include <string.h> +#include <unistd.h> #include <sys/time.h> #include "types.h" #include "stdbool.h" +/* STRINGIFY_VAL_SIZE_MAX will fit all stringify_ strings. */ + +#define STRINGIFY_VAL_SIZE_MAX (16) + void detect_file_args(char **argv, u8 *prog_in, u8 *use_stdin); void check_environment_vars(char **env); @@ -41,31 +48,62 @@ char **get_qemu_argv(u8 *own_loc, u8 **target_path_p, int argc, char **argv); char **get_wine_argv(u8 *own_loc, u8 **target_path_p, int argc, char **argv); char * get_afl_env(char *env); +extern u8 be_quiet; +extern u8 *doc_path; /* path to documentation dir */ + /* Get unix time in milliseconds */ -static u64 get_cur_time(void) { +u64 get_cur_time(void); - struct timeval tv; - struct timezone tz; +/* Get unix time in microseconds */ - gettimeofday(&tv, &tz); +u64 get_cur_time_us(void); - return (tv.tv_sec * 1000ULL) + (tv.tv_usec / 1000); +/* 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); -/* Get unix time in microseconds */ +/* Describe float. Similar as int. */ + +u8 *stringify_float(u8 *buf, size_t len, double val); + +/* Describe integer as memory size. */ + +u8 *stringify_mem_size(u8 *buf, size_t len, u64 val); + +/* Describe time delta as string. + Returns a pointer to buf for convenience. */ + +u8 *stringify_time_diff(u8 *buf, size_t len, u64 cur_ms, u64 event_ms); + +/* Unsafe Describe integer. The buf sizes are not checked. + This is unsafe but fast. + Will return buf for convenience. */ + +u8 *u_stringify_int(u8 *buf, u64 val); + +/* Unsafe describe float. Similar as unsafe int. */ + +u8 *u_stringify_float(u8 *buf, double val); -static u64 get_cur_time_us(void) { +/* Unsafe describe integer as memory size. */ - struct timeval tv; - struct timezone tz; +u8 *u_stringify_mem_size(u8 *buf, u64 val); - gettimeofday(&tv, &tz); +/* Unsafe describe time delta as string. + Returns a pointer to buf for convenience. */ - return (tv.tv_sec * 1000000ULL) + tv.tv_usec; +u8 *u_stringify_time_diff(u8 *buf, u64 cur_ms, u64 event_ms); -} +/* Wrapper for select() and read(), reading exactly len bytes. + Returns the time passed to read. + stop_soon should point to a variable indicating ctrl+c was pressed. + If the wait times out, returns timeout_ms + 1; + Returns 0 if an error occurred (fd closed, signal, ...); */ +u32 read_timed(s32 fd, void *buf, size_t len, u32 timeout_ms, + volatile u8 *stop_soon_p); #endif |