2 * Copyright (C) 2018 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: LGPL-2.1-only
8 #include "common/compat/string.h"
9 #include "common/macros.h"
10 #include "lttng/lttng-error.h"
12 #include <common/buffer-view.h>
13 #include <common/dynamic-array.h>
14 #include <common/dynamic-buffer.h>
15 #include <common/error.h>
16 #include <common/sessiond-comm/sessiond-comm.h>
17 #include <lttng/constant.h>
18 #include <lttng/event-internal.h>
19 #include <lttng/event.h>
20 #include <lttng/userspace-probe-internal.h>
24 struct event_list_element
{
25 struct lttng_event
*event
;
26 struct lttng_event_exclusion
*exclusions
;
27 char *filter_expression
;
30 static void event_list_destructor(void *ptr
)
32 struct event_list_element
*element
= (struct event_list_element
*) ptr
;
34 free(element
->filter_expression
);
35 free(element
->exclusions
);
36 lttng_event_destroy(element
->event
);
41 struct lttng_event
*lttng_event_copy(const struct lttng_event
*event
)
43 struct lttng_event
*new_event
;
44 struct lttng_event_extended
*new_event_extended
;
46 new_event
= zmalloc(sizeof(*event
));
48 PERROR("Error allocating event structure");
52 /* Copy the content of the old event. */
53 memcpy(new_event
, event
, sizeof(*event
));
56 * We need to create a new extended since the previous pointer is now
59 new_event_extended
= zmalloc(sizeof(*new_event_extended
));
60 if (!new_event_extended
) {
61 PERROR("Error allocating event extended structure");
65 new_event
->extended
.ptr
= new_event_extended
;
74 static int lttng_event_probe_attr_serialize(
75 const struct lttng_event_probe_attr
*probe
,
76 struct lttng_dynamic_buffer
*buf
)
79 size_t symbol_name_len
;
80 struct lttng_event_probe_attr_comm comm
= { 0 };
82 symbol_name_len
= lttng_strnlen(probe
->symbol_name
, LTTNG_SYMBOL_NAME_LEN
);
83 if (symbol_name_len
== LTTNG_SYMBOL_NAME_LEN
) {
84 /* Not null-termintated. */
89 /* Include the null terminator. */
92 comm
.symbol_name_len
= (uint32_t) symbol_name_len
;
93 comm
.addr
= probe
->addr
;
94 comm
.offset
= probe
->addr
;
96 ret
= lttng_dynamic_buffer_append(buf
, &comm
, sizeof(comm
));
102 ret
= lttng_dynamic_buffer_append(buf
, probe
->symbol_name
, symbol_name_len
);
108 static int lttng_event_function_attr_serialize(
109 const struct lttng_event_function_attr
*function
,
110 struct lttng_dynamic_buffer
*buf
)
113 size_t symbol_name_len
;
114 struct lttng_event_function_attr_comm comm
= { 0 };
116 symbol_name_len
= lttng_strnlen(function
->symbol_name
, LTTNG_SYMBOL_NAME_LEN
);
117 if (symbol_name_len
== LTTNG_SYMBOL_NAME_LEN
) {
118 /* Not null-termintated. */
123 /* Include the null terminator. */
124 symbol_name_len
+= 1;
126 comm
.symbol_name_len
= (uint32_t) symbol_name_len
;
128 ret
= lttng_dynamic_buffer_append(buf
, &comm
, sizeof(comm
));
134 ret
= lttng_dynamic_buffer_append(buf
, function
->symbol_name
, symbol_name_len
);
139 static ssize_t
lttng_event_probe_attr_create_from_buffer(
140 const struct lttng_buffer_view
*view
,
141 struct lttng_event_probe_attr
**probe_attr
)
143 ssize_t ret
, offset
= 0;
144 const struct lttng_event_probe_attr_comm
*comm
;
145 struct lttng_event_probe_attr
*local_attr
= NULL
;
146 const struct lttng_buffer_view comm_view
= lttng_buffer_view_from_view(
147 view
, offset
, sizeof(*comm
));
149 if (!lttng_buffer_view_is_valid(&comm_view
)) {
154 comm
= (typeof(comm
)) view
->data
;
155 offset
+= sizeof(*comm
);
157 local_attr
= zmalloc(sizeof(*local_attr
));
158 if (local_attr
== NULL
) {
163 local_attr
->addr
= comm
->addr
;
164 local_attr
->offset
= comm
->offset
;
168 const struct lttng_buffer_view name_view
=
169 lttng_buffer_view_from_view(view
, offset
,
170 comm
->symbol_name_len
);
171 if (!lttng_buffer_view_is_valid(&name_view
)) {
176 name
= name_view
.data
;
178 if (!lttng_buffer_view_contains_string(
179 &name_view
, name
, comm
->symbol_name_len
)) {
184 ret
= lttng_strncpy(local_attr
->symbol_name
, name
,
185 LTTNG_SYMBOL_NAME_LEN
);
190 offset
+= comm
->symbol_name_len
;
193 *probe_attr
= local_attr
;
201 static ssize_t
lttng_event_function_attr_create_from_buffer(
202 const struct lttng_buffer_view
*view
,
203 struct lttng_event_function_attr
**function_attr
)
205 ssize_t ret
, offset
= 0;
206 const struct lttng_event_function_attr_comm
*comm
;
207 struct lttng_event_function_attr
*local_attr
= NULL
;
208 const struct lttng_buffer_view comm_view
= lttng_buffer_view_from_view(
209 view
, offset
, sizeof(*comm
));
211 if (!lttng_buffer_view_is_valid(&comm_view
)) {
216 comm
= (typeof(comm
)) view
->data
;
217 offset
+= sizeof(*comm
);
219 local_attr
= zmalloc(sizeof(*local_attr
));
220 if (local_attr
== NULL
) {
227 const struct lttng_buffer_view name_view
=
228 lttng_buffer_view_from_view(view
, offset
,
229 comm
->symbol_name_len
);
230 if (!lttng_buffer_view_is_valid(&name_view
)) {
235 name
= name_view
.data
;
237 if (!lttng_buffer_view_contains_string(
238 &name_view
, name
, comm
->symbol_name_len
)) {
243 ret
= lttng_strncpy(local_attr
->symbol_name
, name
,
244 LTTNG_SYMBOL_NAME_LEN
);
249 offset
+= comm
->symbol_name_len
;
252 *function_attr
= local_attr
;
260 static ssize_t
lttng_event_exclusions_create_from_buffer(const struct lttng_buffer_view
*view
,
261 uint32_t count
, struct lttng_event_exclusion
**exclusions
)
263 ssize_t ret
, offset
= 0;
264 size_t size
= (count
* LTTNG_SYMBOL_NAME_LEN
);
266 const struct lttng_event_exclusion_comm
*comm
;
267 struct lttng_event_exclusion
*local_exclusions
;
270 local_exclusions
= zmalloc(sizeof(struct lttng_event_exclusion
) + size
);
271 if (!local_exclusions
) {
275 local_exclusions
->count
= count
;
277 for (i
= 0; i
< count
; i
++) {
279 struct lttng_buffer_view string_view
;
280 const struct lttng_buffer_view comm_view
=
281 lttng_buffer_view_from_view(
282 view
, offset
, sizeof(*comm
));
284 if (!lttng_buffer_view_is_valid(&comm_view
)) {
289 comm
= (typeof(comm
)) comm_view
.data
;
290 offset
+= sizeof(*comm
);
292 string_view
= lttng_buffer_view_from_view(
293 view
, offset
, comm
->len
);
295 if (!lttng_buffer_view_is_valid(&string_view
)) {
300 string
= string_view
.data
;
302 if (!lttng_buffer_view_contains_string(
303 &string_view
, string
, comm
->len
)) {
309 local_exclusions
->names
[i
],
318 *exclusions
= local_exclusions
;
319 local_exclusions
= NULL
;
322 free(local_exclusions
);
328 ssize_t
lttng_event_create_from_buffer(const struct lttng_buffer_view
*view
,
329 struct lttng_event
**event
,
330 struct lttng_event_exclusion
**exclusion
,
331 char **filter_expression
,
332 struct lttng_filter_bytecode
**bytecode
,
335 ssize_t ret
, offset
= 0;
336 struct lttng_event
*local_event
= NULL
;
337 struct lttng_event_exclusion
*local_exclusions
= NULL
;
338 struct lttng_filter_bytecode
*local_bytecode
= NULL
;
339 char *local_filter_expression
= NULL
;
340 const struct lttng_event_comm
*event_comm
;
341 struct lttng_event_function_attr
*local_function_attr
= NULL
;
342 struct lttng_event_probe_attr
*local_probe_attr
= NULL
;
343 struct lttng_userspace_probe_location
*local_userspace_probe_location
=
345 int received_fd
= -1;
348 * Only event is obligatory, the other output argument are optional and
349 * depends on what the caller is interested in.
355 const struct lttng_buffer_view comm_view
=
356 lttng_buffer_view_from_view(view
, offset
,
357 sizeof(*event_comm
));
359 if (!lttng_buffer_view_is_valid(&comm_view
)) {
364 /* lttng_event_comm header */
365 event_comm
= (typeof(event_comm
)) comm_view
.data
;
366 offset
+= sizeof(*event_comm
);
369 local_event
= lttng_event_create();
370 if (local_event
== NULL
) {
375 local_event
->type
= event_comm
->event_type
;
376 local_event
->loglevel_type
= event_comm
->loglevel_type
;
377 local_event
->loglevel
= event_comm
->loglevel
;
378 local_event
->enabled
= event_comm
->enabled
;
379 local_event
->pid
= event_comm
->pid
;
380 local_event
->flags
= event_comm
->flags
;
384 const struct lttng_buffer_view name_view
=
385 lttng_buffer_view_from_view(view
, offset
,
386 event_comm
->name_len
);
387 if (!lttng_buffer_view_is_valid(&name_view
)) {
392 name
= name_view
.data
;
394 if (!lttng_buffer_view_contains_string(
395 &name_view
, name
, event_comm
->name_len
)) {
401 local_event
->name
, name
, LTTNG_SYMBOL_NAME_LEN
);
406 offset
+= event_comm
->name_len
;
410 if (event_comm
->exclusion_count
== 0) {
411 goto deserialize_filter_expression
;
416 const struct lttng_buffer_view exclusions_view
=
417 lttng_buffer_view_from_view(
420 if (!lttng_buffer_view_is_valid(&exclusions_view
)) {
425 ret
= lttng_event_exclusions_create_from_buffer(&exclusions_view
,
426 event_comm
->exclusion_count
, &local_exclusions
);
433 local_event
->exclusion
= 1;
436 deserialize_filter_expression
:
438 if (event_comm
->filter_expression_len
== 0) {
439 if (event_comm
->bytecode_len
!= 0) {
441 * This is an invalid event payload.
443 * Filter expression without bytecode is possible but
444 * not the other way around.
449 goto deserialize_event_type_payload
;
453 const char *filter_expression_buffer
;
454 const struct lttng_buffer_view filter_expression_view
=
455 lttng_buffer_view_from_view(view
, offset
,
456 event_comm
->filter_expression_len
);
458 if (!lttng_buffer_view_is_valid(&filter_expression_view
)) {
463 filter_expression_buffer
= filter_expression_view
.data
;
465 if (!lttng_buffer_view_contains_string(&filter_expression_view
,
466 filter_expression_buffer
,
467 event_comm
->filter_expression_len
)) {
472 local_filter_expression
= lttng_strndup(
473 filter_expression_buffer
,
474 event_comm
->filter_expression_len
);
475 if (!local_filter_expression
) {
480 local_event
->filter
= 1;
482 offset
+= event_comm
->filter_expression_len
;
485 if (event_comm
->bytecode_len
== 0) {
487 * Filter expression can be present but without bytecode
488 * when dealing with event listing.
490 goto deserialize_event_type_payload
;
495 const struct lttng_buffer_view bytecode_view
=
496 lttng_buffer_view_from_view(view
, offset
,
497 event_comm
->bytecode_len
);
499 if (!lttng_buffer_view_is_valid(&bytecode_view
)) {
504 local_bytecode
= zmalloc(event_comm
->bytecode_len
);
505 if (!local_bytecode
) {
510 memcpy(local_bytecode
, bytecode_view
.data
,
511 event_comm
->bytecode_len
);
512 if ((local_bytecode
->len
+ sizeof(*local_bytecode
)) !=
513 event_comm
->bytecode_len
) {
518 offset
+= event_comm
->bytecode_len
;
521 deserialize_event_type_payload
:
522 /* Event type specific payload */
523 switch (local_event
->type
) {
524 case LTTNG_EVENT_FUNCTION
:
526 case LTTNG_EVENT_PROBE
:
528 const struct lttng_buffer_view probe_attr_view
=
529 lttng_buffer_view_from_view(view
, offset
,
530 event_comm
->lttng_event_probe_attr_len
);
532 if (event_comm
->lttng_event_probe_attr_len
== 0) {
537 if (!lttng_buffer_view_is_valid(&probe_attr_view
)) {
542 ret
= lttng_event_probe_attr_create_from_buffer(
543 &probe_attr_view
, &local_probe_attr
);
544 if (ret
< 0 || ret
!= event_comm
->lttng_event_probe_attr_len
) {
549 /* Copy to the local event. */
550 memcpy(&local_event
->attr
.probe
, local_probe_attr
,
551 sizeof(local_event
->attr
.probe
));
556 case LTTNG_EVENT_FUNCTION_ENTRY
:
558 const struct lttng_buffer_view function_attr_view
=
559 lttng_buffer_view_from_view(view
, offset
,
560 event_comm
->lttng_event_function_attr_len
);
562 if (event_comm
->lttng_event_function_attr_len
== 0) {
567 if (!lttng_buffer_view_is_valid(&function_attr_view
)) {
572 ret
= lttng_event_function_attr_create_from_buffer(
573 &function_attr_view
, &local_function_attr
);
574 if (ret
< 0 || ret
!= event_comm
->lttng_event_function_attr_len
) {
579 /* Copy to the local event. */
580 memcpy(&local_event
->attr
.ftrace
, local_function_attr
,
581 sizeof(local_event
->attr
.ftrace
));
587 case LTTNG_EVENT_USERSPACE_PROBE
:
589 const struct lttng_buffer_view userspace_probe_location_view
=
590 lttng_buffer_view_from_view(view
, offset
,
591 event_comm
->userspace_probe_location_len
);
592 const struct lttng_userspace_probe_location_lookup_method
595 if (event_comm
->userspace_probe_location_len
== 0) {
600 if (!lttng_buffer_view_is_valid(
601 &userspace_probe_location_view
)) {
606 ret
= lttng_userspace_probe_location_create_from_buffer(
607 &userspace_probe_location_view
,
608 &local_userspace_probe_location
);
610 WARN("Failed to create a userspace probe location from the received buffer");
615 if (ret
!= event_comm
->userspace_probe_location_len
) {
616 WARN("Userspace probe location from the received buffer is not the advertised length: header length = %" PRIu32
", payload length = %zd", event_comm
->userspace_probe_location_len
, ret
);
623 * The userspace FD is simply not sent and we do not
624 * care about it. This happens on listing.
626 goto attach_userspace_probe_to_event
;
630 * Receive the file descriptor to the target binary from the
633 DBG("Receiving userspace probe target FD from client ...");
634 ret
= lttcomm_recv_fds_unix_sock(sock
, &received_fd
, 1);
636 DBG("Nothing recv() from client userspace probe fd... continuing");
641 * Set the file descriptor received from the client through the
642 * unix socket in the probe location.
644 lookup
= lttng_userspace_probe_location_get_lookup_method(
645 local_userspace_probe_location
);
647 ret
= LTTNG_ERR_PROBE_LOCATION_INVAL
;
652 * From the kernel tracer's perspective, all userspace probe
653 * event types are all the same: a file and an offset.
655 switch (lttng_userspace_probe_location_lookup_method_get_type(
657 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_ELF
:
658 ret
= lttng_userspace_probe_location_function_set_binary_fd(
659 local_userspace_probe_location
,
662 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT
:
663 ret
= lttng_userspace_probe_location_tracepoint_set_binary_fd(
664 local_userspace_probe_location
,
668 ret
= LTTNG_ERR_PROBE_LOCATION_INVAL
;
673 ret
= LTTNG_ERR_PROBE_LOCATION_INVAL
;
677 /* Fd transfered to the object. */
680 attach_userspace_probe_to_event
:
682 /* Attach the probe location to the event. */
683 ret
= lttng_event_set_userspace_probe_location(
684 local_event
, local_userspace_probe_location
);
686 ret
= LTTNG_ERR_PROBE_LOCATION_INVAL
;
691 * Userspace probe location object ownership transfered to the
694 local_userspace_probe_location
= NULL
;
695 offset
+= event_comm
->userspace_probe_location_len
;
698 case LTTNG_EVENT_TRACEPOINT
:
700 case LTTNG_EVENT_ALL
:
702 case LTTNG_EVENT_SYSCALL
:
704 case LTTNG_EVENT_NOOP
:
705 /* Nothing to do here */
713 /* Transfer ownership to the caller. */
714 *event
= local_event
;
718 *bytecode
= local_bytecode
;
719 local_bytecode
= NULL
;
723 *exclusion
= local_exclusions
;
724 local_exclusions
= NULL
;
727 if (filter_expression
) {
728 *filter_expression
= local_filter_expression
;
729 local_filter_expression
= NULL
;
734 lttng_event_destroy(local_event
);
735 lttng_userspace_probe_location_destroy(local_userspace_probe_location
);
736 free(local_filter_expression
);
737 free(local_exclusions
);
738 free(local_bytecode
);
739 free(local_function_attr
);
740 free(local_probe_attr
);
741 if (received_fd
> -1) {
742 if (close(received_fd
)) {
743 PERROR("Failed to close received fd");
750 int lttng_event_serialize(const struct lttng_event
*event
,
751 unsigned int exclusion_count
,
752 char **exclusion_list
,
753 char *filter_expression
,
756 struct lttng_dynamic_buffer
*buf
,
761 size_t header_offset
, size_before_payload
;
763 struct lttng_event_comm event_comm
= { 0 };
764 struct lttng_event_comm
*header
;
769 /* Save the header location for later in-place header update. */
770 header_offset
= buf
->size
;
772 name_len
= lttng_strnlen(event
->name
, LTTNG_SYMBOL_NAME_LEN
);
773 if (name_len
== LTTNG_SYMBOL_NAME_LEN
) {
774 /* Event name is not NULL-terminated. */
779 /* Add null termination. */
782 if (exclusion_count
> UINT32_MAX
) {
783 /* Possible overflow. */
788 if (bytecode_len
> UINT32_MAX
) {
789 /* Possible overflow. */
794 event_comm
.name_len
= (uint32_t) name_len
;
795 event_comm
.event_type
= (int8_t) event
->type
;
796 event_comm
.loglevel_type
= (int8_t) event
->loglevel_type
;
797 event_comm
.loglevel
= (int32_t) event
->loglevel
;
798 event_comm
.enabled
= (int8_t) event
->enabled
;
799 event_comm
.pid
= (int32_t) event
->pid
;
800 event_comm
.exclusion_count
= (uint32_t) exclusion_count
;
801 event_comm
.bytecode_len
= (uint32_t) bytecode_len
;
802 event_comm
.flags
= (int32_t) event
->flags
;
804 if (filter_expression
) {
805 event_comm
.filter_expression_len
=
806 strlen(filter_expression
) + 1;
810 ret
= lttng_dynamic_buffer_append(buf
, &event_comm
, sizeof(event_comm
));
816 ret
= lttng_dynamic_buffer_append(buf
, event
->name
, name_len
);
822 for (i
= 0; i
< exclusion_count
; i
++) {
823 size_t exclusion_len
;
824 struct lttng_event_exclusion_comm exclusion_comm
= { 0 };
826 assert(exclusion_list
);
828 exclusion_len
= lttng_strnlen(
829 *(exclusion_list
+ i
), LTTNG_SYMBOL_NAME_LEN
);
830 if (exclusion_len
== LTTNG_SYMBOL_NAME_LEN
) {
831 /* Exclusion is not NULL-terminated. */
836 /* Include null terminator '\0'. */
839 exclusion_comm
.len
= exclusion_len
;
841 ret
= lttng_dynamic_buffer_append(buf
, &exclusion_comm
, sizeof(exclusion_comm
));
846 ret
= lttng_dynamic_buffer_append(buf
, *(exclusion_list
+ i
),
853 /* Filter expression and its bytecode */
854 if (filter_expression
) {
855 ret
= lttng_dynamic_buffer_append(buf
, filter_expression
,
856 event_comm
.filter_expression_len
);
862 * Bytecode can be absent when we serialize to the client
866 ret
= lttng_dynamic_buffer_append(
867 buf
, bytecode
, bytecode_len
);
874 size_before_payload
= buf
->size
;
876 /* Event type specific payload */
877 switch (event
->type
) {
878 case LTTNG_EVENT_FUNCTION
:
880 case LTTNG_EVENT_PROBE
:
881 ret
= lttng_event_probe_attr_serialize(&event
->attr
.probe
, buf
);
887 header
= (struct lttng_event_comm
*) ((char *) buf
->data
+
889 header
->lttng_event_probe_attr_len
=
890 buf
->size
- size_before_payload
;
893 case LTTNG_EVENT_FUNCTION_ENTRY
:
894 ret
= lttng_event_function_attr_serialize(
895 &event
->attr
.ftrace
, buf
);
901 /* Update the lttng_event_function_attr len. */
902 header
= (struct lttng_event_comm
*) ((char *) buf
->data
+
904 header
->lttng_event_function_attr_len
=
905 buf
->size
- size_before_payload
;
908 case LTTNG_EVENT_USERSPACE_PROBE
:
910 struct lttng_event_extended
*ev_ext
=
911 (struct lttng_event_extended
*)
913 assert(event
->extended
.ptr
);
914 assert(ev_ext
->probe_location
);
916 size_before_payload
= buf
->size
;
917 if (ev_ext
->probe_location
) {
919 * lttng_userspace_probe_location_serialize returns the
920 * number of bytes that were appended to the buffer.
922 ret
= lttng_userspace_probe_location_serialize(
923 ev_ext
->probe_location
, buf
,
930 /* Update the userspace probe location len. */
931 header
= (struct lttng_event_comm
*) ((char *) buf
->data
+
933 header
->userspace_probe_location_len
=
934 buf
->size
- size_before_payload
;
938 case LTTNG_EVENT_TRACEPOINT
:
940 case LTTNG_EVENT_ALL
:
943 /* Nothing to do here */
951 static ssize_t
lttng_event_context_app_populate_from_buffer(
952 const struct lttng_buffer_view
*view
,
953 struct lttng_event_context
*event_ctx
)
955 ssize_t ret
, offset
= 0;
956 const struct lttng_event_context_app_comm
*comm
;
957 char *provider_name
= NULL
, *context_name
= NULL
;
958 size_t provider_name_len
, context_name_len
;
959 const struct lttng_buffer_view comm_view
= lttng_buffer_view_from_view(
960 view
, offset
, sizeof(*comm
));
962 assert(event_ctx
->ctx
== LTTNG_EVENT_CONTEXT_APP_CONTEXT
);
964 if (!lttng_buffer_view_is_valid(&comm_view
)) {
969 comm
= (typeof(comm
)) comm_view
.data
;
970 offset
+= sizeof(*comm
);
972 provider_name_len
= comm
->provider_name_len
;
973 context_name_len
= comm
->ctx_name_len
;
975 if (provider_name_len
== 0 || context_name_len
== 0) {
977 * Application provider and context names MUST
986 const struct lttng_buffer_view provider_name_view
=
987 lttng_buffer_view_from_view(view
, offset
,
990 if (!lttng_buffer_view_is_valid(&provider_name_view
)) {
995 name
= provider_name_view
.data
;
997 if (!lttng_buffer_view_contains_string(&provider_name_view
,
998 name
, provider_name_len
)) {
1003 provider_name
= lttng_strndup(name
, provider_name_len
);
1004 if (!provider_name
) {
1008 offset
+= provider_name_len
;
1013 const struct lttng_buffer_view context_name_view
=
1014 lttng_buffer_view_from_view(
1015 view
, offset
, context_name_len
);
1017 if (!lttng_buffer_view_is_valid(&context_name_view
)) {
1022 name
= context_name_view
.data
;
1024 if (!lttng_buffer_view_contains_string(&context_name_view
, name
,
1025 context_name_len
)) {
1030 context_name
= lttng_strndup(name
, context_name_len
);
1031 if (!context_name
) {
1036 offset
+= context_name_len
;
1039 /* Transfer ownership of the strings */
1040 event_ctx
->u
.app_ctx
.provider_name
= provider_name
;
1041 event_ctx
->u
.app_ctx
.ctx_name
= context_name
;
1042 provider_name
= NULL
;
1043 context_name
= NULL
;
1047 free(provider_name
);
1053 static ssize_t
lttng_event_context_perf_counter_populate_from_buffer(
1054 const struct lttng_buffer_view
*view
,
1055 struct lttng_event_context
*event_ctx
)
1058 ssize_t consumed
, offset
= 0;
1059 const struct lttng_event_context_perf_counter_comm
*comm
;
1061 const struct lttng_buffer_view comm_view
= lttng_buffer_view_from_view(
1062 view
, offset
, sizeof(*comm
));
1064 assert(event_ctx
->ctx
== LTTNG_EVENT_CONTEXT_PERF_COUNTER
||
1066 LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
||
1067 event_ctx
->ctx
== LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER
);
1069 if (!lttng_buffer_view_is_valid(&comm_view
)) {
1074 comm
= (typeof(comm
)) comm_view
.data
;
1075 offset
+= sizeof(*comm
);
1077 name_len
= comm
->name_len
;
1080 const struct lttng_buffer_view provider_name_view
=
1081 lttng_buffer_view_from_view(
1082 view
, offset
, name_len
);
1083 if (!lttng_buffer_view_is_valid(&provider_name_view
)) {
1088 name
= provider_name_view
.data
;
1090 if (!lttng_buffer_view_contains_string(
1091 &provider_name_view
, name
, name_len
)) {
1096 ret
= lttng_strncpy(event_ctx
->u
.perf_counter
.name
, name
,
1097 sizeof(event_ctx
->u
.perf_counter
.name
));
1105 event_ctx
->u
.perf_counter
.config
= comm
->config
;
1106 event_ctx
->u
.perf_counter
.type
= comm
->type
;
1115 ssize_t
lttng_event_context_create_from_buffer(
1116 const struct lttng_buffer_view
*view
,
1117 struct lttng_event_context
**event_ctx
)
1119 ssize_t ret
, offset
= 0;
1120 const struct lttng_event_context_comm
*comm
;
1121 struct lttng_event_context
*local_context
= NULL
;
1122 struct lttng_buffer_view subtype_view
;
1123 struct lttng_buffer_view comm_view
= lttng_buffer_view_from_view(
1124 view
, offset
, sizeof(*comm
));
1129 if (!lttng_buffer_view_is_valid(&comm_view
)) {
1134 comm
= (typeof(comm
)) comm_view
.data
;
1135 offset
+= sizeof(*comm
);
1137 local_context
= zmalloc(sizeof(*local_context
));
1138 if (!local_context
) {
1143 local_context
->ctx
= comm
->type
;
1145 subtype_view
= lttng_buffer_view_from_view(view
, offset
, -1);
1147 switch (local_context
->ctx
) {
1148 case LTTNG_EVENT_CONTEXT_APP_CONTEXT
:
1149 ret
= lttng_event_context_app_populate_from_buffer(
1150 &subtype_view
, local_context
);
1152 case LTTNG_EVENT_CONTEXT_PERF_COUNTER
:
1153 case LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
:
1154 case LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER
:
1155 ret
= lttng_event_context_perf_counter_populate_from_buffer(
1156 &subtype_view
, local_context
);
1159 /* Nothing else to deserialize. */
1170 *event_ctx
= local_context
;
1171 local_context
= NULL
;
1175 free(local_context
);
1179 static int lttng_event_context_app_serialize(
1180 struct lttng_event_context
*context
,
1181 struct lttng_dynamic_buffer
*buffer
)
1184 struct lttng_event_context_app_comm comm
= { 0 };
1185 size_t provider_len
, ctx_len
;
1186 const char *provider_name
;
1187 const char *ctx_name
;
1191 assert(context
->ctx
== LTTNG_EVENT_CONTEXT_APP_CONTEXT
);
1193 provider_name
= context
->u
.app_ctx
.provider_name
;
1194 ctx_name
= context
->u
.app_ctx
.ctx_name
;
1196 if (!provider_name
|| !ctx_name
) {
1197 ret
= -LTTNG_ERR_INVALID
;
1201 provider_len
= strlen(provider_name
);
1202 if (provider_len
== 0) {
1203 ret
= -LTTNG_ERR_INVALID
;
1207 /* Include the null terminator. */
1209 comm
.provider_name_len
= provider_len
;
1211 ctx_len
= strlen(ctx_name
);
1213 ret
= -LTTNG_ERR_INVALID
;
1217 /* Include the null terminator. */
1219 comm
.ctx_name_len
= ctx_len
;
1222 ret
= lttng_dynamic_buffer_append(buffer
, &comm
, sizeof(comm
));
1228 ret
= lttng_dynamic_buffer_append(buffer
, provider_name
, provider_len
);
1233 ret
= lttng_dynamic_buffer_append(buffer
, ctx_name
, ctx_len
);
1243 static int lttng_event_context_perf_counter_serialize(
1244 struct lttng_event_perf_counter_ctx
*context
,
1245 struct lttng_dynamic_buffer
*buffer
)
1248 struct lttng_event_context_perf_counter_comm comm
= { 0 };
1253 comm
.config
= context
->config
;
1254 comm
.type
= context
->type
;
1255 comm
.name_len
= lttng_strnlen(context
->name
, LTTNG_SYMBOL_NAME_LEN
);
1257 if (comm
.name_len
== LTTNG_SYMBOL_NAME_LEN
) {
1262 /* Include the null terminator. */
1266 ret
= lttng_dynamic_buffer_append(buffer
, &comm
, sizeof(comm
));
1272 ret
= lttng_dynamic_buffer_append(buffer
, context
->name
, comm
.name_len
);
1283 int lttng_event_context_serialize(struct lttng_event_context
*context
,
1284 struct lttng_dynamic_buffer
*buf
)
1287 struct lttng_event_context_comm context_comm
= { 0 };
1292 context_comm
.type
= (uint32_t) context
->ctx
;
1295 ret
= lttng_dynamic_buffer_append(
1296 buf
, &context_comm
, sizeof(context_comm
));
1301 switch (context
->ctx
) {
1302 case LTTNG_EVENT_CONTEXT_APP_CONTEXT
:
1303 ret
= lttng_event_context_app_serialize(context
, buf
);
1305 case LTTNG_EVENT_CONTEXT_PERF_COUNTER
:
1306 case LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
:
1307 case LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER
:
1308 ret
= lttng_event_context_perf_counter_serialize(
1309 &context
->u
.perf_counter
, buf
);
1312 /* Nothing else to serialize. */
1325 void lttng_event_context_destroy(struct lttng_event_context
*context
)
1331 if (context
->ctx
== LTTNG_EVENT_CONTEXT_APP_CONTEXT
) {
1332 free(context
->u
.app_ctx
.provider_name
);
1333 free(context
->u
.app_ctx
.ctx_name
);
1340 * This is a specialized populate for lttng_event_field since it ignores
1341 * the extension field of the lttng_event struct and simply copies what it can
1342 * to the internal struct lttng_event of a lttng_event_field.
1344 static void lttng_event_field_populate_lttng_event_from_event(
1345 const struct lttng_event
*src
, struct lttng_event
*destination
)
1347 memcpy(destination
, src
, sizeof(*destination
));
1349 /* Remove all possible dynamic data from the destination event rule. */
1350 destination
->extended
.ptr
= NULL
;
1354 ssize_t
lttng_event_field_create_from_buffer(
1355 const struct lttng_buffer_view
*view
,
1356 struct lttng_event_field
**field
)
1358 ssize_t ret
, offset
= 0;
1359 struct lttng_event_field
*local_event_field
= NULL
;
1360 struct lttng_event
*event
= NULL
;
1361 const struct lttng_event_field_comm
*comm
;
1362 const char* name
= NULL
;
1368 const struct lttng_buffer_view comm_view
=
1369 lttng_buffer_view_from_view(
1370 view
, offset
, sizeof(*comm
));
1372 if (!lttng_buffer_view_is_valid(&comm_view
)) {
1376 /* lttng_event_field_comm header */
1377 comm
= (const struct lttng_event_field_comm
*) view
->data
;
1378 offset
+= sizeof(*comm
);
1381 local_event_field
= zmalloc(sizeof(*local_event_field
));
1382 if (!local_event_field
) {
1387 local_event_field
->type
= comm
->type
;
1388 local_event_field
->nowrite
= comm
->nowrite
;
1392 const struct lttng_buffer_view name_view
=
1393 lttng_buffer_view_from_view(
1394 view
, offset
, comm
->name_len
);
1396 if (!lttng_buffer_view_is_valid(&name_view
)) {
1401 name
= name_view
.data
;
1403 if (!lttng_buffer_view_contains_string(&name_view
, name_view
.data
, comm
->name_len
)) {
1408 if (comm
->name_len
> LTTNG_SYMBOL_NAME_LEN
- 1) {
1409 /* Name is too long.*/
1413 offset
+= comm
->name_len
;
1418 const struct lttng_buffer_view event_view
=
1419 lttng_buffer_view_from_view(
1420 view
, offset
, comm
->event_len
);
1422 if (!lttng_buffer_view_is_valid(&event_view
)) {
1426 ret
= lttng_event_create_from_buffer(&event_view
, &event
, NULL
,
1428 if (ret
!= comm
->event_len
) {
1437 if (lttng_strncpy(local_event_field
->field_name
, name
, LTTNG_SYMBOL_NAME_LEN
)) {
1442 lttng_event_field_populate_lttng_event_from_event(
1443 event
, &local_event_field
->event
);
1445 *field
= local_event_field
;
1446 local_event_field
= NULL
;
1449 lttng_event_destroy(event
);
1450 free(local_event_field
);
1455 int lttng_event_field_serialize(const struct lttng_event_field
*field
,
1456 struct lttng_dynamic_buffer
*buffer
)
1459 size_t header_offset
, size_before_event
;
1461 struct lttng_event_field_comm event_field_comm
= { 0 };
1462 struct lttng_event_field_comm
*header
;
1467 /* Save the header location for later in-place header update. */
1468 header_offset
= buffer
->size
;
1470 name_len
= strnlen(field
->field_name
, LTTNG_SYMBOL_NAME_LEN
);
1471 if (name_len
== LTTNG_SYMBOL_NAME_LEN
) {
1472 /* Event name is not NULL-terminated. */
1477 /* Add null termination. */
1480 event_field_comm
.type
= field
->type
;
1481 event_field_comm
.nowrite
= (uint8_t)field
->nowrite
;
1482 event_field_comm
.name_len
= name_len
;
1485 ret
= lttng_dynamic_buffer_append(
1486 buffer
, &event_field_comm
, sizeof(event_field_comm
));
1492 ret
= lttng_dynamic_buffer_append(buffer
, field
->field_name
, name_len
);
1497 size_before_event
= buffer
->size
;
1498 ret
= lttng_event_serialize(
1499 &field
->event
, 0, NULL
, NULL
, 0, 0, buffer
, NULL
);
1505 /* Update the event len. */
1506 header
= (struct lttng_event_field_comm
*) ((char *) buffer
->data
+
1508 header
->event_len
= buffer
->size
- size_before_event
;
1514 static enum lttng_error_code
compute_flattened_size(
1515 struct lttng_dynamic_pointer_array
*events
, size_t *size
)
1517 enum lttng_error_code ret_code
;
1519 size_t storage_req
, event_count
, i
;
1524 event_count
= lttng_dynamic_pointer_array_get_count(events
);
1526 /* The basic struct lttng_event */
1527 storage_req
= event_count
* sizeof(struct lttng_event
);
1529 /* The struct lttng_event_extended */
1530 storage_req
+= event_count
* sizeof(struct lttng_event_extended
);
1532 for (i
= 0; i
< event_count
; i
++) {
1533 int probe_storage_req
= 0;
1534 const struct event_list_element
*element
=
1535 lttng_dynamic_pointer_array_get_pointer(
1537 const struct lttng_userspace_probe_location
*location
= NULL
;
1539 location
= lttng_event_get_userspace_probe_location(
1542 ret
= lttng_userspace_probe_location_flatten(
1545 ret_code
= LTTNG_ERR_PROBE_LOCATION_INVAL
;
1549 probe_storage_req
= ret
;
1552 if (element
->filter_expression
) {
1553 storage_req
+= strlen(element
->filter_expression
) + 1;
1556 if (element
->exclusions
) {
1557 storage_req
+= element
->exclusions
->count
*
1558 LTTNG_SYMBOL_NAME_LEN
;
1561 /* Padding to ensure the flat probe is aligned. */
1562 storage_req
= ALIGN_TO(storage_req
, sizeof(uint64_t));
1563 storage_req
+= probe_storage_req
;
1566 *size
= storage_req
;
1567 ret_code
= LTTNG_OK
;
1574 * Flatten a list of struct lttng_event.
1576 * The buffer that is returned to the API client must contain a "flat" version
1577 * of the events that are returned. In other words, all pointers within an
1578 * lttng_event must point to a location within the returned buffer so that the
1579 * user may free everything by simply calling free() on the returned buffer.
1580 * This is needed in order to maintain API compatibility.
1582 * A first pass is performed to compute the size of the buffer that must be
1583 * allocated. A second pass is then performed to setup the returned events so
1584 * that their members always point within the buffer.
1586 * The layout of the returned buffer is as follows:
1587 * - struct lttng_event[nb_events],
1588 * - nb_events times the following:
1589 * - struct lttng_event_extended,
1590 * - filter_expression
1592 * - padding to align to 64-bits
1593 * - flattened version of userspace_probe_location
1595 static enum lttng_error_code
flatten_lttng_events(
1596 struct lttng_dynamic_pointer_array
*events
,
1597 struct lttng_event
**flattened_events
)
1599 enum lttng_error_code ret_code
;
1602 struct lttng_dynamic_buffer local_flattened_events
;
1606 assert(flattened_events
);
1608 lttng_dynamic_buffer_init(&local_flattened_events
);
1609 nb_events
= lttng_dynamic_pointer_array_get_count(events
);
1611 ret_code
= compute_flattened_size(events
, &storage_req
);
1612 if (ret_code
!= LTTNG_OK
) {
1617 * We must ensure that "local_flattened_events" is never resized so as
1618 * to preserve the validity of the flattened objects.
1620 ret
= lttng_dynamic_buffer_set_capacity(
1621 &local_flattened_events
, storage_req
);
1623 ret_code
= LTTNG_ERR_NOMEM
;
1627 /* Start by laying the struct lttng_event */
1628 for (i
= 0; i
< nb_events
; i
++) {
1629 struct event_list_element
*element
=
1630 lttng_dynamic_pointer_array_get_pointer(
1634 ret_code
= LTTNG_ERR_FATAL
;
1637 ret
= lttng_dynamic_buffer_append(&local_flattened_events
,
1638 element
->event
, sizeof(struct lttng_event
));
1640 ret_code
= LTTNG_ERR_NOMEM
;
1645 for (i
= 0; i
< nb_events
; i
++) {
1646 struct event_list_element
*element
= lttng_dynamic_pointer_array_get_pointer(events
, i
);
1647 struct lttng_event
*event
= (struct lttng_event
*)
1648 (local_flattened_events
.data
+ (sizeof(struct lttng_event
) * i
));
1649 struct lttng_event_extended
*event_extended
=
1650 (struct lttng_event_extended
*)
1651 (local_flattened_events
.data
+ local_flattened_events
.size
);
1652 const struct lttng_userspace_probe_location
*location
= NULL
;
1656 /* Insert struct lttng_event_extended. */
1657 ret
= lttng_dynamic_buffer_set_size(&local_flattened_events
,
1658 local_flattened_events
.size
+
1659 sizeof(*event_extended
));
1661 ret_code
= LTTNG_ERR_NOMEM
;
1664 event
->extended
.ptr
= event_extended
;
1666 /* Insert filter expression. */
1667 if (element
->filter_expression
) {
1668 size_t len
= strlen(element
->filter_expression
) + 1;
1670 event_extended
->filter_expression
=
1671 local_flattened_events
.data
+
1672 local_flattened_events
.size
;
1673 ret
= lttng_dynamic_buffer_append(
1674 &local_flattened_events
,
1675 element
->filter_expression
, len
);
1677 ret_code
= LTTNG_ERR_NOMEM
;
1682 /* Insert exclusions. */
1683 if (element
->exclusions
) {
1684 event_extended
->exclusions
.count
=
1685 element
->exclusions
->count
;
1686 event_extended
->exclusions
.strings
=
1687 local_flattened_events
.data
+
1688 local_flattened_events
.size
;
1690 ret
= lttng_dynamic_buffer_append(
1691 &local_flattened_events
,
1692 element
->exclusions
->names
,
1693 element
->exclusions
->count
*
1694 LTTNG_SYMBOL_NAME_LEN
);
1696 ret_code
= LTTNG_ERR_NOMEM
;
1701 /* Insert padding to align to 64-bits. */
1702 ret
= lttng_dynamic_buffer_set_size(&local_flattened_events
,
1703 ALIGN_TO(local_flattened_events
.size
,
1706 ret_code
= LTTNG_ERR_NOMEM
;
1710 location
= lttng_event_get_userspace_probe_location(
1713 event_extended
->probe_location
= (struct lttng_userspace_probe_location
*)
1714 (local_flattened_events
.data
+ local_flattened_events
.size
);
1715 ret
= lttng_userspace_probe_location_flatten(
1716 location
, &local_flattened_events
);
1718 ret_code
= LTTNG_ERR_PROBE_LOCATION_INVAL
;
1724 /* Don't reset local_flattened_events buffer as we return its content. */
1725 *flattened_events
= (struct lttng_event
*) local_flattened_events
.data
;
1726 lttng_dynamic_buffer_init(&local_flattened_events
);
1727 ret_code
= LTTNG_OK
;
1729 lttng_dynamic_buffer_reset(&local_flattened_events
);
1733 static enum lttng_error_code
event_list_create_from_buffer(
1734 const struct lttng_buffer_view
*view
,
1736 struct lttng_dynamic_pointer_array
*event_list
)
1738 enum lttng_error_code ret_code
;
1746 for (i
= 0; i
< count
; i
++) {
1748 const struct lttng_buffer_view event_view
=
1749 lttng_buffer_view_from_view(view
, offset
, -1);
1750 struct event_list_element
*element
= zmalloc(sizeof(*element
));
1753 ret_code
= LTTNG_ERR_NOMEM
;
1758 * Lifetime and management of the object is now bound to the
1761 ret
= lttng_dynamic_pointer_array_add_pointer(
1762 event_list
, element
);
1764 event_list_destructor(element
);
1765 ret_code
= LTTNG_ERR_NOMEM
;
1770 * Bytecode is not transmitted on listing in any case we do not
1773 event_size
= lttng_event_create_from_buffer(&event_view
,
1775 &element
->exclusions
,
1776 &element
->filter_expression
, NULL
, -1);
1777 if (event_size
< 0) {
1778 ret_code
= LTTNG_ERR_INVALID
;
1782 offset
+= event_size
;
1785 if (view
->size
!= offset
) {
1786 ret_code
= LTTNG_ERR_INVALID
;
1790 ret_code
= LTTNG_OK
;
1797 enum lttng_error_code
lttng_events_create_and_flatten_from_buffer(
1798 const struct lttng_buffer_view
*view
,
1800 struct lttng_event
**events
)
1802 enum lttng_error_code ret
= LTTNG_OK
;
1803 struct lttng_dynamic_pointer_array local_events
;
1805 lttng_dynamic_pointer_array_init(&local_events
, event_list_destructor
);
1807 /* Deserialize the events */
1809 const struct lttng_buffer_view events_view
=
1810 lttng_buffer_view_from_view(view
, 0, -1);
1812 ret
= event_list_create_from_buffer(
1813 &events_view
, count
, &local_events
);
1814 if (ret
!= LTTNG_OK
) {
1819 ret
= flatten_lttng_events(&local_events
, events
);
1820 if (ret
!= LTTNG_OK
) {
1825 lttng_dynamic_pointer_array_reset(&local_events
);
1829 static enum lttng_error_code
flatten_lttng_event_fields(
1830 struct lttng_dynamic_pointer_array
*event_fields
,
1831 struct lttng_event_field
**flattened_event_fields
)
1834 enum lttng_error_code ret_code
;
1835 size_t storage_req
= 0;
1836 struct lttng_dynamic_buffer local_flattened_event_fields
;
1839 assert(event_fields
);
1840 assert(flattened_event_fields
);
1842 lttng_dynamic_buffer_init(&local_flattened_event_fields
);
1843 nb_event_field
= lttng_dynamic_pointer_array_get_count(event_fields
);
1846 * Here even if the event field contains a `struct lttng_event` that
1847 * could contain dynamic data, in reality it is not the case.
1848 * Dynamic data is not present. Here the flattening is mostly a direct
1849 * memcpy. This is less than ideal but this code is still better than
1850 * direct usage of an unpacked lttng_event_field array.
1852 storage_req
+= sizeof(struct lttng_event_field
) * nb_event_field
;
1854 lttng_dynamic_buffer_init(&local_flattened_event_fields
);
1857 * We must ensure that "local_flattened_event_fields" is never resized
1858 * so as to preserve the validity of the flattened objects.
1860 ret
= lttng_dynamic_buffer_set_capacity(
1861 &local_flattened_event_fields
, storage_req
);
1863 ret_code
= LTTNG_ERR_NOMEM
;
1867 for (i
= 0; i
< nb_event_field
; i
++) {
1868 const struct lttng_event_field
*element
=
1869 lttng_dynamic_pointer_array_get_pointer(
1873 ret_code
= LTTNG_ERR_FATAL
;
1876 ret
= lttng_dynamic_buffer_append(&local_flattened_event_fields
,
1877 element
, sizeof(struct lttng_event_field
));
1879 ret_code
= LTTNG_ERR_NOMEM
;
1884 /* Don't reset local_flattened_channels buffer as we return its content. */
1885 *flattened_event_fields
= (struct lttng_event_field
*) local_flattened_event_fields
.data
;
1886 lttng_dynamic_buffer_init(&local_flattened_event_fields
);
1887 ret_code
= LTTNG_OK
;
1889 lttng_dynamic_buffer_reset(&local_flattened_event_fields
);
1893 static enum lttng_error_code
event_field_list_create_from_buffer(
1894 const struct lttng_buffer_view
*view
,
1896 struct lttng_dynamic_pointer_array
**event_field_list
)
1898 enum lttng_error_code ret_code
;
1899 int ret
, offset
= 0;
1901 struct lttng_dynamic_pointer_array
*list
= NULL
;
1904 assert(event_field_list
);
1906 list
= zmalloc(sizeof(*list
));
1908 ret_code
= LTTNG_ERR_NOMEM
;
1912 lttng_dynamic_pointer_array_init(list
, free
);
1914 for (i
= 0; i
< count
; i
++) {
1915 ssize_t event_field_size
;
1916 struct lttng_event_field
*field
= NULL
;
1917 const struct lttng_buffer_view event_field_view
=
1918 lttng_buffer_view_from_view(view
, offset
, -1);
1920 event_field_size
= lttng_event_field_create_from_buffer(
1921 &event_field_view
, &field
);
1922 if (event_field_size
< 0) {
1923 ret_code
= LTTNG_ERR_INVALID
;
1927 /* Lifetime and management of the object is now bound to the array. */
1928 ret
= lttng_dynamic_pointer_array_add_pointer(list
, field
);
1931 ret_code
= LTTNG_ERR_NOMEM
;
1934 offset
+= event_field_size
;
1937 if (view
->size
!= offset
) {
1938 ret_code
= LTTNG_ERR_INVALID
;
1942 *event_field_list
= list
;
1944 ret_code
= LTTNG_OK
;
1948 lttng_dynamic_pointer_array_reset(list
);
1955 enum lttng_error_code
lttng_event_fields_create_and_flatten_from_buffer(
1956 const struct lttng_buffer_view
*view
,
1958 struct lttng_event_field
**fields
)
1960 enum lttng_error_code ret
;
1961 struct lttng_dynamic_pointer_array
*local_event_fields
= NULL
;
1963 ret
= event_field_list_create_from_buffer(
1964 view
, count
, &local_event_fields
);
1965 if (ret
!= LTTNG_OK
) {
1969 ret
= flatten_lttng_event_fields(local_event_fields
, fields
);
1970 if (ret
!= LTTNG_OK
) {
1974 if (local_event_fields
) {
1975 lttng_dynamic_pointer_array_reset(local_event_fields
);
1976 free(local_event_fields
);