bytecode: prepare for implementing gep.

0.96
Török Edvin 16 years ago
parent 72617ba209
commit 7a14dc4ce9
  1. 31
      libclamav/bytecode.c
  2. 9
      libclamav/bytecode_vm.c
  3. 2
      libclamav/type_desc.h

@ -69,13 +69,16 @@ static unsigned typesize(const struct cli_bc *bc, uint16_t type)
return 4;
if (type <= 64)
return 8;
return 0;
return bc->types[type-65].size;
}
static unsigned typealign(const struct cli_bc *bc, uint16_t type)
{
unsigned size = typesize(bc, type);
return size ? size : 1;
if (type <= 64) {
unsigned size = typesize(bc, type);
return size ? size : 1;
}
return bc->types[type-65].align;
}
int cli_bytecode_context_setfuncid(struct cli_bc_ctx *ctx, const struct cli_bc *bc, unsigned funcid)
@ -456,6 +459,7 @@ static void add_static_types(struct cli_bc *bc)
bc->types[i].kind = PointerType;
bc->types[i].numElements = 1;
bc->types[i].containedTypes = &containedTy[i];
bc->types[i].size = bc->types[i].align = sizeof(void*);
}
}
@ -485,6 +489,7 @@ static int parseTypes(struct cli_bc *bc, unsigned char *buffer)
switch (t) {
case 1:
ty->kind = FunctionType;
ty->size = ty->align = sizeof(void*);
parseType(bc, ty, buffer, &offset, len, &ok);
if (!ok) {
cli_errmsg("Error parsing type %u\n", i);
@ -494,6 +499,7 @@ static int parseTypes(struct cli_bc *bc, unsigned char *buffer)
case 2:
case 3:
ty->kind = (t == 2) ? StructType : PackedStructType;
ty->size = ty->align = 0;/* TODO:calculate size/align of structs */
parseType(bc, ty, buffer, &offset, len, &ok);
if (!ok) {
cli_errmsg("Error parsing type %u\n", i);
@ -524,6 +530,12 @@ static int parseTypes(struct cli_bc *bc, unsigned char *buffer)
cli_errmsg("Error parsing type %u\n", i);
return CL_EMALFDB;
}
if (t == 5) {
ty->size = ty->align = sizeof(void);
} else {
ty->size = ty->numElements*typesize(bc, ty->containedTypes[0]);
ty->align = typealign(bc, ty->containedTypes[0]);
}
break;
default:
cli_errmsg("Invalid type kind: %u\n", t);
@ -1074,10 +1086,6 @@ static int cli_bytecode_prepare_interpreter(struct cli_bc *bc)
for (j=0;j<bcfunc->numValues;j++) {
uint16_t ty = bcfunc->types[j];
unsigned align;
if (ty > 64) {
cli_errmsg("Bytecode: non-integer types not yet implemented\n");
return CL_EMALFDB;
}
align = typealign(bc, ty);
bcfunc->numBytes = (bcfunc->numBytes + align-1)&(~(align-1));
map[j] = bcfunc->numBytes;
@ -1179,6 +1187,15 @@ static int cli_bytecode_prepare_interpreter(struct cli_bc *bc)
case OP_LOAD:
MAP(inst->u.unaryop);
break;
case OP_GEP1:
MAP(inst->u.binop[0]);
MAP(inst->u.binop[1]);
break;
case OP_GEP2:
MAP(inst->u.three[0]);
MAP(inst->u.three[1]);
MAP(inst->u.three[2]);
break;
default:
cli_dbgmsg("Unhandled opcode: %d\n", inst->opcode);
return CL_EBYTECODE;

@ -601,6 +601,10 @@ int cli_vm_execute(const struct cli_bc *bc, struct cli_bc_ctx *ctx, const struct
old_values = values;
stack_entry = allocate_stack(&stack, stack_entry, func2, func, inst->dest,
bb, bb_inst);
if (!stack_entry) {
stop = CL_EMEM;
break;
}
values = stack_entry->values;
TRACE_EXEC(inst->u.ops.funcid, inst->dest, inst->type, stack_depth);
if (stack_depth > 10000) {
@ -764,7 +768,7 @@ int cli_vm_execute(const struct cli_bc *bc, struct cli_bc_ctx *ctx, const struct
ptr->una_u64 = v;
break;
}
/* TODO: implement OP_GEP1, OP_GEP2, OP_GEPN */
default:
cli_errmsg("Opcode %u of type %u is not implemented yet!\n",
inst->interp_op/5, inst->interp_op%5);
@ -773,7 +777,8 @@ int cli_vm_execute(const struct cli_bc *bc, struct cli_bc_ctx *ctx, const struct
}
bb_inst++;
inst++;
CHECK_GT(bb->numInsts, bb_inst);
if (bb)
CHECK_GT(bb->numInsts, bb_inst);
} while (stop == CL_SUCCESS);
cli_stack_destroy(&stack);

@ -33,7 +33,9 @@ enum derived_t {
struct cli_bc_type {
enum derived_t kind;
uint16_t *containedTypes;
uint32_t size;
unsigned numElements;
unsigned align;
};
typedef int32_t (*cli_apicall_int2)(int32_t, int32_t);

Loading…
Cancel
Save