fuzzing/common: Common definitions

Change-Id: I5a3718b9c19800bd6615b52a050f6f443394136e
This commit is contained in:
Olivier Dion
2021-06-10 15:06:43 -04:00
parent c9757b595d
commit 91adbe56f2
2 changed files with 47 additions and 1 deletions

View File

@ -1,6 +1,6 @@
include $(top_srcdir)/globals.mk
AM_CXXFLAGS += -I$(top_srcdir)/src -I.
AM_CXXFLAGS += -I$(top_srcdir)/src -I. -include common.h
AM_LDFLAGS += $(top_builddir)/src/libring.la
check_PROGRAMS =

46
test/fuzzing/common.h Normal file
View File

@ -0,0 +1,46 @@
#pragma once
#ifndef _GNU_SOURCE
# define _GNU_SOURCE
#endif
#include <cassert>
#include <cstdint>
#include <cstring>
#include <vector>
#include <dlfcn.h>
static inline bool
streq(const char* A, const char* B)
{
return 0 == strcmp(A, B);
}
#define BEGIN_WRAPPER_PRIMITIVE(SYM, RET, NAME, ARGS...) \
RET NAME(ARGS) \
{ \
RET (*this_func)(ARGS) = nullptr; \
\
if (nullptr == this_func) { \
this_func = (typeof(this_func)) dlsym(RTLD_NEXT, #SYM); \
assert(this_func); \
}
#define BEGIN_METHOD_WRAPPER(SYM, RET, NAME, ARGS...) \
RET NAME(ARGS) \
{ \
RET (*this_func)(typeof(this), ##ARGS) = nullptr; \
\
if (nullptr == this_func) { \
this_func = (typeof(this_func)) dlsym(RTLD_NEXT, #SYM); \
assert(this_func); \
}
#define BEGIN_WRAPPER(RET, NAME, ARGS...) BEGIN_WRAPPER_PRIMITIVE(NAME, RET, NAME, ARGS)
#define END_WRAPPER(ARGS...) } static_assert(true, "")
#define __weak __attribute__((weak))
#define __used __attribute__((used))
#define array_size(arr) (sizeof(arr) / sizeof((arr)[0]))