Files
jami-daemon/test/fuzzing/common.h
Olivier Dion 91adbe56f2 fuzzing/common: Common definitions
Change-Id: I5a3718b9c19800bd6615b52a050f6f443394136e
2021-06-25 11:51:27 -04:00

47 lines
1.7 KiB
C++

#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]))