2 * Copyright (C) 2018 Francis Deslauriers <francis.deslauriers@efficios.com>
4 * SPDX-License-Identifier: GPL-2.0-only
11 #include "ust-field-utils.h"
14 * The ustctl_field is made of a combination of C basic types
15 * ustctl_basic_type and _ustctl_basic_type.
17 * ustctl_basic_type contains an enumeration describing the abstract type.
18 * _ustctl_basic_type does _NOT_ contain an enumeration describing the
21 * A layer is needed to use the same code for both structures.
22 * When dealing with _ustctl_basic_type, we need to use the abstract type of
23 * the ustctl_type struct.
27 * Compare two ustctl_integer_type fields.
28 * Returns 1 if both are identical.
30 static bool match_ustctl_field_integer(const struct ustctl_integer_type
*first
,
31 const struct ustctl_integer_type
*second
)
33 if (first
->size
!= second
->size
) {
36 if (first
->alignment
!= second
->alignment
) {
39 if (first
->signedness
!= second
->signedness
) {
42 if (first
->encoding
!= second
->encoding
) {
45 if (first
->base
!= second
->base
) {
48 if (first
->reverse_byte_order
!= second
->reverse_byte_order
) {
59 * Compare two _ustctl_basic_type fields known to be of type integer.
60 * Returns 1 if both are identical.
62 static bool match_ustctl_field_integer_from_raw_basic_type(
63 const union _ustctl_basic_type
*first
,
64 const union _ustctl_basic_type
*second
)
66 return match_ustctl_field_integer(&first
->integer
, &second
->integer
);
70 * Compare two _ustctl_basic_type fields known to be of type enum.
71 * Returns 1 if both are identical.
73 static bool match_ustctl_field_enum_from_raw_basic_type(
74 const union _ustctl_basic_type
*first
,
75 const union _ustctl_basic_type
*second
)
78 * Compare enumeration ID. Enumeration ID is provided to the application by
79 * the session daemon before event registration.
81 if (first
->enumeration
.id
!= second
->enumeration
.id
) {
86 * Sanity check of the name and container type. Those were already checked
87 * during enum registration.
89 if (strncmp(first
->enumeration
.name
, second
->enumeration
.name
,
90 LTTNG_UST_SYM_NAME_LEN
)) {
93 if (!match_ustctl_field_integer(&first
->enumeration
.container_type
,
94 &second
->enumeration
.container_type
)) {
105 * Compare two _ustctl_basic_type fields known to be of type string.
106 * Returns 1 if both are identical.
108 static bool match_ustctl_field_string_from_raw_basic_type(
109 const union _ustctl_basic_type
*first
,
110 const union _ustctl_basic_type
*second
)
112 return first
->string
.encoding
== second
->string
.encoding
;
116 * Compare two _ustctl_basic_type fields known to be of type float.
117 * Returns 1 if both are identical.
119 static bool match_ustctl_field_float_from_raw_basic_type(
120 const union _ustctl_basic_type
*first
,
121 const union _ustctl_basic_type
*second
)
123 if (first
->_float
.exp_dig
!= second
->_float
.exp_dig
) {
127 if (first
->_float
.mant_dig
!= second
->_float
.mant_dig
) {
131 if (first
->_float
.reverse_byte_order
!=
132 second
->_float
.reverse_byte_order
) {
136 if (first
->_float
.alignment
!= second
->_float
.alignment
) {
147 * Compare two _ustctl_basic_type fields given their respective abstract types.
148 * Returns 1 if both are identical.
150 static bool match_ustctl_field_raw_basic_type(
151 enum ustctl_abstract_types first_atype
,
152 const union _ustctl_basic_type
*first
,
153 enum ustctl_abstract_types second_atype
,
154 const union _ustctl_basic_type
*second
)
156 if (first_atype
!= second_atype
) {
160 switch (first_atype
) {
161 case ustctl_atype_integer
:
162 if (!match_ustctl_field_integer_from_raw_basic_type(first
, second
)) {
166 case ustctl_atype_enum
:
167 if (!match_ustctl_field_enum_from_raw_basic_type(first
, second
)) {
171 case ustctl_atype_string
:
172 if (!match_ustctl_field_string_from_raw_basic_type(first
, second
)) {
176 case ustctl_atype_float
:
177 if (!match_ustctl_field_float_from_raw_basic_type(first
, second
)) {
192 * Compatibility layer between the ustctl_basic_type struct and
193 * _ustctl_basic_type union.
195 static bool match_ustctl_field_basic_type(const struct ustctl_basic_type
*first
,
196 const struct ustctl_basic_type
*second
)
198 return match_ustctl_field_raw_basic_type(first
->atype
, &first
->u
.basic
,
199 second
->atype
, &second
->u
.basic
);
202 int match_ustctl_field(const struct ustctl_field
*first
,
203 const struct ustctl_field
*second
)
205 /* Check the name of the field is identical. */
206 if (strncmp(first
->name
, second
->name
, LTTNG_UST_SYM_NAME_LEN
)) {
210 /* Check the field type is identical. */
211 if (first
->type
.atype
!= second
->type
.atype
) {
215 /* Check the field layout. */
216 switch (first
->type
.atype
) {
217 case ustctl_atype_integer
:
218 case ustctl_atype_enum
:
219 case ustctl_atype_string
:
220 case ustctl_atype_float
:
221 if (!match_ustctl_field_raw_basic_type(first
->type
.atype
,
222 &first
->type
.u
.legacy
.basic
, second
->type
.atype
,
223 &second
->type
.u
.legacy
.basic
)) {
227 case ustctl_atype_sequence
:
228 /* Match element type of the sequence. */
229 if (!match_ustctl_field_basic_type(&first
->type
.u
.legacy
.sequence
.elem_type
,
230 &second
->type
.u
.legacy
.sequence
.elem_type
)) {
234 /* Match length type of the sequence. */
235 if (!match_ustctl_field_basic_type(&first
->type
.u
.legacy
.sequence
.length_type
,
236 &second
->type
.u
.legacy
.sequence
.length_type
)) {
240 case ustctl_atype_array
:
241 /* Match element type of the array. */
242 if (!match_ustctl_field_basic_type(&first
->type
.u
.legacy
.array
.elem_type
,
243 &second
->type
.u
.legacy
.array
.elem_type
)) {
247 /* Match length of the array. */
248 if (first
->type
.u
.legacy
.array
.length
!= second
->type
.u
.legacy
.array
.length
) {
252 case ustctl_atype_variant
:
253 /* Compare number of choice of the variants. */
254 if (first
->type
.u
.legacy
.variant
.nr_choices
!=
255 second
->type
.u
.legacy
.variant
.nr_choices
) {
259 /* Compare tag name of the variants. */
260 if (strncmp(first
->type
.u
.legacy
.variant
.tag_name
,
261 second
->type
.u
.legacy
.variant
.tag_name
,
262 LTTNG_UST_SYM_NAME_LEN
)) {
266 case ustctl_atype_struct
:
267 /* Compare number of fields of the structs. */
268 if (first
->type
.u
.legacy
._struct
.nr_fields
!= second
->type
.u
.legacy
._struct
.nr_fields
) {
272 case ustctl_atype_sequence_nestable
:
273 if (first
->type
.u
.sequence_nestable
.alignment
!= second
->type
.u
.sequence_nestable
.alignment
) {
276 /* Compare length_name of the sequences. */
277 if (strncmp(first
->type
.u
.sequence_nestable
.length_name
,
278 second
->type
.u
.sequence_nestable
.length_name
,
279 LTTNG_UST_SYM_NAME_LEN
)) {
282 /* Comparison will be done when marshalling following items. */
284 case ustctl_atype_array_nestable
:
285 if (first
->type
.u
.array_nestable
.alignment
!= second
->type
.u
.array_nestable
.alignment
) {
288 /* Match length of the array. */
289 if (first
->type
.u
.array_nestable
.length
!= second
->type
.u
.array_nestable
.length
) {
292 /* Comparison of element type will be done when marshalling following item. */
294 case ustctl_atype_enum_nestable
:
295 if (first
->type
.u
.enum_nestable
.id
!= second
->type
.u
.enum_nestable
.id
) {
298 /* Compare name of the enums. */
299 if (strncmp(first
->type
.u
.enum_nestable
.name
,
300 second
->type
.u
.enum_nestable
.name
,
301 LTTNG_UST_SYM_NAME_LEN
)) {
304 /* Comparison of element type will be done when marshalling following item. */
306 case ustctl_atype_struct_nestable
:
307 if (first
->type
.u
.struct_nestable
.alignment
!= second
->type
.u
.struct_nestable
.alignment
) {
310 /* Compare number of fields of the structs. */
311 if (first
->type
.u
.struct_nestable
.nr_fields
!= second
->type
.u
.struct_nestable
.nr_fields
) {
315 case ustctl_atype_variant_nestable
:
316 if (first
->type
.u
.variant_nestable
.alignment
!= second
->type
.u
.variant_nestable
.alignment
) {
319 /* Compare number of choice of the variants. */
320 if (first
->type
.u
.variant_nestable
.nr_choices
!=
321 second
->type
.u
.variant_nestable
.nr_choices
) {
325 /* Compare tag name of the variants. */
326 if (strncmp(first
->type
.u
.variant_nestable
.tag_name
,
327 second
->type
.u
.variant_nestable
.tag_name
,
328 LTTNG_UST_SYM_NAME_LEN
)) {