/* Helper macro to convert (foo, __LINE__) into foo134 so we can use __LINE__ for * field/variable names
*/ #define COMBINE1(X, Y) X ## Y #define COMBINE(X, Y) COMBINE1(X, Y)
/* Macro magic: * __uint(foo, 123) creates a int (*foo)[1234] * * We use that macro to declare an anonymous struct with several * fields, each is the declaration of an pointer to an array of size * bus/group/vid/pid. (Because it's a pointer to such an array, actual storage * would be sizeof(pointer) rather than sizeof(array). Not that we ever * instantiate it anyway). * * This is only used for BTF introspection, we can later check "what size * is the bus array" in the introspection data and thus extract the bus ID * again. * * And we use the __LINE__ to give each of our structs a unique name so the * BPF program writer doesn't have to. * * $ bpftool btf dump file target/bpf/HP_Elite_Presenter.bpf.o * shows the inspection data, start by searching for .hid_bpf_config * and working backwards from that (each entry references the type_id of the * content).
*/
/* Macro magic below is to make HID_BPF_CONFIG() look like a function call that * we can pass multiple HID_DEVICE() invocations in. * * For up to 16 arguments, HID_BPF_CONFIG(one, two) resolves to * * union { * HID_DEVICE(...); * HID_DEVICE(...); * } _device_ids SEC(".hid_bpf_config") *
*/
/* Returns the number of macro arguments, this expands * NARGS(a, b, c) to NTH_ARG(a, b, c, 15, 14, 13, .... 4, 3, 2, 1). * NTH_ARG always returns the 16th argument which in our case is 3. * * If we want more than 16 values _COUNTDOWN and _NTH_ARG both need to be * updated.
*/ #define _NARGS(...) _NARGS1(__VA_ARGS__, _COUNTDOWN) #define _NARGS1(...) _NTH_ARG(__VA_ARGS__)
/* Add to this if we need more than 16 args */ #define _COUNTDOWN \
15, 14, 13, 12, 11, 10, 9, 8, \
7, 6, 5, 4, 3, 2, 1, 0
/* Return the 16 argument passed in. See _NARGS above for usage. Note this is * 1-indexed.
*/ #define _NTH_ARG( \
_1, _2, _3, _4, _5, _6, _7, _8, \
_9, _10, _11, _12, _13, _14, _15,\
N, ...) N
/* Turns EXPAND(_ARG, a, b, c) into _ARG3(a, b, c) */ #define _EXPAND(func, ...) COMBINE(func, _NARGS(__VA_ARGS__)) (__VA_ARGS__)
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.