| 1 | /* |
| 2 | * Protect against multiple inclusion of structure declarations, but run the |
| 3 | * stages below each time. |
| 4 | */ |
| 5 | #ifndef _LTTNG_PROBES_LTTNG_TYPES_H |
| 6 | #define _LTTNG_PROBES_LTTNG_TYPES_H |
| 7 | |
| 8 | #include <linux/seq_file.h> |
| 9 | #include <lttng.h> |
| 10 | |
| 11 | #ifdef __KERNEL__ |
| 12 | # include <asm/byteorder.h> |
| 13 | # ifdef __BIG_ENDIAN |
| 14 | # define __BYTE_ORDER __BIG_ENDIAN |
| 15 | # elif defined(__LITTLE_ENDIAN) |
| 16 | # define __BYTE_ORDER __LITTLE_ENDIAN |
| 17 | # else |
| 18 | # error "unknown endianness" |
| 19 | # endif |
| 20 | #ifndef __BIG_ENDIAN |
| 21 | # define __BIG_ENDIAN 4321 |
| 22 | #endif |
| 23 | #ifndef __LITTLE_ENDIAN |
| 24 | # define __LITTLE_ENDIAN 1234 |
| 25 | #endif |
| 26 | #else |
| 27 | # include <endian.h> |
| 28 | #endif |
| 29 | |
| 30 | /* Update the astract_types name table in lttng-types.c along with this enum */ |
| 31 | enum abstract_types { |
| 32 | atype_integer, |
| 33 | atype_enum, |
| 34 | atype_array, |
| 35 | atype_sequence, |
| 36 | atype_string, |
| 37 | NR_ABSTRACT_TYPES, |
| 38 | }; |
| 39 | |
| 40 | /* Update the string_encodings name table in lttng-types.c along with this enum */ |
| 41 | enum lttng_string_encodings { |
| 42 | lttng_encode_UTF8 = 0, |
| 43 | lttng_encode_ASCII = 1, |
| 44 | NR_STRING_ENCODINGS, |
| 45 | }; |
| 46 | |
| 47 | struct lttng_enum_entry { |
| 48 | unsigned long long start, end; /* start and end are inclusive */ |
| 49 | const char *string; |
| 50 | }; |
| 51 | |
| 52 | struct lttng_enum { |
| 53 | const struct lttng_enum_entry *entries; |
| 54 | unsigned int len; |
| 55 | }; |
| 56 | |
| 57 | struct lttng_type { |
| 58 | enum abstract_types atype; |
| 59 | const char *name; |
| 60 | union { |
| 61 | struct { |
| 62 | unsigned int size; /* in bits */ |
| 63 | unsigned short alignment; /* in bits */ |
| 64 | unsigned int signedness:1; |
| 65 | unsigned int reverse_byte_order:1; |
| 66 | } integer; |
| 67 | struct { |
| 68 | const char *parent_type; |
| 69 | const struct lttng_enum def; |
| 70 | } enumeration; |
| 71 | struct { |
| 72 | const char *elem_type; |
| 73 | unsigned int length; /* num. elems. */ |
| 74 | } array; |
| 75 | struct { |
| 76 | const char *elem_type; |
| 77 | const char *length_type; |
| 78 | } sequence; |
| 79 | struct { |
| 80 | enum lttng_string_encodings encoding; |
| 81 | } string; |
| 82 | } u; |
| 83 | } __attribute__((packed)); |
| 84 | |
| 85 | void lttng_print_event_type(struct seq_file *m, unsigned int indent, |
| 86 | const struct lttng_type *type); |
| 87 | |
| 88 | #endif /* _LTTNG_PROBES_LTTNG_TYPES_H */ |
| 89 | |
| 90 | |
| 91 | /* Export enumerations */ |
| 92 | |
| 93 | #ifdef STAGE_EXPORT_ENUMS |
| 94 | |
| 95 | #undef TRACE_EVENT_TYPE |
| 96 | #define TRACE_EVENT_TYPE(_name, _abstract_type, args...) |
| 97 | |
| 98 | #undef TRACE_EVENT_ENUM |
| 99 | #define TRACE_EVENT_ENUM(_name, _entries...) \ |
| 100 | const struct lttng_enum_entry __trace_event_enum_##_name[] = { \ |
| 101 | PARAMS(_entries) \ |
| 102 | }; |
| 103 | |
| 104 | /* Enumeration entry (single value) */ |
| 105 | #undef V |
| 106 | #define V(_string) { _string, _string, #_string} |
| 107 | |
| 108 | /* Enumeration entry (range) */ |
| 109 | #undef R |
| 110 | #define R(_string, _range_start, _range_end) \ |
| 111 | { _range_start, _range_end, #_string } |
| 112 | |
| 113 | #endif /* STAGE_EXPORT_ENUMS */ |
| 114 | |
| 115 | |
| 116 | /* Export named types */ |
| 117 | |
| 118 | #ifdef STAGE_EXPORT_TYPES |
| 119 | |
| 120 | #undef TRACE_EVENT_TYPE___integer_ext |
| 121 | #define TRACE_EVENT_TYPE___integer_ext(_name, _byte_order) \ |
| 122 | { \ |
| 123 | .atype = atype_integer, \ |
| 124 | .name = #_name, \ |
| 125 | .u.integer.size = sizeof(_name) * 8, \ |
| 126 | .u.integer.alignment = __alignof__(_name) * 8,\ |
| 127 | .u.integer.signedness = is_signed_type(_name),\ |
| 128 | .u.integer.reverse_byte_order = ((_byte_order) != __BYTE_ORDER),\ |
| 129 | }, |
| 130 | |
| 131 | #undef TRACE_EVENT_TYPE___integer |
| 132 | #define TRACE_EVENT_TYPE___integer(_name, _unused) \ |
| 133 | TRACE_EVENT_TYPE___integer_ext(_name, __BYTE_ORDER) |
| 134 | |
| 135 | #undef TRACE_EVENT_TYPE___enum |
| 136 | #define TRACE_EVENT_TYPE___enum(_name, _parent_type) \ |
| 137 | { \ |
| 138 | .atype = atype_enum, \ |
| 139 | .name = #_name, \ |
| 140 | .u.enumeration.parent_type = #_parent_type, \ |
| 141 | .u.enumeration.def.entries = __trace_event_enum_##_name, \ |
| 142 | .u.enumeration.def.len = ARRAY_SIZE(__trace_event_enum_##_name), \ |
| 143 | }, |
| 144 | |
| 145 | #undef TRACE_EVENT_TYPE___array |
| 146 | #define TRACE_EVENT_TYPE___array(_name, _elem_type, _length) \ |
| 147 | { \ |
| 148 | .atype = atype_array, \ |
| 149 | .name = #_name, \ |
| 150 | .u.array.elem_type = #_elem_type, \ |
| 151 | .u.array.length = _length, \ |
| 152 | }, |
| 153 | |
| 154 | #undef TRACE_EVENT_TYPE___sequence |
| 155 | #define TRACE_EVENT_TYPE___sequence(_name, _elem_type, _length_type) \ |
| 156 | { \ |
| 157 | .atype = atype_sequence, \ |
| 158 | .name = #_name, \ |
| 159 | .u.sequence.elem_type = #_elem_type, \ |
| 160 | .u.sequence.length_type = #_length_type, \ |
| 161 | }, |
| 162 | |
| 163 | #undef TRACE_EVENT_TYPE___string |
| 164 | #define TRACE_EVENT_TYPE___string(_name, _encoding) \ |
| 165 | { \ |
| 166 | .atype = atype_string, \ |
| 167 | .name = #_name, \ |
| 168 | .u.string.encoding = lttng_encode_##_encoding,\ |
| 169 | }, |
| 170 | |
| 171 | |
| 172 | /* Local declaration */ |
| 173 | #undef TRACE_EVENT_TYPE |
| 174 | #define TRACE_EVENT_TYPE(_name, _abstract_type, args...) \ |
| 175 | TRACE_EVENT_TYPE___##_abstract_type(_name, args) |
| 176 | |
| 177 | #undef TRACE_EVENT_ENUM |
| 178 | #define TRACE_EVENT_ENUM(_name, _entries...) |
| 179 | |
| 180 | #endif /* STAGE_EXPORT_TYPES */ |