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