[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:23:41 UTC 2010
The following commit has been merged in the debian/unstable branch:
commit 52d0d8bc7e3965153daacf81c079b9574eb3dd08
Author: Török Edvin <edwin at clamav.net>
Date: Mon Mar 22 00:01:28 2010 +0200
More fixes for global vars in the interpreter.
diff --git a/libclamav/bytecode.c b/libclamav/bytecode.c
index 44cbb9a..2b9f63c 100644
--- a/libclamav/bytecode.c
+++ b/libclamav/bytecode.c
@@ -1461,10 +1461,16 @@ void cli_bytecode_destroy(struct cli_bc *bc)
}\
val = map[o]; } while (0)
+static inline int64_t ptr_compose(int32_t id, uint32_t offset)
+{
+ uint64_t i = id;
+ return (i << 32) | offset;
+}
+
static int cli_bytecode_prepare_interpreter(struct cli_bc *bc)
{
unsigned i, j, k;
- unsigned *gmap;
+ uint64_t *gmap;
bc->numGlobalBytes = 0;
gmap = cli_malloc(bc->num_globals*sizeof(*gmap));
if (!gmap)
@@ -1480,6 +1486,24 @@ static int cli_bytecode_prepare_interpreter(struct cli_bc *bc)
bc->globalBytes = cli_calloc(1, bc->numGlobalBytes);
if (!bc->globalBytes)
return CL_EMEM;
+ for (j=0;j<bc->num_globals;j++) {
+ struct cli_bc_type *ty;
+ if (bc->globaltys[j] < 65)
+ continue;
+ ty = &bc->types[bc->globaltys[j]-65];
+ switch (ty->kind) {
+ case DPointerType:
+ *(uint64_t*)&bc->globalBytes[gmap[j]] =
+ ptr_compose(bc->globals[j][1] - _FIRST_GLOBAL + 1,
+ bc->globals[j][0]);
+ break;
+ default:
+ /*TODO*/
+ if (!bc->globals[j][1])
+ continue; /* null */
+ break;
+ }
+ }
for (i=0;i<bc->num_func;i++) {
struct cli_bc_func *bcfunc = &bc->funcs[i];
diff --git a/libclamav/bytecode_vm.c b/libclamav/bytecode_vm.c
index c5c121f..101a124 100644
--- a/libclamav/bytecode_vm.c
+++ b/libclamav/bytecode_vm.c
@@ -272,7 +272,7 @@ static always_inline struct stack_entry *pop_stack(struct stack *stack,
do {\
if (p&0x80000000) {\
uint32_t pg = p&0x7fffffff;\
- READNfrom(bc->numGlobalBytes, bc->globals, x, n, pg);\
+ READNfrom(bc->numGlobalBytes, bc->globalBytes, x, n, pg);\
} else {\
READNfrom(func->numBytes, values, x, n, p);\
}\
@@ -287,7 +287,7 @@ static always_inline struct stack_entry *pop_stack(struct stack *stack,
#define PSIZE sizeof(int64_t)
#define READP(x, p, asize) { int64_t iptr__;\
- READN(iptr__, 8, p);\
+ READN(iptr__, 64, p);\
x = ptr_torealptr(&ptrinfos, iptr__, (asize));\
if (!x) {\
stop = CL_EBYTECODE;\
@@ -479,22 +479,29 @@ static inline int32_t ptr_register_stack(struct ptr_infos *infos,
return ptr_compose(-(n-1), 0);
}
-static inline int64_t ptr_register_glob(struct ptr_infos *infos,
- void *values, uint32_t size)
+static inline int64_t ptr_register_glob_fixedid(struct ptr_infos *infos,
+ void *values, uint32_t size, unsigned n)
{
- unsigned n = infos->nstacks + 1;
- struct ptr_info *sinfos = cli_realloc(infos->stack_infos,
- sizeof(*sinfos)*n);
- if (!sinfos)
- return 0;
- infos->stack_infos = sinfos;
- infos->nstacks = n;
- sinfos = &sinfos[n-1];
+ struct ptr_info *sinfos;
+ if (n > infos->nglobs) {
+ sinfos = cli_realloc(infos->glob_infos, sizeof(*sinfos)*n);
+ if (!sinfos)
+ return 0;
+ infos->glob_infos = sinfos;
+ infos->nglobs = n;
+ }
+ sinfos = &infos->glob_infos[n-1];
sinfos->base = values;
sinfos->size = size;
return ptr_compose(n, 0);
}
+static inline int64_t ptr_register_glob(struct ptr_infos *infos,
+ void *values, uint32_t size)
+{
+ return ptr_register_glob_fixedid(infos, values, size, infos->nglobs+1);
+}
+
static inline int64_t ptr_index(int64_t ptr, uint32_t off)
{
int32_t ptrid = ptr >> 32;
@@ -544,6 +551,29 @@ static always_inline int check_sdivops(int64_t op0, int64_t op1)
return op1 == 0 || (op0 == -1 && op1 == (-9223372036854775807LL-1LL));
}
+static unsigned globaltypesize(uint16_t id)
+{
+ const struct cli_bc_type *ty;
+ if (id <= 64)
+ return (id + 7)/8;
+ if (id <= 69)
+ return 8; /* ptr */
+ ty = &cli_apicall_types[id - 69];
+ switch (ty->kind) {
+ case DArrayType:
+ return ty->numElements*globaltypesize(ty->containedTypes[0]);
+ case DStructType:
+ case DPackedStructType:
+ {
+ unsigned i, s = 0;
+ for (i=0;i<ty->numElements;i++)
+ s += globaltypesize(ty->containedTypes[i]);
+ return s;
+ }
+ }
+ return 0;
+}
+
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)
{
unsigned i, j, stack_depth=0, bb_inst=0, stop=0, pc=0;
@@ -557,6 +587,13 @@ int cli_vm_execute(const struct cli_bc *bc, struct cli_bc_ctx *ctx, const struct
memset(&ptrinfos, 0, sizeof(ptrinfos));
memset(&stack, 0, sizeof(stack));
+ for (i=0;i < cli_apicall_maxglobal - _FIRST_GLOBAL; i++) {
+ const struct cli_apiglobal *g = &cli_globals[i];
+ void *apiglobal = (void*)(((char*)&ctx->hooks) + g->offset);
+ uint32_t size = globaltypesize(g->type);
+ ptr_register_glob_fixedid(&ptrinfos, apiglobal, size, g->globalid - _FIRST_GLOBAL+1);
+ }
+
do {
pc++;
switch (inst->interp_op) {
diff --git a/libclamav/c++/bytecode2llvm.cpp b/libclamav/c++/bytecode2llvm.cpp
index bdbd0b9..a30eeff 100644
--- a/libclamav/c++/bytecode2llvm.cpp
+++ b/libclamav/c++/bytecode2llvm.cpp
@@ -484,7 +484,6 @@ private:
Constant *buildConstant(const Type *Ty, uint64_t *components, unsigned &c)
{
if (const PointerType *PTy = dyn_cast<PointerType>(Ty)) {
-
Value *idxs[1] = {
ConstantInt::get(Type::getInt64Ty(Context), components[c++])
};
--
Debian repository for ClamAV
More information about the Pkg-clamav-commits
mailing list