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