.. | .. |
---|
69 | 69 | * to make sure that if the tracepoint handling changes, the |
---|
70 | 70 | * bpf probe will fail to compile unless it too is updated. |
---|
71 | 71 | */ |
---|
72 | | -#undef DEFINE_EVENT |
---|
73 | | -#define DEFINE_EVENT(template, call, proto, args) \ |
---|
| 72 | +#define __DEFINE_EVENT(template, call, proto, args, size) \ |
---|
74 | 73 | static inline void bpf_test_probe_##call(void) \ |
---|
75 | 74 | { \ |
---|
76 | 75 | check_trace_callback_type_##call(__bpf_trace_##template); \ |
---|
77 | 76 | } \ |
---|
78 | | -static struct bpf_raw_event_map __used \ |
---|
79 | | - __attribute__((section("__bpf_raw_tp_map"))) \ |
---|
80 | | -__bpf_trace_tp_map_##call = { \ |
---|
81 | | - .tp = &__tracepoint_##call, \ |
---|
82 | | - .bpf_func = (void *)__bpf_trace_##template, \ |
---|
83 | | - .num_args = COUNT_ARGS(args), \ |
---|
| 77 | +typedef void (*btf_trace_##call)(void *__data, proto); \ |
---|
| 78 | +static union { \ |
---|
| 79 | + struct bpf_raw_event_map event; \ |
---|
| 80 | + btf_trace_##call handler; \ |
---|
| 81 | +} __bpf_trace_tp_map_##call __used \ |
---|
| 82 | +__section("__bpf_raw_tp_map") = { \ |
---|
| 83 | + .event = { \ |
---|
| 84 | + .tp = &__tracepoint_##call, \ |
---|
| 85 | + .bpf_func = __bpf_trace_##template, \ |
---|
| 86 | + .num_args = COUNT_ARGS(args), \ |
---|
| 87 | + .writable_size = size, \ |
---|
| 88 | + }, \ |
---|
84 | 89 | }; |
---|
85 | 90 | |
---|
| 91 | +#define FIRST(x, ...) x |
---|
| 92 | + |
---|
| 93 | +#undef DEFINE_EVENT_WRITABLE |
---|
| 94 | +#define DEFINE_EVENT_WRITABLE(template, call, proto, args, size) \ |
---|
| 95 | +static inline void bpf_test_buffer_##call(void) \ |
---|
| 96 | +{ \ |
---|
| 97 | + /* BUILD_BUG_ON() is ignored if the code is completely eliminated, but \ |
---|
| 98 | + * BUILD_BUG_ON_ZERO() uses a different mechanism that is not \ |
---|
| 99 | + * dead-code-eliminated. \ |
---|
| 100 | + */ \ |
---|
| 101 | + FIRST(proto); \ |
---|
| 102 | + (void)BUILD_BUG_ON_ZERO(size != sizeof(*FIRST(args))); \ |
---|
| 103 | +} \ |
---|
| 104 | +__DEFINE_EVENT(template, call, PARAMS(proto), PARAMS(args), size) |
---|
| 105 | + |
---|
| 106 | +#undef DEFINE_EVENT |
---|
| 107 | +#define DEFINE_EVENT(template, call, proto, args) \ |
---|
| 108 | + __DEFINE_EVENT(template, call, PARAMS(proto), PARAMS(args), 0) |
---|
86 | 109 | |
---|
87 | 110 | #undef DEFINE_EVENT_PRINT |
---|
88 | 111 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ |
---|
89 | 112 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) |
---|
90 | 113 | |
---|
91 | 114 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
---|
| 115 | + |
---|
| 116 | +#undef DEFINE_EVENT_WRITABLE |
---|
| 117 | +#undef __DEFINE_EVENT |
---|
| 118 | +#undef FIRST |
---|
| 119 | + |
---|
92 | 120 | #endif /* CONFIG_BPF_EVENTS */ |
---|