/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */12/*3* Libbpf legacy APIs (either discouraged or deprecated, as mentioned in [0])4*5* [0] https://docs.google.com/document/d/1UyjTZuPFWiPFyKk1tV5an11_iaRuec6U-ZESZ54nNTY6*7* Copyright (C) 2021 Facebook8*/9#ifndef __LIBBPF_LEGACY_BPF_H10#define __LIBBPF_LEGACY_BPF_H1112#include <linux/bpf.h>13#include <stdbool.h>14#include <stddef.h>15#include <stdint.h>16#include "libbpf_common.h"1718#ifdef __cplusplus19extern "C" {20#endif2122/* As of libbpf 1.0 libbpf_set_strict_mode() and enum libbpf_struct_mode have23* no effect. But they are left in libbpf_legacy.h so that applications that24* prepared for libbpf 1.0 before final release by using25* libbpf_set_strict_mode() still work with libbpf 1.0+ without any changes.26*/27enum libbpf_strict_mode {28/* Turn on all supported strict features of libbpf to simulate libbpf29* v1.0 behavior.30* This will be the default behavior in libbpf v1.0.31*/32LIBBPF_STRICT_ALL = 0xffffffff,3334/*35* Disable any libbpf 1.0 behaviors. This is the default before libbpf36* v1.0. It won't be supported anymore in v1.0, please update your37* code so that it handles LIBBPF_STRICT_ALL mode before libbpf v1.0.38*/39LIBBPF_STRICT_NONE = 0x00,40/*41* Return NULL pointers on error, not ERR_PTR(err).42* Additionally, libbpf also always sets errno to corresponding Exx43* (positive) error code.44*/45LIBBPF_STRICT_CLEAN_PTRS = 0x01,46/*47* Return actual error codes from low-level APIs directly, not just -1.48* Additionally, libbpf also always sets errno to corresponding Exx49* (positive) error code.50*/51LIBBPF_STRICT_DIRECT_ERRS = 0x02,52/*53* Enforce strict BPF program section (SEC()) names.54* E.g., while prefiously SEC("xdp_whatever") or SEC("perf_event_blah") were55* allowed, with LIBBPF_STRICT_SEC_PREFIX this will become56* unrecognized by libbpf and would have to be just SEC("xdp") and57* SEC("xdp") and SEC("perf_event").58*59* Note, in this mode the program pin path will be based on the60* function name instead of section name.61*62* Additionally, routines in the .text section are always considered63* sub-programs. Legacy behavior allows for a single routine in .text64* to be a program.65*/66LIBBPF_STRICT_SEC_NAME = 0x04,67/*68* Disable the global 'bpf_objects_list'. Maintaining this list adds69* a race condition to bpf_object__open() and bpf_object__close().70* Clients can maintain it on their own if it is valuable for them.71*/72LIBBPF_STRICT_NO_OBJECT_LIST = 0x08,73/*74* Automatically bump RLIMIT_MEMLOCK using setrlimit() before the75* first BPF program or map creation operation. This is done only if76* kernel is too old to support memcg-based memory accounting for BPF77* subsystem. By default, RLIMIT_MEMLOCK limit is set to RLIM_INFINITY,78* but it can be overridden with libbpf_set_memlock_rlim() API.79* Note that libbpf_set_memlock_rlim() needs to be called before80* the very first bpf_prog_load(), bpf_map_create() or bpf_object__load()81* operation.82*/83LIBBPF_STRICT_AUTO_RLIMIT_MEMLOCK = 0x10,84/*85* Error out on any SEC("maps") map definition, which are deprecated86* in favor of BTF-defined map definitions in SEC(".maps").87*/88LIBBPF_STRICT_MAP_DEFINITIONS = 0x20,8990__LIBBPF_STRICT_LAST,91};9293LIBBPF_API int libbpf_set_strict_mode(enum libbpf_strict_mode mode);9495/**96* @brief **libbpf_get_error()** extracts the error code from the passed97* pointer98* @param ptr pointer returned from libbpf API function99* @return error code; or 0 if no error occurred100*101* Note, as of libbpf 1.0 this function is not necessary and not recommended102* to be used. Libbpf doesn't return error code embedded into the pointer103* itself. Instead, NULL is returned on error and error code is passed through104* thread-local errno variable. **libbpf_get_error()** is just returning -errno105* value if it receives NULL, which is correct only if errno hasn't been106* modified between libbpf API call and corresponding **libbpf_get_error()**107* call. Prefer to check return for NULL and use errno directly.108*109* This API is left in libbpf 1.0 to allow applications that were 1.0-ready110* before final libbpf 1.0 without needing to change them.111*/112LIBBPF_API long libbpf_get_error(const void *ptr);113114#define DECLARE_LIBBPF_OPTS LIBBPF_OPTS115116/* "Discouraged" APIs which don't follow consistent libbpf naming patterns.117* They are normally a trivial aliases or wrappers for proper APIs and are118* left to minimize unnecessary disruption for users of libbpf. But they119* shouldn't be used going forward.120*/121122struct bpf_program;123struct bpf_map;124struct btf;125struct btf_ext;126127LIBBPF_API struct btf *libbpf_find_kernel_btf(void);128129LIBBPF_API enum bpf_prog_type bpf_program__get_type(const struct bpf_program *prog);130LIBBPF_API enum bpf_attach_type bpf_program__get_expected_attach_type(const struct bpf_program *prog);131LIBBPF_API const char *bpf_map__get_pin_path(const struct bpf_map *map);132LIBBPF_API const void *btf__get_raw_data(const struct btf *btf, __u32 *size);133LIBBPF_API const void *btf_ext__get_raw_data(const struct btf_ext *btf_ext, __u32 *size);134135#ifdef __cplusplus136} /* extern "C" */137#endif138139#endif /* __LIBBPF_LEGACY_BPF_H */140141142