forked from usnistgov/ndn-dpdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.h
100 lines (82 loc) · 2.98 KB
/
common.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/**
* @mainpage
*
* https://github.com/usnistgov/ndn-dpdk
*/
#ifndef NDNDPDK_CORE_COMMON_H
#define NDNDPDK_CORE_COMMON_H
/** @file */
#if __INTELLISENSE__
// https://github.com/microsoft/vscode-cpptools/issues/4503
#pragma diag_suppress 1094
#endif
#include <assert.h>
#include <inttypes.h>
#include <limits.h>
#include <memory.h>
#include <stdatomic.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ALLOW_EXPERIMENTAL_API
#include <rte_config.h>
#include <rte_bitops.h>
#include <rte_branch_prediction.h>
#include <rte_common.h>
#ifndef __BPF__
#include <float.h>
#include <math.h>
#include <urcu/list.h>
#include <rte_byteorder.h>
#include <rte_cycles.h>
#include <rte_debug.h>
#include <rte_errno.h>
#include <rte_malloc.h>
#include <rte_memcpy.h>
#include <spdk/util.h>
#ifdef NDEBUG
#define NDNDPDK_ASSERT(x) \
do { \
if (__builtin_constant_p((x)) && !(x)) { \
__builtin_unreachable(); \
} \
} while (false)
#else
#define NDNDPDK_ASSERT(x) RTE_VERIFY((x))
#endif
#endif // __BPF__
#define STATIC_ASSERT_FUNC_TYPE(typ, func) \
static_assert(__builtin_types_compatible_p(typ, typeof(&func)), "")
#ifdef NDEBUG
#define NULLize(x) RTE_SET_USED(x)
#else
/** @brief Set x to NULL to expose memory access bugs. */
#define NULLize(x) \
do { \
(x) = NULL; \
} while (false)
#endif
#ifdef NDNDPDK_POISON
#define POISON_2_(x, size) memset(x, 0x99, size)
#else
#define POISON_2_(x, size) \
do { \
RTE_SET_USED(x); \
RTE_SET_USED(size); \
} while (false)
#endif
#define POISON_1_(x) POISON_2_((x), sizeof(*(x)))
#define POISON_Arg3_(a1, a2, a3, ...) a3
#define POISON_Choose_(...) POISON_Arg3_(__VA_ARGS__, POISON_2_, POISON_1_)
/**
* @brief Write junk to memory region to expose memory access bugs.
* @code
* POISON(&var);
* POISON(&var, sizeof(var));
* @endcode
*/
#define POISON(...) POISON_Choose_(__VA_ARGS__)(__VA_ARGS__)
#define CLAMP(x, lo, hi) RTE_MAX((lo), RTE_MIN((hi), (x)))
#endif // NDNDPDK_CORE_COMMON_H