1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * trace_export.c - export basic ftrace utilities to user space 4 * 5 * Copyright (C) 2009 Steven Rostedt <srostedt@redhat.com> 6 */ 7 #include <linux/stringify.h> 8 #include <linux/kallsyms.h> 9 #include <linux/seq_file.h> 10 #include <linux/uaccess.h> 11 #include <linux/ftrace.h> 12 #include <linux/module.h> 13 #include <linux/init.h> 14 15 #include "trace_output.h" 16 17 /* Stub function for events with triggers */ 18 static int ftrace_event_register(struct trace_event_call *call, 19 enum trace_reg type, void *data) 20 { 21 return 0; 22 } 23 24 #undef TRACE_SYSTEM 25 #define TRACE_SYSTEM ftrace 26 27 /* 28 * The FTRACE_ENTRY_REG macro allows ftrace entry to define register 29 * function and thus become accessible via perf. 30 */ 31 #undef FTRACE_ENTRY_REG 32 #define FTRACE_ENTRY_REG(name, struct_name, id, tstruct, print, regfn) \ 33 FTRACE_ENTRY(name, struct_name, id, PARAMS(tstruct), PARAMS(print)) 34 35 /* not needed for this file */ 36 #undef __field_struct 37 #define __field_struct(type, item) 38 39 #undef __field 40 #define __field(type, item) type item; 41 42 #undef __field_fn 43 #define __field_fn(type, item) type item; 44 45 #undef __field_packed 46 #define __field_packed(type, item) type item; 47 48 #undef __field_desc 49 #define __field_desc(type, container, item) type item; 50 51 #undef __field_desc_packed 52 #define __field_desc_packed(type, container, item) type item; 53 54 #undef __array 55 #define __array(type, item, size) type item[size]; 56 57 #undef __stack_array 58 #define __stack_array(type, item, size, field) __array(type, item, size) 59 60 #undef __array_desc 61 #define __array_desc(type, container, item, size) type item[size]; 62 63 #undef __dynamic_array 64 #define __dynamic_array(type, item) type item[]; 65 66 #undef F_STRUCT 67 #define F_STRUCT(args...) args 68 69 #undef F_printk 70 #define F_printk(fmt, args...) fmt, args 71 72 #undef FTRACE_ENTRY 73 #define FTRACE_ENTRY(name, struct_name, id, tstruct, print) \ 74 struct ____ftrace_##name { \ 75 tstruct \ 76 }; \ 77 static void __always_unused ____ftrace_check_##name(void) \ 78 { \ 79 struct ____ftrace_##name *__entry = NULL; \ 80 \ 81 /* force compile-time check on F_printk() */ \ 82 printk(print); \ 83 } 84 85 #undef FTRACE_ENTRY_DUP 86 #define FTRACE_ENTRY_DUP(name, struct_name, id, tstruct, print) \ 87 FTRACE_ENTRY(name, struct_name, id, PARAMS(tstruct), PARAMS(print)) 88 89 #include "trace_entries.h" 90 91 #undef __field_ext 92 #define __field_ext(_type, _item, _filter_type) { \ 93 .type = #_type, .name = #_item, \ 94 .size = sizeof(_type), .align = __alignof__(_type), \ 95 is_signed_type(_type), .filter_type = _filter_type }, 96 97 98 #undef __field_ext_packed 99 #define __field_ext_packed(_type, _item, _filter_type) { \ 100 .type = #_type, .name = #_item, \ 101 .size = sizeof(_type), .align = 1, \ 102 is_signed_type(_type), .filter_type = _filter_type }, 103 104 #undef __field 105 #define __field(_type, _item) __field_ext(_type, _item, FILTER_OTHER) 106 107 #undef __field_fn 108 #define __field_fn(_type, _item) __field_ext(_type, _item, FILTER_TRACE_FN) 109 110 #undef __field_packed 111 #define __field_packed(_type, _item) __field_ext_packed(_type, _item, FILTER_OTHER) 112 113 #undef __field_desc 114 #define __field_desc(_type, _container, _item) __field_ext(_type, _item, FILTER_OTHER) 115 116 #undef __field_desc_packed 117 #define __field_desc_packed(_type, _container, _item) __field_ext_packed(_type, _item, FILTER_OTHER) 118 119 #undef __array 120 #define __array(_type, _item, _len) { \ 121 .type = #_type"["__stringify(_len)"]", .name = #_item, \ 122 .size = sizeof(_type[_len]), .align = __alignof__(_type), \ 123 is_signed_type(_type), .filter_type = FILTER_OTHER, \ 124 .len = _len }, 125 126 #undef __stack_array 127 #define __stack_array(_type, _item, _len, _field) __array(_type, _item, _len) 128 129 #undef __array_desc 130 #define __array_desc(_type, _container, _item, _len) __array(_type, _item, _len) 131 132 #undef __dynamic_array 133 #define __dynamic_array(_type, _item) { \ 134 .type = #_type "[]", .name = #_item, \ 135 .size = 0, .align = __alignof__(_type), \ 136 is_signed_type(_type), .filter_type = FILTER_OTHER }, 137 138 #undef FTRACE_ENTRY 139 #define FTRACE_ENTRY(name, struct_name, id, tstruct, print) \ 140 static struct trace_event_fields ftrace_event_fields_##name[] = { \ 141 tstruct \ 142 {} }; 143 144 #include "trace_entries.h" 145 146 #undef __entry 147 #define __entry REC 148 149 #undef __field 150 #define __field(type, item) 151 152 #undef __field_fn 153 #define __field_fn(type, item) 154 155 #undef __field_packed 156 #define __field_packed(type, item) 157 158 #undef __field_desc 159 #define __field_desc(type, container, item) 160 161 #undef __field_desc_packed 162 #define __field_desc_packed(type, container, item) 163 164 #undef __array 165 #define __array(type, item, len) 166 167 #undef __stack_array 168 #define __stack_array(type, item, len, field) 169 170 #undef __array_desc 171 #define __array_desc(type, container, item, len) 172 173 #undef __dynamic_array 174 #define __dynamic_array(type, item) 175 176 #undef F_printk 177 #define F_printk(fmt, args...) __stringify(fmt) ", " __stringify(args) 178 179 #undef FTRACE_ENTRY_REG 180 #define FTRACE_ENTRY_REG(call, struct_name, etype, tstruct, print, regfn) \ 181 static struct trace_event_class __refdata event_class_ftrace_##call = { \ 182 .system = __stringify(TRACE_SYSTEM), \ 183 .fields_array = ftrace_event_fields_##call, \ 184 .fields = LIST_HEAD_INIT(event_class_ftrace_##call.fields),\ 185 .reg = regfn, \ 186 }; \ 187 \ 188 struct trace_event_call __used event_##call = { \ 189 .class = &event_class_ftrace_##call, \ 190 { \ 191 .name = #call, \ 192 }, \ 193 .event.type = etype, \ 194 .print_fmt = print, \ 195 .flags = TRACE_EVENT_FL_IGNORE_ENABLE, \ 196 }; \ 197 static struct trace_event_call __used \ 198 __section("_ftrace_events") *__event_##call = &event_##call; 199 200 #undef FTRACE_ENTRY 201 #define FTRACE_ENTRY(call, struct_name, etype, tstruct, print) \ 202 FTRACE_ENTRY_REG(call, struct_name, etype, \ 203 PARAMS(tstruct), PARAMS(print), NULL) 204 205 bool ftrace_event_is_function(struct trace_event_call *call) 206 { 207 return call == &event_function; 208 } 209 210 #include "trace_entries.h" 211