Move to kernel style SPDX license identifiers
[lttng-ust.git] / liblttng-ust / lttng-bytecode.c
1 /*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright (C) 2010-2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 *
6 * LTTng UST bytecode code.
7 */
8
9 #define _LGPL_SOURCE
10 #include <stddef.h>
11 #include <stdint.h>
12
13 #include <urcu/rculist.h>
14
15 #include "lttng-bytecode.h"
16 #include "ust-events-internal.h"
17
18 static const char *opnames[] = {
19 [ BYTECODE_OP_UNKNOWN ] = "UNKNOWN",
20
21 [ BYTECODE_OP_RETURN ] = "RETURN",
22
23 /* binary */
24 [ BYTECODE_OP_MUL ] = "MUL",
25 [ BYTECODE_OP_DIV ] = "DIV",
26 [ BYTECODE_OP_MOD ] = "MOD",
27 [ BYTECODE_OP_PLUS ] = "PLUS",
28 [ BYTECODE_OP_MINUS ] = "MINUS",
29 [ BYTECODE_OP_BIT_RSHIFT ] = "BIT_RSHIFT",
30 [ BYTECODE_OP_BIT_LSHIFT ] = "BIT_LSHIFT",
31 [ BYTECODE_OP_BIT_AND ] = "BIT_AND",
32 [ BYTECODE_OP_BIT_OR ] = "BIT_OR",
33 [ BYTECODE_OP_BIT_XOR ] = "BIT_XOR",
34
35 /* binary comparators */
36 [ BYTECODE_OP_EQ ] = "EQ",
37 [ BYTECODE_OP_NE ] = "NE",
38 [ BYTECODE_OP_GT ] = "GT",
39 [ BYTECODE_OP_LT ] = "LT",
40 [ BYTECODE_OP_GE ] = "GE",
41 [ BYTECODE_OP_LE ] = "LE",
42
43 /* string binary comparators */
44 [ BYTECODE_OP_EQ_STRING ] = "EQ_STRING",
45 [ BYTECODE_OP_NE_STRING ] = "NE_STRING",
46 [ BYTECODE_OP_GT_STRING ] = "GT_STRING",
47 [ BYTECODE_OP_LT_STRING ] = "LT_STRING",
48 [ BYTECODE_OP_GE_STRING ] = "GE_STRING",
49 [ BYTECODE_OP_LE_STRING ] = "LE_STRING",
50
51 /* s64 binary comparators */
52 [ BYTECODE_OP_EQ_S64 ] = "EQ_S64",
53 [ BYTECODE_OP_NE_S64 ] = "NE_S64",
54 [ BYTECODE_OP_GT_S64 ] = "GT_S64",
55 [ BYTECODE_OP_LT_S64 ] = "LT_S64",
56 [ BYTECODE_OP_GE_S64 ] = "GE_S64",
57 [ BYTECODE_OP_LE_S64 ] = "LE_S64",
58
59 /* double binary comparators */
60 [ BYTECODE_OP_EQ_DOUBLE ] = "EQ_DOUBLE",
61 [ BYTECODE_OP_NE_DOUBLE ] = "NE_DOUBLE",
62 [ BYTECODE_OP_GT_DOUBLE ] = "GT_DOUBLE",
63 [ BYTECODE_OP_LT_DOUBLE ] = "LT_DOUBLE",
64 [ BYTECODE_OP_GE_DOUBLE ] = "GE_DOUBLE",
65 [ BYTECODE_OP_LE_DOUBLE ] = "LE_DOUBLE",
66
67 /* Mixed S64-double binary comparators */
68 [ BYTECODE_OP_EQ_DOUBLE_S64 ] = "EQ_DOUBLE_S64",
69 [ BYTECODE_OP_NE_DOUBLE_S64 ] = "NE_DOUBLE_S64",
70 [ BYTECODE_OP_GT_DOUBLE_S64 ] = "GT_DOUBLE_S64",
71 [ BYTECODE_OP_LT_DOUBLE_S64 ] = "LT_DOUBLE_S64",
72 [ BYTECODE_OP_GE_DOUBLE_S64 ] = "GE_DOUBLE_S64",
73 [ BYTECODE_OP_LE_DOUBLE_S64 ] = "LE_DOUBLE_S64",
74
75 [ BYTECODE_OP_EQ_S64_DOUBLE ] = "EQ_S64_DOUBLE",
76 [ BYTECODE_OP_NE_S64_DOUBLE ] = "NE_S64_DOUBLE",
77 [ BYTECODE_OP_GT_S64_DOUBLE ] = "GT_S64_DOUBLE",
78 [ BYTECODE_OP_LT_S64_DOUBLE ] = "LT_S64_DOUBLE",
79 [ BYTECODE_OP_GE_S64_DOUBLE ] = "GE_S64_DOUBLE",
80 [ BYTECODE_OP_LE_S64_DOUBLE ] = "LE_S64_DOUBLE",
81
82 /* unary */
83 [ BYTECODE_OP_UNARY_PLUS ] = "UNARY_PLUS",
84 [ BYTECODE_OP_UNARY_MINUS ] = "UNARY_MINUS",
85 [ BYTECODE_OP_UNARY_NOT ] = "UNARY_NOT",
86 [ BYTECODE_OP_UNARY_PLUS_S64 ] = "UNARY_PLUS_S64",
87 [ BYTECODE_OP_UNARY_MINUS_S64 ] = "UNARY_MINUS_S64",
88 [ BYTECODE_OP_UNARY_NOT_S64 ] = "UNARY_NOT_S64",
89 [ BYTECODE_OP_UNARY_PLUS_DOUBLE ] = "UNARY_PLUS_DOUBLE",
90 [ BYTECODE_OP_UNARY_MINUS_DOUBLE ] = "UNARY_MINUS_DOUBLE",
91 [ BYTECODE_OP_UNARY_NOT_DOUBLE ] = "UNARY_NOT_DOUBLE",
92
93 /* logical */
94 [ BYTECODE_OP_AND ] = "AND",
95 [ BYTECODE_OP_OR ] = "OR",
96
97 /* load field ref */
98 [ BYTECODE_OP_LOAD_FIELD_REF ] = "LOAD_FIELD_REF",
99 [ BYTECODE_OP_LOAD_FIELD_REF_STRING ] = "LOAD_FIELD_REF_STRING",
100 [ BYTECODE_OP_LOAD_FIELD_REF_SEQUENCE ] = "LOAD_FIELD_REF_SEQUENCE",
101 [ BYTECODE_OP_LOAD_FIELD_REF_S64 ] = "LOAD_FIELD_REF_S64",
102 [ BYTECODE_OP_LOAD_FIELD_REF_DOUBLE ] = "LOAD_FIELD_REF_DOUBLE",
103
104 /* load from immediate operand */
105 [ BYTECODE_OP_LOAD_STRING ] = "LOAD_STRING",
106 [ BYTECODE_OP_LOAD_S64 ] = "LOAD_S64",
107 [ BYTECODE_OP_LOAD_DOUBLE ] = "LOAD_DOUBLE",
108
109 /* cast */
110 [ BYTECODE_OP_CAST_TO_S64 ] = "CAST_TO_S64",
111 [ BYTECODE_OP_CAST_DOUBLE_TO_S64 ] = "CAST_DOUBLE_TO_S64",
112 [ BYTECODE_OP_CAST_NOP ] = "CAST_NOP",
113
114 /* get context ref */
115 [ BYTECODE_OP_GET_CONTEXT_REF ] = "GET_CONTEXT_REF",
116 [ BYTECODE_OP_GET_CONTEXT_REF_STRING ] = "GET_CONTEXT_REF_STRING",
117 [ BYTECODE_OP_GET_CONTEXT_REF_S64 ] = "GET_CONTEXT_REF_S64",
118 [ BYTECODE_OP_GET_CONTEXT_REF_DOUBLE ] = "GET_CONTEXT_REF_DOUBLE",
119
120 /* load userspace field ref */
121 [ BYTECODE_OP_LOAD_FIELD_REF_USER_STRING ] = "LOAD_FIELD_REF_USER_STRING",
122 [ BYTECODE_OP_LOAD_FIELD_REF_USER_SEQUENCE ] = "LOAD_FIELD_REF_USER_SEQUENCE",
123
124 /*
125 * load immediate star globbing pattern (literal string)
126 * from immediate.
127 */
128 [ BYTECODE_OP_LOAD_STAR_GLOB_STRING ] = "LOAD_STAR_GLOB_STRING",
129
130 /* globbing pattern binary operator: apply to */
131 [ BYTECODE_OP_EQ_STAR_GLOB_STRING ] = "EQ_STAR_GLOB_STRING",
132 [ BYTECODE_OP_NE_STAR_GLOB_STRING ] = "NE_STAR_GLOB_STRING",
133
134 /*
135 * Instructions for recursive traversal through composed types.
136 */
137 [ BYTECODE_OP_GET_CONTEXT_ROOT ] = "GET_CONTEXT_ROOT",
138 [ BYTECODE_OP_GET_APP_CONTEXT_ROOT ] = "GET_APP_CONTEXT_ROOT",
139 [ BYTECODE_OP_GET_PAYLOAD_ROOT ] = "GET_PAYLOAD_ROOT",
140
141 [ BYTECODE_OP_GET_SYMBOL ] = "GET_SYMBOL",
142 [ BYTECODE_OP_GET_SYMBOL_FIELD ] = "GET_SYMBOL_FIELD",
143 [ BYTECODE_OP_GET_INDEX_U16 ] = "GET_INDEX_U16",
144 [ BYTECODE_OP_GET_INDEX_U64 ] = "GET_INDEX_U64",
145
146 [ BYTECODE_OP_LOAD_FIELD ] = "LOAD_FIELD",
147 [ BYTECODE_OP_LOAD_FIELD_S8 ] = "LOAD_FIELD_S8",
148 [ BYTECODE_OP_LOAD_FIELD_S16 ] = "LOAD_FIELD_S16",
149 [ BYTECODE_OP_LOAD_FIELD_S32 ] = "LOAD_FIELD_S32",
150 [ BYTECODE_OP_LOAD_FIELD_S64 ] = "LOAD_FIELD_S64",
151 [ BYTECODE_OP_LOAD_FIELD_U8 ] = "LOAD_FIELD_U8",
152 [ BYTECODE_OP_LOAD_FIELD_U16 ] = "LOAD_FIELD_U16",
153 [ BYTECODE_OP_LOAD_FIELD_U32 ] = "LOAD_FIELD_U32",
154 [ BYTECODE_OP_LOAD_FIELD_U64 ] = "LOAD_FIELD_U64",
155 [ BYTECODE_OP_LOAD_FIELD_STRING ] = "LOAD_FIELD_STRING",
156 [ BYTECODE_OP_LOAD_FIELD_SEQUENCE ] = "LOAD_FIELD_SEQUENCE",
157 [ BYTECODE_OP_LOAD_FIELD_DOUBLE ] = "LOAD_FIELD_DOUBLE",
158
159 [ BYTECODE_OP_UNARY_BIT_NOT ] = "UNARY_BIT_NOT",
160
161 [ BYTECODE_OP_RETURN_S64 ] = "RETURN_S64",
162 };
163
164 const char *print_op(enum bytecode_op op)
165 {
166 if (op >= NR_BYTECODE_OPS)
167 return "UNKNOWN";
168 else
169 return opnames[op];
170 }
171
172 static
173 int apply_field_reloc(const struct lttng_event_desc *event_desc,
174 struct bytecode_runtime *runtime,
175 uint32_t runtime_len,
176 uint32_t reloc_offset,
177 const char *field_name,
178 enum bytecode_op bytecode_op)
179 {
180 const struct lttng_event_field *fields, *field = NULL;
181 unsigned int nr_fields, i;
182 struct load_op *op;
183 uint32_t field_offset = 0;
184
185 dbg_printf("Apply field reloc: %u %s\n", reloc_offset, field_name);
186
187 /* Lookup event by name */
188 if (!event_desc)
189 return -EINVAL;
190 fields = event_desc->fields;
191 if (!fields)
192 return -EINVAL;
193 nr_fields = event_desc->nr_fields;
194 for (i = 0; i < nr_fields; i++) {
195 if (fields[i].u.ext.nofilter) {
196 continue;
197 }
198 if (!strcmp(fields[i].name, field_name)) {
199 field = &fields[i];
200 break;
201 }
202 /* compute field offset */
203 switch (fields[i].type.atype) {
204 case atype_integer:
205 case atype_enum:
206 case atype_enum_nestable:
207 field_offset += sizeof(int64_t);
208 break;
209 case atype_array:
210 case atype_array_nestable:
211 case atype_sequence:
212 case atype_sequence_nestable:
213 field_offset += sizeof(unsigned long);
214 field_offset += sizeof(void *);
215 break;
216 case atype_string:
217 field_offset += sizeof(void *);
218 break;
219 case atype_float:
220 field_offset += sizeof(double);
221 break;
222 default:
223 return -EINVAL;
224 }
225 }
226 if (!field)
227 return -EINVAL;
228
229 /* Check if field offset is too large for 16-bit offset */
230 if (field_offset > FILTER_BYTECODE_MAX_LEN - 1)
231 return -EINVAL;
232
233 /* set type */
234 op = (struct load_op *) &runtime->code[reloc_offset];
235
236 switch (bytecode_op) {
237 case BYTECODE_OP_LOAD_FIELD_REF:
238 {
239 struct field_ref *field_ref;
240
241 field_ref = (struct field_ref *) op->data;
242 switch (field->type.atype) {
243 case atype_integer:
244 case atype_enum:
245 case atype_enum_nestable:
246 op->op = BYTECODE_OP_LOAD_FIELD_REF_S64;
247 break;
248 case atype_array:
249 case atype_array_nestable:
250 case atype_sequence:
251 case atype_sequence_nestable:
252 op->op = BYTECODE_OP_LOAD_FIELD_REF_SEQUENCE;
253 break;
254 case atype_string:
255 op->op = BYTECODE_OP_LOAD_FIELD_REF_STRING;
256 break;
257 case atype_float:
258 op->op = BYTECODE_OP_LOAD_FIELD_REF_DOUBLE;
259 break;
260 default:
261 return -EINVAL;
262 }
263 /* set offset */
264 field_ref->offset = (uint16_t) field_offset;
265 break;
266 }
267 default:
268 return -EINVAL;
269 }
270 return 0;
271 }
272
273 static
274 int apply_context_reloc(struct bytecode_runtime *runtime,
275 uint32_t runtime_len,
276 uint32_t reloc_offset,
277 const char *context_name,
278 enum bytecode_op bytecode_op)
279 {
280 struct load_op *op;
281 struct lttng_ctx_field *ctx_field;
282 int idx;
283 struct lttng_ctx **pctx = runtime->p.pctx;
284
285 dbg_printf("Apply context reloc: %u %s\n", reloc_offset, context_name);
286
287 /* Get context index */
288 idx = lttng_get_context_index(*pctx, context_name);
289 if (idx < 0) {
290 if (lttng_context_is_app(context_name)) {
291 int ret;
292
293 ret = lttng_ust_add_app_context_to_ctx_rcu(context_name,
294 pctx);
295 if (ret)
296 return ret;
297 idx = lttng_get_context_index(*pctx, context_name);
298 if (idx < 0)
299 return -ENOENT;
300 } else {
301 return -ENOENT;
302 }
303 }
304 /* Check if idx is too large for 16-bit offset */
305 if (idx > FILTER_BYTECODE_MAX_LEN - 1)
306 return -EINVAL;
307
308 /* Get context return type */
309 ctx_field = &(*pctx)->fields[idx];
310 op = (struct load_op *) &runtime->code[reloc_offset];
311
312 switch (bytecode_op) {
313 case BYTECODE_OP_GET_CONTEXT_REF:
314 {
315 struct field_ref *field_ref;
316
317 field_ref = (struct field_ref *) op->data;
318 switch (ctx_field->event_field.type.atype) {
319 case atype_integer:
320 case atype_enum:
321 case atype_enum_nestable:
322 op->op = BYTECODE_OP_GET_CONTEXT_REF_S64;
323 break;
324 /* Sequence and array supported as string */
325 case atype_string:
326 case atype_array:
327 case atype_array_nestable:
328 case atype_sequence:
329 case atype_sequence_nestable:
330 op->op = BYTECODE_OP_GET_CONTEXT_REF_STRING;
331 break;
332 case atype_float:
333 op->op = BYTECODE_OP_GET_CONTEXT_REF_DOUBLE;
334 break;
335 case atype_dynamic:
336 op->op = BYTECODE_OP_GET_CONTEXT_REF;
337 break;
338 default:
339 return -EINVAL;
340 }
341 /* set offset to context index within channel contexts */
342 field_ref->offset = (uint16_t) idx;
343 break;
344 }
345 default:
346 return -EINVAL;
347 }
348 return 0;
349 }
350
351 static
352 int apply_reloc(const struct lttng_event_desc *event_desc,
353 struct bytecode_runtime *runtime,
354 uint32_t runtime_len,
355 uint32_t reloc_offset,
356 const char *name)
357 {
358 struct load_op *op;
359
360 dbg_printf("Apply reloc: %u %s\n", reloc_offset, name);
361
362 /* Ensure that the reloc is within the code */
363 if (runtime_len - reloc_offset < sizeof(uint16_t))
364 return -EINVAL;
365
366 op = (struct load_op *) &runtime->code[reloc_offset];
367 switch (op->op) {
368 case BYTECODE_OP_LOAD_FIELD_REF:
369 return apply_field_reloc(event_desc, runtime, runtime_len,
370 reloc_offset, name, op->op);
371 case BYTECODE_OP_GET_CONTEXT_REF:
372 return apply_context_reloc(runtime, runtime_len,
373 reloc_offset, name, op->op);
374 case BYTECODE_OP_GET_SYMBOL:
375 case BYTECODE_OP_GET_SYMBOL_FIELD:
376 /*
377 * Will be handled by load specialize phase or
378 * dynamically by interpreter.
379 */
380 return 0;
381 default:
382 ERR("Unknown reloc op type %u\n", op->op);
383 return -EINVAL;
384 }
385 return 0;
386 }
387
388 static
389 int bytecode_is_linked(struct lttng_ust_bytecode_node *bytecode,
390 struct cds_list_head *bytecode_runtime_head)
391 {
392 struct lttng_bytecode_runtime *bc_runtime;
393
394 cds_list_for_each_entry(bc_runtime, bytecode_runtime_head, node) {
395 if (bc_runtime->bc == bytecode)
396 return 1;
397 }
398 return 0;
399 }
400
401 /*
402 * Take a bytecode with reloc table and link it to an event to create a
403 * bytecode runtime.
404 */
405 static
406 int link_bytecode(const struct lttng_event_desc *event_desc,
407 struct lttng_ctx **ctx,
408 struct lttng_ust_bytecode_node *bytecode,
409 struct cds_list_head *insert_loc)
410 {
411 int ret, offset, next_offset;
412 struct bytecode_runtime *runtime = NULL;
413 size_t runtime_alloc_len;
414
415 if (!bytecode)
416 return 0;
417 /* Bytecode already linked */
418 if (bytecode_is_linked(bytecode, insert_loc))
419 return 0;
420
421 dbg_printf("Linking...\n");
422
423 /* We don't need the reloc table in the runtime */
424 runtime_alloc_len = sizeof(*runtime) + bytecode->bc.reloc_offset;
425 runtime = zmalloc(runtime_alloc_len);
426 if (!runtime) {
427 ret = -ENOMEM;
428 goto alloc_error;
429 }
430 runtime->p.bc = bytecode;
431 runtime->p.pctx = ctx;
432 runtime->len = bytecode->bc.reloc_offset;
433 /* copy original bytecode */
434 memcpy(runtime->code, bytecode->bc.data, runtime->len);
435 /*
436 * apply relocs. Those are a uint16_t (offset in bytecode)
437 * followed by a string (field name).
438 */
439 for (offset = bytecode->bc.reloc_offset;
440 offset < bytecode->bc.len;
441 offset = next_offset) {
442 uint16_t reloc_offset =
443 *(uint16_t *) &bytecode->bc.data[offset];
444 const char *name =
445 (const char *) &bytecode->bc.data[offset + sizeof(uint16_t)];
446
447 ret = apply_reloc(event_desc, runtime, runtime->len, reloc_offset, name);
448 if (ret) {
449 goto link_error;
450 }
451 next_offset = offset + sizeof(uint16_t) + strlen(name) + 1;
452 }
453 /* Validate bytecode */
454 ret = lttng_bytecode_validate(runtime);
455 if (ret) {
456 goto link_error;
457 }
458 /* Specialize bytecode */
459 ret = lttng_bytecode_specialize(event_desc, runtime);
460 if (ret) {
461 goto link_error;
462 }
463
464 switch (bytecode->type) {
465 case LTTNG_UST_BYTECODE_NODE_TYPE_FILTER:
466 runtime->p.interpreter_funcs.filter = lttng_bytecode_filter_interpret;
467 break;
468 case LTTNG_UST_BYTECODE_NODE_TYPE_CAPTURE:
469 runtime->p.interpreter_funcs.capture = lttng_bytecode_capture_interpret;
470 break;
471 default:
472 abort();
473 }
474
475 runtime->p.link_failed = 0;
476 cds_list_add_rcu(&runtime->p.node, insert_loc);
477 dbg_printf("Linking successful.\n");
478 return 0;
479
480 link_error:
481 switch (bytecode->type) {
482 case LTTNG_UST_BYTECODE_NODE_TYPE_FILTER:
483 runtime->p.interpreter_funcs.filter = lttng_bytecode_filter_interpret_false;
484 break;
485 case LTTNG_UST_BYTECODE_NODE_TYPE_CAPTURE:
486 runtime->p.interpreter_funcs.capture = lttng_bytecode_capture_interpret_false;
487 break;
488 default:
489 abort();
490 }
491
492 runtime->p.link_failed = 1;
493 cds_list_add_rcu(&runtime->p.node, insert_loc);
494 alloc_error:
495 dbg_printf("Linking failed.\n");
496 return ret;
497 }
498
499 void lttng_bytecode_filter_sync_state(struct lttng_bytecode_runtime *runtime)
500 {
501 struct lttng_ust_bytecode_node *bc = runtime->bc;
502
503 if (!bc->enabler->enabled || runtime->link_failed)
504 runtime->interpreter_funcs.filter = lttng_bytecode_filter_interpret_false;
505 else
506 runtime->interpreter_funcs.filter = lttng_bytecode_filter_interpret;
507 }
508
509 void lttng_bytecode_capture_sync_state(struct lttng_bytecode_runtime *runtime)
510 {
511 struct lttng_ust_bytecode_node *bc = runtime->bc;
512
513 if (!bc->enabler->enabled || runtime->link_failed)
514 runtime->interpreter_funcs.capture = lttng_bytecode_capture_interpret_false;
515 else
516 runtime->interpreter_funcs.capture = lttng_bytecode_capture_interpret;
517 }
518
519 /*
520 * Given the lists of bytecode programs of an instance (trigger or event) and
521 * of a matching enabler, try to link all the enabler's bytecode programs with
522 * the instance.
523 *
524 * This function is called after we confirmed that name enabler and the
525 * instance are name matching (or glob pattern matching).
526 */
527 void lttng_enabler_link_bytecode(const struct lttng_event_desc *event_desc,
528 struct lttng_ctx **ctx,
529 struct cds_list_head *instance_bytecode_head,
530 struct cds_list_head *enabler_bytecode_head)
531 {
532 struct lttng_ust_bytecode_node *enabler_bc;
533 struct lttng_bytecode_runtime *runtime;
534
535 assert(event_desc);
536
537 /* Go over all the bytecode programs of the enabler. */
538 cds_list_for_each_entry(enabler_bc, enabler_bytecode_head, node) {
539 int found = 0, ret;
540 struct cds_list_head *insert_loc;
541
542 /*
543 * Check if the current enabler bytecode program is already
544 * linked with the instance.
545 */
546 cds_list_for_each_entry(runtime, instance_bytecode_head, node) {
547 if (runtime->bc == enabler_bc) {
548 found = 1;
549 break;
550 }
551 }
552
553 /*
554 * Skip bytecode already linked, go to the next enabler
555 * bytecode program.
556 */
557 if (found)
558 continue;
559
560 /*
561 * Insert at specified priority (seqnum) in increasing
562 * order. If there already is a bytecode of the same priority,
563 * insert the new bytecode right after it.
564 */
565 cds_list_for_each_entry_reverse(runtime,
566 instance_bytecode_head, node) {
567 if (runtime->bc->bc.seqnum <= enabler_bc->bc.seqnum) {
568 /* insert here */
569 insert_loc = &runtime->node;
570 goto add_within;
571 }
572 }
573
574 /* Add to head to list */
575 insert_loc = instance_bytecode_head;
576 add_within:
577 dbg_printf("linking bytecode\n");
578 ret = link_bytecode(event_desc, ctx, enabler_bc, insert_loc);
579 if (ret) {
580 dbg_printf("[lttng filter] warning: cannot link event bytecode\n");
581 }
582 }
583 }
584
585 /*
586 * We own the bytecode if we return success.
587 */
588 int lttng_filter_enabler_attach_bytecode(struct lttng_enabler *enabler,
589 struct lttng_ust_bytecode_node *bytecode)
590 {
591 cds_list_add(&bytecode->node, &enabler->filter_bytecode_head);
592 return 0;
593 }
594
595 static
596 void free_filter_runtime(struct cds_list_head *bytecode_runtime_head)
597 {
598 struct bytecode_runtime *runtime, *tmp;
599
600 cds_list_for_each_entry_safe(runtime, tmp, bytecode_runtime_head,
601 p.node) {
602 free(runtime->data);
603 free(runtime);
604 }
605 }
606
607 void lttng_free_event_filter_runtime(struct lttng_event *event)
608 {
609 free_filter_runtime(&event->filter_bytecode_runtime_head);
610 }
611
612 void lttng_free_event_notifier_filter_runtime(
613 struct lttng_event_notifier *event_notifier)
614 {
615 free_filter_runtime(&event_notifier->filter_bytecode_runtime_head);
616 }
This page took 0.040795 seconds and 4 git commands to generate.