hc
2024-05-10 23fa18eaa71266feff7ba8d83022d9e1cc83c65a
kernel/include/trace/bpf_probe.h
....@@ -69,24 +69,52 @@
6969 * to make sure that if the tracepoint handling changes, the
7070 * bpf probe will fail to compile unless it too is updated.
7171 */
72
-#undef DEFINE_EVENT
73
-#define DEFINE_EVENT(template, call, proto, args) \
72
+#define __DEFINE_EVENT(template, call, proto, args, size) \
7473 static inline void bpf_test_probe_##call(void) \
7574 { \
7675 check_trace_callback_type_##call(__bpf_trace_##template); \
7776 } \
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
+ }, \
8489 };
8590
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)
86109
87110 #undef DEFINE_EVENT_PRINT
88111 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
89112 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
90113
91114 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
115
+
116
+#undef DEFINE_EVENT_WRITABLE
117
+#undef __DEFINE_EVENT
118
+#undef FIRST
119
+
92120 #endif /* CONFIG_BPF_EVENTS */