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