Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / tools / lib / bpf / libbpf_common.h
blob947d8bd8a7bb63e03524bfc8d916b23674acd230
1 /* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */
3 /*
4 * Common user-facing libbpf helpers.
6 * Copyright (c) 2019 Facebook
7 */
9 #ifndef __LIBBPF_LIBBPF_COMMON_H
10 #define __LIBBPF_LIBBPF_COMMON_H
12 #include <string.h>
14 #ifndef LIBBPF_API
15 #define LIBBPF_API __attribute__((visibility("default")))
16 #endif
18 #define LIBBPF_DEPRECATED(msg) __attribute__((deprecated(msg)))
20 /* Helper macro to declare and initialize libbpf options struct
22 * This dance with uninitialized declaration, followed by memset to zero,
23 * followed by assignment using compound literal syntax is done to preserve
24 * ability to use a nice struct field initialization syntax and **hopefully**
25 * have all the padding bytes initialized to zero. It's not guaranteed though,
26 * when copying literal, that compiler won't copy garbage in literal's padding
27 * bytes, but that's the best way I've found and it seems to work in practice.
29 * Macro declares opts struct of given type and name, zero-initializes,
30 * including any extra padding, it with memset() and then assigns initial
31 * values provided by users in struct initializer-syntax as varargs.
33 #define DECLARE_LIBBPF_OPTS(TYPE, NAME, ...) \
34 struct TYPE NAME = ({ \
35 memset(&NAME, 0, sizeof(struct TYPE)); \
36 (struct TYPE) { \
37 .sz = sizeof(struct TYPE), \
38 __VA_ARGS__ \
39 }; \
42 #endif /* __LIBBPF_LIBBPF_COMMON_H */