[Pkg-clamav-commits] [SCM] Debian repository for ClamAV branch, debian/unstable, updated. debian/0.95+dfsg-1-6156-g094ec9b
Török Edvin
edwin at clamav.net
Sun Apr 4 01:02:28 UTC 2010
The following commit has been merged in the debian/unstable branch:
commit 85a25497bdd7c27ce1990fc9c237031d2d281ced
Author: Török Edvin <edwin at clamav.net>
Date: Thu Aug 27 20:41:29 2009 +0300
really execute the JITed code.
diff --git a/clambc/bcrun.c b/clambc/bcrun.c
index 1926ba7..954d5ee 100644
--- a/clambc/bcrun.c
+++ b/clambc/bcrun.c
@@ -146,7 +146,7 @@ int main(int argc, char *argv[])
}
}
- rc = cli_bytecode_run(bc, ctx);
+ rc = cli_bytecode_run(&bcs, bc, ctx);
if (rc != CL_SUCCESS) {
fprintf(stderr,"Unable to run bytecode: %s\n", cl_strerror(rc));
} else {
diff --git a/libclamav/bytecode.c b/libclamav/bytecode.c
index 1b8278a..a4f1375 100644
--- a/libclamav/bytecode.c
+++ b/libclamav/bytecode.c
@@ -1000,7 +1000,7 @@ int cli_bytecode_load(struct cli_bc *bc, FILE *f, struct cli_dbio *dbio)
return CL_SUCCESS;
}
-int cli_bytecode_run(const struct cli_bc *bc, struct cli_bc_ctx *ctx)
+int cli_bytecode_run(const struct cli_all_bc *bcs, const struct cli_bc *bc, struct cli_bc_ctx *ctx)
{
struct cli_bc_inst inst;
struct cli_bc_func func;
@@ -1012,24 +1012,24 @@ int cli_bytecode_run(const struct cli_bc *bc, struct cli_bc_ctx *ctx)
cli_errmsg("bytecode has to be prepared either for interpreter or JIT!\n");
return CL_EARG;
}
- memset(&func, 0, sizeof(func));
- func.numInsts = 1;
- func.numValues = 1;
- func.numBytes = ctx->bytes;
- memset(ctx->values+ctx->bytes-8, 0, 8);
+ if (bc->state == bc_interp) {
+ memset(&func, 0, sizeof(func));
+ func.numInsts = 1;
+ func.numValues = 1;
+ func.numBytes = ctx->bytes;
+ memset(ctx->values+ctx->bytes-8, 0, 8);
- inst.opcode = OP_CALL_DIRECT;
- inst.interp_op = OP_CALL_DIRECT*5;
- inst.dest = func.numArgs;
- inst.type = 0;
- inst.u.ops.numOps = ctx->numParams;
- inst.u.ops.funcid = ctx->funcid;
- inst.u.ops.ops = ctx->operands;
- inst.u.ops.opsizes = ctx->opsizes;
- if (bc->state == bc_interp)
+ inst.opcode = OP_CALL_DIRECT;
+ inst.interp_op = OP_CALL_DIRECT*5;
+ inst.dest = func.numArgs;
+ inst.type = 0;
+ inst.u.ops.numOps = ctx->numParams;
+ inst.u.ops.funcid = ctx->funcid;
+ inst.u.ops.ops = ctx->operands;
+ inst.u.ops.opsizes = ctx->opsizes;
return cli_vm_execute(ctx->bc, ctx, &func, &inst);
- else
- return cli_vm_execute_jit(ctx->bc, ctx, &func, &inst);
+ }
+ return cli_vm_execute_jit(bcs, ctx, &bc->funcs[ctx->funcid]);
}
uint64_t cli_bytecode_context_getresult_int(struct cli_bc_ctx *ctx)
diff --git a/libclamav/bytecode.h b/libclamav/bytecode.h
index 2f596d1..8d63c65 100644
--- a/libclamav/bytecode.h
+++ b/libclamav/bytecode.h
@@ -70,7 +70,7 @@ void cli_bytecode_context_destroy(struct cli_bc_ctx *ctx);
int cli_bytecode_init(struct cli_all_bc *allbc);
int cli_bytecode_load(struct cli_bc *bc, FILE *f, struct cli_dbio *dbio);
int cli_bytecode_prepare(struct cli_all_bc *allbc);
-int cli_bytecode_run(const struct cli_bc *bc, struct cli_bc_ctx *ctx);
+int cli_bytecode_run(const struct cli_all_bc *bcs, const struct cli_bc *bc, struct cli_bc_ctx *ctx);
void cli_bytecode_destroy(struct cli_bc *bc);
int cli_bytecode_done(struct cli_all_bc *allbc);
diff --git a/libclamav/bytecode2llvm.cpp b/libclamav/bytecode2llvm.cpp
index eb22100..d36e5ff 100644
--- a/libclamav/bytecode2llvm.cpp
+++ b/libclamav/bytecode2llvm.cpp
@@ -418,8 +418,14 @@ public:
};
}
-int cli_vm_execute_jit(const struct cli_bc *bc, struct cli_bc_ctx *ctx, const struct cli_bc_func *func, const struct cli_bc_inst *inst)
+int cli_vm_execute_jit(const struct cli_all_bc *bcs, struct cli_bc_ctx *ctx,
+ const struct cli_bc_func *func)
{
+ void *code = bcs->engine->compiledFunctions[func];
+ assert(code);
+ // execute;
+ uint32_t result = ((uint32_t (*)(void))code)();
+ *(uint32_t*)ctx->values = result;
return 0;
}
@@ -467,6 +473,9 @@ int cli_bytecode_prepare_jit(struct cli_all_bc *bcs)
}
}
+ for (unsigned i=0;i<bcs->count;i++) {
+ bcs->all_bcs[i].state = bc_jit;
+ }
// compile all functions now, not lazily!
for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I) {
Function *Fn = &*I;
diff --git a/libclamav/bytecode_priv.h b/libclamav/bytecode_priv.h
index 635640e..2bbc74a 100644
--- a/libclamav/bytecode_priv.h
+++ b/libclamav/bytecode_priv.h
@@ -103,7 +103,7 @@ int cli_vm_execute(const struct cli_bc *bc, struct cli_bc_ctx *ctx, const struct
extern "C" {
#endif
-int cli_vm_execute_jit(const struct cli_bc *bc, struct cli_bc_ctx *ctx, const struct cli_bc_func *func, const struct cli_bc_inst *inst);
+int cli_vm_execute_jit(const struct cli_all_bc *bcs, struct cli_bc_ctx *ctx, const struct cli_bc_func *func);
int cli_bytecode_prepare_jit(struct cli_all_bc *bc);
int cli_bytecode_init_jit(struct cli_all_bc *bc);
int cli_bytecode_done_jit(struct cli_all_bc *bc);
diff --git a/unit_tests/check_bytecode.c b/unit_tests/check_bytecode.c
index e52d95e..e12d2bf 100644
--- a/unit_tests/check_bytecode.c
+++ b/unit_tests/check_bytecode.c
@@ -67,7 +67,7 @@ static void runtest(const char *file, uint64_t expected)
fail_unless(!!ctx, "cli_bytecode_context_alloc failed");
cli_bytecode_context_setfuncid(ctx, &bc, 0);
- rc = cli_bytecode_run(&bc, ctx);
+ rc = cli_bytecode_run(&bcs, &bc, ctx);
fail_unless(rc == CL_SUCCESS, "cli_bytecode_run failed");
v = cli_bytecode_context_getresult_int(ctx);
--
Debian repository for ClamAV
More information about the Pkg-clamav-commits
mailing list