| 1 | /* |
| 2 | * lttng-bytecode-interpreter.c |
| 3 | * |
| 4 | * LTTng UST bytecode 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 <stddef.h> |
| 29 | #include <stdint.h> |
| 30 | |
| 31 | #include <lttng/urcu/pointer.h> |
| 32 | #include <lttng/ust-endian.h> |
| 33 | #include <lttng/ust-events.h> |
| 34 | |
| 35 | #include "lttng-bytecode.h" |
| 36 | #include "string-utils.h" |
| 37 | |
| 38 | |
| 39 | /* |
| 40 | * -1: wildcard found. |
| 41 | * -2: unknown escape char. |
| 42 | * 0: normal char. |
| 43 | */ |
| 44 | |
| 45 | static |
| 46 | int parse_char(const char **p) |
| 47 | { |
| 48 | switch (**p) { |
| 49 | case '\\': |
| 50 | (*p)++; |
| 51 | switch (**p) { |
| 52 | case '\\': |
| 53 | case '*': |
| 54 | return 0; |
| 55 | default: |
| 56 | return -2; |
| 57 | } |
| 58 | case '*': |
| 59 | return -1; |
| 60 | default: |
| 61 | return 0; |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | /* |
| 66 | * Returns SIZE_MAX if the string is null-terminated, or the number of |
| 67 | * characters if not. |
| 68 | */ |
| 69 | static |
| 70 | size_t get_str_or_seq_len(const struct estack_entry *entry) |
| 71 | { |
| 72 | return entry->u.s.seq_len; |
| 73 | } |
| 74 | |
| 75 | static |
| 76 | int stack_star_glob_match(struct estack *stack, int top, const char *cmp_type) |
| 77 | { |
| 78 | const char *pattern; |
| 79 | const char *candidate; |
| 80 | size_t pattern_len; |
| 81 | size_t candidate_len; |
| 82 | |
| 83 | /* Find out which side is the pattern vs. the candidate. */ |
| 84 | if (estack_ax(stack, top)->u.s.literal_type == ESTACK_STRING_LITERAL_TYPE_STAR_GLOB) { |
| 85 | pattern = estack_ax(stack, top)->u.s.str; |
| 86 | pattern_len = get_str_or_seq_len(estack_ax(stack, top)); |
| 87 | candidate = estack_bx(stack, top)->u.s.str; |
| 88 | candidate_len = get_str_or_seq_len(estack_bx(stack, top)); |
| 89 | } else { |
| 90 | pattern = estack_bx(stack, top)->u.s.str; |
| 91 | pattern_len = get_str_or_seq_len(estack_bx(stack, top)); |
| 92 | candidate = estack_ax(stack, top)->u.s.str; |
| 93 | candidate_len = get_str_or_seq_len(estack_ax(stack, top)); |
| 94 | } |
| 95 | |
| 96 | /* Perform the match. Returns 0 when the result is true. */ |
| 97 | return !strutils_star_glob_match(pattern, pattern_len, candidate, |
| 98 | candidate_len); |
| 99 | } |
| 100 | |
| 101 | static |
| 102 | int stack_strcmp(struct estack *stack, int top, const char *cmp_type) |
| 103 | { |
| 104 | const char *p = estack_bx(stack, top)->u.s.str, *q = estack_ax(stack, top)->u.s.str; |
| 105 | int ret; |
| 106 | int diff; |
| 107 | |
| 108 | for (;;) { |
| 109 | int escaped_r0 = 0; |
| 110 | |
| 111 | if (unlikely(p - estack_bx(stack, top)->u.s.str >= estack_bx(stack, top)->u.s.seq_len || *p == '\0')) { |
| 112 | if (q - estack_ax(stack, top)->u.s.str >= estack_ax(stack, top)->u.s.seq_len || *q == '\0') { |
| 113 | return 0; |
| 114 | } else { |
| 115 | if (estack_ax(stack, top)->u.s.literal_type == |
| 116 | ESTACK_STRING_LITERAL_TYPE_PLAIN) { |
| 117 | ret = parse_char(&q); |
| 118 | if (ret == -1) |
| 119 | return 0; |
| 120 | } |
| 121 | return -1; |
| 122 | } |
| 123 | } |
| 124 | if (unlikely(q - estack_ax(stack, top)->u.s.str >= estack_ax(stack, top)->u.s.seq_len || *q == '\0')) { |
| 125 | if (estack_bx(stack, top)->u.s.literal_type == |
| 126 | ESTACK_STRING_LITERAL_TYPE_PLAIN) { |
| 127 | ret = parse_char(&p); |
| 128 | if (ret == -1) |
| 129 | return 0; |
| 130 | } |
| 131 | return 1; |
| 132 | } |
| 133 | if (estack_bx(stack, top)->u.s.literal_type == |
| 134 | ESTACK_STRING_LITERAL_TYPE_PLAIN) { |
| 135 | ret = parse_char(&p); |
| 136 | if (ret == -1) { |
| 137 | return 0; |
| 138 | } else if (ret == -2) { |
| 139 | escaped_r0 = 1; |
| 140 | } |
| 141 | /* else compare both char */ |
| 142 | } |
| 143 | if (estack_ax(stack, top)->u.s.literal_type == |
| 144 | ESTACK_STRING_LITERAL_TYPE_PLAIN) { |
| 145 | ret = parse_char(&q); |
| 146 | if (ret == -1) { |
| 147 | return 0; |
| 148 | } else if (ret == -2) { |
| 149 | if (!escaped_r0) |
| 150 | return -1; |
| 151 | } else { |
| 152 | if (escaped_r0) |
| 153 | return 1; |
| 154 | } |
| 155 | } else { |
| 156 | if (escaped_r0) |
| 157 | return 1; |
| 158 | } |
| 159 | diff = *p - *q; |
| 160 | if (diff != 0) |
| 161 | break; |
| 162 | p++; |
| 163 | q++; |
| 164 | } |
| 165 | return diff; |
| 166 | } |
| 167 | |
| 168 | uint64_t lttng_bytecode_filter_interpret_false(void *filter_data, |
| 169 | const char *filter_stack_data) |
| 170 | { |
| 171 | return LTTNG_INTERPRETER_DISCARD; |
| 172 | } |
| 173 | |
| 174 | uint64_t lttng_bytecode_capture_interpret_false(void *capture_data, |
| 175 | const char *capture_stack_data, |
| 176 | struct lttng_interpreter_output *output) |
| 177 | { |
| 178 | return LTTNG_INTERPRETER_DISCARD; |
| 179 | } |
| 180 | |
| 181 | #ifdef INTERPRETER_USE_SWITCH |
| 182 | |
| 183 | /* |
| 184 | * Fallback for compilers that do not support taking address of labels. |
| 185 | */ |
| 186 | |
| 187 | #define START_OP \ |
| 188 | start_pc = &bytecode->data[0]; \ |
| 189 | for (pc = next_pc = start_pc; pc - start_pc < bytecode->len; \ |
| 190 | pc = next_pc) { \ |
| 191 | dbg_printf("Executing op %s (%u)\n", \ |
| 192 | print_op((unsigned int) *(bytecode_opcode_t *) pc), \ |
| 193 | (unsigned int) *(bytecode_opcode_t *) pc); \ |
| 194 | switch (*(bytecode_opcode_t *) pc) { |
| 195 | |
| 196 | #define OP(name) jump_target_##name: __attribute__((unused)); \ |
| 197 | case name |
| 198 | |
| 199 | #define PO break |
| 200 | |
| 201 | #define END_OP } \ |
| 202 | } |
| 203 | |
| 204 | #define JUMP_TO(name) \ |
| 205 | goto jump_target_##name |
| 206 | |
| 207 | #else |
| 208 | |
| 209 | /* |
| 210 | * Dispatch-table based interpreter. |
| 211 | */ |
| 212 | |
| 213 | #define START_OP \ |
| 214 | start_pc = &bytecode->code[0]; \ |
| 215 | pc = next_pc = start_pc; \ |
| 216 | if (unlikely(pc - start_pc >= bytecode->len)) \ |
| 217 | goto end; \ |
| 218 | goto *dispatch[*(bytecode_opcode_t *) pc]; |
| 219 | |
| 220 | #define OP(name) \ |
| 221 | LABEL_##name |
| 222 | |
| 223 | #define PO \ |
| 224 | pc = next_pc; \ |
| 225 | goto *dispatch[*(bytecode_opcode_t *) pc]; |
| 226 | |
| 227 | #define END_OP |
| 228 | |
| 229 | #define JUMP_TO(name) \ |
| 230 | goto LABEL_##name |
| 231 | |
| 232 | #endif |
| 233 | |
| 234 | #define IS_INTEGER_REGISTER(reg_type) \ |
| 235 | (reg_type == REG_U64 || reg_type == REG_S64) |
| 236 | |
| 237 | static int context_get_index(struct lttng_ctx *ctx, |
| 238 | struct load_ptr *ptr, |
| 239 | uint32_t idx) |
| 240 | { |
| 241 | |
| 242 | struct lttng_ctx_field *ctx_field; |
| 243 | struct lttng_event_field *field; |
| 244 | struct lttng_ctx_value v; |
| 245 | |
| 246 | ctx_field = &ctx->fields[idx]; |
| 247 | field = &ctx_field->event_field; |
| 248 | ptr->type = LOAD_OBJECT; |
| 249 | ptr->field = field; |
| 250 | |
| 251 | switch (field->type.atype) { |
| 252 | case atype_integer: |
| 253 | ctx_field->get_value(ctx_field, &v); |
| 254 | if (field->type.u.integer.signedness) { |
| 255 | ptr->object_type = OBJECT_TYPE_S64; |
| 256 | ptr->u.s64 = v.u.s64; |
| 257 | ptr->ptr = &ptr->u.s64; |
| 258 | } else { |
| 259 | ptr->object_type = OBJECT_TYPE_U64; |
| 260 | ptr->u.u64 = v.u.s64; /* Cast. */ |
| 261 | ptr->ptr = &ptr->u.u64; |
| 262 | } |
| 263 | break; |
| 264 | case atype_enum: /* Fall-through */ |
| 265 | case atype_enum_nestable: |
| 266 | { |
| 267 | const struct lttng_integer_type *itype; |
| 268 | |
| 269 | if (field->type.atype == atype_enum) { |
| 270 | itype = &field->type.u.legacy.basic.enumeration.container_type; |
| 271 | } else { |
| 272 | itype = &field->type.u.enum_nestable.container_type->u.integer; |
| 273 | } |
| 274 | ctx_field->get_value(ctx_field, &v); |
| 275 | if (itype->signedness) { |
| 276 | ptr->object_type = OBJECT_TYPE_SIGNED_ENUM; |
| 277 | ptr->u.s64 = v.u.s64; |
| 278 | ptr->ptr = &ptr->u.s64; |
| 279 | } else { |
| 280 | ptr->object_type = OBJECT_TYPE_UNSIGNED_ENUM; |
| 281 | ptr->u.u64 = v.u.s64; /* Cast. */ |
| 282 | ptr->ptr = &ptr->u.u64; |
| 283 | } |
| 284 | break; |
| 285 | } |
| 286 | case atype_array: |
| 287 | if (field->type.u.legacy.array.elem_type.atype != atype_integer) { |
| 288 | ERR("Array nesting only supports integer types."); |
| 289 | return -EINVAL; |
| 290 | } |
| 291 | if (field->type.u.legacy.array.elem_type.u.basic.integer.encoding == lttng_encode_none) { |
| 292 | ERR("Only string arrays are supported for contexts."); |
| 293 | return -EINVAL; |
| 294 | } |
| 295 | ptr->object_type = OBJECT_TYPE_STRING; |
| 296 | ctx_field->get_value(ctx_field, &v); |
| 297 | ptr->ptr = v.u.str; |
| 298 | break; |
| 299 | case atype_array_nestable: |
| 300 | if (field->type.u.array_nestable.elem_type->atype != atype_integer) { |
| 301 | ERR("Array nesting only supports integer types."); |
| 302 | return -EINVAL; |
| 303 | } |
| 304 | if (field->type.u.array_nestable.elem_type->u.integer.encoding == lttng_encode_none) { |
| 305 | ERR("Only string arrays are supported for contexts."); |
| 306 | return -EINVAL; |
| 307 | } |
| 308 | ptr->object_type = OBJECT_TYPE_STRING; |
| 309 | ctx_field->get_value(ctx_field, &v); |
| 310 | ptr->ptr = v.u.str; |
| 311 | break; |
| 312 | case atype_sequence: |
| 313 | if (field->type.u.legacy.sequence.elem_type.atype != atype_integer) { |
| 314 | ERR("Sequence nesting only supports integer types."); |
| 315 | return -EINVAL; |
| 316 | } |
| 317 | if (field->type.u.legacy.sequence.elem_type.u.basic.integer.encoding == lttng_encode_none) { |
| 318 | ERR("Only string sequences are supported for contexts."); |
| 319 | return -EINVAL; |
| 320 | } |
| 321 | ptr->object_type = OBJECT_TYPE_STRING; |
| 322 | ctx_field->get_value(ctx_field, &v); |
| 323 | ptr->ptr = v.u.str; |
| 324 | break; |
| 325 | case atype_sequence_nestable: |
| 326 | if (field->type.u.sequence_nestable.elem_type->atype != atype_integer) { |
| 327 | ERR("Sequence nesting only supports integer types."); |
| 328 | return -EINVAL; |
| 329 | } |
| 330 | if (field->type.u.sequence_nestable.elem_type->u.integer.encoding == lttng_encode_none) { |
| 331 | ERR("Only string sequences are supported for contexts."); |
| 332 | return -EINVAL; |
| 333 | } |
| 334 | ptr->object_type = OBJECT_TYPE_STRING; |
| 335 | ctx_field->get_value(ctx_field, &v); |
| 336 | ptr->ptr = v.u.str; |
| 337 | break; |
| 338 | case atype_string: |
| 339 | ptr->object_type = OBJECT_TYPE_STRING; |
| 340 | ctx_field->get_value(ctx_field, &v); |
| 341 | ptr->ptr = v.u.str; |
| 342 | break; |
| 343 | case atype_float: |
| 344 | ptr->object_type = OBJECT_TYPE_DOUBLE; |
| 345 | ctx_field->get_value(ctx_field, &v); |
| 346 | ptr->u.d = v.u.d; |
| 347 | ptr->ptr = &ptr->u.d; |
| 348 | break; |
| 349 | case atype_dynamic: |
| 350 | ctx_field->get_value(ctx_field, &v); |
| 351 | switch (v.sel) { |
| 352 | case LTTNG_UST_DYNAMIC_TYPE_NONE: |
| 353 | return -EINVAL; |
| 354 | case LTTNG_UST_DYNAMIC_TYPE_U8: |
| 355 | case LTTNG_UST_DYNAMIC_TYPE_U16: |
| 356 | case LTTNG_UST_DYNAMIC_TYPE_U32: |
| 357 | case LTTNG_UST_DYNAMIC_TYPE_U64: |
| 358 | ptr->object_type = OBJECT_TYPE_U64; |
| 359 | ptr->u.u64 = v.u.u64; |
| 360 | ptr->ptr = &ptr->u.u64; |
| 361 | dbg_printf("context get index dynamic u64 %" PRIi64 "\n", ptr->u.u64); |
| 362 | break; |
| 363 | case LTTNG_UST_DYNAMIC_TYPE_S8: |
| 364 | case LTTNG_UST_DYNAMIC_TYPE_S16: |
| 365 | case LTTNG_UST_DYNAMIC_TYPE_S32: |
| 366 | case LTTNG_UST_DYNAMIC_TYPE_S64: |
| 367 | ptr->object_type = OBJECT_TYPE_S64; |
| 368 | ptr->u.s64 = v.u.s64; |
| 369 | ptr->ptr = &ptr->u.s64; |
| 370 | dbg_printf("context get index dynamic s64 %" PRIi64 "\n", ptr->u.s64); |
| 371 | break; |
| 372 | case LTTNG_UST_DYNAMIC_TYPE_FLOAT: |
| 373 | case LTTNG_UST_DYNAMIC_TYPE_DOUBLE: |
| 374 | ptr->object_type = OBJECT_TYPE_DOUBLE; |
| 375 | ptr->u.d = v.u.d; |
| 376 | ptr->ptr = &ptr->u.d; |
| 377 | dbg_printf("context get index dynamic double %g\n", ptr->u.d); |
| 378 | break; |
| 379 | case LTTNG_UST_DYNAMIC_TYPE_STRING: |
| 380 | ptr->object_type = OBJECT_TYPE_STRING; |
| 381 | ptr->ptr = v.u.str; |
| 382 | dbg_printf("context get index dynamic string %s\n", (const char *) ptr->ptr); |
| 383 | break; |
| 384 | default: |
| 385 | dbg_printf("Interpreter warning: unknown dynamic type (%d).\n", (int) v.sel); |
| 386 | return -EINVAL; |
| 387 | } |
| 388 | break; |
| 389 | case atype_struct: |
| 390 | ERR("Structure type cannot be loaded."); |
| 391 | return -EINVAL; |
| 392 | default: |
| 393 | ERR("Unknown type: %d", (int) field->type.atype); |
| 394 | return -EINVAL; |
| 395 | } |
| 396 | return 0; |
| 397 | } |
| 398 | |
| 399 | static int dynamic_get_index(struct lttng_ctx *ctx, |
| 400 | struct bytecode_runtime *runtime, |
| 401 | uint64_t index, struct estack_entry *stack_top) |
| 402 | { |
| 403 | int ret; |
| 404 | const struct bytecode_get_index_data *gid; |
| 405 | |
| 406 | gid = (const struct bytecode_get_index_data *) &runtime->data[index]; |
| 407 | switch (stack_top->u.ptr.type) { |
| 408 | case LOAD_OBJECT: |
| 409 | switch (stack_top->u.ptr.object_type) { |
| 410 | case OBJECT_TYPE_ARRAY: |
| 411 | { |
| 412 | const char *ptr; |
| 413 | |
| 414 | assert(gid->offset < gid->array_len); |
| 415 | /* Skip count (unsigned long) */ |
| 416 | ptr = *(const char **) (stack_top->u.ptr.ptr + sizeof(unsigned long)); |
| 417 | ptr = ptr + gid->offset; |
| 418 | stack_top->u.ptr.ptr = ptr; |
| 419 | stack_top->u.ptr.object_type = gid->elem.type; |
| 420 | stack_top->u.ptr.rev_bo = gid->elem.rev_bo; |
| 421 | assert(stack_top->u.ptr.field->type.atype == atype_array || |
| 422 | stack_top->u.ptr.field->type.atype == atype_array_nestable); |
| 423 | stack_top->u.ptr.field = NULL; |
| 424 | break; |
| 425 | } |
| 426 | case OBJECT_TYPE_SEQUENCE: |
| 427 | { |
| 428 | const char *ptr; |
| 429 | size_t ptr_seq_len; |
| 430 | |
| 431 | ptr = *(const char **) (stack_top->u.ptr.ptr + sizeof(unsigned long)); |
| 432 | ptr_seq_len = *(unsigned long *) stack_top->u.ptr.ptr; |
| 433 | if (gid->offset >= gid->elem.len * ptr_seq_len) { |
| 434 | ret = -EINVAL; |
| 435 | goto end; |
| 436 | } |
| 437 | ptr = ptr + gid->offset; |
| 438 | stack_top->u.ptr.ptr = ptr; |
| 439 | stack_top->u.ptr.object_type = gid->elem.type; |
| 440 | stack_top->u.ptr.rev_bo = gid->elem.rev_bo; |
| 441 | assert(stack_top->u.ptr.field->type.atype == atype_sequence || |
| 442 | stack_top->u.ptr.field->type.atype == atype_sequence_nestable); |
| 443 | stack_top->u.ptr.field = NULL; |
| 444 | break; |
| 445 | } |
| 446 | case OBJECT_TYPE_STRUCT: |
| 447 | ERR("Nested structures are not supported yet."); |
| 448 | ret = -EINVAL; |
| 449 | goto end; |
| 450 | case OBJECT_TYPE_VARIANT: |
| 451 | default: |
| 452 | ERR("Unexpected get index type %d", |
| 453 | (int) stack_top->u.ptr.object_type); |
| 454 | ret = -EINVAL; |
| 455 | goto end; |
| 456 | } |
| 457 | break; |
| 458 | case LOAD_ROOT_CONTEXT: |
| 459 | case LOAD_ROOT_APP_CONTEXT: /* Fall-through */ |
| 460 | { |
| 461 | ret = context_get_index(ctx, |
| 462 | &stack_top->u.ptr, |
| 463 | gid->ctx_index); |
| 464 | if (ret) { |
| 465 | goto end; |
| 466 | } |
| 467 | break; |
| 468 | } |
| 469 | case LOAD_ROOT_PAYLOAD: |
| 470 | stack_top->u.ptr.ptr += gid->offset; |
| 471 | if (gid->elem.type == OBJECT_TYPE_STRING) |
| 472 | stack_top->u.ptr.ptr = *(const char * const *) stack_top->u.ptr.ptr; |
| 473 | stack_top->u.ptr.object_type = gid->elem.type; |
| 474 | stack_top->u.ptr.type = LOAD_OBJECT; |
| 475 | stack_top->u.ptr.field = gid->field; |
| 476 | stack_top->u.ptr.rev_bo = gid->elem.rev_bo; |
| 477 | break; |
| 478 | } |
| 479 | |
| 480 | stack_top->type = REG_PTR; |
| 481 | |
| 482 | return 0; |
| 483 | |
| 484 | end: |
| 485 | return ret; |
| 486 | } |
| 487 | |
| 488 | static int dynamic_load_field(struct estack_entry *stack_top) |
| 489 | { |
| 490 | int ret; |
| 491 | |
| 492 | switch (stack_top->u.ptr.type) { |
| 493 | case LOAD_OBJECT: |
| 494 | break; |
| 495 | case LOAD_ROOT_CONTEXT: |
| 496 | case LOAD_ROOT_APP_CONTEXT: |
| 497 | case LOAD_ROOT_PAYLOAD: |
| 498 | default: |
| 499 | dbg_printf("Interpreter warning: cannot load root, missing field name.\n"); |
| 500 | ret = -EINVAL; |
| 501 | goto end; |
| 502 | } |
| 503 | switch (stack_top->u.ptr.object_type) { |
| 504 | case OBJECT_TYPE_S8: |
| 505 | dbg_printf("op load field s8\n"); |
| 506 | stack_top->u.v = *(int8_t *) stack_top->u.ptr.ptr; |
| 507 | stack_top->type = REG_S64; |
| 508 | break; |
| 509 | case OBJECT_TYPE_S16: |
| 510 | { |
| 511 | int16_t tmp; |
| 512 | |
| 513 | dbg_printf("op load field s16\n"); |
| 514 | tmp = *(int16_t *) stack_top->u.ptr.ptr; |
| 515 | if (stack_top->u.ptr.rev_bo) |
| 516 | tmp = bswap_16(tmp); |
| 517 | stack_top->u.v = tmp; |
| 518 | stack_top->type = REG_S64; |
| 519 | break; |
| 520 | } |
| 521 | case OBJECT_TYPE_S32: |
| 522 | { |
| 523 | int32_t tmp; |
| 524 | |
| 525 | dbg_printf("op load field s32\n"); |
| 526 | tmp = *(int32_t *) stack_top->u.ptr.ptr; |
| 527 | if (stack_top->u.ptr.rev_bo) |
| 528 | tmp = bswap_32(tmp); |
| 529 | stack_top->u.v = tmp; |
| 530 | stack_top->type = REG_S64; |
| 531 | break; |
| 532 | } |
| 533 | case OBJECT_TYPE_S64: |
| 534 | { |
| 535 | int64_t tmp; |
| 536 | |
| 537 | dbg_printf("op load field s64\n"); |
| 538 | tmp = *(int64_t *) stack_top->u.ptr.ptr; |
| 539 | if (stack_top->u.ptr.rev_bo) |
| 540 | tmp = bswap_64(tmp); |
| 541 | stack_top->u.v = tmp; |
| 542 | stack_top->type = REG_S64; |
| 543 | break; |
| 544 | } |
| 545 | case OBJECT_TYPE_SIGNED_ENUM: |
| 546 | { |
| 547 | int64_t tmp; |
| 548 | |
| 549 | dbg_printf("op load field signed enumeration\n"); |
| 550 | tmp = *(int64_t *) stack_top->u.ptr.ptr; |
| 551 | if (stack_top->u.ptr.rev_bo) |
| 552 | tmp = bswap_64(tmp); |
| 553 | stack_top->u.v = tmp; |
| 554 | stack_top->type = REG_S64; |
| 555 | break; |
| 556 | } |
| 557 | case OBJECT_TYPE_U8: |
| 558 | dbg_printf("op load field u8\n"); |
| 559 | stack_top->u.v = *(uint8_t *) stack_top->u.ptr.ptr; |
| 560 | stack_top->type = REG_U64; |
| 561 | break; |
| 562 | case OBJECT_TYPE_U16: |
| 563 | { |
| 564 | uint16_t tmp; |
| 565 | |
| 566 | dbg_printf("op load field u16\n"); |
| 567 | tmp = *(uint16_t *) stack_top->u.ptr.ptr; |
| 568 | if (stack_top->u.ptr.rev_bo) |
| 569 | tmp = bswap_16(tmp); |
| 570 | stack_top->u.v = tmp; |
| 571 | stack_top->type = REG_U64; |
| 572 | break; |
| 573 | } |
| 574 | case OBJECT_TYPE_U32: |
| 575 | { |
| 576 | uint32_t tmp; |
| 577 | |
| 578 | dbg_printf("op load field u32\n"); |
| 579 | tmp = *(uint32_t *) stack_top->u.ptr.ptr; |
| 580 | if (stack_top->u.ptr.rev_bo) |
| 581 | tmp = bswap_32(tmp); |
| 582 | stack_top->u.v = tmp; |
| 583 | stack_top->type = REG_U64; |
| 584 | break; |
| 585 | } |
| 586 | case OBJECT_TYPE_U64: |
| 587 | { |
| 588 | uint64_t tmp; |
| 589 | |
| 590 | dbg_printf("op load field u64\n"); |
| 591 | tmp = *(uint64_t *) stack_top->u.ptr.ptr; |
| 592 | if (stack_top->u.ptr.rev_bo) |
| 593 | tmp = bswap_64(tmp); |
| 594 | stack_top->u.v = tmp; |
| 595 | stack_top->type = REG_U64; |
| 596 | break; |
| 597 | } |
| 598 | case OBJECT_TYPE_UNSIGNED_ENUM: |
| 599 | { |
| 600 | uint64_t tmp; |
| 601 | |
| 602 | dbg_printf("op load field unsigned enumeration\n"); |
| 603 | tmp = *(uint64_t *) stack_top->u.ptr.ptr; |
| 604 | if (stack_top->u.ptr.rev_bo) |
| 605 | tmp = bswap_64(tmp); |
| 606 | stack_top->u.v = tmp; |
| 607 | stack_top->type = REG_U64; |
| 608 | break; |
| 609 | } |
| 610 | case OBJECT_TYPE_DOUBLE: |
| 611 | memcpy(&stack_top->u.d, |
| 612 | stack_top->u.ptr.ptr, |
| 613 | sizeof(struct literal_double)); |
| 614 | stack_top->type = REG_DOUBLE; |
| 615 | break; |
| 616 | case OBJECT_TYPE_STRING: |
| 617 | { |
| 618 | const char *str; |
| 619 | |
| 620 | dbg_printf("op load field string\n"); |
| 621 | str = (const char *) stack_top->u.ptr.ptr; |
| 622 | stack_top->u.s.str = str; |
| 623 | if (unlikely(!stack_top->u.s.str)) { |
| 624 | dbg_printf("Interpreter warning: loading a NULL string.\n"); |
| 625 | ret = -EINVAL; |
| 626 | goto end; |
| 627 | } |
| 628 | stack_top->u.s.seq_len = SIZE_MAX; |
| 629 | stack_top->u.s.literal_type = |
| 630 | ESTACK_STRING_LITERAL_TYPE_NONE; |
| 631 | stack_top->type = REG_STRING; |
| 632 | break; |
| 633 | } |
| 634 | case OBJECT_TYPE_STRING_SEQUENCE: |
| 635 | { |
| 636 | const char *ptr; |
| 637 | |
| 638 | dbg_printf("op load field string sequence\n"); |
| 639 | ptr = stack_top->u.ptr.ptr; |
| 640 | stack_top->u.s.seq_len = *(unsigned long *) ptr; |
| 641 | stack_top->u.s.str = *(const char **) (ptr + sizeof(unsigned long)); |
| 642 | stack_top->type = REG_STRING; |
| 643 | if (unlikely(!stack_top->u.s.str)) { |
| 644 | dbg_printf("Interpreter warning: loading a NULL sequence.\n"); |
| 645 | ret = -EINVAL; |
| 646 | goto end; |
| 647 | } |
| 648 | stack_top->u.s.literal_type = |
| 649 | ESTACK_STRING_LITERAL_TYPE_NONE; |
| 650 | break; |
| 651 | } |
| 652 | case OBJECT_TYPE_DYNAMIC: |
| 653 | /* |
| 654 | * Dynamic types in context are looked up |
| 655 | * by context get index. |
| 656 | */ |
| 657 | ret = -EINVAL; |
| 658 | goto end; |
| 659 | case OBJECT_TYPE_SEQUENCE: |
| 660 | case OBJECT_TYPE_ARRAY: |
| 661 | case OBJECT_TYPE_STRUCT: |
| 662 | case OBJECT_TYPE_VARIANT: |
| 663 | ERR("Sequences, arrays, struct and variant cannot be loaded (nested types)."); |
| 664 | ret = -EINVAL; |
| 665 | goto end; |
| 666 | } |
| 667 | return 0; |
| 668 | |
| 669 | end: |
| 670 | return ret; |
| 671 | } |
| 672 | |
| 673 | static |
| 674 | int lttng_bytecode_interpret_format_output(struct estack_entry *ax, |
| 675 | struct lttng_interpreter_output *output) |
| 676 | { |
| 677 | int ret; |
| 678 | |
| 679 | again: |
| 680 | switch (ax->type) { |
| 681 | case REG_S64: |
| 682 | output->type = LTTNG_INTERPRETER_TYPE_S64; |
| 683 | output->u.s = ax->u.v; |
| 684 | break; |
| 685 | case REG_U64: |
| 686 | output->type = LTTNG_INTERPRETER_TYPE_U64; |
| 687 | output->u.u = (uint64_t) ax->u.v; |
| 688 | break; |
| 689 | case REG_DOUBLE: |
| 690 | output->type = LTTNG_INTERPRETER_TYPE_DOUBLE; |
| 691 | output->u.d = ax->u.d; |
| 692 | break; |
| 693 | case REG_STRING: |
| 694 | output->type = LTTNG_INTERPRETER_TYPE_STRING; |
| 695 | output->u.str.str = ax->u.s.str; |
| 696 | output->u.str.len = ax->u.s.seq_len; |
| 697 | break; |
| 698 | case REG_PTR: |
| 699 | switch (ax->u.ptr.object_type) { |
| 700 | case OBJECT_TYPE_S8: |
| 701 | case OBJECT_TYPE_S16: |
| 702 | case OBJECT_TYPE_S32: |
| 703 | case OBJECT_TYPE_S64: |
| 704 | case OBJECT_TYPE_U8: |
| 705 | case OBJECT_TYPE_U16: |
| 706 | case OBJECT_TYPE_U32: |
| 707 | case OBJECT_TYPE_U64: |
| 708 | case OBJECT_TYPE_DOUBLE: |
| 709 | case OBJECT_TYPE_STRING: |
| 710 | case OBJECT_TYPE_STRING_SEQUENCE: |
| 711 | ret = dynamic_load_field(ax); |
| 712 | if (ret) |
| 713 | return ret; |
| 714 | /* Retry after loading ptr into stack top. */ |
| 715 | goto again; |
| 716 | case OBJECT_TYPE_SEQUENCE: |
| 717 | output->type = LTTNG_INTERPRETER_TYPE_SEQUENCE; |
| 718 | output->u.sequence.ptr = *(const char **) (ax->u.ptr.ptr + sizeof(unsigned long)); |
| 719 | output->u.sequence.nr_elem = *(unsigned long *) ax->u.ptr.ptr; |
| 720 | output->u.sequence.nested_type = ax->u.ptr.field->type.u.sequence_nestable.elem_type; |
| 721 | break; |
| 722 | case OBJECT_TYPE_ARRAY: |
| 723 | /* Skip count (unsigned long) */ |
| 724 | output->type = LTTNG_INTERPRETER_TYPE_SEQUENCE; |
| 725 | output->u.sequence.ptr = *(const char **) (ax->u.ptr.ptr + sizeof(unsigned long)); |
| 726 | output->u.sequence.nr_elem = ax->u.ptr.field->type.u.array_nestable.length; |
| 727 | output->u.sequence.nested_type = ax->u.ptr.field->type.u.array_nestable.elem_type; |
| 728 | break; |
| 729 | case OBJECT_TYPE_SIGNED_ENUM: |
| 730 | ret = dynamic_load_field(ax); |
| 731 | if (ret) |
| 732 | return ret; |
| 733 | output->type = LTTNG_INTERPRETER_TYPE_SIGNED_ENUM; |
| 734 | output->u.s = ax->u.v; |
| 735 | break; |
| 736 | case OBJECT_TYPE_UNSIGNED_ENUM: |
| 737 | ret = dynamic_load_field(ax); |
| 738 | if (ret) |
| 739 | return ret; |
| 740 | output->type = LTTNG_INTERPRETER_TYPE_UNSIGNED_ENUM; |
| 741 | output->u.u = ax->u.v; |
| 742 | break; |
| 743 | case OBJECT_TYPE_STRUCT: |
| 744 | case OBJECT_TYPE_VARIANT: |
| 745 | default: |
| 746 | return -EINVAL; |
| 747 | } |
| 748 | |
| 749 | break; |
| 750 | case REG_STAR_GLOB_STRING: |
| 751 | case REG_UNKNOWN: |
| 752 | default: |
| 753 | return -EINVAL; |
| 754 | } |
| 755 | |
| 756 | return LTTNG_INTERPRETER_RECORD_FLAG; |
| 757 | } |
| 758 | |
| 759 | /* |
| 760 | * For `output` equal to NULL: |
| 761 | * Return 0 (discard), or raise the 0x1 flag (log event). |
| 762 | * Currently, other flags are kept for future extensions and have no |
| 763 | * effect. |
| 764 | * For `output` not equal to NULL: |
| 765 | * Return 0 on success, negative error value on error. |
| 766 | */ |
| 767 | static |
| 768 | uint64_t bytecode_interpret(void *interpreter_data, |
| 769 | const char *interpreter_stack_data, |
| 770 | struct lttng_interpreter_output *output) |
| 771 | { |
| 772 | struct bytecode_runtime *bytecode = interpreter_data; |
| 773 | struct lttng_ctx *ctx = lttng_ust_rcu_dereference(*bytecode->p.pctx); |
| 774 | void *pc, *next_pc, *start_pc; |
| 775 | int ret = -EINVAL; |
| 776 | uint64_t retval = 0; |
| 777 | struct estack _stack; |
| 778 | struct estack *stack = &_stack; |
| 779 | register int64_t ax = 0, bx = 0; |
| 780 | register enum entry_type ax_t = REG_UNKNOWN, bx_t = REG_UNKNOWN; |
| 781 | register int top = INTERPRETER_STACK_EMPTY; |
| 782 | #ifndef INTERPRETER_USE_SWITCH |
| 783 | static void *dispatch[NR_BYTECODE_OPS] = { |
| 784 | [ BYTECODE_OP_UNKNOWN ] = &&LABEL_BYTECODE_OP_UNKNOWN, |
| 785 | |
| 786 | [ BYTECODE_OP_RETURN ] = &&LABEL_BYTECODE_OP_RETURN, |
| 787 | |
| 788 | /* binary */ |
| 789 | [ BYTECODE_OP_MUL ] = &&LABEL_BYTECODE_OP_MUL, |
| 790 | [ BYTECODE_OP_DIV ] = &&LABEL_BYTECODE_OP_DIV, |
| 791 | [ BYTECODE_OP_MOD ] = &&LABEL_BYTECODE_OP_MOD, |
| 792 | [ BYTECODE_OP_PLUS ] = &&LABEL_BYTECODE_OP_PLUS, |
| 793 | [ BYTECODE_OP_MINUS ] = &&LABEL_BYTECODE_OP_MINUS, |
| 794 | [ BYTECODE_OP_BIT_RSHIFT ] = &&LABEL_BYTECODE_OP_BIT_RSHIFT, |
| 795 | [ BYTECODE_OP_BIT_LSHIFT ] = &&LABEL_BYTECODE_OP_BIT_LSHIFT, |
| 796 | [ BYTECODE_OP_BIT_AND ] = &&LABEL_BYTECODE_OP_BIT_AND, |
| 797 | [ BYTECODE_OP_BIT_OR ] = &&LABEL_BYTECODE_OP_BIT_OR, |
| 798 | [ BYTECODE_OP_BIT_XOR ] = &&LABEL_BYTECODE_OP_BIT_XOR, |
| 799 | |
| 800 | /* binary comparators */ |
| 801 | [ BYTECODE_OP_EQ ] = &&LABEL_BYTECODE_OP_EQ, |
| 802 | [ BYTECODE_OP_NE ] = &&LABEL_BYTECODE_OP_NE, |
| 803 | [ BYTECODE_OP_GT ] = &&LABEL_BYTECODE_OP_GT, |
| 804 | [ BYTECODE_OP_LT ] = &&LABEL_BYTECODE_OP_LT, |
| 805 | [ BYTECODE_OP_GE ] = &&LABEL_BYTECODE_OP_GE, |
| 806 | [ BYTECODE_OP_LE ] = &&LABEL_BYTECODE_OP_LE, |
| 807 | |
| 808 | /* string binary comparator */ |
| 809 | [ BYTECODE_OP_EQ_STRING ] = &&LABEL_BYTECODE_OP_EQ_STRING, |
| 810 | [ BYTECODE_OP_NE_STRING ] = &&LABEL_BYTECODE_OP_NE_STRING, |
| 811 | [ BYTECODE_OP_GT_STRING ] = &&LABEL_BYTECODE_OP_GT_STRING, |
| 812 | [ BYTECODE_OP_LT_STRING ] = &&LABEL_BYTECODE_OP_LT_STRING, |
| 813 | [ BYTECODE_OP_GE_STRING ] = &&LABEL_BYTECODE_OP_GE_STRING, |
| 814 | [ BYTECODE_OP_LE_STRING ] = &&LABEL_BYTECODE_OP_LE_STRING, |
| 815 | |
| 816 | /* globbing pattern binary comparator */ |
| 817 | [ BYTECODE_OP_EQ_STAR_GLOB_STRING ] = &&LABEL_BYTECODE_OP_EQ_STAR_GLOB_STRING, |
| 818 | [ BYTECODE_OP_NE_STAR_GLOB_STRING ] = &&LABEL_BYTECODE_OP_NE_STAR_GLOB_STRING, |
| 819 | |
| 820 | /* s64 binary comparator */ |
| 821 | [ BYTECODE_OP_EQ_S64 ] = &&LABEL_BYTECODE_OP_EQ_S64, |
| 822 | [ BYTECODE_OP_NE_S64 ] = &&LABEL_BYTECODE_OP_NE_S64, |
| 823 | [ BYTECODE_OP_GT_S64 ] = &&LABEL_BYTECODE_OP_GT_S64, |
| 824 | [ BYTECODE_OP_LT_S64 ] = &&LABEL_BYTECODE_OP_LT_S64, |
| 825 | [ BYTECODE_OP_GE_S64 ] = &&LABEL_BYTECODE_OP_GE_S64, |
| 826 | [ BYTECODE_OP_LE_S64 ] = &&LABEL_BYTECODE_OP_LE_S64, |
| 827 | |
| 828 | /* double binary comparator */ |
| 829 | [ BYTECODE_OP_EQ_DOUBLE ] = &&LABEL_BYTECODE_OP_EQ_DOUBLE, |
| 830 | [ BYTECODE_OP_NE_DOUBLE ] = &&LABEL_BYTECODE_OP_NE_DOUBLE, |
| 831 | [ BYTECODE_OP_GT_DOUBLE ] = &&LABEL_BYTECODE_OP_GT_DOUBLE, |
| 832 | [ BYTECODE_OP_LT_DOUBLE ] = &&LABEL_BYTECODE_OP_LT_DOUBLE, |
| 833 | [ BYTECODE_OP_GE_DOUBLE ] = &&LABEL_BYTECODE_OP_GE_DOUBLE, |
| 834 | [ BYTECODE_OP_LE_DOUBLE ] = &&LABEL_BYTECODE_OP_LE_DOUBLE, |
| 835 | |
| 836 | /* Mixed S64-double binary comparators */ |
| 837 | [ BYTECODE_OP_EQ_DOUBLE_S64 ] = &&LABEL_BYTECODE_OP_EQ_DOUBLE_S64, |
| 838 | [ BYTECODE_OP_NE_DOUBLE_S64 ] = &&LABEL_BYTECODE_OP_NE_DOUBLE_S64, |
| 839 | [ BYTECODE_OP_GT_DOUBLE_S64 ] = &&LABEL_BYTECODE_OP_GT_DOUBLE_S64, |
| 840 | [ BYTECODE_OP_LT_DOUBLE_S64 ] = &&LABEL_BYTECODE_OP_LT_DOUBLE_S64, |
| 841 | [ BYTECODE_OP_GE_DOUBLE_S64 ] = &&LABEL_BYTECODE_OP_GE_DOUBLE_S64, |
| 842 | [ BYTECODE_OP_LE_DOUBLE_S64 ] = &&LABEL_BYTECODE_OP_LE_DOUBLE_S64, |
| 843 | |
| 844 | [ BYTECODE_OP_EQ_S64_DOUBLE ] = &&LABEL_BYTECODE_OP_EQ_S64_DOUBLE, |
| 845 | [ BYTECODE_OP_NE_S64_DOUBLE ] = &&LABEL_BYTECODE_OP_NE_S64_DOUBLE, |
| 846 | [ BYTECODE_OP_GT_S64_DOUBLE ] = &&LABEL_BYTECODE_OP_GT_S64_DOUBLE, |
| 847 | [ BYTECODE_OP_LT_S64_DOUBLE ] = &&LABEL_BYTECODE_OP_LT_S64_DOUBLE, |
| 848 | [ BYTECODE_OP_GE_S64_DOUBLE ] = &&LABEL_BYTECODE_OP_GE_S64_DOUBLE, |
| 849 | [ BYTECODE_OP_LE_S64_DOUBLE ] = &&LABEL_BYTECODE_OP_LE_S64_DOUBLE, |
| 850 | |
| 851 | /* unary */ |
| 852 | [ BYTECODE_OP_UNARY_PLUS ] = &&LABEL_BYTECODE_OP_UNARY_PLUS, |
| 853 | [ BYTECODE_OP_UNARY_MINUS ] = &&LABEL_BYTECODE_OP_UNARY_MINUS, |
| 854 | [ BYTECODE_OP_UNARY_NOT ] = &&LABEL_BYTECODE_OP_UNARY_NOT, |
| 855 | [ BYTECODE_OP_UNARY_PLUS_S64 ] = &&LABEL_BYTECODE_OP_UNARY_PLUS_S64, |
| 856 | [ BYTECODE_OP_UNARY_MINUS_S64 ] = &&LABEL_BYTECODE_OP_UNARY_MINUS_S64, |
| 857 | [ BYTECODE_OP_UNARY_NOT_S64 ] = &&LABEL_BYTECODE_OP_UNARY_NOT_S64, |
| 858 | [ BYTECODE_OP_UNARY_PLUS_DOUBLE ] = &&LABEL_BYTECODE_OP_UNARY_PLUS_DOUBLE, |
| 859 | [ BYTECODE_OP_UNARY_MINUS_DOUBLE ] = &&LABEL_BYTECODE_OP_UNARY_MINUS_DOUBLE, |
| 860 | [ BYTECODE_OP_UNARY_NOT_DOUBLE ] = &&LABEL_BYTECODE_OP_UNARY_NOT_DOUBLE, |
| 861 | |
| 862 | /* logical */ |
| 863 | [ BYTECODE_OP_AND ] = &&LABEL_BYTECODE_OP_AND, |
| 864 | [ BYTECODE_OP_OR ] = &&LABEL_BYTECODE_OP_OR, |
| 865 | |
| 866 | /* load field ref */ |
| 867 | [ BYTECODE_OP_LOAD_FIELD_REF ] = &&LABEL_BYTECODE_OP_LOAD_FIELD_REF, |
| 868 | [ BYTECODE_OP_LOAD_FIELD_REF_STRING ] = &&LABEL_BYTECODE_OP_LOAD_FIELD_REF_STRING, |
| 869 | [ BYTECODE_OP_LOAD_FIELD_REF_SEQUENCE ] = &&LABEL_BYTECODE_OP_LOAD_FIELD_REF_SEQUENCE, |
| 870 | [ BYTECODE_OP_LOAD_FIELD_REF_S64 ] = &&LABEL_BYTECODE_OP_LOAD_FIELD_REF_S64, |
| 871 | [ BYTECODE_OP_LOAD_FIELD_REF_DOUBLE ] = &&LABEL_BYTECODE_OP_LOAD_FIELD_REF_DOUBLE, |
| 872 | |
| 873 | /* load from immediate operand */ |
| 874 | [ BYTECODE_OP_LOAD_STRING ] = &&LABEL_BYTECODE_OP_LOAD_STRING, |
| 875 | [ BYTECODE_OP_LOAD_STAR_GLOB_STRING ] = &&LABEL_BYTECODE_OP_LOAD_STAR_GLOB_STRING, |
| 876 | [ BYTECODE_OP_LOAD_S64 ] = &&LABEL_BYTECODE_OP_LOAD_S64, |
| 877 | [ BYTECODE_OP_LOAD_DOUBLE ] = &&LABEL_BYTECODE_OP_LOAD_DOUBLE, |
| 878 | |
| 879 | /* cast */ |
| 880 | [ BYTECODE_OP_CAST_TO_S64 ] = &&LABEL_BYTECODE_OP_CAST_TO_S64, |
| 881 | [ BYTECODE_OP_CAST_DOUBLE_TO_S64 ] = &&LABEL_BYTECODE_OP_CAST_DOUBLE_TO_S64, |
| 882 | [ BYTECODE_OP_CAST_NOP ] = &&LABEL_BYTECODE_OP_CAST_NOP, |
| 883 | |
| 884 | /* get context ref */ |
| 885 | [ BYTECODE_OP_GET_CONTEXT_REF ] = &&LABEL_BYTECODE_OP_GET_CONTEXT_REF, |
| 886 | [ BYTECODE_OP_GET_CONTEXT_REF_STRING ] = &&LABEL_BYTECODE_OP_GET_CONTEXT_REF_STRING, |
| 887 | [ BYTECODE_OP_GET_CONTEXT_REF_S64 ] = &&LABEL_BYTECODE_OP_GET_CONTEXT_REF_S64, |
| 888 | [ BYTECODE_OP_GET_CONTEXT_REF_DOUBLE ] = &&LABEL_BYTECODE_OP_GET_CONTEXT_REF_DOUBLE, |
| 889 | |
| 890 | /* Instructions for recursive traversal through composed types. */ |
| 891 | [ BYTECODE_OP_GET_CONTEXT_ROOT ] = &&LABEL_BYTECODE_OP_GET_CONTEXT_ROOT, |
| 892 | [ BYTECODE_OP_GET_APP_CONTEXT_ROOT ] = &&LABEL_BYTECODE_OP_GET_APP_CONTEXT_ROOT, |
| 893 | [ BYTECODE_OP_GET_PAYLOAD_ROOT ] = &&LABEL_BYTECODE_OP_GET_PAYLOAD_ROOT, |
| 894 | |
| 895 | [ BYTECODE_OP_GET_SYMBOL ] = &&LABEL_BYTECODE_OP_GET_SYMBOL, |
| 896 | [ BYTECODE_OP_GET_SYMBOL_FIELD ] = &&LABEL_BYTECODE_OP_GET_SYMBOL_FIELD, |
| 897 | [ BYTECODE_OP_GET_INDEX_U16 ] = &&LABEL_BYTECODE_OP_GET_INDEX_U16, |
| 898 | [ BYTECODE_OP_GET_INDEX_U64 ] = &&LABEL_BYTECODE_OP_GET_INDEX_U64, |
| 899 | |
| 900 | [ BYTECODE_OP_LOAD_FIELD ] = &&LABEL_BYTECODE_OP_LOAD_FIELD, |
| 901 | [ BYTECODE_OP_LOAD_FIELD_S8 ] = &&LABEL_BYTECODE_OP_LOAD_FIELD_S8, |
| 902 | [ BYTECODE_OP_LOAD_FIELD_S16 ] = &&LABEL_BYTECODE_OP_LOAD_FIELD_S16, |
| 903 | [ BYTECODE_OP_LOAD_FIELD_S32 ] = &&LABEL_BYTECODE_OP_LOAD_FIELD_S32, |
| 904 | [ BYTECODE_OP_LOAD_FIELD_S64 ] = &&LABEL_BYTECODE_OP_LOAD_FIELD_S64, |
| 905 | [ BYTECODE_OP_LOAD_FIELD_U8 ] = &&LABEL_BYTECODE_OP_LOAD_FIELD_U8, |
| 906 | [ BYTECODE_OP_LOAD_FIELD_U16 ] = &&LABEL_BYTECODE_OP_LOAD_FIELD_U16, |
| 907 | [ BYTECODE_OP_LOAD_FIELD_U32 ] = &&LABEL_BYTECODE_OP_LOAD_FIELD_U32, |
| 908 | [ BYTECODE_OP_LOAD_FIELD_U64 ] = &&LABEL_BYTECODE_OP_LOAD_FIELD_U64, |
| 909 | [ BYTECODE_OP_LOAD_FIELD_STRING ] = &&LABEL_BYTECODE_OP_LOAD_FIELD_STRING, |
| 910 | [ BYTECODE_OP_LOAD_FIELD_SEQUENCE ] = &&LABEL_BYTECODE_OP_LOAD_FIELD_SEQUENCE, |
| 911 | [ BYTECODE_OP_LOAD_FIELD_DOUBLE ] = &&LABEL_BYTECODE_OP_LOAD_FIELD_DOUBLE, |
| 912 | |
| 913 | [ BYTECODE_OP_UNARY_BIT_NOT ] = &&LABEL_BYTECODE_OP_UNARY_BIT_NOT, |
| 914 | |
| 915 | [ BYTECODE_OP_RETURN_S64 ] = &&LABEL_BYTECODE_OP_RETURN_S64, |
| 916 | }; |
| 917 | #endif /* #ifndef INTERPRETER_USE_SWITCH */ |
| 918 | |
| 919 | START_OP |
| 920 | |
| 921 | OP(BYTECODE_OP_UNKNOWN): |
| 922 | OP(BYTECODE_OP_LOAD_FIELD_REF): |
| 923 | #ifdef INTERPRETER_USE_SWITCH |
| 924 | default: |
| 925 | #endif /* INTERPRETER_USE_SWITCH */ |
| 926 | ERR("unknown bytecode op %u", |
| 927 | (unsigned int) *(bytecode_opcode_t *) pc); |
| 928 | ret = -EINVAL; |
| 929 | goto end; |
| 930 | |
| 931 | OP(BYTECODE_OP_RETURN): |
| 932 | /* LTTNG_INTERPRETER_DISCARD or LTTNG_INTERPRETER_RECORD_FLAG */ |
| 933 | /* Handle dynamic typing. */ |
| 934 | switch (estack_ax_t) { |
| 935 | case REG_S64: |
| 936 | case REG_U64: |
| 937 | retval = !!estack_ax_v; |
| 938 | break; |
| 939 | case REG_DOUBLE: |
| 940 | case REG_STRING: |
| 941 | case REG_PTR: |
| 942 | if (!output) { |
| 943 | ret = -EINVAL; |
| 944 | goto end; |
| 945 | } |
| 946 | retval = 0; |
| 947 | break; |
| 948 | case REG_STAR_GLOB_STRING: |
| 949 | case REG_UNKNOWN: |
| 950 | default: |
| 951 | ret = -EINVAL; |
| 952 | goto end; |
| 953 | } |
| 954 | ret = 0; |
| 955 | goto end; |
| 956 | |
| 957 | OP(BYTECODE_OP_RETURN_S64): |
| 958 | /* LTTNG_INTERPRETER_DISCARD or LTTNG_INTERPRETER_RECORD_FLAG */ |
| 959 | retval = !!estack_ax_v; |
| 960 | ret = 0; |
| 961 | goto end; |
| 962 | |
| 963 | /* binary */ |
| 964 | OP(BYTECODE_OP_MUL): |
| 965 | OP(BYTECODE_OP_DIV): |
| 966 | OP(BYTECODE_OP_MOD): |
| 967 | OP(BYTECODE_OP_PLUS): |
| 968 | OP(BYTECODE_OP_MINUS): |
| 969 | ERR("unsupported bytecode op %u", |
| 970 | (unsigned int) *(bytecode_opcode_t *) pc); |
| 971 | ret = -EINVAL; |
| 972 | goto end; |
| 973 | |
| 974 | OP(BYTECODE_OP_EQ): |
| 975 | { |
| 976 | /* Dynamic typing. */ |
| 977 | switch (estack_ax_t) { |
| 978 | case REG_S64: /* Fall-through */ |
| 979 | case REG_U64: |
| 980 | switch (estack_bx_t) { |
| 981 | case REG_S64: /* Fall-through */ |
| 982 | case REG_U64: |
| 983 | JUMP_TO(BYTECODE_OP_EQ_S64); |
| 984 | case REG_DOUBLE: |
| 985 | JUMP_TO(BYTECODE_OP_EQ_DOUBLE_S64); |
| 986 | case REG_STRING: /* Fall-through */ |
| 987 | case REG_STAR_GLOB_STRING: |
| 988 | ret = -EINVAL; |
| 989 | goto end; |
| 990 | default: |
| 991 | ERR("Unknown interpreter register type (%d)", |
| 992 | (int) estack_bx_t); |
| 993 | ret = -EINVAL; |
| 994 | goto end; |
| 995 | } |
| 996 | break; |
| 997 | case REG_DOUBLE: |
| 998 | switch (estack_bx_t) { |
| 999 | case REG_S64: /* Fall-through */ |
| 1000 | case REG_U64: |
| 1001 | JUMP_TO(BYTECODE_OP_EQ_S64_DOUBLE); |
| 1002 | case REG_DOUBLE: |
| 1003 | JUMP_TO(BYTECODE_OP_EQ_DOUBLE); |
| 1004 | case REG_STRING: /* Fall-through */ |
| 1005 | case REG_STAR_GLOB_STRING: |
| 1006 | ret = -EINVAL; |
| 1007 | goto end; |
| 1008 | default: |
| 1009 | ERR("Unknown interpreter register type (%d)", |
| 1010 | (int) estack_bx_t); |
| 1011 | ret = -EINVAL; |
| 1012 | goto end; |
| 1013 | } |
| 1014 | break; |
| 1015 | case REG_STRING: |
| 1016 | switch (estack_bx_t) { |
| 1017 | case REG_S64: /* Fall-through */ |
| 1018 | case REG_U64: /* Fall-through */ |
| 1019 | case REG_DOUBLE: |
| 1020 | ret = -EINVAL; |
| 1021 | goto end; |
| 1022 | case REG_STRING: |
| 1023 | JUMP_TO(BYTECODE_OP_EQ_STRING); |
| 1024 | case REG_STAR_GLOB_STRING: |
| 1025 | JUMP_TO(BYTECODE_OP_EQ_STAR_GLOB_STRING); |
| 1026 | default: |
| 1027 | ERR("Unknown interpreter register type (%d)", |
| 1028 | (int) estack_bx_t); |
| 1029 | ret = -EINVAL; |
| 1030 | goto end; |
| 1031 | } |
| 1032 | break; |
| 1033 | case REG_STAR_GLOB_STRING: |
| 1034 | switch (estack_bx_t) { |
| 1035 | case REG_S64: /* Fall-through */ |
| 1036 | case REG_U64: /* Fall-through */ |
| 1037 | case REG_DOUBLE: |
| 1038 | ret = -EINVAL; |
| 1039 | goto end; |
| 1040 | case REG_STRING: |
| 1041 | JUMP_TO(BYTECODE_OP_EQ_STAR_GLOB_STRING); |
| 1042 | case REG_STAR_GLOB_STRING: |
| 1043 | ret = -EINVAL; |
| 1044 | goto end; |
| 1045 | default: |
| 1046 | ERR("Unknown interpreter register type (%d)", |
| 1047 | (int) estack_bx_t); |
| 1048 | ret = -EINVAL; |
| 1049 | goto end; |
| 1050 | } |
| 1051 | break; |
| 1052 | default: |
| 1053 | ERR("Unknown interpreter register type (%d)", |
| 1054 | (int) estack_ax_t); |
| 1055 | ret = -EINVAL; |
| 1056 | goto end; |
| 1057 | } |
| 1058 | } |
| 1059 | OP(BYTECODE_OP_NE): |
| 1060 | { |
| 1061 | /* Dynamic typing. */ |
| 1062 | switch (estack_ax_t) { |
| 1063 | case REG_S64: /* Fall-through */ |
| 1064 | case REG_U64: |
| 1065 | switch (estack_bx_t) { |
| 1066 | case REG_S64: /* Fall-through */ |
| 1067 | case REG_U64: |
| 1068 | JUMP_TO(BYTECODE_OP_NE_S64); |
| 1069 | case REG_DOUBLE: |
| 1070 | JUMP_TO(BYTECODE_OP_NE_DOUBLE_S64); |
| 1071 | case REG_STRING: /* Fall-through */ |
| 1072 | case REG_STAR_GLOB_STRING: |
| 1073 | ret = -EINVAL; |
| 1074 | goto end; |
| 1075 | default: |
| 1076 | ERR("Unknown interpreter register type (%d)", |
| 1077 | (int) estack_bx_t); |
| 1078 | ret = -EINVAL; |
| 1079 | goto end; |
| 1080 | } |
| 1081 | break; |
| 1082 | case REG_DOUBLE: |
| 1083 | switch (estack_bx_t) { |
| 1084 | case REG_S64: /* Fall-through */ |
| 1085 | case REG_U64: |
| 1086 | JUMP_TO(BYTECODE_OP_NE_S64_DOUBLE); |
| 1087 | case REG_DOUBLE: |
| 1088 | JUMP_TO(BYTECODE_OP_NE_DOUBLE); |
| 1089 | case REG_STRING: /* Fall-through */ |
| 1090 | case REG_STAR_GLOB_STRING: |
| 1091 | ret = -EINVAL; |
| 1092 | goto end; |
| 1093 | default: |
| 1094 | ERR("Unknown interpreter register type (%d)", |
| 1095 | (int) estack_bx_t); |
| 1096 | ret = -EINVAL; |
| 1097 | goto end; |
| 1098 | } |
| 1099 | break; |
| 1100 | case REG_STRING: |
| 1101 | switch (estack_bx_t) { |
| 1102 | case REG_S64: /* Fall-through */ |
| 1103 | case REG_U64: |
| 1104 | case REG_DOUBLE: |
| 1105 | ret = -EINVAL; |
| 1106 | goto end; |
| 1107 | case REG_STRING: |
| 1108 | JUMP_TO(BYTECODE_OP_NE_STRING); |
| 1109 | case REG_STAR_GLOB_STRING: |
| 1110 | JUMP_TO(BYTECODE_OP_NE_STAR_GLOB_STRING); |
| 1111 | default: |
| 1112 | ERR("Unknown interpreter register type (%d)", |
| 1113 | (int) estack_bx_t); |
| 1114 | ret = -EINVAL; |
| 1115 | goto end; |
| 1116 | } |
| 1117 | break; |
| 1118 | case REG_STAR_GLOB_STRING: |
| 1119 | switch (estack_bx_t) { |
| 1120 | case REG_S64: /* Fall-through */ |
| 1121 | case REG_U64: |
| 1122 | case REG_DOUBLE: |
| 1123 | ret = -EINVAL; |
| 1124 | goto end; |
| 1125 | case REG_STRING: |
| 1126 | JUMP_TO(BYTECODE_OP_NE_STAR_GLOB_STRING); |
| 1127 | case REG_STAR_GLOB_STRING: |
| 1128 | ret = -EINVAL; |
| 1129 | goto end; |
| 1130 | default: |
| 1131 | ERR("Unknown interpreter register type (%d)", |
| 1132 | (int) estack_bx_t); |
| 1133 | ret = -EINVAL; |
| 1134 | goto end; |
| 1135 | } |
| 1136 | break; |
| 1137 | default: |
| 1138 | ERR("Unknown interpreter register type (%d)", |
| 1139 | (int) estack_ax_t); |
| 1140 | ret = -EINVAL; |
| 1141 | goto end; |
| 1142 | } |
| 1143 | } |
| 1144 | OP(BYTECODE_OP_GT): |
| 1145 | { |
| 1146 | /* Dynamic typing. */ |
| 1147 | switch (estack_ax_t) { |
| 1148 | case REG_S64: /* Fall-through */ |
| 1149 | case REG_U64: |
| 1150 | switch (estack_bx_t) { |
| 1151 | case REG_S64: /* Fall-through */ |
| 1152 | case REG_U64: |
| 1153 | JUMP_TO(BYTECODE_OP_GT_S64); |
| 1154 | case REG_DOUBLE: |
| 1155 | JUMP_TO(BYTECODE_OP_GT_DOUBLE_S64); |
| 1156 | case REG_STRING: /* Fall-through */ |
| 1157 | case REG_STAR_GLOB_STRING: |
| 1158 | ret = -EINVAL; |
| 1159 | goto end; |
| 1160 | default: |
| 1161 | ERR("Unknown interpreter register type (%d)", |
| 1162 | (int) estack_bx_t); |
| 1163 | ret = -EINVAL; |
| 1164 | goto end; |
| 1165 | } |
| 1166 | break; |
| 1167 | case REG_DOUBLE: |
| 1168 | switch (estack_bx_t) { |
| 1169 | case REG_S64: /* Fall-through */ |
| 1170 | case REG_U64: |
| 1171 | JUMP_TO(BYTECODE_OP_GT_S64_DOUBLE); |
| 1172 | case REG_DOUBLE: |
| 1173 | JUMP_TO(BYTECODE_OP_GT_DOUBLE); |
| 1174 | case REG_STRING: /* Fall-through */ |
| 1175 | case REG_STAR_GLOB_STRING: |
| 1176 | ret = -EINVAL; |
| 1177 | goto end; |
| 1178 | default: |
| 1179 | ERR("Unknown interpreter register type (%d)", |
| 1180 | (int) estack_bx_t); |
| 1181 | ret = -EINVAL; |
| 1182 | goto end; |
| 1183 | } |
| 1184 | break; |
| 1185 | case REG_STRING: |
| 1186 | switch (estack_bx_t) { |
| 1187 | case REG_S64: /* Fall-through */ |
| 1188 | case REG_U64: /* Fall-through */ |
| 1189 | case REG_DOUBLE: /* Fall-through */ |
| 1190 | case REG_STAR_GLOB_STRING: |
| 1191 | ret = -EINVAL; |
| 1192 | goto end; |
| 1193 | case REG_STRING: |
| 1194 | JUMP_TO(BYTECODE_OP_GT_STRING); |
| 1195 | default: |
| 1196 | ERR("Unknown interpreter register type (%d)", |
| 1197 | (int) estack_bx_t); |
| 1198 | ret = -EINVAL; |
| 1199 | goto end; |
| 1200 | } |
| 1201 | break; |
| 1202 | default: |
| 1203 | ERR("Unknown interpreter register type (%d)", |
| 1204 | (int) estack_ax_t); |
| 1205 | ret = -EINVAL; |
| 1206 | goto end; |
| 1207 | } |
| 1208 | } |
| 1209 | OP(BYTECODE_OP_LT): |
| 1210 | { |
| 1211 | /* Dynamic typing. */ |
| 1212 | switch (estack_ax_t) { |
| 1213 | case REG_S64: /* Fall-through */ |
| 1214 | case REG_U64: |
| 1215 | switch (estack_bx_t) { |
| 1216 | case REG_S64: /* Fall-through */ |
| 1217 | case REG_U64: |
| 1218 | JUMP_TO(BYTECODE_OP_LT_S64); |
| 1219 | case REG_DOUBLE: |
| 1220 | JUMP_TO(BYTECODE_OP_LT_DOUBLE_S64); |
| 1221 | case REG_STRING: /* Fall-through */ |
| 1222 | case REG_STAR_GLOB_STRING: |
| 1223 | ret = -EINVAL; |
| 1224 | goto end; |
| 1225 | default: |
| 1226 | ERR("Unknown interpreter register type (%d)", |
| 1227 | (int) estack_bx_t); |
| 1228 | ret = -EINVAL; |
| 1229 | goto end; |
| 1230 | } |
| 1231 | break; |
| 1232 | case REG_DOUBLE: |
| 1233 | switch (estack_bx_t) { |
| 1234 | case REG_S64: /* Fall-through */ |
| 1235 | case REG_U64: |
| 1236 | JUMP_TO(BYTECODE_OP_LT_S64_DOUBLE); |
| 1237 | case REG_DOUBLE: |
| 1238 | JUMP_TO(BYTECODE_OP_LT_DOUBLE); |
| 1239 | case REG_STRING: /* Fall-through */ |
| 1240 | case REG_STAR_GLOB_STRING: |
| 1241 | ret = -EINVAL; |
| 1242 | goto end; |
| 1243 | default: |
| 1244 | ERR("Unknown interpreter register type (%d)", |
| 1245 | (int) estack_bx_t); |
| 1246 | ret = -EINVAL; |
| 1247 | goto end; |
| 1248 | } |
| 1249 | break; |
| 1250 | case REG_STRING: |
| 1251 | switch (estack_bx_t) { |
| 1252 | case REG_S64: /* Fall-through */ |
| 1253 | case REG_U64: /* Fall-through */ |
| 1254 | case REG_DOUBLE: /* Fall-through */ |
| 1255 | case REG_STAR_GLOB_STRING: |
| 1256 | ret = -EINVAL; |
| 1257 | goto end; |
| 1258 | case REG_STRING: |
| 1259 | JUMP_TO(BYTECODE_OP_LT_STRING); |
| 1260 | default: |
| 1261 | ERR("Unknown interpreter register type (%d)", |
| 1262 | (int) estack_bx_t); |
| 1263 | ret = -EINVAL; |
| 1264 | goto end; |
| 1265 | } |
| 1266 | break; |
| 1267 | default: |
| 1268 | ERR("Unknown interpreter register type (%d)", |
| 1269 | (int) estack_ax_t); |
| 1270 | ret = -EINVAL; |
| 1271 | goto end; |
| 1272 | } |
| 1273 | } |
| 1274 | OP(BYTECODE_OP_GE): |
| 1275 | { |
| 1276 | /* Dynamic typing. */ |
| 1277 | switch (estack_ax_t) { |
| 1278 | case REG_S64: /* Fall-through */ |
| 1279 | case REG_U64: |
| 1280 | switch (estack_bx_t) { |
| 1281 | case REG_S64: /* Fall-through */ |
| 1282 | case REG_U64: |
| 1283 | JUMP_TO(BYTECODE_OP_GE_S64); |
| 1284 | case REG_DOUBLE: |
| 1285 | JUMP_TO(BYTECODE_OP_GE_DOUBLE_S64); |
| 1286 | case REG_STRING: /* Fall-through */ |
| 1287 | case REG_STAR_GLOB_STRING: |
| 1288 | ret = -EINVAL; |
| 1289 | goto end; |
| 1290 | default: |
| 1291 | ERR("Unknown interpreter register type (%d)", |
| 1292 | (int) estack_bx_t); |
| 1293 | ret = -EINVAL; |
| 1294 | goto end; |
| 1295 | } |
| 1296 | break; |
| 1297 | case REG_DOUBLE: |
| 1298 | switch (estack_bx_t) { |
| 1299 | case REG_S64: /* Fall-through */ |
| 1300 | case REG_U64: |
| 1301 | JUMP_TO(BYTECODE_OP_GE_S64_DOUBLE); |
| 1302 | case REG_DOUBLE: |
| 1303 | JUMP_TO(BYTECODE_OP_GE_DOUBLE); |
| 1304 | case REG_STRING: /* Fall-through */ |
| 1305 | case REG_STAR_GLOB_STRING: |
| 1306 | ret = -EINVAL; |
| 1307 | goto end; |
| 1308 | default: |
| 1309 | ERR("Unknown interpreter register type (%d)", |
| 1310 | (int) estack_bx_t); |
| 1311 | ret = -EINVAL; |
| 1312 | goto end; |
| 1313 | } |
| 1314 | break; |
| 1315 | case REG_STRING: |
| 1316 | switch (estack_bx_t) { |
| 1317 | case REG_S64: /* Fall-through */ |
| 1318 | case REG_U64: /* Fall-through */ |
| 1319 | case REG_DOUBLE: /* Fall-through */ |
| 1320 | case REG_STAR_GLOB_STRING: |
| 1321 | ret = -EINVAL; |
| 1322 | goto end; |
| 1323 | case REG_STRING: |
| 1324 | JUMP_TO(BYTECODE_OP_GE_STRING); |
| 1325 | default: |
| 1326 | ERR("Unknown interpreter register type (%d)", |
| 1327 | (int) estack_bx_t); |
| 1328 | ret = -EINVAL; |
| 1329 | goto end; |
| 1330 | } |
| 1331 | break; |
| 1332 | default: |
| 1333 | ERR("Unknown interpreter register type (%d)", |
| 1334 | (int) estack_ax_t); |
| 1335 | ret = -EINVAL; |
| 1336 | goto end; |
| 1337 | } |
| 1338 | } |
| 1339 | OP(BYTECODE_OP_LE): |
| 1340 | { |
| 1341 | /* Dynamic typing. */ |
| 1342 | switch (estack_ax_t) { |
| 1343 | case REG_S64: /* Fall-through */ |
| 1344 | case REG_U64: |
| 1345 | switch (estack_bx_t) { |
| 1346 | case REG_S64: /* Fall-through */ |
| 1347 | case REG_U64: |
| 1348 | JUMP_TO(BYTECODE_OP_LE_S64); |
| 1349 | case REG_DOUBLE: |
| 1350 | JUMP_TO(BYTECODE_OP_LE_DOUBLE_S64); |
| 1351 | case REG_STRING: /* Fall-through */ |
| 1352 | case REG_STAR_GLOB_STRING: |
| 1353 | ret = -EINVAL; |
| 1354 | goto end; |
| 1355 | default: |
| 1356 | ERR("Unknown interpreter register type (%d)", |
| 1357 | (int) estack_bx_t); |
| 1358 | ret = -EINVAL; |
| 1359 | goto end; |
| 1360 | } |
| 1361 | break; |
| 1362 | case REG_DOUBLE: |
| 1363 | switch (estack_bx_t) { |
| 1364 | case REG_S64: /* Fall-through */ |
| 1365 | case REG_U64: |
| 1366 | JUMP_TO(BYTECODE_OP_LE_S64_DOUBLE); |
| 1367 | case REG_DOUBLE: |
| 1368 | JUMP_TO(BYTECODE_OP_LE_DOUBLE); |
| 1369 | case REG_STRING: /* Fall-through */ |
| 1370 | case REG_STAR_GLOB_STRING: |
| 1371 | ret = -EINVAL; |
| 1372 | goto end; |
| 1373 | default: |
| 1374 | ERR("Unknown interpreter register type (%d)", |
| 1375 | (int) estack_bx_t); |
| 1376 | ret = -EINVAL; |
| 1377 | goto end; |
| 1378 | } |
| 1379 | break; |
| 1380 | case REG_STRING: |
| 1381 | switch (estack_bx_t) { |
| 1382 | case REG_S64: /* Fall-through */ |
| 1383 | case REG_U64: /* Fall-through */ |
| 1384 | case REG_DOUBLE: /* Fall-through */ |
| 1385 | case REG_STAR_GLOB_STRING: |
| 1386 | ret = -EINVAL; |
| 1387 | goto end; |
| 1388 | case REG_STRING: |
| 1389 | JUMP_TO(BYTECODE_OP_LE_STRING); |
| 1390 | default: |
| 1391 | ERR("Unknown interpreter register type (%d)", |
| 1392 | (int) estack_bx_t); |
| 1393 | ret = -EINVAL; |
| 1394 | goto end; |
| 1395 | } |
| 1396 | break; |
| 1397 | default: |
| 1398 | ERR("Unknown interpreter register type (%d)", |
| 1399 | (int) estack_ax_t); |
| 1400 | ret = -EINVAL; |
| 1401 | goto end; |
| 1402 | } |
| 1403 | } |
| 1404 | |
| 1405 | OP(BYTECODE_OP_EQ_STRING): |
| 1406 | { |
| 1407 | int res; |
| 1408 | |
| 1409 | res = (stack_strcmp(stack, top, "==") == 0); |
| 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 | OP(BYTECODE_OP_NE_STRING): |
| 1417 | { |
| 1418 | int res; |
| 1419 | |
| 1420 | res = (stack_strcmp(stack, top, "!=") != 0); |
| 1421 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1422 | estack_ax_v = res; |
| 1423 | estack_ax_t = REG_S64; |
| 1424 | next_pc += sizeof(struct binary_op); |
| 1425 | PO; |
| 1426 | } |
| 1427 | OP(BYTECODE_OP_GT_STRING): |
| 1428 | { |
| 1429 | int res; |
| 1430 | |
| 1431 | res = (stack_strcmp(stack, top, ">") > 0); |
| 1432 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1433 | estack_ax_v = res; |
| 1434 | estack_ax_t = REG_S64; |
| 1435 | next_pc += sizeof(struct binary_op); |
| 1436 | PO; |
| 1437 | } |
| 1438 | OP(BYTECODE_OP_LT_STRING): |
| 1439 | { |
| 1440 | int res; |
| 1441 | |
| 1442 | res = (stack_strcmp(stack, top, "<") < 0); |
| 1443 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1444 | estack_ax_v = res; |
| 1445 | estack_ax_t = REG_S64; |
| 1446 | next_pc += sizeof(struct binary_op); |
| 1447 | PO; |
| 1448 | } |
| 1449 | OP(BYTECODE_OP_GE_STRING): |
| 1450 | { |
| 1451 | int res; |
| 1452 | |
| 1453 | res = (stack_strcmp(stack, top, ">=") >= 0); |
| 1454 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1455 | estack_ax_v = res; |
| 1456 | estack_ax_t = REG_S64; |
| 1457 | next_pc += sizeof(struct binary_op); |
| 1458 | PO; |
| 1459 | } |
| 1460 | OP(BYTECODE_OP_LE_STRING): |
| 1461 | { |
| 1462 | int res; |
| 1463 | |
| 1464 | res = (stack_strcmp(stack, top, "<=") <= 0); |
| 1465 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1466 | estack_ax_v = res; |
| 1467 | estack_ax_t = REG_S64; |
| 1468 | next_pc += sizeof(struct binary_op); |
| 1469 | PO; |
| 1470 | } |
| 1471 | |
| 1472 | OP(BYTECODE_OP_EQ_STAR_GLOB_STRING): |
| 1473 | { |
| 1474 | int res; |
| 1475 | |
| 1476 | res = (stack_star_glob_match(stack, top, "==") == 0); |
| 1477 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1478 | estack_ax_v = res; |
| 1479 | estack_ax_t = REG_S64; |
| 1480 | next_pc += sizeof(struct binary_op); |
| 1481 | PO; |
| 1482 | } |
| 1483 | OP(BYTECODE_OP_NE_STAR_GLOB_STRING): |
| 1484 | { |
| 1485 | int res; |
| 1486 | |
| 1487 | res = (stack_star_glob_match(stack, top, "!=") != 0); |
| 1488 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1489 | estack_ax_v = res; |
| 1490 | estack_ax_t = REG_S64; |
| 1491 | next_pc += sizeof(struct binary_op); |
| 1492 | PO; |
| 1493 | } |
| 1494 | |
| 1495 | OP(BYTECODE_OP_EQ_S64): |
| 1496 | { |
| 1497 | int res; |
| 1498 | |
| 1499 | res = (estack_bx_v == estack_ax_v); |
| 1500 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1501 | estack_ax_v = res; |
| 1502 | estack_ax_t = REG_S64; |
| 1503 | next_pc += sizeof(struct binary_op); |
| 1504 | PO; |
| 1505 | } |
| 1506 | OP(BYTECODE_OP_NE_S64): |
| 1507 | { |
| 1508 | int res; |
| 1509 | |
| 1510 | res = (estack_bx_v != estack_ax_v); |
| 1511 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1512 | estack_ax_v = res; |
| 1513 | estack_ax_t = REG_S64; |
| 1514 | next_pc += sizeof(struct binary_op); |
| 1515 | PO; |
| 1516 | } |
| 1517 | OP(BYTECODE_OP_GT_S64): |
| 1518 | { |
| 1519 | int res; |
| 1520 | |
| 1521 | res = (estack_bx_v > estack_ax_v); |
| 1522 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1523 | estack_ax_v = res; |
| 1524 | estack_ax_t = REG_S64; |
| 1525 | next_pc += sizeof(struct binary_op); |
| 1526 | PO; |
| 1527 | } |
| 1528 | OP(BYTECODE_OP_LT_S64): |
| 1529 | { |
| 1530 | int res; |
| 1531 | |
| 1532 | res = (estack_bx_v < estack_ax_v); |
| 1533 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1534 | estack_ax_v = res; |
| 1535 | estack_ax_t = REG_S64; |
| 1536 | next_pc += sizeof(struct binary_op); |
| 1537 | PO; |
| 1538 | } |
| 1539 | OP(BYTECODE_OP_GE_S64): |
| 1540 | { |
| 1541 | int res; |
| 1542 | |
| 1543 | res = (estack_bx_v >= estack_ax_v); |
| 1544 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1545 | estack_ax_v = res; |
| 1546 | estack_ax_t = REG_S64; |
| 1547 | next_pc += sizeof(struct binary_op); |
| 1548 | PO; |
| 1549 | } |
| 1550 | OP(BYTECODE_OP_LE_S64): |
| 1551 | { |
| 1552 | int res; |
| 1553 | |
| 1554 | res = (estack_bx_v <= estack_ax_v); |
| 1555 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1556 | estack_ax_v = res; |
| 1557 | estack_ax_t = REG_S64; |
| 1558 | next_pc += sizeof(struct binary_op); |
| 1559 | PO; |
| 1560 | } |
| 1561 | |
| 1562 | OP(BYTECODE_OP_EQ_DOUBLE): |
| 1563 | { |
| 1564 | int res; |
| 1565 | |
| 1566 | res = (estack_bx(stack, top)->u.d == estack_ax(stack, top)->u.d); |
| 1567 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1568 | estack_ax_v = res; |
| 1569 | estack_ax_t = REG_S64; |
| 1570 | next_pc += sizeof(struct binary_op); |
| 1571 | PO; |
| 1572 | } |
| 1573 | OP(BYTECODE_OP_NE_DOUBLE): |
| 1574 | { |
| 1575 | int res; |
| 1576 | |
| 1577 | res = (estack_bx(stack, top)->u.d != estack_ax(stack, top)->u.d); |
| 1578 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1579 | estack_ax_v = res; |
| 1580 | estack_ax_t = REG_S64; |
| 1581 | next_pc += sizeof(struct binary_op); |
| 1582 | PO; |
| 1583 | } |
| 1584 | OP(BYTECODE_OP_GT_DOUBLE): |
| 1585 | { |
| 1586 | int res; |
| 1587 | |
| 1588 | res = (estack_bx(stack, top)->u.d > estack_ax(stack, top)->u.d); |
| 1589 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1590 | estack_ax_v = res; |
| 1591 | estack_ax_t = REG_S64; |
| 1592 | next_pc += sizeof(struct binary_op); |
| 1593 | PO; |
| 1594 | } |
| 1595 | OP(BYTECODE_OP_LT_DOUBLE): |
| 1596 | { |
| 1597 | int res; |
| 1598 | |
| 1599 | res = (estack_bx(stack, top)->u.d < estack_ax(stack, top)->u.d); |
| 1600 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1601 | estack_ax_v = res; |
| 1602 | estack_ax_t = REG_S64; |
| 1603 | next_pc += sizeof(struct binary_op); |
| 1604 | PO; |
| 1605 | } |
| 1606 | OP(BYTECODE_OP_GE_DOUBLE): |
| 1607 | { |
| 1608 | int res; |
| 1609 | |
| 1610 | res = (estack_bx(stack, top)->u.d >= estack_ax(stack, top)->u.d); |
| 1611 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1612 | estack_ax_v = res; |
| 1613 | estack_ax_t = REG_S64; |
| 1614 | next_pc += sizeof(struct binary_op); |
| 1615 | PO; |
| 1616 | } |
| 1617 | OP(BYTECODE_OP_LE_DOUBLE): |
| 1618 | { |
| 1619 | int res; |
| 1620 | |
| 1621 | res = (estack_bx(stack, top)->u.d <= estack_ax(stack, top)->u.d); |
| 1622 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1623 | estack_ax_v = res; |
| 1624 | estack_ax_t = REG_S64; |
| 1625 | next_pc += sizeof(struct binary_op); |
| 1626 | PO; |
| 1627 | } |
| 1628 | |
| 1629 | /* Mixed S64-double binary comparators */ |
| 1630 | OP(BYTECODE_OP_EQ_DOUBLE_S64): |
| 1631 | { |
| 1632 | int res; |
| 1633 | |
| 1634 | res = (estack_bx(stack, top)->u.d == estack_ax_v); |
| 1635 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1636 | estack_ax_v = res; |
| 1637 | estack_ax_t = REG_S64; |
| 1638 | next_pc += sizeof(struct binary_op); |
| 1639 | PO; |
| 1640 | } |
| 1641 | OP(BYTECODE_OP_NE_DOUBLE_S64): |
| 1642 | { |
| 1643 | int res; |
| 1644 | |
| 1645 | res = (estack_bx(stack, top)->u.d != estack_ax_v); |
| 1646 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1647 | estack_ax_v = res; |
| 1648 | estack_ax_t = REG_S64; |
| 1649 | next_pc += sizeof(struct binary_op); |
| 1650 | PO; |
| 1651 | } |
| 1652 | OP(BYTECODE_OP_GT_DOUBLE_S64): |
| 1653 | { |
| 1654 | int res; |
| 1655 | |
| 1656 | res = (estack_bx(stack, top)->u.d > estack_ax_v); |
| 1657 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1658 | estack_ax_v = res; |
| 1659 | estack_ax_t = REG_S64; |
| 1660 | next_pc += sizeof(struct binary_op); |
| 1661 | PO; |
| 1662 | } |
| 1663 | OP(BYTECODE_OP_LT_DOUBLE_S64): |
| 1664 | { |
| 1665 | int res; |
| 1666 | |
| 1667 | res = (estack_bx(stack, top)->u.d < estack_ax_v); |
| 1668 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1669 | estack_ax_v = res; |
| 1670 | estack_ax_t = REG_S64; |
| 1671 | next_pc += sizeof(struct binary_op); |
| 1672 | PO; |
| 1673 | } |
| 1674 | OP(BYTECODE_OP_GE_DOUBLE_S64): |
| 1675 | { |
| 1676 | int res; |
| 1677 | |
| 1678 | res = (estack_bx(stack, top)->u.d >= estack_ax_v); |
| 1679 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1680 | estack_ax_v = res; |
| 1681 | estack_ax_t = REG_S64; |
| 1682 | next_pc += sizeof(struct binary_op); |
| 1683 | PO; |
| 1684 | } |
| 1685 | OP(BYTECODE_OP_LE_DOUBLE_S64): |
| 1686 | { |
| 1687 | int res; |
| 1688 | |
| 1689 | res = (estack_bx(stack, top)->u.d <= estack_ax_v); |
| 1690 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1691 | estack_ax_v = res; |
| 1692 | estack_ax_t = REG_S64; |
| 1693 | next_pc += sizeof(struct binary_op); |
| 1694 | PO; |
| 1695 | } |
| 1696 | |
| 1697 | OP(BYTECODE_OP_EQ_S64_DOUBLE): |
| 1698 | { |
| 1699 | int res; |
| 1700 | |
| 1701 | res = (estack_bx_v == estack_ax(stack, top)->u.d); |
| 1702 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1703 | estack_ax_v = res; |
| 1704 | estack_ax_t = REG_S64; |
| 1705 | next_pc += sizeof(struct binary_op); |
| 1706 | PO; |
| 1707 | } |
| 1708 | OP(BYTECODE_OP_NE_S64_DOUBLE): |
| 1709 | { |
| 1710 | int res; |
| 1711 | |
| 1712 | res = (estack_bx_v != estack_ax(stack, top)->u.d); |
| 1713 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1714 | estack_ax_v = res; |
| 1715 | estack_ax_t = REG_S64; |
| 1716 | next_pc += sizeof(struct binary_op); |
| 1717 | PO; |
| 1718 | } |
| 1719 | OP(BYTECODE_OP_GT_S64_DOUBLE): |
| 1720 | { |
| 1721 | int res; |
| 1722 | |
| 1723 | res = (estack_bx_v > estack_ax(stack, top)->u.d); |
| 1724 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1725 | estack_ax_v = res; |
| 1726 | estack_ax_t = REG_S64; |
| 1727 | next_pc += sizeof(struct binary_op); |
| 1728 | PO; |
| 1729 | } |
| 1730 | OP(BYTECODE_OP_LT_S64_DOUBLE): |
| 1731 | { |
| 1732 | int res; |
| 1733 | |
| 1734 | res = (estack_bx_v < estack_ax(stack, top)->u.d); |
| 1735 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1736 | estack_ax_v = res; |
| 1737 | estack_ax_t = REG_S64; |
| 1738 | next_pc += sizeof(struct binary_op); |
| 1739 | PO; |
| 1740 | } |
| 1741 | OP(BYTECODE_OP_GE_S64_DOUBLE): |
| 1742 | { |
| 1743 | int res; |
| 1744 | |
| 1745 | res = (estack_bx_v >= estack_ax(stack, top)->u.d); |
| 1746 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1747 | estack_ax_v = res; |
| 1748 | estack_ax_t = REG_S64; |
| 1749 | next_pc += sizeof(struct binary_op); |
| 1750 | PO; |
| 1751 | } |
| 1752 | OP(BYTECODE_OP_LE_S64_DOUBLE): |
| 1753 | { |
| 1754 | int res; |
| 1755 | |
| 1756 | res = (estack_bx_v <= estack_ax(stack, top)->u.d); |
| 1757 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1758 | estack_ax_v = res; |
| 1759 | estack_ax_t = REG_S64; |
| 1760 | next_pc += sizeof(struct binary_op); |
| 1761 | PO; |
| 1762 | } |
| 1763 | OP(BYTECODE_OP_BIT_RSHIFT): |
| 1764 | { |
| 1765 | int64_t res; |
| 1766 | |
| 1767 | if (!IS_INTEGER_REGISTER(estack_ax_t) || !IS_INTEGER_REGISTER(estack_bx_t)) { |
| 1768 | ret = -EINVAL; |
| 1769 | goto end; |
| 1770 | } |
| 1771 | |
| 1772 | /* Catch undefined behavior. */ |
| 1773 | if (caa_unlikely(estack_ax_v < 0 || estack_ax_v >= 64)) { |
| 1774 | ret = -EINVAL; |
| 1775 | goto end; |
| 1776 | } |
| 1777 | res = ((uint64_t) estack_bx_v >> (uint32_t) estack_ax_v); |
| 1778 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1779 | estack_ax_v = res; |
| 1780 | estack_ax_t = REG_U64; |
| 1781 | next_pc += sizeof(struct binary_op); |
| 1782 | PO; |
| 1783 | } |
| 1784 | OP(BYTECODE_OP_BIT_LSHIFT): |
| 1785 | { |
| 1786 | int64_t res; |
| 1787 | |
| 1788 | if (!IS_INTEGER_REGISTER(estack_ax_t) || !IS_INTEGER_REGISTER(estack_bx_t)) { |
| 1789 | ret = -EINVAL; |
| 1790 | goto end; |
| 1791 | } |
| 1792 | |
| 1793 | /* Catch undefined behavior. */ |
| 1794 | if (caa_unlikely(estack_ax_v < 0 || estack_ax_v >= 64)) { |
| 1795 | ret = -EINVAL; |
| 1796 | goto end; |
| 1797 | } |
| 1798 | res = ((uint64_t) estack_bx_v << (uint32_t) estack_ax_v); |
| 1799 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1800 | estack_ax_v = res; |
| 1801 | estack_ax_t = REG_U64; |
| 1802 | next_pc += sizeof(struct binary_op); |
| 1803 | PO; |
| 1804 | } |
| 1805 | OP(BYTECODE_OP_BIT_AND): |
| 1806 | { |
| 1807 | int64_t res; |
| 1808 | |
| 1809 | if (!IS_INTEGER_REGISTER(estack_ax_t) || !IS_INTEGER_REGISTER(estack_bx_t)) { |
| 1810 | ret = -EINVAL; |
| 1811 | goto end; |
| 1812 | } |
| 1813 | |
| 1814 | res = ((uint64_t) estack_bx_v & (uint64_t) estack_ax_v); |
| 1815 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1816 | estack_ax_v = res; |
| 1817 | estack_ax_t = REG_U64; |
| 1818 | next_pc += sizeof(struct binary_op); |
| 1819 | PO; |
| 1820 | } |
| 1821 | OP(BYTECODE_OP_BIT_OR): |
| 1822 | { |
| 1823 | int64_t res; |
| 1824 | |
| 1825 | if (!IS_INTEGER_REGISTER(estack_ax_t) || !IS_INTEGER_REGISTER(estack_bx_t)) { |
| 1826 | ret = -EINVAL; |
| 1827 | goto end; |
| 1828 | } |
| 1829 | |
| 1830 | res = ((uint64_t) estack_bx_v | (uint64_t) estack_ax_v); |
| 1831 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1832 | estack_ax_v = res; |
| 1833 | estack_ax_t = REG_U64; |
| 1834 | next_pc += sizeof(struct binary_op); |
| 1835 | PO; |
| 1836 | } |
| 1837 | OP(BYTECODE_OP_BIT_XOR): |
| 1838 | { |
| 1839 | int64_t res; |
| 1840 | |
| 1841 | if (!IS_INTEGER_REGISTER(estack_ax_t) || !IS_INTEGER_REGISTER(estack_bx_t)) { |
| 1842 | ret = -EINVAL; |
| 1843 | goto end; |
| 1844 | } |
| 1845 | |
| 1846 | res = ((uint64_t) estack_bx_v ^ (uint64_t) estack_ax_v); |
| 1847 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1848 | estack_ax_v = res; |
| 1849 | estack_ax_t = REG_U64; |
| 1850 | next_pc += sizeof(struct binary_op); |
| 1851 | PO; |
| 1852 | } |
| 1853 | |
| 1854 | /* unary */ |
| 1855 | OP(BYTECODE_OP_UNARY_PLUS): |
| 1856 | { |
| 1857 | /* Dynamic typing. */ |
| 1858 | switch (estack_ax_t) { |
| 1859 | case REG_S64: /* Fall-through. */ |
| 1860 | case REG_U64: |
| 1861 | JUMP_TO(BYTECODE_OP_UNARY_PLUS_S64); |
| 1862 | case REG_DOUBLE: |
| 1863 | JUMP_TO(BYTECODE_OP_UNARY_PLUS_DOUBLE); |
| 1864 | case REG_STRING: /* Fall-through */ |
| 1865 | case REG_STAR_GLOB_STRING: |
| 1866 | ret = -EINVAL; |
| 1867 | goto end; |
| 1868 | default: |
| 1869 | ERR("Unknown interpreter register type (%d)", |
| 1870 | (int) estack_ax_t); |
| 1871 | ret = -EINVAL; |
| 1872 | goto end; |
| 1873 | } |
| 1874 | } |
| 1875 | OP(BYTECODE_OP_UNARY_MINUS): |
| 1876 | { |
| 1877 | /* Dynamic typing. */ |
| 1878 | switch (estack_ax_t) { |
| 1879 | case REG_S64: /* Fall-through. */ |
| 1880 | case REG_U64: |
| 1881 | JUMP_TO(BYTECODE_OP_UNARY_MINUS_S64); |
| 1882 | case REG_DOUBLE: |
| 1883 | JUMP_TO(BYTECODE_OP_UNARY_MINUS_DOUBLE); |
| 1884 | case REG_STRING: /* Fall-through */ |
| 1885 | case REG_STAR_GLOB_STRING: |
| 1886 | ret = -EINVAL; |
| 1887 | goto end; |
| 1888 | default: |
| 1889 | ERR("Unknown interpreter register type (%d)", |
| 1890 | (int) estack_ax_t); |
| 1891 | ret = -EINVAL; |
| 1892 | goto end; |
| 1893 | } |
| 1894 | } |
| 1895 | OP(BYTECODE_OP_UNARY_NOT): |
| 1896 | { |
| 1897 | /* Dynamic typing. */ |
| 1898 | switch (estack_ax_t) { |
| 1899 | case REG_S64: /* Fall-through. */ |
| 1900 | case REG_U64: |
| 1901 | JUMP_TO(BYTECODE_OP_UNARY_NOT_S64); |
| 1902 | case REG_DOUBLE: |
| 1903 | JUMP_TO(BYTECODE_OP_UNARY_NOT_DOUBLE); |
| 1904 | case REG_STRING: /* Fall-through */ |
| 1905 | case REG_STAR_GLOB_STRING: |
| 1906 | ret = -EINVAL; |
| 1907 | goto end; |
| 1908 | default: |
| 1909 | ERR("Unknown interpreter register type (%d)", |
| 1910 | (int) estack_ax_t); |
| 1911 | ret = -EINVAL; |
| 1912 | goto end; |
| 1913 | } |
| 1914 | next_pc += sizeof(struct unary_op); |
| 1915 | PO; |
| 1916 | } |
| 1917 | |
| 1918 | OP(BYTECODE_OP_UNARY_BIT_NOT): |
| 1919 | { |
| 1920 | /* Dynamic typing. */ |
| 1921 | if (!IS_INTEGER_REGISTER(estack_ax_t)) { |
| 1922 | ret = -EINVAL; |
| 1923 | goto end; |
| 1924 | } |
| 1925 | |
| 1926 | estack_ax_v = ~(uint64_t) estack_ax_v; |
| 1927 | estack_ax_t = REG_U64; |
| 1928 | next_pc += sizeof(struct unary_op); |
| 1929 | PO; |
| 1930 | } |
| 1931 | |
| 1932 | OP(BYTECODE_OP_UNARY_PLUS_S64): |
| 1933 | OP(BYTECODE_OP_UNARY_PLUS_DOUBLE): |
| 1934 | { |
| 1935 | next_pc += sizeof(struct unary_op); |
| 1936 | PO; |
| 1937 | } |
| 1938 | OP(BYTECODE_OP_UNARY_MINUS_S64): |
| 1939 | { |
| 1940 | estack_ax_v = -estack_ax_v; |
| 1941 | next_pc += sizeof(struct unary_op); |
| 1942 | PO; |
| 1943 | } |
| 1944 | OP(BYTECODE_OP_UNARY_MINUS_DOUBLE): |
| 1945 | { |
| 1946 | estack_ax(stack, top)->u.d = -estack_ax(stack, top)->u.d; |
| 1947 | next_pc += sizeof(struct unary_op); |
| 1948 | PO; |
| 1949 | } |
| 1950 | OP(BYTECODE_OP_UNARY_NOT_S64): |
| 1951 | { |
| 1952 | estack_ax_v = !estack_ax_v; |
| 1953 | estack_ax_t = REG_S64; |
| 1954 | next_pc += sizeof(struct unary_op); |
| 1955 | PO; |
| 1956 | } |
| 1957 | OP(BYTECODE_OP_UNARY_NOT_DOUBLE): |
| 1958 | { |
| 1959 | estack_ax_v = !estack_ax(stack, top)->u.d; |
| 1960 | estack_ax_t = REG_S64; |
| 1961 | next_pc += sizeof(struct unary_op); |
| 1962 | PO; |
| 1963 | } |
| 1964 | |
| 1965 | /* logical */ |
| 1966 | OP(BYTECODE_OP_AND): |
| 1967 | { |
| 1968 | struct logical_op *insn = (struct logical_op *) pc; |
| 1969 | |
| 1970 | if (estack_ax_t != REG_S64 && estack_ax_t != REG_U64) { |
| 1971 | ret = -EINVAL; |
| 1972 | goto end; |
| 1973 | } |
| 1974 | /* If AX is 0, skip and evaluate to 0 */ |
| 1975 | if (unlikely(estack_ax_v == 0)) { |
| 1976 | dbg_printf("Jumping to bytecode offset %u\n", |
| 1977 | (unsigned int) insn->skip_offset); |
| 1978 | next_pc = start_pc + insn->skip_offset; |
| 1979 | } else { |
| 1980 | /* Pop 1 when jump not taken */ |
| 1981 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 1982 | next_pc += sizeof(struct logical_op); |
| 1983 | } |
| 1984 | PO; |
| 1985 | } |
| 1986 | OP(BYTECODE_OP_OR): |
| 1987 | { |
| 1988 | struct logical_op *insn = (struct logical_op *) pc; |
| 1989 | |
| 1990 | if (estack_ax_t != REG_S64 && estack_ax_t != REG_U64) { |
| 1991 | ret = -EINVAL; |
| 1992 | goto end; |
| 1993 | } |
| 1994 | /* If AX is nonzero, skip and evaluate to 1 */ |
| 1995 | if (unlikely(estack_ax_v != 0)) { |
| 1996 | estack_ax_v = 1; |
| 1997 | dbg_printf("Jumping to bytecode offset %u\n", |
| 1998 | (unsigned int) insn->skip_offset); |
| 1999 | next_pc = start_pc + insn->skip_offset; |
| 2000 | } else { |
| 2001 | /* Pop 1 when jump not taken */ |
| 2002 | estack_pop(stack, top, ax, bx, ax_t, bx_t); |
| 2003 | next_pc += sizeof(struct logical_op); |
| 2004 | } |
| 2005 | PO; |
| 2006 | } |
| 2007 | |
| 2008 | |
| 2009 | /* load field ref */ |
| 2010 | OP(BYTECODE_OP_LOAD_FIELD_REF_STRING): |
| 2011 | { |
| 2012 | struct load_op *insn = (struct load_op *) pc; |
| 2013 | struct field_ref *ref = (struct field_ref *) insn->data; |
| 2014 | |
| 2015 | dbg_printf("load field ref offset %u type string\n", |
| 2016 | ref->offset); |
| 2017 | estack_push(stack, top, ax, bx, ax_t, bx_t); |
| 2018 | estack_ax(stack, top)->u.s.str = |
| 2019 | *(const char * const *) &interpreter_stack_data[ref->offset]; |
| 2020 | if (unlikely(!estack_ax(stack, top)->u.s.str)) { |
| 2021 | dbg_printf("Interpreter warning: loading a NULL string.\n"); |
| 2022 | ret = -EINVAL; |
| 2023 | goto end; |
| 2024 | } |
| 2025 | estack_ax(stack, top)->u.s.seq_len = SIZE_MAX; |
| 2026 | estack_ax(stack, top)->u.s.literal_type = |
| 2027 | ESTACK_STRING_LITERAL_TYPE_NONE; |
| 2028 | estack_ax_t = REG_STRING; |
| 2029 | dbg_printf("ref load string %s\n", estack_ax(stack, top)->u.s.str); |
| 2030 | next_pc += sizeof(struct load_op) + sizeof(struct field_ref); |
| 2031 | PO; |
| 2032 | } |
| 2033 | |
| 2034 | OP(BYTECODE_OP_LOAD_FIELD_REF_SEQUENCE): |
| 2035 | { |
| 2036 | struct load_op *insn = (struct load_op *) pc; |
| 2037 | struct field_ref *ref = (struct field_ref *) insn->data; |
| 2038 | |
| 2039 | dbg_printf("load field ref offset %u type sequence\n", |
| 2040 | ref->offset); |
| 2041 | estack_push(stack, top, ax, bx, ax_t, bx_t); |
| 2042 | estack_ax(stack, top)->u.s.seq_len = |
| 2043 | *(unsigned long *) &interpreter_stack_data[ref->offset]; |
| 2044 | estack_ax(stack, top)->u.s.str = |
| 2045 | *(const char **) (&interpreter_stack_data[ref->offset |
| 2046 | + sizeof(unsigned long)]); |
| 2047 | estack_ax_t = REG_STRING; |
| 2048 | if (unlikely(!estack_ax(stack, top)->u.s.str)) { |
| 2049 | dbg_printf("Interpreter warning: loading a NULL sequence.\n"); |
| 2050 | ret = -EINVAL; |
| 2051 | goto end; |
| 2052 | } |
| 2053 | estack_ax(stack, top)->u.s.literal_type = |
| 2054 | ESTACK_STRING_LITERAL_TYPE_NONE; |
| 2055 | next_pc += sizeof(struct load_op) + sizeof(struct field_ref); |
| 2056 | PO; |
| 2057 | } |
| 2058 | |
| 2059 | OP(BYTECODE_OP_LOAD_FIELD_REF_S64): |
| 2060 | { |
| 2061 | struct load_op *insn = (struct load_op *) pc; |
| 2062 | struct field_ref *ref = (struct field_ref *) insn->data; |
| 2063 | |
| 2064 | dbg_printf("load field ref offset %u type s64\n", |
| 2065 | ref->offset); |
| 2066 | estack_push(stack, top, ax, bx, ax_t, bx_t); |
| 2067 | estack_ax_v = |
| 2068 | ((struct literal_numeric *) &interpreter_stack_data[ref->offset])->v; |
| 2069 | estack_ax_t = REG_S64; |
| 2070 | dbg_printf("ref load s64 %" PRIi64 "\n", estack_ax_v); |
| 2071 | next_pc += sizeof(struct load_op) + sizeof(struct field_ref); |
| 2072 | PO; |
| 2073 | } |
| 2074 | |
| 2075 | OP(BYTECODE_OP_LOAD_FIELD_REF_DOUBLE): |
| 2076 | { |
| 2077 | struct load_op *insn = (struct load_op *) pc; |
| 2078 | struct field_ref *ref = (struct field_ref *) insn->data; |
| 2079 | |
| 2080 | dbg_printf("load field ref offset %u type double\n", |
| 2081 | ref->offset); |
| 2082 | estack_push(stack, top, ax, bx, ax_t, bx_t); |
| 2083 | memcpy(&estack_ax(stack, top)->u.d, &interpreter_stack_data[ref->offset], |
| 2084 | sizeof(struct literal_double)); |
| 2085 | estack_ax_t = REG_DOUBLE; |
| 2086 | dbg_printf("ref load double %g\n", estack_ax(stack, top)->u.d); |
| 2087 | next_pc += sizeof(struct load_op) + sizeof(struct field_ref); |
| 2088 | PO; |
| 2089 | } |
| 2090 | |
| 2091 | /* load from immediate operand */ |
| 2092 | OP(BYTECODE_OP_LOAD_STRING): |
| 2093 | { |
| 2094 | struct load_op *insn = (struct load_op *) pc; |
| 2095 | |
| 2096 | dbg_printf("load string %s\n", insn->data); |
| 2097 | estack_push(stack, top, ax, bx, ax_t, bx_t); |
| 2098 | estack_ax(stack, top)->u.s.str = insn->data; |
| 2099 | estack_ax(stack, top)->u.s.seq_len = SIZE_MAX; |
| 2100 | estack_ax(stack, top)->u.s.literal_type = |
| 2101 | ESTACK_STRING_LITERAL_TYPE_PLAIN; |
| 2102 | estack_ax_t = REG_STRING; |
| 2103 | next_pc += sizeof(struct load_op) + strlen(insn->data) + 1; |
| 2104 | PO; |
| 2105 | } |
| 2106 | |
| 2107 | OP(BYTECODE_OP_LOAD_STAR_GLOB_STRING): |
| 2108 | { |
| 2109 | struct load_op *insn = (struct load_op *) pc; |
| 2110 | |
| 2111 | dbg_printf("load globbing pattern %s\n", insn->data); |
| 2112 | estack_push(stack, top, ax, bx, ax_t, bx_t); |
| 2113 | estack_ax(stack, top)->u.s.str = insn->data; |
| 2114 | estack_ax(stack, top)->u.s.seq_len = SIZE_MAX; |
| 2115 | estack_ax(stack, top)->u.s.literal_type = |
| 2116 | ESTACK_STRING_LITERAL_TYPE_STAR_GLOB; |
| 2117 | estack_ax_t = REG_STAR_GLOB_STRING; |
| 2118 | next_pc += sizeof(struct load_op) + strlen(insn->data) + 1; |
| 2119 | PO; |
| 2120 | } |
| 2121 | |
| 2122 | OP(BYTECODE_OP_LOAD_S64): |
| 2123 | { |
| 2124 | struct load_op *insn = (struct load_op *) pc; |
| 2125 | |
| 2126 | estack_push(stack, top, ax, bx, ax_t, bx_t); |
| 2127 | estack_ax_v = ((struct literal_numeric *) insn->data)->v; |
| 2128 | estack_ax_t = REG_S64; |
| 2129 | dbg_printf("load s64 %" PRIi64 "\n", estack_ax_v); |
| 2130 | next_pc += sizeof(struct load_op) |
| 2131 | + sizeof(struct literal_numeric); |
| 2132 | PO; |
| 2133 | } |
| 2134 | |
| 2135 | OP(BYTECODE_OP_LOAD_DOUBLE): |
| 2136 | { |
| 2137 | struct load_op *insn = (struct load_op *) pc; |
| 2138 | |
| 2139 | estack_push(stack, top, ax, bx, ax_t, bx_t); |
| 2140 | memcpy(&estack_ax(stack, top)->u.d, insn->data, |
| 2141 | sizeof(struct literal_double)); |
| 2142 | estack_ax_t = REG_DOUBLE; |
| 2143 | dbg_printf("load double %g\n", estack_ax(stack, top)->u.d); |
| 2144 | next_pc += sizeof(struct load_op) |
| 2145 | + sizeof(struct literal_double); |
| 2146 | PO; |
| 2147 | } |
| 2148 | |
| 2149 | /* cast */ |
| 2150 | OP(BYTECODE_OP_CAST_TO_S64): |
| 2151 | { |
| 2152 | /* Dynamic typing. */ |
| 2153 | switch (estack_ax_t) { |
| 2154 | case REG_S64: |
| 2155 | JUMP_TO(BYTECODE_OP_CAST_NOP); |
| 2156 | case REG_DOUBLE: |
| 2157 | JUMP_TO(BYTECODE_OP_CAST_DOUBLE_TO_S64); |
| 2158 | case REG_U64: |
| 2159 | estack_ax_t = REG_S64; |
| 2160 | next_pc += sizeof(struct cast_op); |
| 2161 | case REG_STRING: /* Fall-through */ |
| 2162 | case REG_STAR_GLOB_STRING: |
| 2163 | ret = -EINVAL; |
| 2164 | goto end; |
| 2165 | default: |
| 2166 | ERR("Unknown interpreter register type (%d)", |
| 2167 | (int) estack_ax_t); |
| 2168 | ret = -EINVAL; |
| 2169 | goto end; |
| 2170 | } |
| 2171 | } |
| 2172 | |
| 2173 | OP(BYTECODE_OP_CAST_DOUBLE_TO_S64): |
| 2174 | { |
| 2175 | estack_ax_v = (int64_t) estack_ax(stack, top)->u.d; |
| 2176 | estack_ax_t = REG_S64; |
| 2177 | next_pc += sizeof(struct cast_op); |
| 2178 | PO; |
| 2179 | } |
| 2180 | |
| 2181 | OP(BYTECODE_OP_CAST_NOP): |
| 2182 | { |
| 2183 | next_pc += sizeof(struct cast_op); |
| 2184 | PO; |
| 2185 | } |
| 2186 | |
| 2187 | /* get context ref */ |
| 2188 | OP(BYTECODE_OP_GET_CONTEXT_REF): |
| 2189 | { |
| 2190 | struct load_op *insn = (struct load_op *) pc; |
| 2191 | struct field_ref *ref = (struct field_ref *) insn->data; |
| 2192 | struct lttng_ctx_field *ctx_field; |
| 2193 | struct lttng_ctx_value v; |
| 2194 | |
| 2195 | dbg_printf("get context ref offset %u type dynamic\n", |
| 2196 | ref->offset); |
| 2197 | ctx_field = &ctx->fields[ref->offset]; |
| 2198 | ctx_field->get_value(ctx_field, &v); |
| 2199 | estack_push(stack, top, ax, bx, ax_t, bx_t); |
| 2200 | switch (v.sel) { |
| 2201 | case LTTNG_UST_DYNAMIC_TYPE_NONE: |
| 2202 | ret = -EINVAL; |
| 2203 | goto end; |
| 2204 | case LTTNG_UST_DYNAMIC_TYPE_S64: |
| 2205 | estack_ax_v = v.u.s64; |
| 2206 | estack_ax_t = REG_S64; |
| 2207 | dbg_printf("ref get context dynamic s64 %" PRIi64 "\n", estack_ax_v); |
| 2208 | break; |
| 2209 | case LTTNG_UST_DYNAMIC_TYPE_DOUBLE: |
| 2210 | estack_ax(stack, top)->u.d = v.u.d; |
| 2211 | estack_ax_t = REG_DOUBLE; |
| 2212 | dbg_printf("ref get context dynamic double %g\n", estack_ax(stack, top)->u.d); |
| 2213 | break; |
| 2214 | case LTTNG_UST_DYNAMIC_TYPE_STRING: |
| 2215 | estack_ax(stack, top)->u.s.str = v.u.str; |
| 2216 | if (unlikely(!estack_ax(stack, top)->u.s.str)) { |
| 2217 | dbg_printf("Interpreter warning: loading a NULL string.\n"); |
| 2218 | ret = -EINVAL; |
| 2219 | goto end; |
| 2220 | } |
| 2221 | estack_ax(stack, top)->u.s.seq_len = SIZE_MAX; |
| 2222 | estack_ax(stack, top)->u.s.literal_type = |
| 2223 | ESTACK_STRING_LITERAL_TYPE_NONE; |
| 2224 | dbg_printf("ref get context dynamic string %s\n", estack_ax(stack, top)->u.s.str); |
| 2225 | estack_ax_t = REG_STRING; |
| 2226 | break; |
| 2227 | default: |
| 2228 | dbg_printf("Interpreter warning: unknown dynamic type (%d).\n", (int) v.sel); |
| 2229 | ret = -EINVAL; |
| 2230 | goto end; |
| 2231 | } |
| 2232 | next_pc += sizeof(struct load_op) + sizeof(struct field_ref); |
| 2233 | PO; |
| 2234 | } |
| 2235 | |
| 2236 | OP(BYTECODE_OP_GET_CONTEXT_REF_STRING): |
| 2237 | { |
| 2238 | struct load_op *insn = (struct load_op *) pc; |
| 2239 | struct field_ref *ref = (struct field_ref *) insn->data; |
| 2240 | struct lttng_ctx_field *ctx_field; |
| 2241 | struct lttng_ctx_value v; |
| 2242 | |
| 2243 | dbg_printf("get context ref offset %u type string\n", |
| 2244 | ref->offset); |
| 2245 | ctx_field = &ctx->fields[ref->offset]; |
| 2246 | ctx_field->get_value(ctx_field, &v); |
| 2247 | estack_push(stack, top, ax, bx, ax_t, bx_t); |
| 2248 | estack_ax(stack, top)->u.s.str = v.u.str; |
| 2249 | if (unlikely(!estack_ax(stack, top)->u.s.str)) { |
| 2250 | dbg_printf("Interpreter warning: loading a NULL string.\n"); |
| 2251 | ret = -EINVAL; |
| 2252 | goto end; |
| 2253 | } |
| 2254 | estack_ax(stack, top)->u.s.seq_len = SIZE_MAX; |
| 2255 | estack_ax(stack, top)->u.s.literal_type = |
| 2256 | ESTACK_STRING_LITERAL_TYPE_NONE; |
| 2257 | estack_ax_t = REG_STRING; |
| 2258 | dbg_printf("ref get context string %s\n", estack_ax(stack, top)->u.s.str); |
| 2259 | next_pc += sizeof(struct load_op) + sizeof(struct field_ref); |
| 2260 | PO; |
| 2261 | } |
| 2262 | |
| 2263 | OP(BYTECODE_OP_GET_CONTEXT_REF_S64): |
| 2264 | { |
| 2265 | struct load_op *insn = (struct load_op *) pc; |
| 2266 | struct field_ref *ref = (struct field_ref *) insn->data; |
| 2267 | struct lttng_ctx_field *ctx_field; |
| 2268 | struct lttng_ctx_value v; |
| 2269 | |
| 2270 | dbg_printf("get context ref offset %u type s64\n", |
| 2271 | ref->offset); |
| 2272 | ctx_field = &ctx->fields[ref->offset]; |
| 2273 | ctx_field->get_value(ctx_field, &v); |
| 2274 | estack_push(stack, top, ax, bx, ax_t, bx_t); |
| 2275 | estack_ax_v = v.u.s64; |
| 2276 | estack_ax_t = REG_S64; |
| 2277 | dbg_printf("ref get context s64 %" PRIi64 "\n", estack_ax_v); |
| 2278 | next_pc += sizeof(struct load_op) + sizeof(struct field_ref); |
| 2279 | PO; |
| 2280 | } |
| 2281 | |
| 2282 | OP(BYTECODE_OP_GET_CONTEXT_REF_DOUBLE): |
| 2283 | { |
| 2284 | struct load_op *insn = (struct load_op *) pc; |
| 2285 | struct field_ref *ref = (struct field_ref *) insn->data; |
| 2286 | struct lttng_ctx_field *ctx_field; |
| 2287 | struct lttng_ctx_value v; |
| 2288 | |
| 2289 | dbg_printf("get context ref offset %u type double\n", |
| 2290 | ref->offset); |
| 2291 | ctx_field = &ctx->fields[ref->offset]; |
| 2292 | ctx_field->get_value(ctx_field, &v); |
| 2293 | estack_push(stack, top, ax, bx, ax_t, bx_t); |
| 2294 | memcpy(&estack_ax(stack, top)->u.d, &v.u.d, sizeof(struct literal_double)); |
| 2295 | estack_ax_t = REG_DOUBLE; |
| 2296 | dbg_printf("ref get context double %g\n", estack_ax(stack, top)->u.d); |
| 2297 | next_pc += sizeof(struct load_op) + sizeof(struct field_ref); |
| 2298 | PO; |
| 2299 | } |
| 2300 | |
| 2301 | OP(BYTECODE_OP_GET_CONTEXT_ROOT): |
| 2302 | { |
| 2303 | dbg_printf("op get context root\n"); |
| 2304 | estack_push(stack, top, ax, bx, ax_t, bx_t); |
| 2305 | estack_ax(stack, top)->u.ptr.type = LOAD_ROOT_CONTEXT; |
| 2306 | /* "field" only needed for variants. */ |
| 2307 | estack_ax(stack, top)->u.ptr.field = NULL; |
| 2308 | estack_ax_t = REG_PTR; |
| 2309 | next_pc += sizeof(struct load_op); |
| 2310 | PO; |
| 2311 | } |
| 2312 | |
| 2313 | OP(BYTECODE_OP_GET_APP_CONTEXT_ROOT): |
| 2314 | { |
| 2315 | dbg_printf("op get app context root\n"); |
| 2316 | estack_push(stack, top, ax, bx, ax_t, bx_t); |
| 2317 | estack_ax(stack, top)->u.ptr.type = LOAD_ROOT_APP_CONTEXT; |
| 2318 | /* "field" only needed for variants. */ |
| 2319 | estack_ax(stack, top)->u.ptr.field = NULL; |
| 2320 | estack_ax_t = REG_PTR; |
| 2321 | next_pc += sizeof(struct load_op); |
| 2322 | PO; |
| 2323 | } |
| 2324 | |
| 2325 | OP(BYTECODE_OP_GET_PAYLOAD_ROOT): |
| 2326 | { |
| 2327 | dbg_printf("op get app payload root\n"); |
| 2328 | estack_push(stack, top, ax, bx, ax_t, bx_t); |
| 2329 | estack_ax(stack, top)->u.ptr.type = LOAD_ROOT_PAYLOAD; |
| 2330 | estack_ax(stack, top)->u.ptr.ptr = interpreter_stack_data; |
| 2331 | /* "field" only needed for variants. */ |
| 2332 | estack_ax(stack, top)->u.ptr.field = NULL; |
| 2333 | estack_ax_t = REG_PTR; |
| 2334 | next_pc += sizeof(struct load_op); |
| 2335 | PO; |
| 2336 | } |
| 2337 | |
| 2338 | OP(BYTECODE_OP_GET_SYMBOL): |
| 2339 | { |
| 2340 | dbg_printf("op get symbol\n"); |
| 2341 | switch (estack_ax(stack, top)->u.ptr.type) { |
| 2342 | case LOAD_OBJECT: |
| 2343 | ERR("Nested fields not implemented yet."); |
| 2344 | ret = -EINVAL; |
| 2345 | goto end; |
| 2346 | case LOAD_ROOT_CONTEXT: |
| 2347 | case LOAD_ROOT_APP_CONTEXT: |
| 2348 | case LOAD_ROOT_PAYLOAD: |
| 2349 | /* |
| 2350 | * symbol lookup is performed by |
| 2351 | * specialization. |
| 2352 | */ |
| 2353 | ret = -EINVAL; |
| 2354 | goto end; |
| 2355 | } |
| 2356 | next_pc += sizeof(struct load_op) + sizeof(struct get_symbol); |
| 2357 | PO; |
| 2358 | } |
| 2359 | |
| 2360 | OP(BYTECODE_OP_GET_SYMBOL_FIELD): |
| 2361 | { |
| 2362 | /* |
| 2363 | * Used for first variant encountered in a |
| 2364 | * traversal. Variants are not implemented yet. |
| 2365 | */ |
| 2366 | ret = -EINVAL; |
| 2367 | goto end; |
| 2368 | } |
| 2369 | |
| 2370 | OP(BYTECODE_OP_GET_INDEX_U16): |
| 2371 | { |
| 2372 | struct load_op *insn = (struct load_op *) pc; |
| 2373 | struct get_index_u16 *index = (struct get_index_u16 *) insn->data; |
| 2374 | |
| 2375 | dbg_printf("op get index u16\n"); |
| 2376 | ret = dynamic_get_index(ctx, bytecode, index->index, estack_ax(stack, top)); |
| 2377 | if (ret) |
| 2378 | goto end; |
| 2379 | estack_ax_v = estack_ax(stack, top)->u.v; |
| 2380 | estack_ax_t = estack_ax(stack, top)->type; |
| 2381 | next_pc += sizeof(struct load_op) + sizeof(struct get_index_u16); |
| 2382 | PO; |
| 2383 | } |
| 2384 | |
| 2385 | OP(BYTECODE_OP_GET_INDEX_U64): |
| 2386 | { |
| 2387 | struct load_op *insn = (struct load_op *) pc; |
| 2388 | struct get_index_u64 *index = (struct get_index_u64 *) insn->data; |
| 2389 | |
| 2390 | dbg_printf("op get index u64\n"); |
| 2391 | ret = dynamic_get_index(ctx, bytecode, index->index, estack_ax(stack, top)); |
| 2392 | if (ret) |
| 2393 | goto end; |
| 2394 | estack_ax_v = estack_ax(stack, top)->u.v; |
| 2395 | estack_ax_t = estack_ax(stack, top)->type; |
| 2396 | next_pc += sizeof(struct load_op) + sizeof(struct get_index_u64); |
| 2397 | PO; |
| 2398 | } |
| 2399 | |
| 2400 | OP(BYTECODE_OP_LOAD_FIELD): |
| 2401 | { |
| 2402 | dbg_printf("op load field\n"); |
| 2403 | ret = dynamic_load_field(estack_ax(stack, top)); |
| 2404 | if (ret) |
| 2405 | goto end; |
| 2406 | estack_ax_v = estack_ax(stack, top)->u.v; |
| 2407 | estack_ax_t = estack_ax(stack, top)->type; |
| 2408 | next_pc += sizeof(struct load_op); |
| 2409 | PO; |
| 2410 | } |
| 2411 | |
| 2412 | OP(BYTECODE_OP_LOAD_FIELD_S8): |
| 2413 | { |
| 2414 | dbg_printf("op load field s8\n"); |
| 2415 | |
| 2416 | estack_ax_v = *(int8_t *) estack_ax(stack, top)->u.ptr.ptr; |
| 2417 | estack_ax_t = REG_S64; |
| 2418 | next_pc += sizeof(struct load_op); |
| 2419 | PO; |
| 2420 | } |
| 2421 | OP(BYTECODE_OP_LOAD_FIELD_S16): |
| 2422 | { |
| 2423 | dbg_printf("op load field s16\n"); |
| 2424 | |
| 2425 | estack_ax_v = *(int16_t *) estack_ax(stack, top)->u.ptr.ptr; |
| 2426 | estack_ax_t = REG_S64; |
| 2427 | next_pc += sizeof(struct load_op); |
| 2428 | PO; |
| 2429 | } |
| 2430 | OP(BYTECODE_OP_LOAD_FIELD_S32): |
| 2431 | { |
| 2432 | dbg_printf("op load field s32\n"); |
| 2433 | |
| 2434 | estack_ax_v = *(int32_t *) estack_ax(stack, top)->u.ptr.ptr; |
| 2435 | estack_ax_t = REG_S64; |
| 2436 | next_pc += sizeof(struct load_op); |
| 2437 | PO; |
| 2438 | } |
| 2439 | OP(BYTECODE_OP_LOAD_FIELD_S64): |
| 2440 | { |
| 2441 | dbg_printf("op load field s64\n"); |
| 2442 | |
| 2443 | estack_ax_v = *(int64_t *) estack_ax(stack, top)->u.ptr.ptr; |
| 2444 | estack_ax_t = REG_S64; |
| 2445 | next_pc += sizeof(struct load_op); |
| 2446 | PO; |
| 2447 | } |
| 2448 | OP(BYTECODE_OP_LOAD_FIELD_U8): |
| 2449 | { |
| 2450 | dbg_printf("op load field u8\n"); |
| 2451 | |
| 2452 | estack_ax_v = *(uint8_t *) estack_ax(stack, top)->u.ptr.ptr; |
| 2453 | estack_ax_t = REG_U64; |
| 2454 | next_pc += sizeof(struct load_op); |
| 2455 | PO; |
| 2456 | } |
| 2457 | OP(BYTECODE_OP_LOAD_FIELD_U16): |
| 2458 | { |
| 2459 | dbg_printf("op load field u16\n"); |
| 2460 | |
| 2461 | estack_ax_v = *(uint16_t *) estack_ax(stack, top)->u.ptr.ptr; |
| 2462 | estack_ax_t = REG_U64; |
| 2463 | next_pc += sizeof(struct load_op); |
| 2464 | PO; |
| 2465 | } |
| 2466 | OP(BYTECODE_OP_LOAD_FIELD_U32): |
| 2467 | { |
| 2468 | dbg_printf("op load field u32\n"); |
| 2469 | |
| 2470 | estack_ax_v = *(uint32_t *) estack_ax(stack, top)->u.ptr.ptr; |
| 2471 | estack_ax_t = REG_U64; |
| 2472 | next_pc += sizeof(struct load_op); |
| 2473 | PO; |
| 2474 | } |
| 2475 | OP(BYTECODE_OP_LOAD_FIELD_U64): |
| 2476 | { |
| 2477 | dbg_printf("op load field u64\n"); |
| 2478 | |
| 2479 | estack_ax_v = *(uint64_t *) estack_ax(stack, top)->u.ptr.ptr; |
| 2480 | estack_ax_t = REG_U64; |
| 2481 | next_pc += sizeof(struct load_op); |
| 2482 | PO; |
| 2483 | } |
| 2484 | OP(BYTECODE_OP_LOAD_FIELD_DOUBLE): |
| 2485 | { |
| 2486 | dbg_printf("op load field double\n"); |
| 2487 | |
| 2488 | memcpy(&estack_ax(stack, top)->u.d, |
| 2489 | estack_ax(stack, top)->u.ptr.ptr, |
| 2490 | sizeof(struct literal_double)); |
| 2491 | estack_ax(stack, top)->type = REG_DOUBLE; |
| 2492 | next_pc += sizeof(struct load_op); |
| 2493 | PO; |
| 2494 | } |
| 2495 | |
| 2496 | OP(BYTECODE_OP_LOAD_FIELD_STRING): |
| 2497 | { |
| 2498 | const char *str; |
| 2499 | |
| 2500 | dbg_printf("op load field string\n"); |
| 2501 | str = (const char *) estack_ax(stack, top)->u.ptr.ptr; |
| 2502 | estack_ax(stack, top)->u.s.str = str; |
| 2503 | if (unlikely(!estack_ax(stack, top)->u.s.str)) { |
| 2504 | dbg_printf("Interpreter warning: loading a NULL string.\n"); |
| 2505 | ret = -EINVAL; |
| 2506 | goto end; |
| 2507 | } |
| 2508 | estack_ax(stack, top)->u.s.seq_len = SIZE_MAX; |
| 2509 | estack_ax(stack, top)->u.s.literal_type = |
| 2510 | ESTACK_STRING_LITERAL_TYPE_NONE; |
| 2511 | estack_ax(stack, top)->type = REG_STRING; |
| 2512 | next_pc += sizeof(struct load_op); |
| 2513 | PO; |
| 2514 | } |
| 2515 | |
| 2516 | OP(BYTECODE_OP_LOAD_FIELD_SEQUENCE): |
| 2517 | { |
| 2518 | const char *ptr; |
| 2519 | |
| 2520 | dbg_printf("op load field string sequence\n"); |
| 2521 | ptr = estack_ax(stack, top)->u.ptr.ptr; |
| 2522 | estack_ax(stack, top)->u.s.seq_len = *(unsigned long *) ptr; |
| 2523 | estack_ax(stack, top)->u.s.str = *(const char **) (ptr + sizeof(unsigned long)); |
| 2524 | estack_ax(stack, top)->type = REG_STRING; |
| 2525 | if (unlikely(!estack_ax(stack, top)->u.s.str)) { |
| 2526 | dbg_printf("Interpreter warning: loading a NULL sequence.\n"); |
| 2527 | ret = -EINVAL; |
| 2528 | goto end; |
| 2529 | } |
| 2530 | estack_ax(stack, top)->u.s.literal_type = |
| 2531 | ESTACK_STRING_LITERAL_TYPE_NONE; |
| 2532 | next_pc += sizeof(struct load_op); |
| 2533 | PO; |
| 2534 | } |
| 2535 | |
| 2536 | END_OP |
| 2537 | end: |
| 2538 | /* Return _DISCARD on error. */ |
| 2539 | if (ret) |
| 2540 | return LTTNG_INTERPRETER_DISCARD; |
| 2541 | |
| 2542 | if (output) { |
| 2543 | return lttng_bytecode_interpret_format_output(estack_ax(stack, top), |
| 2544 | output); |
| 2545 | } |
| 2546 | |
| 2547 | return retval; |
| 2548 | } |
| 2549 | |
| 2550 | uint64_t lttng_bytecode_filter_interpret(void *filter_data, |
| 2551 | const char *filter_stack_data) |
| 2552 | { |
| 2553 | return bytecode_interpret(filter_data, filter_stack_data, NULL); |
| 2554 | } |
| 2555 | |
| 2556 | uint64_t lttng_bytecode_capture_interpret(void *capture_data, |
| 2557 | const char *capture_stack_data, |
| 2558 | struct lttng_interpreter_output *output) |
| 2559 | { |
| 2560 | return bytecode_interpret(capture_data, capture_stack_data, |
| 2561 | (struct lttng_interpreter_output *) output); |
| 2562 | } |
| 2563 | |
| 2564 | #undef START_OP |
| 2565 | #undef OP |
| 2566 | #undef PO |
| 2567 | #undef END_OP |