| 1 | /* |
| 2 | * lttng-filter-interpreter.c |
| 3 | * |
| 4 | * LTTng UST filter interpreter. |
| 5 | * |
| 6 | * Copyright (C) 2010-2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 7 | * |
| 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 9 | * of this software and associated documentation files (the "Software"), to deal |
| 10 | * in the Software without restriction, including without limitation the rights |
| 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 12 | * copies of the Software, and to permit persons to whom the Software is |
| 13 | * furnished to do so, subject to the following conditions: |
| 14 | * |
| 15 | * The above copyright notice and this permission notice shall be included in |
| 16 | * all copies or substantial portions of the Software. |
| 17 | * |
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 24 | * SOFTWARE. |
| 25 | */ |
| 26 | |
| 27 | #define _LGPL_SOURCE |
| 28 | #include <urcu-pointer.h> |
| 29 | #include <stdint.h> |
| 30 | #include <byteswap.h> |
| 31 | #include "lttng-filter.h" |
| 32 | #include "string-utils.h" |
| 33 | |
| 34 | /* |
| 35 | * -1: wildcard found. |
| 36 | * -2: unknown escape char. |
| 37 | * 0: normal char. |
| 38 | */ |
| 39 | |
| 40 | static |
| 41 | int parse_char(const char **p) |
| 42 | { |
| 43 | switch (**p) { |
| 44 | case '\\': |
| 45 | (*p)++; |
| 46 | switch (**p) { |
| 47 | case '\\': |
| 48 | case '*': |
| 49 | return 0; |
| 50 | default: |
| 51 | return -2; |
| 52 | } |
| 53 | case '*': |
| 54 | return -1; |
| 55 | default: |
| 56 | return 0; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | /* |
| 61 | * Returns SIZE_MAX if the string is null-terminated, or the number of |
| 62 | * characters if not. |
| 63 | */ |
| 64 | static |
| 65 | size_t get_str_or_seq_len(const struct estack_entry *entry) |
| 66 | { |
| 67 | return entry->u.s.seq_len; |
| 68 | } |
| 69 | |
| 70 | static |
| 71 | int stack_star_glob_match(struct estack *stack, int top, const char *cmp_type) |
| 72 | { |
| 73 | const char *pattern; |
| 74 | const char *candidate; |
| 75 | size_t pattern_len; |
| 76 | size_t candidate_len; |
| 77 | |
| 78 | /* Find out which side is the pattern vs. the candidate. */ |
| 79 | if (estack_ax(stack, top)->u.s.literal_type == ESTACK_STRING_LITERAL_TYPE_STAR_GLOB) { |
| 80 | pattern = estack_ax(stack, top)->u.s.str; |
| 81 | pattern_len = get_str_or_seq_len(estack_ax(stack, top)); |
| 82 | candidate = estack_bx(stack, top)->u.s.str; |
| 83 | candidate_len = get_str_or_seq_len(estack_bx(stack, top)); |
| 84 | } else { |
| 85 | pattern = estack_bx(stack, top)->u.s.str; |
| 86 | pattern_len = get_str_or_seq_len(estack_bx(stack, top)); |
| 87 | candidate = estack_ax(stack, top)->u.s.str; |
| 88 | candidate_len = get_str_or_seq_len(estack_ax(stack, top)); |
| 89 | } |
| 90 | |
| 91 | /* Perform the match. Returns 0 when the result is true. */ |
| 92 | return !strutils_star_glob_match(pattern, pattern_len, candidate, |
| 93 | candidate_len); |
| 94 | } |
| 95 | |
| 96 | static |
| 97 | int stack_strcmp(struct estack *stack, int top, const char *cmp_type) |
| 98 | { |
| 99 | const char *p = estack_bx(stack, top)->u.s.str, *q = estack_ax(stack, top)->u.s.str; |
| 100 | int ret; |
| 101 | int diff; |
| 102 | |
| 103 | for (;;) { |
| 104 | int escaped_r0 = 0; |
| 105 | |
| 106 | if (unlikely(p - estack_bx(stack, top)->u.s.str >= estack_bx(stack, top)->u.s.seq_len || *p == '\0')) { |
| 107 | if (q - estack_ax(stack, top)->u.s.str >= estack_ax(stack, top)->u.s.seq_len || *q == '\0') { |
| 108 | return 0; |
| 109 | } else { |
| 110 | if (estack_ax(stack, top)->u.s.literal_type == |
| 111 | ESTACK_STRING_LITERAL_TYPE_PLAIN) { |
| 112 | ret = parse_char(&q); |
| 113 | if (ret == -1) |
| 114 | return 0; |
| 115 | } |
| 116 | return -1; |
| 117 | } |
| 118 | } |
| 119 | if (unlikely(q - estack_ax(stack, top)->u.s.str >= estack_ax(stack, top)->u.s.seq_len || *q == '\0')) { |
| 120 | if (estack_bx(stack, top)->u.s.literal_type == |
| 121 | ESTACK_STRING_LITERAL_TYPE_PLAIN) { |
| 122 | ret = parse_char(&p); |
| 123 | if (ret == -1) |
| 124 | return 0; |
| 125 | } |
| 126 | return 1; |
| 127 | } |
| 128 | if (estack_bx(stack, top)->u.s.literal_type == |
| 129 | ESTACK_STRING_LITERAL_TYPE_PLAIN) { |
| 130 | ret = parse_char(&p); |
| 131 | if (ret == -1) { |
| 132 | return 0; |
| 133 | } else if (ret == -2) { |
| 134 | escaped_r0 = 1; |
| 135 | } |
| 136 | /* else compare both char */ |
| 137 | } |
| 138 | if (estack_ax(stack, top)->u.s.literal_type == |
| 139 | ESTACK_STRING_LITERAL_TYPE_PLAIN) { |
| 140 | ret = parse_char(&q); |
| 141 | if (ret == -1) { |
| 142 | return 0; |
| 143 | } else if (ret == -2) { |
| 144 | if (!escaped_r0) |
| 145 | return -1; |
| 146 | } else { |
| 147 | if (escaped_r0) |
| 148 | return 1; |
| 149 | } |
| 150 | } else { |
| 151 | if (escaped_r0) |
| 152 | return 1; |
| 153 | } |
| 154 | diff = *p - *q; |
| 155 | if (diff != 0) |
| 156 | break; |
| 157 | p++; |
| 158 | q++; |
| 159 | } |
| 160 | return diff; |
| 161 | } |
| 162 | |
| 163 | uint64_t lttng_filter_false(void *filter_data, |
| 164 | const char *filter_stack_data) |
| 165 | { |
| 166 | return 0; |
| 167 | } |
| 168 | |
| 169 | #ifdef INTERPRETER_USE_SWITCH |
| 170 | |
| 171 | /* |
| 172 | * Fallback for compilers that do not support taking address of labels. |
| 173 | */ |
| 174 | |
| 175 | #define START_OP \ |
| 176 | start_pc = &bytecode->data[0]; \ |
| 177 | for (pc = next_pc = start_pc; pc - start_pc < bytecode->len; \ |
| 178 | pc = next_pc) { \ |
| 179 | dbg_printf("Executing op %s (%u)\n", \ |
| 180 | print_op((unsigned int) *(filter_opcode_t *) pc), \ |
| 181 | (unsigned int) *(filter_opcode_t *) pc); \ |
| 182 | switch (*(filter_opcode_t *) pc) { |
| 183 | |
| 184 | #define OP(name) jump_target_##name: __attribute__((unused)); \ |
| 185 | case name |
| 186 | |
| 187 | #define PO break |
| 188 | |
| 189 | #define END_OP } \ |
| 190 | } |
| 191 | |
| 192 | #define JUMP_TO(name) \ |
| 193 | goto jump_target_##name |
| 194 | |
| 195 | #else |
| 196 | |
| 197 | /* |
| 198 | * Dispatch-table based interpreter. |
| 199 | */ |
| 200 | |
| 201 | #define START_OP \ |
| 202 | start_pc = &bytecode->code[0]; \ |
| 203 | pc = next_pc = start_pc; \ |
| 204 | if (unlikely(pc - start_pc >= bytecode->len)) \ |
| 205 | goto end; \ |
| 206 | goto *dispatch[*(filter_opcode_t *) pc]; |
| 207 | |
| 208 | #define OP(name) \ |
| 209 | LABEL_##name |
| 210 | |
| 211 | #define PO \ |
| 212 | pc = next_pc; \ |
| 213 | goto *dispatch[*(filter_opcode_t *) pc]; |
| 214 | |
| 215 | #define END_OP |
| 216 | |
| 217 | #define JUMP_TO(name) \ |
| 218 | goto LABEL_##name |
| 219 | |
| 220 | #endif |
| 221 | |
| 222 | static int context_get_index(struct lttng_ctx *ctx, |
| 223 | struct load_ptr *ptr, |
| 224 | uint32_t idx) |
| 225 | { |
| 226 | |
| 227 | struct lttng_ctx_field *ctx_field; |
| 228 | struct lttng_event_field *field; |
| 229 | struct lttng_ctx_value v; |
| 230 | |
| 231 | ctx_field = &ctx->fields[idx]; |
| 232 | field = &ctx_field->event_field; |
| 233 | ptr->type = LOAD_OBJECT; |
| 234 | /* field is only used for types nested within variants. */ |
| 235 | ptr->field = NULL; |
| 236 | |
| 237 | switch (field->type.atype) { |
| 238 | case atype_integer: |
| 239 | ctx_field->get_value(ctx_field, &v); |
| 240 | if (field->type.u.basic.integer.signedness) { |
| 241 | ptr->object_type = OBJECT_TYPE_S64; |
| 242 | ptr->u.s64 = v.u.s64; |
| 243 | ptr->ptr = &ptr->u.s64; |
| 244 | } else { |
| 245 | ptr->object_type = OBJECT_TYPE_U64; |
| 246 | ptr->u.u64 = v.u.s64; /* Cast. */ |
| 247 | ptr->ptr = &ptr->u.u64; |
| 248 | } |
| 249 | break; |
| 250 | case atype_enum: |
| 251 | { |
| 252 | const struct lttng_integer_type *itype = |
| 253 | &field->type.u.basic.enumeration.container_type; |
| 254 | |
| 255 | ctx_field->get_value(ctx_field, &v); |
| 256 | if (itype->signedness) { |
| 257 | ptr->object_type = OBJECT_TYPE_S64; |
| 258 | ptr->u.s64 = v.u.s64; |
| 259 | ptr->ptr = &ptr->u.s64; |
| 260 | } else { |
| 261 | ptr->object_type = OBJECT_TYPE_U64; |
| 262 | ptr->u.u64 = v.u.s64; /* Cast. */ |
| 263 | ptr->ptr = &ptr->u.u64; |
| 264 | } |
| 265 | break; |
| 266 | } |
| 267 | case atype_array: |
| 268 | if (field->type.u.array.elem_type.atype != atype_integer) { |
| 269 | ERR("Array nesting only supports integer types."); |
| 270 | return -EINVAL; |
| 271 | } |
| 272 | if (field->type.u.array.elem_type.u.basic.integer.encoding == lttng_encode_none) { |
| 273 | ERR("Only string arrays are supported for contexts."); |
| 274 | return -EINVAL; |
| 275 | } |
| 276 | ptr->object_type = OBJECT_TYPE_STRING; |
| 277 | ctx_field->get_value(ctx_field, &v); |
| 278 | ptr->ptr = v.u.str; |
| 279 | break; |
| 280 | case atype_sequence: |
| 281 | if (field->type.u.sequence.elem_type.atype != atype_integer) { |
| 282 | ERR("Sequence nesting only supports integer types."); |
| 283 | return -EINVAL; |
| 284 | } |
| 285 | if (field->type.u.sequence.elem_type.u.basic.integer.encoding == lttng_encode_none) { |
| 286 | ERR("Only string sequences are supported for contexts."); |
| 287 | return -EINVAL; |
| 288 | } |
| 289 | ptr->object_type = OBJECT_TYPE_STRING; |
| 290 | ctx_field->get_value(ctx_field, &v); |
| 291 | ptr->ptr = v.u.str; |
| 292 | break; |
| 293 | case atype_string: |
| 294 | ptr->object_type = OBJECT_TYPE_STRING; |
| 295 | ctx_field->get_value(ctx_field, &v); |
| 296 | ptr->ptr = v.u.str; |
| 297 | break; |
| 298 | case atype_float: |
| 299 | ptr->object_type = OBJECT_TYPE_DOUBLE; |
| 300 | ptr->u.d = v.u.d; |
| 301 | ptr->ptr = &ptr->u.d; |
| 302 | break; |
| 303 | case atype_dynamic: |
| 304 | ctx_field->get_value(ctx_field, &v); |
| 305 | switch (v.sel) { |
| 306 | case LTTNG_UST_DYNAMIC_TYPE_NONE: |
| 307 | return -EINVAL; |
| 308 | case LTTNG_UST_DYNAMIC_TYPE_S64: |
| 309 | ptr->object_type = OBJECT_TYPE_S64; |
| 310 | ptr->u.s64 = v.u.s64; |
| 311 | ptr->ptr = &ptr->u.s64; |
| 312 | dbg_printf("context get index dynamic s64 %" PRIi64 "\n", ptr->u.s64); |
| 313 | break; |
| 314 | case LTTNG_UST_DYNAMIC_TYPE_DOUBLE: |
| 315 | ptr->object_type = OBJECT_TYPE_DOUBLE; |
| 316 | ptr->u.d = v.u.d; |
| 317 | ptr->ptr = &ptr->u.d; |
| 318 | dbg_printf("context get index dynamic double %g\n", ptr->u.d); |
| 319 | break; |
| 320 | case LTTNG_UST_DYNAMIC_TYPE_STRING: |
| 321 | ptr->object_type = OBJECT_TYPE_STRING; |
| 322 | ptr->ptr = v.u.str; |
| 323 | dbg_printf("context get index dynamic string %s\n", (const char *) ptr->ptr); |
| 324 | break; |
| 325 | default: |
| 326 | dbg_printf("Filter warning: unknown dynamic type (%d).\n", (int) v.sel); |
| 327 | return -EINVAL; |
| 328 | } |
| 329 | break; |
| 330 | case atype_struct: |
| 331 | ERR("Structure type cannot be loaded."); |
| 332 | return -EINVAL; |
| 333 | default: |
| 334 | ERR("Unknown type: %d", (int) field->type.atype); |
| 335 | return -EINVAL; |
| 336 | } |
| 337 | return 0; |
| 338 | } |
| 339 | |
| 340 | static int dynamic_get_index(struct lttng_session *session, |
| 341 | struct bytecode_runtime *runtime, |
| 342 | uint64_t index, struct estack_entry *stack_top) |
| 343 | { |
| 344 | int ret; |
| 345 | const struct filter_get_index_data *gid; |
| 346 | |
| 347 | /* |
| 348 | * Types nested within variants need to perform dynamic lookup |
| 349 | * based on the field descriptions. LTTng-UST does not implement |
| 350 | * variants for now. |
| 351 | */ |
| 352 | if (stack_top->u.ptr.field) |
| 353 | return -EINVAL; |
| 354 | gid = (const struct filter_get_index_data *) &runtime->data[index]; |
| 355 | switch (stack_top->u.ptr.type) { |
| 356 | case LOAD_OBJECT: |
| 357 | switch (stack_top->u.ptr.object_type) { |
| 358 | case OBJECT_TYPE_ARRAY: |
| 359 | { |
| 360 | const char *ptr; |
| 361 | |
| 362 | assert(gid->offset < gid->array_len); |
| 363 | /* Skip count (unsigned long) */ |
| 364 | ptr = *(const char **) (stack_top->u.ptr.ptr + sizeof(unsigned long)); |
| 365 | ptr = ptr + gid->offset; |
| 366 | stack_top->u.ptr.ptr = ptr; |
| 367 | stack_top->u.ptr.object_type = gid->elem.type; |
| 368 | stack_top->u.ptr.rev_bo = gid->elem.rev_bo; |
| 369 | /* field is only used for types nested within variants. */ |
| 370 | stack_top->u.ptr.field = NULL; |
| 371 | break; |
| 372 | } |
| 373 | case OBJECT_TYPE_SEQUENCE: |
| 374 | { |
| 375 | const char *ptr; |
| 376 | size_t ptr_seq_len; |
| 377 | |
| 378 | ptr = *(const char **) (stack_top->u.ptr.ptr + sizeof(unsigned long)); |
| 379 | ptr_seq_len = *(unsigned long *) stack_top->u.ptr.ptr; |
| 380 | if (gid->offset >= gid->elem.len * ptr_seq_len) { |
| 381 | ret = -EINVAL; |
| 382 | goto end; |
| 383 | } |
| 384 | ptr = ptr + gid->offset; |
| 385 | stack_top->u.ptr.ptr = ptr; |
| 386 | stack_top->u.ptr.object_type = gid->elem.type; |
| 387 | stack_top->u.ptr.rev_bo = gid->elem.rev_bo; |
| 388 | /* field is only used for types nested within variants. */ |
| 389 | stack_top->u.ptr.field = NULL; |
| 390 | break; |
| 391 | } |
| 392 | case OBJECT_TYPE_STRUCT: |
| 393 | ERR("Nested structures are not supported yet."); |
| 394 | ret = -EINVAL; |
| 395 | goto end; |
| 396 | case OBJECT_TYPE_VARIANT: |
| 397 | default: |
| 398 | ERR("Unexpected get index type %d", |
| 399 | (int) stack_top->u.ptr.object_type); |
| 400 | ret = -EINVAL; |
| 401 | goto end; |
| 402 | } |
| 403 | break; |
| 404 | case LOAD_ROOT_CONTEXT: |
| 405 | case LOAD_ROOT_APP_CONTEXT: /* Fall-through */ |
| 406 | { |
| 407 | struct lttng_ctx *ctx; |
| 408 | |
| 409 | ctx = rcu_dereference(session->ctx); |
| 410 | ret = context_get_index(ctx, |
| 411 | &stack_top->u.ptr, |
| 412 | gid->ctx_index); |
| 413 | if (ret) { |
| 414 | goto end; |
| 415 | } |
| 416 | break; |
| 417 | } |
| 418 | case LOAD_ROOT_PAYLOAD: |
| 419 | stack_top->u.ptr.ptr += gid->offset; |
| 420 | if (gid->elem.type == OBJECT_TYPE_STRING) |
| 421 | stack_top->u.ptr.ptr = *(const char * const *) stack_top->u.ptr.ptr; |
| 422 | stack_top->u.ptr.object_type = gid->elem.type; |
| 423 | stack_top->u.ptr.type = LOAD_OBJECT; |
| 424 | /* field is only used for types nested within variants. */ |
| 425 | stack_top->u.ptr.field = NULL; |
| 426 | break; |
| 427 | } |
| 428 | return 0; |
| 429 | |
| 430 | end: |
| 431 | return ret; |
| 432 | } |
| 433 | |
| 434 | static int dynamic_load_field(struct estack_entry *stack_top) |
| 435 | { |
| 436 | int ret; |
| 437 | |
| 438 | switch (stack_top->u.ptr.type) { |
| 439 | case LOAD_OBJECT: |
| 440 | break; |
| 441 | case LOAD_ROOT_CONTEXT: |
| 442 | case LOAD_ROOT_APP_CONTEXT: |
| 443 | case LOAD_ROOT_PAYLOAD: |
| 444 | default: |
| 445 | dbg_printf("Filter warning: cannot load root, missing field name.\n"); |
| 446 | ret = -EINVAL; |
| 447 | goto end; |
| 448 | } |
| 449 | switch (stack_top->u.ptr.object_type) { |
| 450 | case OBJECT_TYPE_S8: |
| 451 | dbg_printf("op load field s8\n"); |
| 452 | stack_top->u.v = *(int8_t *) stack_top->u.ptr.ptr; |
| 453 | stack_top->type = REG_S64; |
| 454 | break; |
| 455 | case OBJECT_TYPE_S16: |
| 456 | { |
| 457 | int16_t tmp; |
| 458 | |
| 459 | dbg_printf("op load field s16\n"); |
| 460 | tmp = *(int16_t *) stack_top->u.ptr.ptr; |
| 461 | if (stack_top->u.ptr.rev_bo) |
| 462 | tmp = bswap_16(tmp); |
| 463 | stack_top->u.v = tmp; |
| 464 | stack_top->type = REG_S64; |
| 465 | break; |
| 466 | } |
| 467 | case OBJECT_TYPE_S32: |
| 468 | { |
| 469 | int32_t tmp; |
| 470 | |
| 471 | dbg_printf("op load field s32\n"); |
| 472 | tmp = *(int32_t *) stack_top->u.ptr.ptr; |
| 473 | if (stack_top->u.ptr.rev_bo) |
| 474 | tmp = bswap_32(tmp); |
| 475 | stack_top->u.v = tmp; |
| 476 | stack_top->type = REG_S64; |
| 477 | break; |
| 478 | } |
| 479 | case OBJECT_TYPE_S64: |
| 480 | { |
| 481 | int64_t tmp; |
| 482 | |
| 483 | dbg_printf("op load field s64\n"); |
| 484 | tmp = *(int64_t *) stack_top->u.ptr.ptr; |
| 485 | if (stack_top->u.ptr.rev_bo) |
| 486 | tmp = bswap_64(tmp); |
| 487 | stack_top->u.v = tmp; |
| 488 | stack_top->type = REG_S64; |
| 489 | break; |
| 490 | } |
| 491 | case OBJECT_TYPE_U8: |
| 492 | dbg_printf("op load field u8\n"); |
| 493 | stack_top->u.v = *(uint8_t *) stack_top->u.ptr.ptr; |
| 494 | stack_top->type = REG_S64; |
| 495 | break; |
| 496 | case OBJECT_TYPE_U16: |
| 497 | { |
| 498 | uint16_t tmp; |
| 499 | |
| 500 | dbg_printf("op load field s16\n"); |
| 501 | tmp = *(uint16_t *) stack_top->u.ptr.ptr; |
| 502 | if (stack_top->u.ptr.rev_bo) |
| 503 | tmp = bswap_16(tmp); |
| 504 | stack_top->u.v = tmp; |
| 505 | stack_top->type = REG_S64; |
| 506 | break; |
| 507 | } |
| 508 | case OBJECT_TYPE_U32: |
| 509 | { |
| 510 | uint32_t tmp; |
| 511 | |
| 512 | dbg_printf("op load field u32\n"); |
| 513 | tmp = *(uint32_t *) stack_top->u.ptr.ptr; |
| 514 | if (stack_top->u.ptr.rev_bo) |
| 515 | tmp = bswap_32(tmp); |
| 516 | stack_top->u.v = tmp; |
| 517 | stack_top->type = REG_S64; |
| 518 | break; |
| 519 | } |
| 520 | case OBJECT_TYPE_U64: |
| 521 | { |
| 522 | uint64_t tmp; |
| 523 | |
| 524 | dbg_printf("op load field u64\n"); |
| 525 | tmp = *(uint64_t *) stack_top->u.ptr.ptr; |
| 526 | if (stack_top->u.ptr.rev_bo) |
| 527 | tmp = bswap_64(tmp); |
| 528 | stack_top->u.v = tmp; |
| 529 | stack_top->type = REG_S64; |
| 530 | break; |
| 531 | } |
| 532 | case OBJECT_TYPE_DOUBLE: |
| 533 | memcpy(&stack_top->u.d, |
| 534 | stack_top->u.ptr.ptr, |
| 535 | sizeof(struct literal_double)); |
| 536 | stack_top->type = REG_DOUBLE; |
| 537 | break; |
| 538 | case OBJECT_TYPE_STRING: |
| 539 | { |
| 540 | const char *str; |
| 541 | |
| 542 | dbg_printf("op load field string\n"); |
| 543 | str = (const char *) stack_top->u.ptr.ptr; |
| 544 | stack_top->u.s.str = str; |
| 545 | if (unlikely(!stack_top->u.s.str)) { |
| 546 | dbg_printf("Filter warning: loading a NULL string.\n"); |
| 547 | ret = -EINVAL; |
| 548 | goto end; |
| 549 | } |
| 550 | stack_top->u.s.seq_len = SIZE_MAX; |
| 551 | stack_top->u.s.literal_type = |
| 552 | ESTACK_STRING_LITERAL_TYPE_NONE; |
| 553 | stack_top->type = REG_STRING; |
| 554 | break; |
| 555 | } |
| 556 | case OBJECT_TYPE_STRING_SEQUENCE: |
| 557 | { |
| 558 | const char *ptr; |
| 559 | |
| 560 | dbg_printf("op load field string sequence\n"); |
| 561 | ptr = stack_top->u.ptr.ptr; |
| 562 | stack_top->u.s.seq_len = *(unsigned long *) ptr; |
| 563 | stack_top->u.s.str = *(const char **) (ptr + sizeof(unsigned long)); |
| 564 | stack_top->type = REG_STRING; |
| 565 | if (unlikely(!stack_top->u.s.str)) { |
| 566 | dbg_printf("Filter warning: loading a NULL sequence.\n"); |
| 567 | ret = -EINVAL; |
| 568 | goto end; |
| 569 | } |
| 570 | stack_top->u.s.literal_type = |
| 571 | ESTACK_STRING_LITERAL_TYPE_NONE; |
| 572 | break; |
| 573 | } |
| 574 | case OBJECT_TYPE_DYNAMIC: |
| 575 | /* |
| 576 | * Dynamic types in context are looked up |
| 577 | * by context get index. |
| 578 | */ |
| 579 | ret = -EINVAL; |
| 580 | goto end; |
| 581 | case OBJECT_TYPE_SEQUENCE: |
| 582 | case OBJECT_TYPE_ARRAY: |
| 583 | case OBJECT_TYPE_STRUCT: |
| 584 | case OBJECT_TYPE_VARIANT: |
| 585 | ERR("Sequences, arrays, struct and variant cannot be loaded (nested types)."); |
| 586 | ret = -EINVAL; |
| 587 | goto end; |
| 588 | } |
| 589 | return 0; |
| 590 | |
| 591 | end: |
| 592 | return ret; |
| 593 | } |
| 594 | |
| 595 | /* |
| 596 | * Return 0 (discard), or raise the 0x1 flag (log event). |
| 597 | * Currently, other flags are kept for future extensions and have no |
| 598 | * effect. |
| 599 | */ |
| 600 | uint64_t lttng_filter_interpret_bytecode(void *filter_data, |
| 601 | const char *filter_stack_data) |
| 602 | { |
| 603 | struct bytecode_runtime *bytecode = filter_data; |
| 604 | struct lttng_session *session = bytecode->p.session; |
| 605 | void *pc, *next_pc, *start_pc; |
| 606 | int ret = -EINVAL; |
| 607 | uint64_t retval = 0; |
| 608 | struct estack _stack; |
| 609 | struct estack *stack = &_stack; |
| 610 | register int64_t ax = 0, bx = 0; |
| 611 | register enum entry_type ax_t = REG_UNKNOWN, bx_t = REG_UNKNOWN; |
| 612 | register int top = FILTER_STACK_EMPTY; |
| 613 | #ifndef INTERPRETER_USE_SWITCH |
| 614 | static void *dispatch[NR_FILTER_OPS] = { |
| 615 | [ FILTER_OP_UNKNOWN ] = &&LABEL_FILTER_OP_UNKNOWN, |
| 616 | |
| 617 | [ FILTER_OP_RETURN ] = &&LABEL_FILTER_OP_RETURN, |
| 618 | |
| 619 | /* binary */ |
| 620 | [ FILTER_OP_MUL ] = &&LABEL_FILTER_OP_MUL, |
| 621 | [ FILTER_OP_DIV ] = &&LABEL_FILTER_OP_DIV, |
| 622 | [ FILTER_OP_MOD ] = &&LABEL_FILTER_OP_MOD, |
| 623 | [ FILTER_OP_PLUS ] = &&LABEL_FILTER_OP_PLUS, |
| 624 | [ FILTER_OP_MINUS ] = &&LABEL_FILTER_OP_MINUS, |
| 625 | [ FILTER_OP_BIT_RSHIFT ] = &&LABEL_FILTER_OP_BIT_RSHIFT, |
| 626 | [ FILTER_OP_BIT_LSHIFT ] = &&LABEL_FILTER_OP_BIT_LSHIFT, |
| 627 | [ FILTER_OP_BIT_AND ] = &&LABEL_FILTER_OP_BIT_AND, |
| 628 | [ FILTER_OP_BIT_OR ] = &&LABEL_FILTER_OP_BIT_OR, |
| 629 | [ FILTER_OP_BIT_XOR ] = &&LABEL_FILTER_OP_BIT_XOR, |
| 630 | |
| 631 | /* binary comparators */ |
| 632 | [ FILTER_OP_EQ ] = &&LABEL_FILTER_OP_EQ, |
| 633 | [ FILTER_OP_NE ] = &&LABEL_FILTER_OP_NE, |
| 634 | [ FILTER_OP_GT ] = &&LABEL_FILTER_OP_GT, |
| 635 | [ FILTER_OP_LT ] = &&LABEL_FILTER_OP_LT, |
| 636 | [ FILTER_OP_GE ] = &&LABEL_FILTER_OP_GE, |
| 637 | [ FILTER_OP_LE ] = &&LABEL_FILTER_OP_LE, |
| 638 | |
| 639 | /* string binary comparator */ |
| 640 | [ FILTER_OP_EQ_STRING ] = &&LABEL_FILTER_OP_EQ_STRING, |
| 641 | [ FILTER_OP_NE_STRING ] = &&LABEL_FILTER_OP_NE_STRING, |
| 642 | [ FILTER_OP_GT_STRING ] = &&LABEL_FILTER_OP_GT_STRING, |
| 643 | [ FILTER_OP_LT_STRING ] = &&LABEL_FILTER_OP_LT_STRING, |
| 644 | [ FILTER_OP_GE_STRING ] = &&LABEL_FILTER_OP_GE_STRING, |
| 645 | [ FILTER_OP_LE_STRING ] = &&LABEL_FILTER_OP_LE_STRING, |
| 646 | |
| 647 | /* globbing pattern binary comparator */ |
| 648 | [ FILTER_OP_EQ_STAR_GLOB_STRING ] = &&LABEL_FILTER_OP_EQ_STAR_GLOB_STRING, |
| 649 | [ FILTER_OP_NE_STAR_GLOB_STRING ] = &&LABEL_FILTER_OP_NE_STAR_GLOB_STRING, |
| 650 | |
| 651 | /* s64 binary comparator */ |
| 652 | [ FILTER_OP_EQ_S64 ] = &&LABEL_FILTER_OP_EQ_S64, |
| 653 | [ FILTER_OP_NE_S64 ] = &&LABEL_FILTER_OP_NE_S64, |
| 654 | [ FILTER_OP_GT_S64 ] = &&LABEL_FILTER_OP_GT_S64, |
| 655 | [ FILTER_OP_LT_S64 ] = &&LABEL_FILTER_OP_LT_S64, |
| 656 | [ FILTER_OP_GE_S64 ] = &&LABEL_FILTER_OP_GE_S64, |
| 657 | [ FILTER_OP_LE_S64 ] = &&LABEL_FILTER_OP_LE_S64, |
| 658 | |
| 659 | /* double binary comparator */ |
| 660 | [ FILTER_OP_EQ_DOUBLE ] = &&LABEL_FILTER_OP_EQ_DOUBLE, |
| 661 | [ FILTER_OP_NE_DOUBLE ] = &&LABEL_FILTER_OP_NE_DOUBLE, |
| 662 | [ FILTER_OP_GT_DOUBLE ] = &&LABEL_FILTER_OP_GT_DOUBLE, |
| 663 | [ FILTER_OP_LT_DOUBLE ] = &&LABEL_FILTER_OP_LT_DOUBLE, |
| 664 | [ FILTER_OP_GE_DOUBLE ] = &&LABEL_FILTER_OP_GE_DOUBLE, |
| 665 | [ FILTER_OP_LE_DOUBLE ] = &&LABEL_FILTER_OP_LE_DOUBLE, |
| 666 | |
| 667 | /* Mixed S64-double binary comparators */ |
| 668 | [ FILTER_OP_EQ_DOUBLE_S64 ] = &&LABEL_FILTER_OP_EQ_DOUBLE_S64, |
| 669 | [ FILTER_OP_NE_DOUBLE_S64 ] = &&LABEL_FILTER_OP_NE_DOUBLE_S64, |
| 670 | [ FILTER_OP_GT_DOUBLE_S64 ] = &&LABEL_FILTER_OP_GT_DOUBLE_S64, |
| 671 | [ FILTER_OP_LT_DOUBLE_S64 ] = &&LABEL_FILTER_OP_LT_DOUBLE_S64, |
| 672 | [ FILTER_OP_GE_DOUBLE_S64 ] = &&LABEL_FILTER_OP_GE_DOUBLE_S64, |
| 673 | [ FILTER_OP_LE_DOUBLE_S64 ] = &&LABEL_FILTER_OP_LE_DOUBLE_S64, |
| 674 | |
| 675 | [ FILTER_OP_EQ_S64_DOUBLE ] = &&LABEL_FILTER_OP_EQ_S64_DOUBLE, |
| 676 | [ FILTER_OP_NE_S64_DOUBLE ] = &&LABEL_FILTER_OP_NE_S64_DOUBLE, |
| 677 | [ FILTER_OP_GT_S64_DOUBLE ] = &&LABEL_FILTER_OP_GT_S64_DOUBLE, |
| 678 | [ FILTER_OP_LT_S64_DOUBLE ] = &&LABEL_FILTER_OP_LT_S64_DOUBLE, |
| 679 | [ FILTER_OP_GE_S64_DOUBLE ] = &&LABEL_FILTER_OP_GE_S64_DOUBLE, |
| 680 | [ FILTER_OP_LE_S64_DOUBLE ] = &&LABEL_FILTER_OP_LE_S64_DOUBLE, |
| 681 | |
| 682 | /* unary */ |
| 683 | [ FILTER_OP_UNARY_PLUS ] = &&LABEL_FILTER_OP_UNARY_PLUS, |
| 684 | [ FILTER_OP_UNARY_MINUS ] = &&LABEL_FILTER_OP_UNARY_MINUS, |
| 685 | [ FILTER_OP_UNARY_NOT ] = &&LABEL_FILTER_OP_UNARY_NOT, |
| 686 | [ FILTER_OP_UNARY_PLUS_S64 ] = &&LABEL_FILTER_OP_UNARY_PLUS_S64, |
| 687 | [ FILTER_OP_UNARY_MINUS_S64 ] = &&LABEL_FILTER_OP_UNARY_MINUS_S64, |
| 688 | [ FILTER_OP_UNARY_NOT_S64 ] = &&LABEL_FILTER_OP_UNARY_NOT_S64, |
| 689 | [ FILTER_OP_UNARY_PLUS_DOUBLE ] = &&LABEL_FILTER_OP_UNARY_PLUS_DOUBLE, |
| 690 | [ FILTER_OP_UNARY_MINUS_DOUBLE ] = &&LABEL_FILTER_OP_UNARY_MINUS_DOUBLE, |
| 691 | [ FILTER_OP_UNARY_NOT_DOUBLE ] = &&LABEL_FILTER_OP_UNARY_NOT_DOUBLE, |
| 692 | |
| 693 | /* logical */ |
| 694 | [ FILTER_OP_AND ] = &&LABEL_FILTER_OP_AND, |
| 695 | [ FILTER_OP_OR ] = &&LABEL_FILTER_OP_OR, |
| 696 | |
| 697 | /* load field ref */ |
| 698 | [ FILTER_OP_LOAD_FIELD_REF ] = &&LABEL_FILTER_OP_LOAD_FIELD_REF, |
| 699 | [ FILTER_OP_LOAD_FIELD_REF_STRING ] = &&LABEL_FILTER_OP_LOAD_FIELD_REF_STRING, |
| 700 | [ FILTER_OP_LOAD_FIELD_REF_SEQUENCE ] = &&LABEL_FILTER_OP_LOAD_FIELD_REF_SEQUENCE, |
| 701 | [ FILTER_OP_LOAD_FIELD_REF_S64 ] = &&LABEL_FILTER_OP_LOAD_FIELD_REF_S64, |
| 702 | [ FILTER_OP_LOAD_FIELD_REF_DOUBLE ] = &&LABEL_FILTER_OP_LOAD_FIELD_REF_DOUBLE, |
| 703 | |
| 704 | /* load from immediate operand */ |
| 705 | [ FILTER_OP_LOAD_STRING ] = &&LABEL_FILTER_OP_LOAD_STRING, |
| 706 | [ FILTER_OP_LOAD_STAR_GLOB_STRING ] = &&LABEL_FILTER_OP_LOAD_STAR_GLOB_STRING, |
| 707 | [ FILTER_OP_LOAD_S64 ] = &&LABEL_FILTER_OP_LOAD_S64, |
| 708 | [ FILTER_OP_LOAD_DOUBLE ] = &&LABEL_FILTER_OP_LOAD_DOUBLE, |
| 709 | |
| 710 | /* cast */ |
| 711 | [ FILTER_OP_CAST_TO_S64 ] = &&LABEL_FILTER_OP_CAST_TO_S64, |
| 712 | [ FILTER_OP_CAST_DOUBLE_TO_S64 ] = &&LABEL_FILTER_OP_CAST_DOUBLE_TO_S64, |
| 713 | [ FILTER_OP_CAST_NOP ] = &&LABEL_FILTER_OP_CAST_NOP, |
| 714 | |
| 715 | /* get context ref */ |
| 716 | [ FILTER_OP_GET_CONTEXT_REF ] = &&LABEL_FILTER_OP_GET_CONTEXT_REF, |
| 717 | [ FILTER_OP_GET_CONTEXT_REF_STRING ] = &&LABEL_FILTER_OP_GET_CONTEXT_REF_STRING, |
| 718 | [ FILTER_OP_GET_CONTEXT_REF_S64 ] = &&LABEL_FILTER_OP_GET_CONTEXT_REF_S64, |
| 719 | [ FILTER_OP_GET_CONTEXT_REF_DOUBLE ] = &&LABEL_FILTER_OP_GET_CONTEXT_REF_DOUBLE, |
| 720 | |
| 721 | /* Instructions for recursive traversal through composed types. */ |
| 722 | [ FILTER_OP_GET_CONTEXT_ROOT ] = &&LABEL_FILTER_OP_GET_CONTEXT_ROOT, |
| 723 | [ FILTER_OP_GET_APP_CONTEXT_ROOT ] = &&LABEL_FILTER_OP_GET_APP_CONTEXT_ROOT, |
| 724 | [ FILTER_OP_GET_PAYLOAD_ROOT ] = &&LABEL_FILTER_OP_GET_PAYLOAD_ROOT, |
| 725 | |
| 726 | [ FILTER_OP_GET_SYMBOL ] = &&LABEL_FILTER_OP_GET_SYMBOL, |
| 727 | [ FILTER_OP_GET_SYMBOL_FIELD ] = &&LABEL_FILTER_OP_GET_SYMBOL_FIELD, |
| 728 | [ FILTER_OP_GET_INDEX_U16 ] = &&LABEL_FILTER_OP_GET_INDEX_U16, |
| 729 | [ FILTER_OP_GET_INDEX_U64 ] = &&LABEL_FILTER_OP_GET_INDEX_U64, |
| 730 | |
| 731 | [ FILTER_OP_LOAD_FIELD ] = &&LABEL_FILTER_OP_LOAD_FIELD, |
| 732 | [ FILTER_OP_LOAD_FIELD_S8 ] = &&LABEL_FILTER_OP_LOAD_FIELD_S8, |
| 733 | [ FILTER_OP_LOAD_FIELD_S16 ] = &&LABEL_FILTER_OP_LOAD_FIELD_S16, |
| 734 | [ FILTER_OP_LOAD_FIELD_S32 ] = &&LABEL_FILTER_OP_LOAD_FIELD_S32, |
| 735 | [ FILTER_OP_LOAD_FIELD_S64 ] = &&LABEL_FILTER_OP_LOAD_FIELD_S64, |
| 736 | [ FILTER_OP_LOAD_FIELD_U8 ] = &&LABEL_FILTER_OP_LOAD_FIELD_U8, |
| 737 | [ FILTER_OP_LOAD_FIELD_U16 ] = &&LABEL_FILTER_OP_LOAD_FIELD_U16, |
| 738 | [ FILTER_OP_LOAD_FIELD_U32 ] = &&LABEL_FILTER_OP_LOAD_FIELD_U32, |
| 739 | [ FILTER_OP_LOAD_FIELD_U64 ] = &&LABEL_FILTER_OP_LOAD_FIELD_U64, |
| 740 | [ FILTER_OP_LOAD_FIELD_STRING ] = &&LABEL_FILTER_OP_LOAD_FIELD_STRING, |
| 741 | [ FILTER_OP_LOAD_FIELD_SEQUENCE ] = &&LABEL_FILTER_OP_LOAD_FIELD_SEQUENCE, |
| 742 | [ FILTER_OP_LOAD_FIELD_DOUBLE ] = &&LABEL_FILTER_OP_LOAD_FIELD_DOUBLE, |
| 743 | |
| 744 | [ FILTER_OP_UNARY_BIT_NOT ] = &&LABEL_FILTER_OP_UNARY_BIT_NOT, |
| 745 | }; |
| 746 | #endif /* #ifndef INTERPRETER_USE_SWITCH */ |
| 747 | |
| 748 | START_OP |
| 749 | |
| 750 | OP(FILTER_OP_UNKNOWN): |
| 751 | OP(FILTER_OP_LOAD_FIELD_REF): |
| 752 | #ifdef INTERPRETER_USE_SWITCH |
| 753 | default: |
| 754 | #endif /* INTERPRETER_USE_SWITCH */ |
| 755 | ERR("unknown bytecode op %u", |
| 756 | (unsigned int) *(filter_opcode_t *) pc); |
| 757 | ret = -EINVAL; |
| 758 | goto end; |
| 759 | |
| 760 | OP(FILTER_OP_RETURN): |
| 761 | /* LTTNG_FILTER_DISCARD or LTTNG_FILTER_RECORD_FLAG */ |
| 762 | /* Handle dynamic typing. */ |
| 763 | switch (estack_ax_t) { |
| 764 | case REG_S64: |
| 765 | retval = !!estack_ax_v; |
| 766 | break; |
| 767 | case REG_DOUBLE: |
| 768 | case REG_STRING: |
| 769 | case REG_STAR_GLOB_STRING: |
| 770 | default: |
| 771 | ret = -EINVAL; |
| 772 | goto end; |
| 773 | } |
| 774 | ret = 0; |
| 775 | goto end; |
| 776 | |
| 777 | /* binary */ |
| 778 | OP(FILTER_OP_MUL): |
| 779 | OP(FILTER_OP_DIV): |
| 780 | OP(FILTER_OP_MOD): |
| 781 | OP(FILTER_OP_PLUS): |
| 782 | OP(FILTER_OP_MINUS): |
| 783 | ERR("unsupported bytecode op %u", |
| 784 | (unsigned int) *(filter_opcode_t *) pc); |
| 785 | ret = -EINVAL; |
| 786 | goto end; |
| 787 | |
| 788 | OP(FILTER_OP_EQ): |
| 789 | { |
| 790 | /* Dynamic typing. */ |
| 791 | switch (estack_ax_t) { |
| 792 | case REG_S64: |
| 793 | switch (estack_bx_t) { |
| 794 | case REG_S64: |
| 795 | JUMP_TO(FILTER_OP_EQ_S64); |
| 796 | case REG_DOUBLE: |
| 797 | JUMP_TO(FILTER_OP_EQ_DOUBLE_S64); |
| 798 | case REG_STRING: /* Fall-through */ |
| 799 | case REG_STAR_GLOB_STRING: |
| 800 | ret = -EINVAL; |
| 801 | goto end; |
| 802 | default: |
| 803 | ERR("Unknown filter register type (%d)", |
| 804 | (int) estack_bx_t); |
| 805 | ret = -EINVAL; |
| 806 | goto end; |
| 807 | } |
| 808 | break; |
| 809 | case REG_DOUBLE: |
| 810 | switch (estack_bx_t) { |
| 811 | case REG_S64: |
| 812 | JUMP_TO(FILTER_OP_EQ_S64_DOUBLE); |
| 813 | case REG_DOUBLE: |
| 814 | JUMP_TO(FILTER_OP_EQ_DOUBLE); |
| 815 | case REG_STRING: /* Fall-through */ |
| 816 | case REG_STAR_GLOB_STRING: |
| 817 | ret = -EINVAL; |
| 818 | goto end; |
| 819 | default: |
| 820 | ERR("Unknown filter register type (%d)", |
| 821 | (int) estack_bx_t); |
| 822 | ret = -EINVAL; |
| 823 | goto end; |
| 824 | } |
| 825 | break; |
| 826 | case REG_STRING: |
| 827 | switch (estack_bx_t) { |
| 828 | case REG_S64: /* Fall-through */ |
| 829 | case REG_DOUBLE: |
| 830 | ret = -EINVAL; |
| 831 | goto end; |
| 832 | case REG_STRING: |
| 833 | JUMP_TO(FILTER_OP_EQ_STRING); |
| 834 | case REG_STAR_GLOB_STRING: |
| 835 | JUMP_TO(FILTER_OP_EQ_STAR_GLOB_STRING); |
| 836 | default: |
| 837 | ERR("Unknown filter register type (%d)", |
| 838 | (int) estack_bx_t); |
| 839 | ret = -EINVAL; |
| 840 | goto end; |
| 841 | } |
| 842 | break; |
| 843 | case REG_STAR_GLOB_STRING: |
| 844 | switch (estack_bx_t) { |
| 845 | case REG_S64: /* Fall-through */ |
| 846 | case REG_DOUBLE: |
| 847 | ret = -EINVAL; |
| 848 | goto end; |
| 849 | case REG_STRING: |
| 850 | JUMP_TO(FILTER_OP_EQ_STAR_GLOB_STRING); |
| 851 | case REG_STAR_GLOB_STRING: |
| 852 | ret = -EINVAL; |
| 853 | goto end; |
| 854 | default: |
| 855 | ERR("Unknown filter register type (%d)", |
| 856 | (int) estack_bx_t); |
| 857 | ret = -EINVAL; |
| 858 | goto end; |
| 859 | } |
| 860 | break; |
| 861 | default: |
| 862 | ERR("Unknown filter register type (%d)", |
| 863 | (int) estack_ax_t); |
| 864 | ret = -EINVAL; |
| 865 | goto end; |
| 866 | } |
| 867 | } |
| 868 | OP(FILTER_OP_NE): |
| 869 | { |
| 870 | /* Dynamic typing. */ |
| 871 | switch (estack_ax_t) { |
| 872 | case REG_S64: |
| 873 | switch (estack_bx_t) { |
| 874 | case REG_S64: |
| 875 | JUMP_TO(FILTER_OP_NE_S64); |
| 876 | case REG_DOUBLE: |
| 877 | JUMP_TO(FILTER_OP_NE_DOUBLE_S64); |
| 878 | case REG_STRING: /* Fall-through */ |
| 879 | case REG_STAR_GLOB_STRING: |
| 880 | ret = -EINVAL; |
| 881 | goto end; |
| 882 | default: |
| 883 | ERR("Unknown filter register type (%d)", |
| 884 | (int) estack_bx_t); |
| 885 | ret = -EINVAL; |
| 886 | goto end; |
| 887 | } |
| 888 | break; |
| 889 | case REG_DOUBLE: |
| 890 | switch (estack_bx_t) { |
| 891 | case REG_S64: |
| 892 | JUMP_TO(FILTER_OP_NE_S64_DOUBLE); |
| 893 | case REG_DOUBLE: |
| 894 | JUMP_TO(FILTER_OP_NE_DOUBLE); |
| 895 | case REG_STRING: /* Fall-through */ |
| 896 | case REG_STAR_GLOB_STRING: |
| 897 | ret = -EINVAL; |
| 898 | goto end; |
| 899 | default: |
| 900 | ERR("Unknown filter register type (%d)", |
| 901 | (int) estack_bx_t); |
| 902 | ret = -EINVAL; |
| 903 | goto end; |
| 904 | } |
| 905 | break; |
| 906 | case REG_STRING: |
| 907 | switch (estack_bx_t) { |
| 908 | case REG_S64: /* Fall-through */ |
| 909 | case REG_DOUBLE: |
| 910 | ret = -EINVAL; |
| 911 | goto end; |
| 912 | case REG_STRING: |
| 913 | JUMP_TO(FILTER_OP_NE_STRING); |
| 914 | case REG_STAR_GLOB_STRING: |
| 915 | JUMP_TO(FILTER_OP_NE_STAR_GLOB_STRING); |
| 916 | default: |
| 917 | ERR("Unknown filter register type (%d)", |
| 918 | (int) estack_bx_t); |
| 919 | ret = -EINVAL; |
| 920 | goto end; |
| 921 | } |
| 922 | break; |
| 923 | case REG_STAR_GLOB_STRING: |
| 924 | switch (estack_bx_t) { |
| 925 | case REG_S64: /* Fall-through */ |
| 926 | case REG_DOUBLE: |
| 927 | ret = -EINVAL; |
| 928 | goto end; |
| 929 | case REG_STRING: |
| 930 | JUMP_TO(FILTER_OP_NE_STAR_GLOB_STRING); |
| 931 | case REG_STAR_GLOB_STRING: |
| 932 | ret = -EINVAL; |
| 933 | goto end; |
| 934 | default: |
| 935 | ERR("Unknown filter register type (%d)", |
| 936 | (int) estack_bx_t); |
| 937 | ret = -EINVAL; |
| 938 | goto end; |
| 939 | } |
| 940 | break; |
| 941 | default: |
| 942 | ERR("Unknown filter register type (%d)", |
| 943 | (int) estack_ax_t); |
| 944 | ret = -EINVAL; |
| 945 | goto end; |
| 946 | } |
| 947 | } |
| 948 | OP(FILTER_OP_GT): |
| 949 | { |
| 950 | /* Dynamic typing. */ |
| 951 | switch (estack_ax_t) { |
| 952 | case REG_S64: |
| 953 | switch (estack_bx_t) { |
| 954 | case REG_S64: |
| 955 | JUMP_TO(FILTER_OP_GT_S64); |
| 956 | case REG_DOUBLE: |
| 957 | JUMP_TO(FILTER_OP_GT_DOUBLE_S64); |
| 958 | case REG_STRING: /* Fall-through */ |
| 959 | case REG_STAR_GLOB_STRING: |
| 960 | ret = -EINVAL; |
| 961 | goto end; |
| 962 | default: |
| 963 | ERR("Unknown filter register type (%d)", |
| 964 | (int) estack_bx_t); |
| 965 | ret = -EINVAL; |
| 966 | goto end; |
| 967 | } |
| 968 | break; |
| 969 | case REG_DOUBLE: |
| 970 | switch (estack_bx_t) { |
| 971 | case REG_S64: |
| 972 | JUMP_TO(FILTER_OP_GT_S64_DOUBLE); |
| 973 | case REG_DOUBLE: |
| 974 | JUMP_TO(FILTER_OP_GT_DOUBLE); |
| 975 | case REG_STRING: /* Fall-through */ |
| 976 | case REG_STAR_GLOB_STRING: |
| 977 | ret = -EINVAL; |
| 978 | goto end; |
| 979 | default: |
| 980 | ERR("Unknown filter register type (%d)", |
| 981 | (int) estack_bx_t); |
| 982 | ret = -EINVAL; |
| 983 | goto end; |
| 984 | } |
| 985 | break; |
| 986 | case REG_STRING: |
| 987 | switch (estack_bx_t) { |
| 988 | case REG_S64: /* Fall-through */ |
| 989 | case REG_DOUBLE: /* Fall-through */ |
| 990 | case REG_STAR_GLOB_STRING: |
| 991 | ret = -EINVAL; |
| 992 | goto end; |
| 993 | case REG_STRING: |
| 994 | JUMP_TO(FILTER_OP_GT_STRING); |
| 995 | default: |
| 996 | ERR("Unknown filter register type (%d)", |
| 997 | (int) estack_bx_t); |
| 998 | ret = -EINVAL; |
| 999 | goto end; |
| 1000 | } |
| 1001 | break; |
| 1002 | default: |
| 1003 | ERR("Unknown filter register type (%d)", |
| 1004 | (int) estack_ax_t); |
| 1005 | ret = -EINVAL; |
| 1006 | goto end; |
| 1007 | } |
| 1008 | } |
| 1009 | OP(FILTER_OP_LT): |
| 1010 | { |
| 1011 | /* Dynamic typing. */ |
| 1012 | switch (estack_ax_t) { |
| 1013 | case REG_S64: |
| 1014 | switch (estack_bx_t) { |
| 1015 | case REG_S64: |
| 1016 | JUMP_TO(FILTER_OP_LT_S64); |
| 1017 | case REG_DOUBLE: |
| 1018 | JUMP_TO(FILTER_OP_LT_DOUBLE_S64); |
| 1019 | case REG_STRING: /* Fall-through */ |
| 1020 | case REG_STAR_GLOB_STRING: |
| 1021 | ret = -EINVAL; |
| 1022 | goto end; |
| 1023 | default: |
| 1024 | ERR("Unknown filter register type (%d)", |
| 1025 | (int) estack_bx_t); |
| 1026 | ret = -EINVAL; |
| 1027 | goto end; |
| 1028 | } |
| 1029 | break; |
| 1030 | case REG_DOUBLE: |
| 1031 | switch (estack_bx_t) { |
| 1032 | case REG_S64: |
| 1033 | JUMP_TO(FILTER_OP_LT_S64_DOUBLE); |
| 1034 | case REG_DOUBLE: |
| 1035 | JUMP_TO(FILTER_OP_LT_DOUBLE); |
| 1036 | case REG_STRING: /* Fall-through */ |
| 1037 | case REG_STAR_GLOB_STRING: |
| 1038 | ret = -EINVAL; |
| 1039 | goto end; |
| 1040 | default: |
| 1041 | ERR("Unknown filter register type (%d)", |
| 1042 | (int) estack_bx_t); |
| 1043 | ret = -EINVAL; |
| 1044 | goto end; |
| 1045 | } |
| 1046 | break; |
| 1047 | case REG_STRING: |
| 1048 | switch (estack_bx_t) { |
| 1049 | case REG_S64: /* Fall-through */ |
| 1050 | case REG_DOUBLE: /* Fall-through */ |
| 1051 | case REG_STAR_GLOB_STRING: |
| 1052 | ret = -EINVAL; |
| 1053 | goto end; |
| 1054 | case REG_STRING: |
| 1055 | JUMP_TO(FILTER_OP_LT_STRING); |
| 1056 | default: |
| 1057 | ERR("Unknown filter register type (%d)", |
| 1058 | (int) estack_bx_t); |
| 1059 | ret = -EINVAL; |
| 1060 | goto end; |
| 1061 | } |
| 1062 | break; |
| 1063 | default: |
| 1064 | ERR("Unknown filter register type (%d)", |
| 1065 | (int) estack_ax_t); |
| 1066 | ret = -EINVAL; |
| 1067 | goto end; |
| 1068 | } |
| 1069 | } |
| 1070 | OP(FILTER_OP_GE): |
| 1071 | { |
| 1072 | /* Dynamic typing. */ |
| 1073 | switch (estack_ax_t) { |
| 1074 | case REG_S64: |
| 1075 | switch (estack_bx_t) { |
| 1076 | case REG_S64: |
| 1077 | JUMP_TO(FILTER_OP_GE_S64); |
| 1078 | case REG_DOUBLE: |
| 1079 | JUMP_TO(FILTER_OP_GE_DOUBLE_S64); |
| 1080 | case REG_STRING: /* Fall-through */ |
| 1081 | case REG_STAR_GLOB_STRING: |
| 1082 | ret = -EINVAL; |
| 1083 | goto end; |
| 1084 | default: |
| 1085 | ERR("Unknown filter register type (%d)", |
| 1086 | (int) estack_bx_t); |
| 1087 | ret = -EINVAL; |
| 1088 | goto end; |
| 1089 | } |
| 1090 | break; |
| 1091 | case REG_DOUBLE: |
| 1092 | switch (estack_bx_t) { |
| 1093 | case REG_S64: |
| 1094 | JUMP_TO(FILTER_OP_GE_S64_DOUBLE); |
| 1095 | case REG_DOUBLE: |
| 1096 | JUMP_TO(FILTER_OP_GE_DOUBLE); |
| 1097 | case REG_STRING: /* Fall-through */ |
| 1098 | case REG_STAR_GLOB_STRING: |
| 1099 | ret = -EINVAL; |
| 1100 | goto end; |
| 1101 | default: |
| 1102 | ERR("Unknown filter register type (%d)", |
| 1103 | (int) estack_bx_t); |
| 1104 | ret = -EINVAL; |
| 1105 | goto end; |
| 1106 | } |
| 1107 | break; |
| 1108 | case REG_STRING: |
| 1109 | switch (estack_bx_t) { |
| 1110 | case REG_S64: /* Fall-through */ |
| 1111 | case REG_DOUBLE: /* Fall-through */ |
| 1112 | case REG_STAR_GLOB_STRING: |
| 1113 | ret = -EINVAL; |
| 1114 | goto end; |
| 1115 | case REG_STRING: |
| 1116 | JUMP_TO(FILTER_OP_GE_STRING); |
| 1117 | default: |
| 1118 | ERR("Unknown filter register type (%d)", |
| 1119 | (int) estack_bx_t); |
| 1120 | ret = -EINVAL; |
| 1121 | goto end; |
| 1122 | } |
| 1123 | break; |
| 1124 | default: |
| 1125 | ERR("Unknown filter register type (%d)", |
| 1126 | (int) estack_ax_t); |
| 1127 | ret = -EINVAL; |
| 1128 | goto end; |
| 1129 | } |
| 1130 | } |
| 1131 | OP(FILTER_OP_LE): |
| 1132 | { |
| 1133 | /* Dynamic typing. */ |
| 1134 | switch (estack_ax_t) { |
| 1135 | case REG_S64: |
| 1136 | switch (estack_bx_t) { |
| 1137 | case REG_S64: |
| 1138 | JUMP_TO(FILTER_OP_LE_S64); |
| 1139 | case REG_DOUBLE: |
| 1140 | JUMP_TO(FILTER_OP_LE_DOUBLE_S64); |
| 1141 | case REG_STRING: /* Fall-through */ |
| 1142 | case REG_STAR_GLOB_STRING: |
| 1143 | ret = -EINVAL; |
| 1144 | goto end; |
| 1145 | default: |
| 1146 | ERR("Unknown filter register type (%d)", |
| 1147 | (int) estack_bx_t); |
| 1148 | ret = -EINVAL; |
| 1149 | goto end; |
| 1150 | } |
| 1151 | break; |
| 1152 | case REG_DOUBLE: |
| 1153 | switch (estack_bx_t) { |
| 1154 | case REG_S64: |
| 1155 | JUMP_TO(FILTER_OP_LE_S64_DOUBLE); |
| 1156 | case REG_DOUBLE: |
| 1157 | JUMP_TO(FILTER_OP_LE_DOUBLE); |
| 1158 | case REG_STRING: /* Fall-through */ |
| 1159 | case REG_STAR_GLOB_STRING: |
| 1160 | ret = -EINVAL; |
| 1161 | goto end; |
| 1162 | default: |
| 1163 | ERR("Unknown filter register type (%d)", |
| 1164 | (int) estack_bx_t); |
| 1165 | ret = -EINVAL; |
| 1166 | goto end; |
| 1167 | } |
| 1168 | break; |
| 1169 | case REG_STRING: |
| 1170 | switch (estack_bx_t) { |
| 1171 | case REG_S64: /* Fall-through */ |
| 1172 | case REG_DOUBLE: /* Fall-through */ |
| 1173 | case REG_STAR_GLOB_STRING: |
| 1174 | ret = -EINVAL; |
| 1175 | goto end; |
| 1176 | case REG_STRING: |
| 1177 | JUMP_TO(FILTER_OP_LE_STRING); |
| 1178 | default: |
| 1179 | ERR("Unknown filter register type (%d)", |
| 1180 | (int) estack_bx_t); |
| 1181 | ret = -EINVAL; |
| 1182 | goto end; |
| 1183 | } |
| 1184 | break; |
| 1185 | default: |
| 1186 | ERR("Unknown filter register type (%d)", |
| 1187 | (int) estack_ax_t); |
| 1188 | ret = -EINVAL; |
| 1189 | goto end; |
| 1190 | } |
| 1191 | } |
| 1192 | |
| 1193 | OP(FILTER_OP_EQ_STRING): |
| 1194 | { |
| 1195 | int res; |
| 1196 | |
| 1197 | res = (stack_strcmp(stack, top, "==") == 0); |
| 1198 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1199 | estack_ax_v = res; |
| 1200 | estack_ax_t = REG_S64; |
| 1201 | next_pc += sizeof(struct binary_op); |
| 1202 | PO; |
| 1203 | } |
| 1204 | OP(FILTER_OP_NE_STRING): |
| 1205 | { |
| 1206 | int res; |
| 1207 | |
| 1208 | res = (stack_strcmp(stack, top, "!=") != 0); |
| 1209 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1210 | estack_ax_v = res; |
| 1211 | estack_ax_t = REG_S64; |
| 1212 | next_pc += sizeof(struct binary_op); |
| 1213 | PO; |
| 1214 | } |
| 1215 | OP(FILTER_OP_GT_STRING): |
| 1216 | { |
| 1217 | int res; |
| 1218 | |
| 1219 | res = (stack_strcmp(stack, top, ">") > 0); |
| 1220 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1221 | estack_ax_v = res; |
| 1222 | estack_ax_t = REG_S64; |
| 1223 | next_pc += sizeof(struct binary_op); |
| 1224 | PO; |
| 1225 | } |
| 1226 | OP(FILTER_OP_LT_STRING): |
| 1227 | { |
| 1228 | int res; |
| 1229 | |
| 1230 | res = (stack_strcmp(stack, top, "<") < 0); |
| 1231 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1232 | estack_ax_v = res; |
| 1233 | estack_ax_t = REG_S64; |
| 1234 | next_pc += sizeof(struct binary_op); |
| 1235 | PO; |
| 1236 | } |
| 1237 | OP(FILTER_OP_GE_STRING): |
| 1238 | { |
| 1239 | int res; |
| 1240 | |
| 1241 | res = (stack_strcmp(stack, top, ">=") >= 0); |
| 1242 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1243 | estack_ax_v = res; |
| 1244 | estack_ax_t = REG_S64; |
| 1245 | next_pc += sizeof(struct binary_op); |
| 1246 | PO; |
| 1247 | } |
| 1248 | OP(FILTER_OP_LE_STRING): |
| 1249 | { |
| 1250 | int res; |
| 1251 | |
| 1252 | res = (stack_strcmp(stack, top, "<=") <= 0); |
| 1253 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1254 | estack_ax_v = res; |
| 1255 | estack_ax_t = REG_S64; |
| 1256 | next_pc += sizeof(struct binary_op); |
| 1257 | PO; |
| 1258 | } |
| 1259 | |
| 1260 | OP(FILTER_OP_EQ_STAR_GLOB_STRING): |
| 1261 | { |
| 1262 | int res; |
| 1263 | |
| 1264 | res = (stack_star_glob_match(stack, top, "==") == 0); |
| 1265 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1266 | estack_ax_v = res; |
| 1267 | estack_ax_t = REG_S64; |
| 1268 | next_pc += sizeof(struct binary_op); |
| 1269 | PO; |
| 1270 | } |
| 1271 | OP(FILTER_OP_NE_STAR_GLOB_STRING): |
| 1272 | { |
| 1273 | int res; |
| 1274 | |
| 1275 | res = (stack_star_glob_match(stack, top, "!=") != 0); |
| 1276 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1277 | estack_ax_v = res; |
| 1278 | estack_ax_t = REG_S64; |
| 1279 | next_pc += sizeof(struct binary_op); |
| 1280 | PO; |
| 1281 | } |
| 1282 | |
| 1283 | OP(FILTER_OP_EQ_S64): |
| 1284 | { |
| 1285 | int res; |
| 1286 | |
| 1287 | res = (estack_bx_v == estack_ax_v); |
| 1288 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1289 | estack_ax_v = res; |
| 1290 | estack_ax_t = REG_S64; |
| 1291 | next_pc += sizeof(struct binary_op); |
| 1292 | PO; |
| 1293 | } |
| 1294 | OP(FILTER_OP_NE_S64): |
| 1295 | { |
| 1296 | int res; |
| 1297 | |
| 1298 | res = (estack_bx_v != estack_ax_v); |
| 1299 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1300 | estack_ax_v = res; |
| 1301 | estack_ax_t = REG_S64; |
| 1302 | next_pc += sizeof(struct binary_op); |
| 1303 | PO; |
| 1304 | } |
| 1305 | OP(FILTER_OP_GT_S64): |
| 1306 | { |
| 1307 | int res; |
| 1308 | |
| 1309 | res = (estack_bx_v > estack_ax_v); |
| 1310 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1311 | estack_ax_v = res; |
| 1312 | estack_ax_t = REG_S64; |
| 1313 | next_pc += sizeof(struct binary_op); |
| 1314 | PO; |
| 1315 | } |
| 1316 | OP(FILTER_OP_LT_S64): |
| 1317 | { |
| 1318 | int res; |
| 1319 | |
| 1320 | res = (estack_bx_v < estack_ax_v); |
| 1321 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1322 | estack_ax_v = res; |
| 1323 | estack_ax_t = REG_S64; |
| 1324 | next_pc += sizeof(struct binary_op); |
| 1325 | PO; |
| 1326 | } |
| 1327 | OP(FILTER_OP_GE_S64): |
| 1328 | { |
| 1329 | int res; |
| 1330 | |
| 1331 | res = (estack_bx_v >= estack_ax_v); |
| 1332 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1333 | estack_ax_v = res; |
| 1334 | estack_ax_t = REG_S64; |
| 1335 | next_pc += sizeof(struct binary_op); |
| 1336 | PO; |
| 1337 | } |
| 1338 | OP(FILTER_OP_LE_S64): |
| 1339 | { |
| 1340 | int res; |
| 1341 | |
| 1342 | res = (estack_bx_v <= estack_ax_v); |
| 1343 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1344 | estack_ax_v = res; |
| 1345 | estack_ax_t = REG_S64; |
| 1346 | next_pc += sizeof(struct binary_op); |
| 1347 | PO; |
| 1348 | } |
| 1349 | |
| 1350 | OP(FILTER_OP_EQ_DOUBLE): |
| 1351 | { |
| 1352 | int res; |
| 1353 | |
| 1354 | res = (estack_bx(stack, top)->u.d == estack_ax(stack, top)->u.d); |
| 1355 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1356 | estack_ax_v = res; |
| 1357 | estack_ax_t = REG_S64; |
| 1358 | next_pc += sizeof(struct binary_op); |
| 1359 | PO; |
| 1360 | } |
| 1361 | OP(FILTER_OP_NE_DOUBLE): |
| 1362 | { |
| 1363 | int res; |
| 1364 | |
| 1365 | res = (estack_bx(stack, top)->u.d != estack_ax(stack, top)->u.d); |
| 1366 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1367 | estack_ax_v = res; |
| 1368 | estack_ax_t = REG_S64; |
| 1369 | next_pc += sizeof(struct binary_op); |
| 1370 | PO; |
| 1371 | } |
| 1372 | OP(FILTER_OP_GT_DOUBLE): |
| 1373 | { |
| 1374 | int res; |
| 1375 | |
| 1376 | res = (estack_bx(stack, top)->u.d > estack_ax(stack, top)->u.d); |
| 1377 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1378 | estack_ax_v = res; |
| 1379 | estack_ax_t = REG_S64; |
| 1380 | next_pc += sizeof(struct binary_op); |
| 1381 | PO; |
| 1382 | } |
| 1383 | OP(FILTER_OP_LT_DOUBLE): |
| 1384 | { |
| 1385 | int res; |
| 1386 | |
| 1387 | res = (estack_bx(stack, top)->u.d < estack_ax(stack, top)->u.d); |
| 1388 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1389 | estack_ax_v = res; |
| 1390 | estack_ax_t = REG_S64; |
| 1391 | next_pc += sizeof(struct binary_op); |
| 1392 | PO; |
| 1393 | } |
| 1394 | OP(FILTER_OP_GE_DOUBLE): |
| 1395 | { |
| 1396 | int res; |
| 1397 | |
| 1398 | res = (estack_bx(stack, top)->u.d >= estack_ax(stack, top)->u.d); |
| 1399 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1400 | estack_ax_v = res; |
| 1401 | estack_ax_t = REG_S64; |
| 1402 | next_pc += sizeof(struct binary_op); |
| 1403 | PO; |
| 1404 | } |
| 1405 | OP(FILTER_OP_LE_DOUBLE): |
| 1406 | { |
| 1407 | int res; |
| 1408 | |
| 1409 | res = (estack_bx(stack, top)->u.d <= estack_ax(stack, top)->u.d); |
| 1410 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1411 | estack_ax_v = res; |
| 1412 | estack_ax_t = REG_S64; |
| 1413 | next_pc += sizeof(struct binary_op); |
| 1414 | PO; |
| 1415 | } |
| 1416 | |
| 1417 | /* Mixed S64-double binary comparators */ |
| 1418 | OP(FILTER_OP_EQ_DOUBLE_S64): |
| 1419 | { |
| 1420 | int res; |
| 1421 | |
| 1422 | res = (estack_bx(stack, top)->u.d == estack_ax_v); |
| 1423 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1424 | estack_ax_v = res; |
| 1425 | estack_ax_t = REG_S64; |
| 1426 | next_pc += sizeof(struct binary_op); |
| 1427 | PO; |
| 1428 | } |
| 1429 | OP(FILTER_OP_NE_DOUBLE_S64): |
| 1430 | { |
| 1431 | int res; |
| 1432 | |
| 1433 | res = (estack_bx(stack, top)->u.d != estack_ax_v); |
| 1434 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1435 | estack_ax_v = res; |
| 1436 | estack_ax_t = REG_S64; |
| 1437 | next_pc += sizeof(struct binary_op); |
| 1438 | PO; |
| 1439 | } |
| 1440 | OP(FILTER_OP_GT_DOUBLE_S64): |
| 1441 | { |
| 1442 | int res; |
| 1443 | |
| 1444 | res = (estack_bx(stack, top)->u.d > estack_ax_v); |
| 1445 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1446 | estack_ax_v = res; |
| 1447 | estack_ax_t = REG_S64; |
| 1448 | next_pc += sizeof(struct binary_op); |
| 1449 | PO; |
| 1450 | } |
| 1451 | OP(FILTER_OP_LT_DOUBLE_S64): |
| 1452 | { |
| 1453 | int res; |
| 1454 | |
| 1455 | res = (estack_bx(stack, top)->u.d < estack_ax_v); |
| 1456 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1457 | estack_ax_v = res; |
| 1458 | estack_ax_t = REG_S64; |
| 1459 | next_pc += sizeof(struct binary_op); |
| 1460 | PO; |
| 1461 | } |
| 1462 | OP(FILTER_OP_GE_DOUBLE_S64): |
| 1463 | { |
| 1464 | int res; |
| 1465 | |
| 1466 | res = (estack_bx(stack, top)->u.d >= estack_ax_v); |
| 1467 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1468 | estack_ax_v = res; |
| 1469 | estack_ax_t = REG_S64; |
| 1470 | next_pc += sizeof(struct binary_op); |
| 1471 | PO; |
| 1472 | } |
| 1473 | OP(FILTER_OP_LE_DOUBLE_S64): |
| 1474 | { |
| 1475 | int res; |
| 1476 | |
| 1477 | res = (estack_bx(stack, top)->u.d <= estack_ax_v); |
| 1478 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1479 | estack_ax_v = res; |
| 1480 | estack_ax_t = REG_S64; |
| 1481 | next_pc += sizeof(struct binary_op); |
| 1482 | PO; |
| 1483 | } |
| 1484 | |
| 1485 | OP(FILTER_OP_EQ_S64_DOUBLE): |
| 1486 | { |
| 1487 | int res; |
| 1488 | |
| 1489 | res = (estack_bx_v == estack_ax(stack, top)->u.d); |
| 1490 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1491 | estack_ax_v = res; |
| 1492 | estack_ax_t = REG_S64; |
| 1493 | next_pc += sizeof(struct binary_op); |
| 1494 | PO; |
| 1495 | } |
| 1496 | OP(FILTER_OP_NE_S64_DOUBLE): |
| 1497 | { |
| 1498 | int res; |
| 1499 | |
| 1500 | res = (estack_bx_v != estack_ax(stack, top)->u.d); |
| 1501 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1502 | estack_ax_v = res; |
| 1503 | estack_ax_t = REG_S64; |
| 1504 | next_pc += sizeof(struct binary_op); |
| 1505 | PO; |
| 1506 | } |
| 1507 | OP(FILTER_OP_GT_S64_DOUBLE): |
| 1508 | { |
| 1509 | int res; |
| 1510 | |
| 1511 | res = (estack_bx_v > estack_ax(stack, top)->u.d); |
| 1512 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1513 | estack_ax_v = res; |
| 1514 | estack_ax_t = REG_S64; |
| 1515 | next_pc += sizeof(struct binary_op); |
| 1516 | PO; |
| 1517 | } |
| 1518 | OP(FILTER_OP_LT_S64_DOUBLE): |
| 1519 | { |
| 1520 | int res; |
| 1521 | |
| 1522 | res = (estack_bx_v < estack_ax(stack, top)->u.d); |
| 1523 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1524 | estack_ax_v = res; |
| 1525 | estack_ax_t = REG_S64; |
| 1526 | next_pc += sizeof(struct binary_op); |
| 1527 | PO; |
| 1528 | } |
| 1529 | OP(FILTER_OP_GE_S64_DOUBLE): |
| 1530 | { |
| 1531 | int res; |
| 1532 | |
| 1533 | res = (estack_bx_v >= estack_ax(stack, top)->u.d); |
| 1534 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1535 | estack_ax_v = res; |
| 1536 | estack_ax_t = REG_S64; |
| 1537 | next_pc += sizeof(struct binary_op); |
| 1538 | PO; |
| 1539 | } |
| 1540 | OP(FILTER_OP_LE_S64_DOUBLE): |
| 1541 | { |
| 1542 | int res; |
| 1543 | |
| 1544 | res = (estack_bx_v <= estack_ax(stack, top)->u.d); |
| 1545 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1546 | estack_ax_v = res; |
| 1547 | estack_ax_t = REG_S64; |
| 1548 | next_pc += sizeof(struct binary_op); |
| 1549 | PO; |
| 1550 | } |
| 1551 | OP(FILTER_OP_BIT_RSHIFT): |
| 1552 | { |
| 1553 | int64_t res; |
| 1554 | |
| 1555 | /* Dynamic typing. */ |
| 1556 | if (estack_ax_t != REG_S64 || estack_bx_t != REG_S64) { |
| 1557 | ret = -EINVAL; |
| 1558 | goto end; |
| 1559 | } |
| 1560 | /* Catch undefined behavior. */ |
| 1561 | if (caa_unlikely(estack_ax_v < 0 || estack_ax_v >= 64)) { |
| 1562 | ret = -EINVAL; |
| 1563 | goto end; |
| 1564 | } |
| 1565 | res = (estack_bx_v >> estack_ax_v); |
| 1566 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1567 | estack_ax_v = res; |
| 1568 | estack_ax_t = REG_S64; |
| 1569 | next_pc += sizeof(struct binary_op); |
| 1570 | PO; |
| 1571 | } |
| 1572 | OP(FILTER_OP_BIT_LSHIFT): |
| 1573 | { |
| 1574 | int64_t res; |
| 1575 | |
| 1576 | /* Dynamic typing. */ |
| 1577 | if (estack_ax_t != REG_S64 || estack_bx_t != REG_S64) { |
| 1578 | ret = -EINVAL; |
| 1579 | goto end; |
| 1580 | } |
| 1581 | /* Catch undefined behavior. */ |
| 1582 | if (caa_unlikely(estack_ax_v < 0 || estack_ax_v >= 64)) { |
| 1583 | ret = -EINVAL; |
| 1584 | goto end; |
| 1585 | } |
| 1586 | res = (estack_bx_v << estack_ax_v); |
| 1587 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1588 | estack_ax_v = res; |
| 1589 | estack_ax_t = REG_S64; |
| 1590 | next_pc += sizeof(struct binary_op); |
| 1591 | PO; |
| 1592 | } |
| 1593 | OP(FILTER_OP_BIT_AND): |
| 1594 | { |
| 1595 | int64_t res; |
| 1596 | |
| 1597 | /* Dynamic typing. */ |
| 1598 | if (estack_ax_t != REG_S64 || estack_bx_t != REG_S64) { |
| 1599 | ret = -EINVAL; |
| 1600 | goto end; |
| 1601 | } |
| 1602 | |
| 1603 | res = (estack_bx_v & estack_ax_v); |
| 1604 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1605 | estack_ax_v = res; |
| 1606 | estack_ax_t = REG_S64; |
| 1607 | next_pc += sizeof(struct binary_op); |
| 1608 | PO; |
| 1609 | } |
| 1610 | OP(FILTER_OP_BIT_OR): |
| 1611 | { |
| 1612 | int64_t res; |
| 1613 | |
| 1614 | /* Dynamic typing. */ |
| 1615 | if (estack_ax_t != REG_S64 || estack_bx_t != REG_S64) { |
| 1616 | ret = -EINVAL; |
| 1617 | goto end; |
| 1618 | } |
| 1619 | |
| 1620 | res = (estack_bx_v | estack_ax_v); |
| 1621 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1622 | estack_ax_v = res; |
| 1623 | estack_ax_t = REG_S64; |
| 1624 | next_pc += sizeof(struct binary_op); |
| 1625 | PO; |
| 1626 | } |
| 1627 | OP(FILTER_OP_BIT_XOR): |
| 1628 | { |
| 1629 | int64_t res; |
| 1630 | |
| 1631 | /* Dynamic typing. */ |
| 1632 | if (estack_ax_t != REG_S64 || estack_bx_t != REG_S64) { |
| 1633 | ret = -EINVAL; |
| 1634 | goto end; |
| 1635 | } |
| 1636 | |
| 1637 | res = (estack_bx_v ^ estack_ax_v); |
| 1638 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1639 | estack_ax_v = res; |
| 1640 | estack_ax_t = REG_S64; |
| 1641 | next_pc += sizeof(struct binary_op); |
| 1642 | PO; |
| 1643 | } |
| 1644 | |
| 1645 | /* unary */ |
| 1646 | OP(FILTER_OP_UNARY_PLUS): |
| 1647 | { |
| 1648 | /* Dynamic typing. */ |
| 1649 | switch (estack_ax_t) { |
| 1650 | case REG_S64: /* Fall-through. */ |
| 1651 | JUMP_TO(FILTER_OP_UNARY_PLUS_S64); |
| 1652 | case REG_DOUBLE: |
| 1653 | JUMP_TO(FILTER_OP_UNARY_PLUS_DOUBLE); |
| 1654 | case REG_STRING: /* Fall-through */ |
| 1655 | case REG_STAR_GLOB_STRING: |
| 1656 | ret = -EINVAL; |
| 1657 | goto end; |
| 1658 | default: |
| 1659 | ERR("Unknown filter register type (%d)", |
| 1660 | (int) estack_ax_t); |
| 1661 | ret = -EINVAL; |
| 1662 | goto end; |
| 1663 | } |
| 1664 | } |
| 1665 | OP(FILTER_OP_UNARY_MINUS): |
| 1666 | { |
| 1667 | /* Dynamic typing. */ |
| 1668 | switch (estack_ax_t) { |
| 1669 | case REG_S64: |
| 1670 | JUMP_TO(FILTER_OP_UNARY_MINUS_S64); |
| 1671 | case REG_DOUBLE: |
| 1672 | JUMP_TO(FILTER_OP_UNARY_MINUS_DOUBLE); |
| 1673 | case REG_STRING: /* Fall-through */ |
| 1674 | case REG_STAR_GLOB_STRING: |
| 1675 | ret = -EINVAL; |
| 1676 | goto end; |
| 1677 | default: |
| 1678 | ERR("Unknown filter register type (%d)", |
| 1679 | (int) estack_ax_t); |
| 1680 | ret = -EINVAL; |
| 1681 | goto end; |
| 1682 | } |
| 1683 | } |
| 1684 | OP(FILTER_OP_UNARY_NOT): |
| 1685 | { |
| 1686 | /* Dynamic typing. */ |
| 1687 | switch (estack_ax_t) { |
| 1688 | case REG_S64: |
| 1689 | JUMP_TO(FILTER_OP_UNARY_NOT_S64); |
| 1690 | case REG_DOUBLE: |
| 1691 | JUMP_TO(FILTER_OP_UNARY_NOT_DOUBLE); |
| 1692 | case REG_STRING: /* Fall-through */ |
| 1693 | case REG_STAR_GLOB_STRING: |
| 1694 | ret = -EINVAL; |
| 1695 | goto end; |
| 1696 | default: |
| 1697 | ERR("Unknown filter register type (%d)", |
| 1698 | (int) estack_ax_t); |
| 1699 | ret = -EINVAL; |
| 1700 | goto end; |
| 1701 | } |
| 1702 | next_pc += sizeof(struct unary_op); |
| 1703 | PO; |
| 1704 | } |
| 1705 | |
| 1706 | OP(FILTER_OP_UNARY_BIT_NOT): |
| 1707 | { |
| 1708 | /* Dynamic typing. */ |
| 1709 | if (estack_ax_t != REG_S64) { |
| 1710 | ret = -EINVAL; |
| 1711 | goto end; |
| 1712 | } |
| 1713 | |
| 1714 | estack_ax_v = ~estack_ax_v; |
| 1715 | next_pc += sizeof(struct unary_op); |
| 1716 | PO; |
| 1717 | } |
| 1718 | |
| 1719 | OP(FILTER_OP_UNARY_PLUS_S64): |
| 1720 | OP(FILTER_OP_UNARY_PLUS_DOUBLE): |
| 1721 | { |
| 1722 | next_pc += sizeof(struct unary_op); |
| 1723 | PO; |
| 1724 | } |
| 1725 | OP(FILTER_OP_UNARY_MINUS_S64): |
| 1726 | { |
| 1727 | estack_ax_v = -estack_ax_v; |
| 1728 | next_pc += sizeof(struct unary_op); |
| 1729 | PO; |
| 1730 | } |
| 1731 | OP(FILTER_OP_UNARY_MINUS_DOUBLE): |
| 1732 | { |
| 1733 | estack_ax(stack, top)->u.d = -estack_ax(stack, top)->u.d; |
| 1734 | next_pc += sizeof(struct unary_op); |
| 1735 | PO; |
| 1736 | } |
| 1737 | OP(FILTER_OP_UNARY_NOT_S64): |
| 1738 | { |
| 1739 | estack_ax_v = !estack_ax_v; |
| 1740 | next_pc += sizeof(struct unary_op); |
| 1741 | PO; |
| 1742 | } |
| 1743 | OP(FILTER_OP_UNARY_NOT_DOUBLE): |
| 1744 | { |
| 1745 | estack_ax_v = !estack_ax(stack, top)->u.d; |
| 1746 | estack_ax_t = REG_S64; |
| 1747 | next_pc += sizeof(struct unary_op); |
| 1748 | PO; |
| 1749 | } |
| 1750 | |
| 1751 | /* logical */ |
| 1752 | OP(FILTER_OP_AND): |
| 1753 | { |
| 1754 | struct logical_op *insn = (struct logical_op *) pc; |
| 1755 | |
| 1756 | if (estack_ax_t != REG_S64) { |
| 1757 | ret = -EINVAL; |
| 1758 | goto end; |
| 1759 | } |
| 1760 | /* If AX is 0, skip and evaluate to 0 */ |
| 1761 | if (unlikely(estack_ax_v == 0)) { |
| 1762 | dbg_printf("Jumping to bytecode offset %u\n", |
| 1763 | (unsigned int) insn->skip_offset); |
| 1764 | next_pc = start_pc + insn->skip_offset; |
| 1765 | } else { |
| 1766 | /* Pop 1 when jump not taken */ |
| 1767 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1768 | next_pc += sizeof(struct logical_op); |
| 1769 | } |
| 1770 | PO; |
| 1771 | } |
| 1772 | OP(FILTER_OP_OR): |
| 1773 | { |
| 1774 | struct logical_op *insn = (struct logical_op *) pc; |
| 1775 | |
| 1776 | if (estack_ax_t != REG_S64) { |
| 1777 | ret = -EINVAL; |
| 1778 | goto end; |
| 1779 | } |
| 1780 | /* If AX is nonzero, skip and evaluate to 1 */ |
| 1781 | if (unlikely(estack_ax_v != 0)) { |
| 1782 | estack_ax_v = 1; |
| 1783 | dbg_printf("Jumping to bytecode offset %u\n", |
| 1784 | (unsigned int) insn->skip_offset); |
| 1785 | next_pc = start_pc + insn->skip_offset; |
| 1786 | } else { |
| 1787 | /* Pop 1 when jump not taken */ |
| 1788 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1789 | next_pc += sizeof(struct logical_op); |
| 1790 | } |
| 1791 | PO; |
| 1792 | } |
| 1793 | |
| 1794 | |
| 1795 | /* load field ref */ |
| 1796 | OP(FILTER_OP_LOAD_FIELD_REF_STRING): |
| 1797 | { |
| 1798 | struct load_op *insn = (struct load_op *) pc; |
| 1799 | struct field_ref *ref = (struct field_ref *) insn->data; |
| 1800 | |
| 1801 | dbg_printf("load field ref offset %u type string\n", |
| 1802 | ref->offset); |
| 1803 | estack_push(stack, top, ax, bx, ax_t, bx_t); |
| 1804 | estack_ax(stack, top)->u.s.str = |
| 1805 | *(const char * const *) &filter_stack_data[ref->offset]; |
| 1806 | if (unlikely(!estack_ax(stack, top)->u.s.str)) { |
| 1807 | dbg_printf("Filter warning: loading a NULL string.\n"); |
| 1808 | ret = -EINVAL; |
| 1809 | goto end; |
| 1810 | } |
| 1811 | estack_ax(stack, top)->u.s.seq_len = SIZE_MAX; |
| 1812 | estack_ax(stack, top)->u.s.literal_type = |
| 1813 | ESTACK_STRING_LITERAL_TYPE_NONE; |
| 1814 | estack_ax_t = REG_STRING; |
| 1815 | dbg_printf("ref load string %s\n", estack_ax(stack, top)->u.s.str); |
| 1816 | next_pc += sizeof(struct load_op) + sizeof(struct field_ref); |
| 1817 | PO; |
| 1818 | } |
| 1819 | |
| 1820 | OP(FILTER_OP_LOAD_FIELD_REF_SEQUENCE): |
| 1821 | { |
| 1822 | struct load_op *insn = (struct load_op *) pc; |
| 1823 | struct field_ref *ref = (struct field_ref *) insn->data; |
| 1824 | |
| 1825 | dbg_printf("load field ref offset %u type sequence\n", |
| 1826 | ref->offset); |
| 1827 | estack_push(stack, top, ax, bx, ax_t, bx_t); |
| 1828 | estack_ax(stack, top)->u.s.seq_len = |
| 1829 | *(unsigned long *) &filter_stack_data[ref->offset]; |
| 1830 | estack_ax(stack, top)->u.s.str = |
| 1831 | *(const char **) (&filter_stack_data[ref->offset |
| 1832 | + sizeof(unsigned long)]); |
| 1833 | estack_ax_t = REG_STRING; |
| 1834 | if (unlikely(!estack_ax(stack, top)->u.s.str)) { |
| 1835 | dbg_printf("Filter warning: loading a NULL sequence.\n"); |
| 1836 | ret = -EINVAL; |
| 1837 | goto end; |
| 1838 | } |
| 1839 | estack_ax(stack, top)->u.s.literal_type = |
| 1840 | ESTACK_STRING_LITERAL_TYPE_NONE; |
| 1841 | next_pc += sizeof(struct load_op) + sizeof(struct field_ref); |
| 1842 | PO; |
| 1843 | } |
| 1844 | |
| 1845 | OP(FILTER_OP_LOAD_FIELD_REF_S64): |
| 1846 | { |
| 1847 | struct load_op *insn = (struct load_op *) pc; |
| 1848 | struct field_ref *ref = (struct field_ref *) insn->data; |
| 1849 | |
| 1850 | dbg_printf("load field ref offset %u type s64\n", |
| 1851 | ref->offset); |
| 1852 | estack_push(stack, top, ax, bx, ax_t, bx_t); |
| 1853 | estack_ax_v = |
| 1854 | ((struct literal_numeric *) &filter_stack_data[ref->offset])->v; |
| 1855 | estack_ax_t = REG_S64; |
| 1856 | dbg_printf("ref load s64 %" PRIi64 "\n", estack_ax_v); |
| 1857 | next_pc += sizeof(struct load_op) + sizeof(struct field_ref); |
| 1858 | PO; |
| 1859 | } |
| 1860 | |
| 1861 | OP(FILTER_OP_LOAD_FIELD_REF_DOUBLE): |
| 1862 | { |
| 1863 | struct load_op *insn = (struct load_op *) pc; |
| 1864 | struct field_ref *ref = (struct field_ref *) insn->data; |
| 1865 | |
| 1866 | dbg_printf("load field ref offset %u type double\n", |
| 1867 | ref->offset); |
| 1868 | estack_push(stack, top, ax, bx, ax_t, bx_t); |
| 1869 | memcpy(&estack_ax(stack, top)->u.d, &filter_stack_data[ref->offset], |
| 1870 | sizeof(struct literal_double)); |
| 1871 | estack_ax_t = REG_DOUBLE; |
| 1872 | dbg_printf("ref load double %g\n", estack_ax(stack, top)->u.d); |
| 1873 | next_pc += sizeof(struct load_op) + sizeof(struct field_ref); |
| 1874 | PO; |
| 1875 | } |
| 1876 | |
| 1877 | /* load from immediate operand */ |
| 1878 | OP(FILTER_OP_LOAD_STRING): |
| 1879 | { |
| 1880 | struct load_op *insn = (struct load_op *) pc; |
| 1881 | |
| 1882 | dbg_printf("load string %s\n", insn->data); |
| 1883 | estack_push(stack, top, ax, bx, ax_t, bx_t); |
| 1884 | estack_ax(stack, top)->u.s.str = insn->data; |
| 1885 | estack_ax(stack, top)->u.s.seq_len = SIZE_MAX; |
| 1886 | estack_ax(stack, top)->u.s.literal_type = |
| 1887 | ESTACK_STRING_LITERAL_TYPE_PLAIN; |
| 1888 | estack_ax_t = REG_STRING; |
| 1889 | next_pc += sizeof(struct load_op) + strlen(insn->data) + 1; |
| 1890 | PO; |
| 1891 | } |
| 1892 | |
| 1893 | OP(FILTER_OP_LOAD_STAR_GLOB_STRING): |
| 1894 | { |
| 1895 | struct load_op *insn = (struct load_op *) pc; |
| 1896 | |
| 1897 | dbg_printf("load globbing pattern %s\n", insn->data); |
| 1898 | estack_push(stack, top, ax, bx, ax_t, bx_t); |
| 1899 | estack_ax(stack, top)->u.s.str = insn->data; |
| 1900 | estack_ax(stack, top)->u.s.seq_len = SIZE_MAX; |
| 1901 | estack_ax(stack, top)->u.s.literal_type = |
| 1902 | ESTACK_STRING_LITERAL_TYPE_STAR_GLOB; |
| 1903 | estack_ax_t = REG_STAR_GLOB_STRING; |
| 1904 | next_pc += sizeof(struct load_op) + strlen(insn->data) + 1; |
| 1905 | PO; |
| 1906 | } |
| 1907 | |
| 1908 | OP(FILTER_OP_LOAD_S64): |
| 1909 | { |
| 1910 | struct load_op *insn = (struct load_op *) pc; |
| 1911 | |
| 1912 | estack_push(stack, top, ax, bx, ax_t, bx_t); |
| 1913 | estack_ax_v = ((struct literal_numeric *) insn->data)->v; |
| 1914 | estack_ax_t = REG_S64; |
| 1915 | dbg_printf("load s64 %" PRIi64 "\n", estack_ax_v); |
| 1916 | next_pc += sizeof(struct load_op) |
| 1917 | + sizeof(struct literal_numeric); |
| 1918 | PO; |
| 1919 | } |
| 1920 | |
| 1921 | OP(FILTER_OP_LOAD_DOUBLE): |
| 1922 | { |
| 1923 | struct load_op *insn = (struct load_op *) pc; |
| 1924 | |
| 1925 | estack_push(stack, top, ax, bx, ax_t, bx_t); |
| 1926 | memcpy(&estack_ax(stack, top)->u.d, insn->data, |
| 1927 | sizeof(struct literal_double)); |
| 1928 | estack_ax_t = REG_DOUBLE; |
| 1929 | dbg_printf("load double %g\n", estack_ax(stack, top)->u.d); |
| 1930 | next_pc += sizeof(struct load_op) |
| 1931 | + sizeof(struct literal_double); |
| 1932 | PO; |
| 1933 | } |
| 1934 | |
| 1935 | /* cast */ |
| 1936 | OP(FILTER_OP_CAST_TO_S64): |
| 1937 | { |
| 1938 | /* Dynamic typing. */ |
| 1939 | switch (estack_ax_t) { |
| 1940 | case REG_S64: |
| 1941 | JUMP_TO(FILTER_OP_CAST_NOP); |
| 1942 | case REG_DOUBLE: |
| 1943 | JUMP_TO(FILTER_OP_CAST_DOUBLE_TO_S64); |
| 1944 | case REG_STRING: /* Fall-through */ |
| 1945 | case REG_STAR_GLOB_STRING: |
| 1946 | ret = -EINVAL; |
| 1947 | goto end; |
| 1948 | default: |
| 1949 | ERR("Unknown filter register type (%d)", |
| 1950 | (int) estack_ax_t); |
| 1951 | ret = -EINVAL; |
| 1952 | goto end; |
| 1953 | } |
| 1954 | } |
| 1955 | |
| 1956 | OP(FILTER_OP_CAST_DOUBLE_TO_S64): |
| 1957 | { |
| 1958 | estack_ax_v = (int64_t) estack_ax(stack, top)->u.d; |
| 1959 | estack_ax_t = REG_S64; |
| 1960 | next_pc += sizeof(struct cast_op); |
| 1961 | PO; |
| 1962 | } |
| 1963 | |
| 1964 | OP(FILTER_OP_CAST_NOP): |
| 1965 | { |
| 1966 | next_pc += sizeof(struct cast_op); |
| 1967 | PO; |
| 1968 | } |
| 1969 | |
| 1970 | /* get context ref */ |
| 1971 | OP(FILTER_OP_GET_CONTEXT_REF): |
| 1972 | { |
| 1973 | struct load_op *insn = (struct load_op *) pc; |
| 1974 | struct field_ref *ref = (struct field_ref *) insn->data; |
| 1975 | struct lttng_ctx *ctx; |
| 1976 | struct lttng_ctx_field *ctx_field; |
| 1977 | struct lttng_ctx_value v; |
| 1978 | |
| 1979 | dbg_printf("get context ref offset %u type dynamic\n", |
| 1980 | ref->offset); |
| 1981 | ctx = rcu_dereference(session->ctx); |
| 1982 | ctx_field = &ctx->fields[ref->offset]; |
| 1983 | ctx_field->get_value(ctx_field, &v); |
| 1984 | estack_push(stack, top, ax, bx, ax_t, bx_t); |
| 1985 | switch (v.sel) { |
| 1986 | case LTTNG_UST_DYNAMIC_TYPE_NONE: |
| 1987 | ret = -EINVAL; |
| 1988 | goto end; |
| 1989 | case LTTNG_UST_DYNAMIC_TYPE_S64: |
| 1990 | estack_ax_v = v.u.s64; |
| 1991 | estack_ax_t = REG_S64; |
| 1992 | dbg_printf("ref get context dynamic s64 %" PRIi64 "\n", estack_ax_v); |
| 1993 | break; |
| 1994 | case LTTNG_UST_DYNAMIC_TYPE_DOUBLE: |
| 1995 | estack_ax(stack, top)->u.d = v.u.d; |
| 1996 | estack_ax_t = REG_DOUBLE; |
| 1997 | dbg_printf("ref get context dynamic double %g\n", estack_ax(stack, top)->u.d); |
| 1998 | break; |
| 1999 | case LTTNG_UST_DYNAMIC_TYPE_STRING: |
| 2000 | estack_ax(stack, top)->u.s.str = v.u.str; |
| 2001 | if (unlikely(!estack_ax(stack, top)->u.s.str)) { |
| 2002 | dbg_printf("Filter warning: loading a NULL string.\n"); |
| 2003 | ret = -EINVAL; |
| 2004 | goto end; |
| 2005 | } |
| 2006 | estack_ax(stack, top)->u.s.seq_len = SIZE_MAX; |
| 2007 | estack_ax(stack, top)->u.s.literal_type = |
| 2008 | ESTACK_STRING_LITERAL_TYPE_NONE; |
| 2009 | dbg_printf("ref get context dynamic string %s\n", estack_ax(stack, top)->u.s.str); |
| 2010 | estack_ax_t = REG_STRING; |
| 2011 | break; |
| 2012 | default: |
| 2013 | dbg_printf("Filter warning: unknown dynamic type (%d).\n", (int) v.sel); |
| 2014 | ret = -EINVAL; |
| 2015 | goto end; |
| 2016 | } |
| 2017 | next_pc += sizeof(struct load_op) + sizeof(struct field_ref); |
| 2018 | PO; |
| 2019 | } |
| 2020 | |
| 2021 | OP(FILTER_OP_GET_CONTEXT_REF_STRING): |
| 2022 | { |
| 2023 | struct load_op *insn = (struct load_op *) pc; |
| 2024 | struct field_ref *ref = (struct field_ref *) insn->data; |
| 2025 | struct lttng_ctx *ctx; |
| 2026 | struct lttng_ctx_field *ctx_field; |
| 2027 | struct lttng_ctx_value v; |
| 2028 | |
| 2029 | dbg_printf("get context ref offset %u type string\n", |
| 2030 | ref->offset); |
| 2031 | ctx = rcu_dereference(session->ctx); |
| 2032 | ctx_field = &ctx->fields[ref->offset]; |
| 2033 | ctx_field->get_value(ctx_field, &v); |
| 2034 | estack_push(stack, top, ax, bx, ax_t, bx_t); |
| 2035 | estack_ax(stack, top)->u.s.str = v.u.str; |
| 2036 | if (unlikely(!estack_ax(stack, top)->u.s.str)) { |
| 2037 | dbg_printf("Filter warning: loading a NULL string.\n"); |
| 2038 | ret = -EINVAL; |
| 2039 | goto end; |
| 2040 | } |
| 2041 | estack_ax(stack, top)->u.s.seq_len = SIZE_MAX; |
| 2042 | estack_ax(stack, top)->u.s.literal_type = |
| 2043 | ESTACK_STRING_LITERAL_TYPE_NONE; |
| 2044 | estack_ax_t = REG_STRING; |
| 2045 | dbg_printf("ref get context string %s\n", estack_ax(stack, top)->u.s.str); |
| 2046 | next_pc += sizeof(struct load_op) + sizeof(struct field_ref); |
| 2047 | PO; |
| 2048 | } |
| 2049 | |
| 2050 | OP(FILTER_OP_GET_CONTEXT_REF_S64): |
| 2051 | { |
| 2052 | struct load_op *insn = (struct load_op *) pc; |
| 2053 | struct field_ref *ref = (struct field_ref *) insn->data; |
| 2054 | struct lttng_ctx *ctx; |
| 2055 | struct lttng_ctx_field *ctx_field; |
| 2056 | struct lttng_ctx_value v; |
| 2057 | |
| 2058 | dbg_printf("get context ref offset %u type s64\n", |
| 2059 | ref->offset); |
| 2060 | ctx = rcu_dereference(session->ctx); |
| 2061 | ctx_field = &ctx->fields[ref->offset]; |
| 2062 | ctx_field->get_value(ctx_field, &v); |
| 2063 | estack_push(stack, top, ax, bx, ax_t, bx_t); |
| 2064 | estack_ax_v = v.u.s64; |
| 2065 | estack_ax_t = REG_S64; |
| 2066 | dbg_printf("ref get context s64 %" PRIi64 "\n", estack_ax_v); |
| 2067 | next_pc += sizeof(struct load_op) + sizeof(struct field_ref); |
| 2068 | PO; |
| 2069 | } |
| 2070 | |
| 2071 | OP(FILTER_OP_GET_CONTEXT_REF_DOUBLE): |
| 2072 | { |
| 2073 | struct load_op *insn = (struct load_op *) pc; |
| 2074 | struct field_ref *ref = (struct field_ref *) insn->data; |
| 2075 | struct lttng_ctx *ctx; |
| 2076 | struct lttng_ctx_field *ctx_field; |
| 2077 | struct lttng_ctx_value v; |
| 2078 | |
| 2079 | dbg_printf("get context ref offset %u type double\n", |
| 2080 | ref->offset); |
| 2081 | ctx = rcu_dereference(session->ctx); |
| 2082 | ctx_field = &ctx->fields[ref->offset]; |
| 2083 | ctx_field->get_value(ctx_field, &v); |
| 2084 | estack_push(stack, top, ax, bx, ax_t, bx_t); |
| 2085 | memcpy(&estack_ax(stack, top)->u.d, &v.u.d, sizeof(struct literal_double)); |
| 2086 | estack_ax_t = REG_DOUBLE; |
| 2087 | dbg_printf("ref get context double %g\n", estack_ax(stack, top)->u.d); |
| 2088 | next_pc += sizeof(struct load_op) + sizeof(struct field_ref); |
| 2089 | PO; |
| 2090 | } |
| 2091 | |
| 2092 | OP(FILTER_OP_GET_CONTEXT_ROOT): |
| 2093 | { |
| 2094 | dbg_printf("op get context root\n"); |
| 2095 | estack_push(stack, top, ax, bx, ax_t, bx_t); |
| 2096 | estack_ax(stack, top)->u.ptr.type = LOAD_ROOT_CONTEXT; |
| 2097 | /* "field" only needed for variants. */ |
| 2098 | estack_ax(stack, top)->u.ptr.field = NULL; |
| 2099 | estack_ax_t = REG_PTR; |
| 2100 | next_pc += sizeof(struct load_op); |
| 2101 | PO; |
| 2102 | } |
| 2103 | |
| 2104 | OP(FILTER_OP_GET_APP_CONTEXT_ROOT): |
| 2105 | { |
| 2106 | dbg_printf("op get app context root\n"); |
| 2107 | estack_push(stack, top, ax, bx, ax_t, bx_t); |
| 2108 | estack_ax(stack, top)->u.ptr.type = LOAD_ROOT_APP_CONTEXT; |
| 2109 | /* "field" only needed for variants. */ |
| 2110 | estack_ax(stack, top)->u.ptr.field = NULL; |
| 2111 | estack_ax_t = REG_PTR; |
| 2112 | next_pc += sizeof(struct load_op); |
| 2113 | PO; |
| 2114 | } |
| 2115 | |
| 2116 | OP(FILTER_OP_GET_PAYLOAD_ROOT): |
| 2117 | { |
| 2118 | dbg_printf("op get app payload root\n"); |
| 2119 | estack_push(stack, top, ax, bx, ax_t, bx_t); |
| 2120 | estack_ax(stack, top)->u.ptr.type = LOAD_ROOT_PAYLOAD; |
| 2121 | estack_ax(stack, top)->u.ptr.ptr = filter_stack_data; |
| 2122 | /* "field" only needed for variants. */ |
| 2123 | estack_ax(stack, top)->u.ptr.field = NULL; |
| 2124 | estack_ax_t = REG_PTR; |
| 2125 | next_pc += sizeof(struct load_op); |
| 2126 | PO; |
| 2127 | } |
| 2128 | |
| 2129 | OP(FILTER_OP_GET_SYMBOL): |
| 2130 | { |
| 2131 | dbg_printf("op get symbol\n"); |
| 2132 | switch (estack_ax(stack, top)->u.ptr.type) { |
| 2133 | case LOAD_OBJECT: |
| 2134 | ERR("Nested fields not implemented yet."); |
| 2135 | ret = -EINVAL; |
| 2136 | goto end; |
| 2137 | case LOAD_ROOT_CONTEXT: |
| 2138 | case LOAD_ROOT_APP_CONTEXT: |
| 2139 | case LOAD_ROOT_PAYLOAD: |
| 2140 | /* |
| 2141 | * symbol lookup is performed by |
| 2142 | * specialization. |
| 2143 | */ |
| 2144 | ret = -EINVAL; |
| 2145 | goto end; |
| 2146 | } |
| 2147 | next_pc += sizeof(struct load_op) + sizeof(struct get_symbol); |
| 2148 | PO; |
| 2149 | } |
| 2150 | |
| 2151 | OP(FILTER_OP_GET_SYMBOL_FIELD): |
| 2152 | { |
| 2153 | /* |
| 2154 | * Used for first variant encountered in a |
| 2155 | * traversal. Variants are not implemented yet. |
| 2156 | */ |
| 2157 | ret = -EINVAL; |
| 2158 | goto end; |
| 2159 | } |
| 2160 | |
| 2161 | OP(FILTER_OP_GET_INDEX_U16): |
| 2162 | { |
| 2163 | struct load_op *insn = (struct load_op *) pc; |
| 2164 | struct get_index_u16 *index = (struct get_index_u16 *) insn->data; |
| 2165 | |
| 2166 | dbg_printf("op get index u16\n"); |
| 2167 | ret = dynamic_get_index(session, bytecode, index->index, estack_ax(stack, top)); |
| 2168 | if (ret) |
| 2169 | goto end; |
| 2170 | estack_ax_v = estack_ax(stack, top)->u.v; |
| 2171 | estack_ax_t = estack_ax(stack, top)->type; |
| 2172 | next_pc += sizeof(struct load_op) + sizeof(struct get_index_u16); |
| 2173 | PO; |
| 2174 | } |
| 2175 | |
| 2176 | OP(FILTER_OP_GET_INDEX_U64): |
| 2177 | { |
| 2178 | struct load_op *insn = (struct load_op *) pc; |
| 2179 | struct get_index_u64 *index = (struct get_index_u64 *) insn->data; |
| 2180 | |
| 2181 | dbg_printf("op get index u64\n"); |
| 2182 | ret = dynamic_get_index(session, bytecode, index->index, estack_ax(stack, top)); |
| 2183 | if (ret) |
| 2184 | goto end; |
| 2185 | estack_ax_v = estack_ax(stack, top)->u.v; |
| 2186 | estack_ax_t = estack_ax(stack, top)->type; |
| 2187 | next_pc += sizeof(struct load_op) + sizeof(struct get_index_u64); |
| 2188 | PO; |
| 2189 | } |
| 2190 | |
| 2191 | OP(FILTER_OP_LOAD_FIELD): |
| 2192 | { |
| 2193 | dbg_printf("op load field\n"); |
| 2194 | ret = dynamic_load_field(estack_ax(stack, top)); |
| 2195 | if (ret) |
| 2196 | goto end; |
| 2197 | estack_ax_v = estack_ax(stack, top)->u.v; |
| 2198 | estack_ax_t = estack_ax(stack, top)->type; |
| 2199 | next_pc += sizeof(struct load_op); |
| 2200 | PO; |
| 2201 | } |
| 2202 | |
| 2203 | OP(FILTER_OP_LOAD_FIELD_S8): |
| 2204 | { |
| 2205 | dbg_printf("op load field s8\n"); |
| 2206 | |
| 2207 | estack_ax_v = *(int8_t *) estack_ax(stack, top)->u.ptr.ptr; |
| 2208 | estack_ax_t = REG_S64; |
| 2209 | next_pc += sizeof(struct load_op); |
| 2210 | PO; |
| 2211 | } |
| 2212 | OP(FILTER_OP_LOAD_FIELD_S16): |
| 2213 | { |
| 2214 | dbg_printf("op load field s16\n"); |
| 2215 | |
| 2216 | estack_ax_v = *(int16_t *) estack_ax(stack, top)->u.ptr.ptr; |
| 2217 | estack_ax_t = REG_S64; |
| 2218 | next_pc += sizeof(struct load_op); |
| 2219 | PO; |
| 2220 | } |
| 2221 | OP(FILTER_OP_LOAD_FIELD_S32): |
| 2222 | { |
| 2223 | dbg_printf("op load field s32\n"); |
| 2224 | |
| 2225 | estack_ax_v = *(int32_t *) estack_ax(stack, top)->u.ptr.ptr; |
| 2226 | estack_ax_t = REG_S64; |
| 2227 | next_pc += sizeof(struct load_op); |
| 2228 | PO; |
| 2229 | } |
| 2230 | OP(FILTER_OP_LOAD_FIELD_S64): |
| 2231 | { |
| 2232 | dbg_printf("op load field s64\n"); |
| 2233 | |
| 2234 | estack_ax_v = *(int64_t *) estack_ax(stack, top)->u.ptr.ptr; |
| 2235 | estack_ax_t = REG_S64; |
| 2236 | next_pc += sizeof(struct load_op); |
| 2237 | PO; |
| 2238 | } |
| 2239 | OP(FILTER_OP_LOAD_FIELD_U8): |
| 2240 | { |
| 2241 | dbg_printf("op load field u8\n"); |
| 2242 | |
| 2243 | estack_ax_v = *(uint8_t *) estack_ax(stack, top)->u.ptr.ptr; |
| 2244 | estack_ax_t = REG_S64; |
| 2245 | next_pc += sizeof(struct load_op); |
| 2246 | PO; |
| 2247 | } |
| 2248 | OP(FILTER_OP_LOAD_FIELD_U16): |
| 2249 | { |
| 2250 | dbg_printf("op load field u16\n"); |
| 2251 | |
| 2252 | estack_ax_v = *(uint16_t *) estack_ax(stack, top)->u.ptr.ptr; |
| 2253 | estack_ax_t = REG_S64; |
| 2254 | next_pc += sizeof(struct load_op); |
| 2255 | PO; |
| 2256 | } |
| 2257 | OP(FILTER_OP_LOAD_FIELD_U32): |
| 2258 | { |
| 2259 | dbg_printf("op load field u32\n"); |
| 2260 | |
| 2261 | estack_ax_v = *(uint32_t *) estack_ax(stack, top)->u.ptr.ptr; |
| 2262 | estack_ax_t = REG_S64; |
| 2263 | next_pc += sizeof(struct load_op); |
| 2264 | PO; |
| 2265 | } |
| 2266 | OP(FILTER_OP_LOAD_FIELD_U64): |
| 2267 | { |
| 2268 | dbg_printf("op load field u64\n"); |
| 2269 | |
| 2270 | estack_ax_v = *(uint64_t *) estack_ax(stack, top)->u.ptr.ptr; |
| 2271 | estack_ax_t = REG_S64; |
| 2272 | next_pc += sizeof(struct load_op); |
| 2273 | PO; |
| 2274 | } |
| 2275 | OP(FILTER_OP_LOAD_FIELD_DOUBLE): |
| 2276 | { |
| 2277 | dbg_printf("op load field double\n"); |
| 2278 | |
| 2279 | memcpy(&estack_ax(stack, top)->u.d, |
| 2280 | estack_ax(stack, top)->u.ptr.ptr, |
| 2281 | sizeof(struct literal_double)); |
| 2282 | estack_ax(stack, top)->type = REG_DOUBLE; |
| 2283 | next_pc += sizeof(struct load_op); |
| 2284 | PO; |
| 2285 | } |
| 2286 | |
| 2287 | OP(FILTER_OP_LOAD_FIELD_STRING): |
| 2288 | { |
| 2289 | const char *str; |
| 2290 | |
| 2291 | dbg_printf("op load field string\n"); |
| 2292 | str = (const char *) estack_ax(stack, top)->u.ptr.ptr; |
| 2293 | estack_ax(stack, top)->u.s.str = str; |
| 2294 | if (unlikely(!estack_ax(stack, top)->u.s.str)) { |
| 2295 | dbg_printf("Filter warning: loading a NULL string.\n"); |
| 2296 | ret = -EINVAL; |
| 2297 | goto end; |
| 2298 | } |
| 2299 | estack_ax(stack, top)->u.s.seq_len = SIZE_MAX; |
| 2300 | estack_ax(stack, top)->u.s.literal_type = |
| 2301 | ESTACK_STRING_LITERAL_TYPE_NONE; |
| 2302 | estack_ax(stack, top)->type = REG_STRING; |
| 2303 | next_pc += sizeof(struct load_op); |
| 2304 | PO; |
| 2305 | } |
| 2306 | |
| 2307 | OP(FILTER_OP_LOAD_FIELD_SEQUENCE): |
| 2308 | { |
| 2309 | const char *ptr; |
| 2310 | |
| 2311 | dbg_printf("op load field string sequence\n"); |
| 2312 | ptr = estack_ax(stack, top)->u.ptr.ptr; |
| 2313 | estack_ax(stack, top)->u.s.seq_len = *(unsigned long *) ptr; |
| 2314 | estack_ax(stack, top)->u.s.str = *(const char **) (ptr + sizeof(unsigned long)); |
| 2315 | estack_ax(stack, top)->type = REG_STRING; |
| 2316 | if (unlikely(!estack_ax(stack, top)->u.s.str)) { |
| 2317 | dbg_printf("Filter warning: loading a NULL sequence.\n"); |
| 2318 | ret = -EINVAL; |
| 2319 | goto end; |
| 2320 | } |
| 2321 | estack_ax(stack, top)->u.s.literal_type = |
| 2322 | ESTACK_STRING_LITERAL_TYPE_NONE; |
| 2323 | next_pc += sizeof(struct load_op); |
| 2324 | PO; |
| 2325 | } |
| 2326 | |
| 2327 | END_OP |
| 2328 | end: |
| 2329 | /* return 0 (discard) on error */ |
| 2330 | if (ret) |
| 2331 | return 0; |
| 2332 | return retval; |
| 2333 | } |
| 2334 | |
| 2335 | #undef START_OP |
| 2336 | #undef OP |
| 2337 | #undef PO |
| 2338 | #undef END_OP |