2019-12-13 17:43:29 -08:00
/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */
/*
* Common user - facing libbpf helpers .
*
* Copyright ( c ) 2019 Facebook
*/
# ifndef __LIBBPF_LIBBPF_COMMON_H
# define __LIBBPF_LIBBPF_COMMON_H
2019-12-17 12:28:10 +01:00
# include <string.h>
libbpf: Add LIBBPF_DEPRECATED_SINCE macro for scheduling API deprecations
Introduce a macro LIBBPF_DEPRECATED_SINCE(major, minor, message) to prepare
the deprecation of two API functions. This macro marks functions as deprecated
when libbpf's version reaches the values passed as an argument.
As part of this change libbpf_version.h header is added with recorded major
(LIBBPF_MAJOR_VERSION) and minor (LIBBPF_MINOR_VERSION) libbpf version macros.
They are now part of libbpf public API and can be relied upon by user code.
libbpf_version.h is installed system-wide along other libbpf public headers.
Due to this new build-time auto-generated header, in-kernel applications
relying on libbpf (resolve_btfids, bpftool, bpf_preload) are updated to
include libbpf's output directory as part of a list of include search paths.
Better fix would be to use libbpf's make_install target to install public API
headers, but that clean up is left out as a future improvement. The build
changes were tested by building kernel (with KBUILD_OUTPUT and O= specified
explicitly), bpftool, libbpf, selftests/bpf, and resolve_btfids builds. No
problems were detected.
Note that because of the constraints of the C preprocessor we have to write
a few lines of macro magic for each version used to prepare deprecation (0.6
for now).
Also, use LIBBPF_DEPRECATED_SINCE() to schedule deprecation of
btf__get_from_id() and btf__load(), which are replaced by
btf__load_from_kernel_by_id() and btf__load_into_kernel(), respectively,
starting from future libbpf v0.6. This is part of libbpf 1.0 effort ([0]).
[0] Closes: https://github.com/libbpf/libbpf/issues/278
Co-developed-by: Quentin Monnet <quentin@isovalent.com>
Co-developed-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Quentin Monnet <quentin@isovalent.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20210908213226.1871016-1-andrii@kernel.org
2021-09-08 14:32:26 -07:00
# include "libbpf_version.h"
2019-12-17 12:28:10 +01:00
2019-12-13 17:43:29 -08:00
# ifndef LIBBPF_API
# define LIBBPF_API __attribute__((visibility("default")))
# endif
2020-09-03 13:35:33 -07:00
# define LIBBPF_DEPRECATED(msg) __attribute__((deprecated(msg)))
libbpf: Add LIBBPF_DEPRECATED_SINCE macro for scheduling API deprecations
Introduce a macro LIBBPF_DEPRECATED_SINCE(major, minor, message) to prepare
the deprecation of two API functions. This macro marks functions as deprecated
when libbpf's version reaches the values passed as an argument.
As part of this change libbpf_version.h header is added with recorded major
(LIBBPF_MAJOR_VERSION) and minor (LIBBPF_MINOR_VERSION) libbpf version macros.
They are now part of libbpf public API and can be relied upon by user code.
libbpf_version.h is installed system-wide along other libbpf public headers.
Due to this new build-time auto-generated header, in-kernel applications
relying on libbpf (resolve_btfids, bpftool, bpf_preload) are updated to
include libbpf's output directory as part of a list of include search paths.
Better fix would be to use libbpf's make_install target to install public API
headers, but that clean up is left out as a future improvement. The build
changes were tested by building kernel (with KBUILD_OUTPUT and O= specified
explicitly), bpftool, libbpf, selftests/bpf, and resolve_btfids builds. No
problems were detected.
Note that because of the constraints of the C preprocessor we have to write
a few lines of macro magic for each version used to prepare deprecation (0.6
for now).
Also, use LIBBPF_DEPRECATED_SINCE() to schedule deprecation of
btf__get_from_id() and btf__load(), which are replaced by
btf__load_from_kernel_by_id() and btf__load_into_kernel(), respectively,
starting from future libbpf v0.6. This is part of libbpf 1.0 effort ([0]).
[0] Closes: https://github.com/libbpf/libbpf/issues/278
Co-developed-by: Quentin Monnet <quentin@isovalent.com>
Co-developed-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Quentin Monnet <quentin@isovalent.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20210908213226.1871016-1-andrii@kernel.org
2021-09-08 14:32:26 -07:00
/* Mark a symbol as deprecated when libbpf version is >= {major}.{minor} */
# define LIBBPF_DEPRECATED_SINCE(major, minor, msg) \
__LIBBPF_MARK_DEPRECATED_ # # major # # _ # # minor \
( LIBBPF_DEPRECATED ( " libbpf v " # major " . " # minor " +: " msg ) )
# define __LIBBPF_CURRENT_VERSION_GEQ(major, minor) \
( LIBBPF_MAJOR_VERSION > ( major ) | | \
( LIBBPF_MAJOR_VERSION = = ( major ) & & LIBBPF_MINOR_VERSION > = ( minor ) ) )
/* Add checks for other versions below when planning deprecation of API symbols
* with the LIBBPF_DEPRECATED_SINCE macro .
*/
# if __LIBBPF_CURRENT_VERSION_GEQ(0, 6)
# define __LIBBPF_MARK_DEPRECATED_0_6(X) X
# else
# define __LIBBPF_MARK_DEPRECATED_0_6(X)
# endif
2021-09-15 18:58:35 -07:00
# if __LIBBPF_CURRENT_VERSION_GEQ(0, 7)
# define __LIBBPF_MARK_DEPRECATED_0_7(X) X
# else
# define __LIBBPF_MARK_DEPRECATED_0_7(X)
# endif
libbpf: Add LIBBPF_DEPRECATED_SINCE macro for scheduling API deprecations
Introduce a macro LIBBPF_DEPRECATED_SINCE(major, minor, message) to prepare
the deprecation of two API functions. This macro marks functions as deprecated
when libbpf's version reaches the values passed as an argument.
As part of this change libbpf_version.h header is added with recorded major
(LIBBPF_MAJOR_VERSION) and minor (LIBBPF_MINOR_VERSION) libbpf version macros.
They are now part of libbpf public API and can be relied upon by user code.
libbpf_version.h is installed system-wide along other libbpf public headers.
Due to this new build-time auto-generated header, in-kernel applications
relying on libbpf (resolve_btfids, bpftool, bpf_preload) are updated to
include libbpf's output directory as part of a list of include search paths.
Better fix would be to use libbpf's make_install target to install public API
headers, but that clean up is left out as a future improvement. The build
changes were tested by building kernel (with KBUILD_OUTPUT and O= specified
explicitly), bpftool, libbpf, selftests/bpf, and resolve_btfids builds. No
problems were detected.
Note that because of the constraints of the C preprocessor we have to write
a few lines of macro magic for each version used to prepare deprecation (0.6
for now).
Also, use LIBBPF_DEPRECATED_SINCE() to schedule deprecation of
btf__get_from_id() and btf__load(), which are replaced by
btf__load_from_kernel_by_id() and btf__load_into_kernel(), respectively,
starting from future libbpf v0.6. This is part of libbpf 1.0 effort ([0]).
[0] Closes: https://github.com/libbpf/libbpf/issues/278
Co-developed-by: Quentin Monnet <quentin@isovalent.com>
Co-developed-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Quentin Monnet <quentin@isovalent.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20210908213226.1871016-1-andrii@kernel.org
2021-09-08 14:32:26 -07:00
2019-12-13 17:43:29 -08:00
/* Helper macro to declare and initialize libbpf options struct
*
* This dance with uninitialized declaration , followed by memset to zero ,
* followed by assignment using compound literal syntax is done to preserve
* ability to use a nice struct field initialization syntax and * * hopefully * *
* have all the padding bytes initialized to zero . It ' s not guaranteed though ,
* when copying literal , that compiler won ' t copy garbage in literal ' s padding
* bytes , but that ' s the best way I ' ve found and it seems to work in practice .
*
* Macro declares opts struct of given type and name , zero - initializes ,
* including any extra padding , it with memset ( ) and then assigns initial
* values provided by users in struct initializer - syntax as varargs .
*/
# define DECLARE_LIBBPF_OPTS(TYPE, NAME, ...) \
struct TYPE NAME = ( { \
memset ( & NAME , 0 , sizeof ( struct TYPE ) ) ; \
( struct TYPE ) { \
. sz = sizeof ( struct TYPE ) , \
__VA_ARGS__ \
} ; \
} )
# endif /* __LIBBPF_LIBBPF_COMMON_H */