github.com/cilium/cilium@v1.16.2/bpf/lib/tailcall.h (about) 1 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */ 2 /* Copyright Authors of Cilium */ 3 #ifndef TAILCALL_H 4 #define TAILCALL_H 5 6 #include "config.h" 7 8 #define __eval(x, ...) x ## __VA_ARGS__ 9 10 #define __and_00 0 11 #define __and_01 0 12 #define __and_10 0 13 #define __and_11 1 14 #define __and_0(y) __eval(__and_0, y) 15 #define __and_1(y) __eval(__and_1, y) 16 #define __and(x, y) __eval(__and_, x)(y) 17 18 #define __or_00 0 19 #define __or_01 1 20 #define __or_10 1 21 #define __or_11 1 22 #define __or_0(y) __eval(__or_0, y) 23 #define __or_1(y) __eval(__or_1, y) 24 #define __or(x, y) __eval(__or_, x)(y) 25 26 #define __or3_1(y, z) 1 27 #define __or3_0(y, z) __or(y, z) 28 #define __or3(x, y, z) __eval(__or3_, x)(y, z) 29 30 #define __or4_1(x, y, z) 1 31 #define __or4_0(x, y, z) __eval(__or3_, x)(y, z) 32 #define __or4(w, x, y, z) __eval(__or4_, w)(x, y, z) 33 34 #define __not_0 1 35 #define __not_1 0 36 #define __not(x) __eval(__not_, x) 37 38 /* invoke_tailcall_if() is a helper which based on COND either selects to emit 39 * a tail call for the underlying function when true or emits it as inlined 40 * when false. COND can be selected by one or multiple compile time flags. 41 * 42 * [...] 43 * invoke_tailcall_if(__and(is_defined(ENABLE_IPV4), is_defined(ENABLE_IPV6)), 44 * CILIUM_CALL_FOO, foo_fn); 45 * [...] 46 * 47 * The loader will only load tail calls if they are invoked at least once. 48 */ 49 50 #define __invoke_tailcall_if_0(NAME, FUNC, EXT_ERR) \ 51 FUNC(ctx) 52 #define __invoke_tailcall_if_1(NAME, FUNC, EXT_ERR) \ 53 ({ \ 54 tail_call_internal(ctx, NAME, EXT_ERR); \ 55 }) 56 #define invoke_tailcall_if(COND, NAME, FUNC, EXT_ERR) \ 57 __eval(__invoke_tailcall_if_, COND)(NAME, FUNC, EXT_ERR) 58 59 #define __invoke_traced_tailcall_if_0(NAME, FUNC, TRACE, EXT_ERR) \ 60 FUNC(ctx, TRACE, EXT_ERR) 61 #define __invoke_traced_tailcall_if_1(NAME, FUNC, TRACE, EXT_ERR) \ 62 ({ \ 63 tail_call_internal(ctx, NAME, EXT_ERR); \ 64 }) 65 #define invoke_traced_tailcall_if(COND, NAME, FUNC, TRACE, EXT_ERR) \ 66 __eval(__invoke_traced_tailcall_if_, COND)(NAME, FUNC, TRACE, \ 67 EXT_ERR) 68 69 #endif /* TAILCALL_H */