1*f7c14bbaSAndroid Build Coastguard Worker.. SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) 2*f7c14bbaSAndroid Build Coastguard Worker 3*f7c14bbaSAndroid Build Coastguard Worker.. _api: 4*f7c14bbaSAndroid Build Coastguard Worker 5*f7c14bbaSAndroid Build Coastguard Worker.. toctree:: Table of Contents 6*f7c14bbaSAndroid Build Coastguard Worker 7*f7c14bbaSAndroid Build Coastguard Worker 8*f7c14bbaSAndroid Build Coastguard WorkerLIBBPF API 9*f7c14bbaSAndroid Build Coastguard Worker========== 10*f7c14bbaSAndroid Build Coastguard Worker 11*f7c14bbaSAndroid Build Coastguard WorkerError Handling 12*f7c14bbaSAndroid Build Coastguard Worker-------------- 13*f7c14bbaSAndroid Build Coastguard Worker 14*f7c14bbaSAndroid Build Coastguard WorkerWhen libbpf is used in "libbpf 1.0 mode", API functions can return errors in one of two ways. 15*f7c14bbaSAndroid Build Coastguard Worker 16*f7c14bbaSAndroid Build Coastguard WorkerYou can set "libbpf 1.0" mode with the following line: 17*f7c14bbaSAndroid Build Coastguard Worker 18*f7c14bbaSAndroid Build Coastguard Worker.. code-block:: 19*f7c14bbaSAndroid Build Coastguard Worker 20*f7c14bbaSAndroid Build Coastguard Worker libbpf_set_strict_mode(LIBBPF_STRICT_DIRECT_ERRS | LIBBPF_STRICT_CLEAN_PTRS); 21*f7c14bbaSAndroid Build Coastguard Worker 22*f7c14bbaSAndroid Build Coastguard WorkerIf the function returns an error code directly, it uses 0 to indicate success 23*f7c14bbaSAndroid Build Coastguard Workerand a negative error code to indicate what caused the error. In this case the 24*f7c14bbaSAndroid Build Coastguard Workererror code should be checked directly from the return, you do not need to check 25*f7c14bbaSAndroid Build Coastguard Workererrno. 26*f7c14bbaSAndroid Build Coastguard Worker 27*f7c14bbaSAndroid Build Coastguard WorkerFor example: 28*f7c14bbaSAndroid Build Coastguard Worker 29*f7c14bbaSAndroid Build Coastguard Worker.. code-block:: 30*f7c14bbaSAndroid Build Coastguard Worker 31*f7c14bbaSAndroid Build Coastguard Worker err = some_libbpf_api_with_error_return(...); 32*f7c14bbaSAndroid Build Coastguard Worker if (err < 0) { 33*f7c14bbaSAndroid Build Coastguard Worker /* Handle error accordingly */ 34*f7c14bbaSAndroid Build Coastguard Worker } 35*f7c14bbaSAndroid Build Coastguard Worker 36*f7c14bbaSAndroid Build Coastguard WorkerIf the function returns a pointer, it will return NULL to indicate there was 37*f7c14bbaSAndroid Build Coastguard Workeran error. In this case errno should be checked for the error code. 38*f7c14bbaSAndroid Build Coastguard Worker 39*f7c14bbaSAndroid Build Coastguard WorkerFor example: 40*f7c14bbaSAndroid Build Coastguard Worker 41*f7c14bbaSAndroid Build Coastguard Worker.. code-block:: 42*f7c14bbaSAndroid Build Coastguard Worker 43*f7c14bbaSAndroid Build Coastguard Worker ptr = some_libbpf_api_returning_ptr(); 44*f7c14bbaSAndroid Build Coastguard Worker if (!ptr) { 45*f7c14bbaSAndroid Build Coastguard Worker /* note no minus sign for EINVAL and E2BIG below */ 46*f7c14bbaSAndroid Build Coastguard Worker if (errno == EINVAL) { 47*f7c14bbaSAndroid Build Coastguard Worker /* handle EINVAL error */ 48*f7c14bbaSAndroid Build Coastguard Worker } else if (errno == E2BIG) { 49*f7c14bbaSAndroid Build Coastguard Worker /* handle E2BIG error */ 50*f7c14bbaSAndroid Build Coastguard Worker } 51*f7c14bbaSAndroid Build Coastguard Worker } 52*f7c14bbaSAndroid Build Coastguard Worker 53*f7c14bbaSAndroid Build Coastguard Workerlibbpf.h 54*f7c14bbaSAndroid Build Coastguard Worker-------- 55*f7c14bbaSAndroid Build Coastguard Worker.. doxygenfile:: libbpf.h 56*f7c14bbaSAndroid Build Coastguard Worker :project: libbpf 57*f7c14bbaSAndroid Build Coastguard Worker :sections: func define public-type enum 58*f7c14bbaSAndroid Build Coastguard Worker 59*f7c14bbaSAndroid Build Coastguard Workerbpf.h 60*f7c14bbaSAndroid Build Coastguard Worker----- 61*f7c14bbaSAndroid Build Coastguard Worker.. doxygenfile:: bpf.h 62*f7c14bbaSAndroid Build Coastguard Worker :project: libbpf 63*f7c14bbaSAndroid Build Coastguard Worker :sections: func define public-type enum 64*f7c14bbaSAndroid Build Coastguard Worker 65*f7c14bbaSAndroid Build Coastguard Workerbtf.h 66*f7c14bbaSAndroid Build Coastguard Worker----- 67*f7c14bbaSAndroid Build Coastguard Worker.. doxygenfile:: btf.h 68*f7c14bbaSAndroid Build Coastguard Worker :project: libbpf 69*f7c14bbaSAndroid Build Coastguard Worker :sections: func define public-type enum 70*f7c14bbaSAndroid Build Coastguard Worker 71*f7c14bbaSAndroid Build Coastguard Workerxsk.h 72*f7c14bbaSAndroid Build Coastguard Worker----- 73*f7c14bbaSAndroid Build Coastguard Worker.. doxygenfile:: xsk.h 74*f7c14bbaSAndroid Build Coastguard Worker :project: libbpf 75*f7c14bbaSAndroid Build Coastguard Worker :sections: func define public-type enum 76*f7c14bbaSAndroid Build Coastguard Worker 77*f7c14bbaSAndroid Build Coastguard Workerbpf_tracing.h 78*f7c14bbaSAndroid Build Coastguard Worker------------- 79*f7c14bbaSAndroid Build Coastguard Worker.. doxygenfile:: bpf_tracing.h 80*f7c14bbaSAndroid Build Coastguard Worker :project: libbpf 81*f7c14bbaSAndroid Build Coastguard Worker :sections: func define public-type enum 82*f7c14bbaSAndroid Build Coastguard Worker 83*f7c14bbaSAndroid Build Coastguard Workerbpf_core_read.h 84*f7c14bbaSAndroid Build Coastguard Worker--------------- 85*f7c14bbaSAndroid Build Coastguard Worker.. doxygenfile:: bpf_core_read.h 86*f7c14bbaSAndroid Build Coastguard Worker :project: libbpf 87*f7c14bbaSAndroid Build Coastguard Worker :sections: func define public-type enum 88*f7c14bbaSAndroid Build Coastguard Worker 89*f7c14bbaSAndroid Build Coastguard Workerbpf_endian.h 90*f7c14bbaSAndroid Build Coastguard Worker------------ 91*f7c14bbaSAndroid Build Coastguard Worker.. doxygenfile:: bpf_endian.h 92*f7c14bbaSAndroid Build Coastguard Worker :project: libbpf 93*f7c14bbaSAndroid Build Coastguard Worker :sections: func define public-type enum 94