From bc157ce35714de4bdda39fd13a67f708f316cbc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=B6r=C3=B6k=20Edvin?= Date: Sat, 6 Mar 2010 16:00:54 +0200 Subject: [PATCH] prepare for reading globals from ctx --- libclamav/bytecode.c | 2 ++ libclamav/bytecode_priv.h | 2 ++ libclamav/bytecode_vm.c | 10 +++++++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/libclamav/bytecode.c b/libclamav/bytecode.c index b2219d5b4..dd5ebd057 100644 --- a/libclamav/bytecode.c +++ b/libclamav/bytecode.c @@ -67,6 +67,8 @@ struct cli_bc_ctx *cli_bytecode_context_alloc(void) ctx->line = 0; ctx->col = 0; ctx->mpool = NULL; + ctx->numGlobals = 0; + ctx->globals = NULL; return ctx; } diff --git a/libclamav/bytecode_priv.h b/libclamav/bytecode_priv.h index 860408479..2daa3f7d3 100644 --- a/libclamav/bytecode_priv.h +++ b/libclamav/bytecode_priv.h @@ -147,6 +147,8 @@ struct cli_bc_ctx { unsigned line; unsigned col; mpool_t *mpool; + uint32_t numGlobals; + uint8_t* globals; }; struct cli_all_bc; int cli_vm_execute(const struct cli_bc *bc, struct cli_bc_ctx *ctx, const struct cli_bc_func *func, const struct cli_bc_inst *inst); diff --git a/libclamav/bytecode_vm.c b/libclamav/bytecode_vm.c index 85d95e947..05c4522e8 100644 --- a/libclamav/bytecode_vm.c +++ b/libclamav/bytecode_vm.c @@ -262,7 +262,15 @@ static always_inline struct stack_entry *pop_stack(struct stack *stack, x = *(uint_type(n)*)&(from)[(p)];\ TRACE_R(x) -#define READN(x, n, p) READNfrom(func->numBytes, values, x, n, p) +#define READN(x, n, p)\ + do {\ + if (p&0x80000000) {\ + uint32_t pg = p&0x7fffffff;\ + READNfrom(ctx->numGlobals, ctx->globals, x, n, p);\ + } else {\ + READNfrom(func->numBytes, values, x, n, p);\ + }\ + } while (0) #define READ1(x, p) READN(x, 8, p);\ x = x&1