xref: /linux/tools/lib/bpf/libbpf_legacy.h (revision 164666fa66669d437bdcc8d5f1744a2aee73be41)
1 /* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */
2 
3 /*
4  * Libbpf legacy APIs (either discouraged or deprecated, as mentioned in [0])
5  *
6  *   [0] https://docs.google.com/document/d/1UyjTZuPFWiPFyKk1tV5an11_iaRuec6U-ZESZ54nNTY
7  *
8  * Copyright (C) 2021 Facebook
9  */
10 #ifndef __LIBBPF_LEGACY_BPF_H
11 #define __LIBBPF_LEGACY_BPF_H
12 
13 #include <linux/bpf.h>
14 #include <stdbool.h>
15 #include <stddef.h>
16 #include <stdint.h>
17 #include "libbpf_common.h"
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 enum libbpf_strict_mode {
24 	/* Turn on all supported strict features of libbpf to simulate libbpf
25 	 * v1.0 behavior.
26 	 * This will be the default behavior in libbpf v1.0.
27 	 */
28 	LIBBPF_STRICT_ALL = 0xffffffff,
29 
30 	/*
31 	 * Disable any libbpf 1.0 behaviors. This is the default before libbpf
32 	 * v1.0. It won't be supported anymore in v1.0, please update your
33 	 * code so that it handles LIBBPF_STRICT_ALL mode before libbpf v1.0.
34 	 */
35 	LIBBPF_STRICT_NONE = 0x00,
36 	/*
37 	 * Return NULL pointers on error, not ERR_PTR(err).
38 	 * Additionally, libbpf also always sets errno to corresponding Exx
39 	 * (positive) error code.
40 	 */
41 	LIBBPF_STRICT_CLEAN_PTRS = 0x01,
42 	/*
43 	 * Return actual error codes from low-level APIs directly, not just -1.
44 	 * Additionally, libbpf also always sets errno to corresponding Exx
45 	 * (positive) error code.
46 	 */
47 	LIBBPF_STRICT_DIRECT_ERRS = 0x02,
48 	/*
49 	 * Enforce strict BPF program section (SEC()) names.
50 	 * E.g., while prefiously SEC("xdp_whatever") or SEC("perf_event_blah") were
51 	 * allowed, with LIBBPF_STRICT_SEC_PREFIX this will become
52 	 * unrecognized by libbpf and would have to be just SEC("xdp") and
53 	 * SEC("xdp") and SEC("perf_event").
54 	 *
55 	 * Note, in this mode the program pin path will be based on the
56 	 * function name instead of section name.
57 	 */
58 	LIBBPF_STRICT_SEC_NAME = 0x04,
59 	/*
60 	 * Disable the global 'bpf_objects_list'. Maintaining this list adds
61 	 * a race condition to bpf_object__open() and bpf_object__close().
62 	 * Clients can maintain it on their own if it is valuable for them.
63 	 */
64 	LIBBPF_STRICT_NO_OBJECT_LIST = 0x08,
65 	/*
66 	 * Automatically bump RLIMIT_MEMLOCK using setrlimit() before the
67 	 * first BPF program or map creation operation. This is done only if
68 	 * kernel is too old to support memcg-based memory accounting for BPF
69 	 * subsystem. By default, RLIMIT_MEMLOCK limit is set to RLIM_INFINITY,
70 	 * but it can be overriden with libbpf_set_memlock_rlim_max() API.
71 	 * Note that libbpf_set_memlock_rlim_max() needs to be called before
72 	 * the very first bpf_prog_load(), bpf_map_create() or bpf_object__load()
73 	 * operation.
74 	 */
75 	LIBBPF_STRICT_AUTO_RLIMIT_MEMLOCK = 0x10,
76 
77 	__LIBBPF_STRICT_LAST,
78 };
79 
80 LIBBPF_API int libbpf_set_strict_mode(enum libbpf_strict_mode mode);
81 
82 #define DECLARE_LIBBPF_OPTS LIBBPF_OPTS
83 
84 #ifdef __cplusplus
85 } /* extern "C" */
86 #endif
87 
88 #endif /* __LIBBPF_LEGACY_BPF_H */
89