... | ... |
@@ -32,6 +32,7 @@ |
32 | 32 |
#include "clamav.h" |
33 | 33 |
#include "shared/optparser.h" |
34 | 34 |
#include "shared/misc.h" |
35 |
+#include "libclamav/dconf.h" |
|
35 | 36 |
|
36 | 37 |
#include <fcntl.h> |
37 | 38 |
#include <stdlib.h> |
... | ... |
@@ -224,7 +225,7 @@ int main(int argc, char *argv[]) |
224 | 224 |
if (optget(opts, "force-interpreter")->enabled) { |
225 | 225 |
bcs.engine = NULL; |
226 | 226 |
} else { |
227 |
- rc = cli_bytecode_init(&bcs); |
|
227 |
+ rc = cli_bytecode_init(&bcs, BYTECODE_ENGINE_MASK); |
|
228 | 228 |
if (rc != CL_SUCCESS) { |
229 | 229 |
fprintf(stderr,"Unable to init bytecode engine: %s\n", cl_strerror(rc)); |
230 | 230 |
optfree(opts); |
... | ... |
@@ -249,7 +250,7 @@ int main(int argc, char *argv[]) |
249 | 249 |
} else if (optget(opts, "printsrc")->enabled) { |
250 | 250 |
print_src(opts->filename[0]); |
251 | 251 |
} else { |
252 |
- rc = cli_bytecode_prepare(&bcs); |
|
252 |
+ rc = cli_bytecode_prepare(&bcs, BYTECODE_ENGINE_MASK); |
|
253 | 253 |
if (rc != CL_SUCCESS) { |
254 | 254 |
fprintf(stderr,"Unable to prepare bytecode: %s\n", cl_strerror(rc)); |
255 | 255 |
optfree(opts); |
... | ... |
@@ -24,6 +24,7 @@ |
24 | 24 |
#include "clamav-config.h" |
25 | 25 |
#endif |
26 | 26 |
|
27 |
+#include "dconf.h" |
|
27 | 28 |
#include "clamav.h" |
28 | 29 |
#include "others.h" |
29 | 30 |
#include "pe.h" |
... | ... |
@@ -1476,6 +1477,7 @@ void cli_bytecode_destroy(struct cli_bc *bc) |
1476 | 1476 |
static int cli_bytecode_prepare_interpreter(struct cli_bc *bc) |
1477 | 1477 |
{ |
1478 | 1478 |
unsigned i, j, k; |
1479 |
+ |
|
1479 | 1480 |
for (i=0;i<bc->num_func;i++) { |
1480 | 1481 |
struct cli_bc_func *bcfunc = &bc->funcs[i]; |
1481 | 1482 |
unsigned totValues = bcfunc->numValues + bcfunc->numConstants; |
... | ... |
@@ -1604,7 +1606,7 @@ static int cli_bytecode_prepare_interpreter(struct cli_bc *bc) |
1604 | 1604 |
return CL_SUCCESS; |
1605 | 1605 |
} |
1606 | 1606 |
|
1607 |
-int cli_bytecode_prepare(struct cli_all_bc *bcs) |
|
1607 |
+int cli_bytecode_prepare(struct cli_all_bc *bcs, unsigned dconfmask) |
|
1608 | 1608 |
{ |
1609 | 1609 |
unsigned i; |
1610 | 1610 |
int rc; |
... | ... |
@@ -1614,6 +1616,10 @@ int cli_bytecode_prepare(struct cli_all_bc *bcs) |
1614 | 1614 |
struct cli_bc *bc = &bcs->all_bcs[i]; |
1615 | 1615 |
if (bc->state == bc_interp || bc->state == bc_jit) |
1616 | 1616 |
continue; |
1617 |
+ if (!(dconfmask & BYTECODE_INTERPRETER)) { |
|
1618 |
+ cli_warnmsg("Bytecode needs interpreter, but interpreter is disabled\n"); |
|
1619 |
+ continue; |
|
1620 |
+ } |
|
1617 | 1621 |
rc = cli_bytecode_prepare_interpreter(bc); |
1618 | 1622 |
if (rc != CL_SUCCESS) |
1619 | 1623 |
return rc; |
... | ... |
@@ -1621,10 +1627,10 @@ int cli_bytecode_prepare(struct cli_all_bc *bcs) |
1621 | 1621 |
return CL_SUCCESS; |
1622 | 1622 |
} |
1623 | 1623 |
|
1624 |
-int cli_bytecode_init(struct cli_all_bc *allbc) |
|
1624 |
+int cli_bytecode_init(struct cli_all_bc *allbc, unsigned dconfmask) |
|
1625 | 1625 |
{ |
1626 | 1626 |
memset(allbc, 0, sizeof(*allbc)); |
1627 |
- return cli_bytecode_init_jit(allbc); |
|
1627 |
+ return cli_bytecode_init_jit(allbc, dconfmask); |
|
1628 | 1628 |
} |
1629 | 1629 |
|
1630 | 1630 |
int cli_bytecode_done(struct cli_all_bc *allbc) |
... | ... |
@@ -98,9 +98,9 @@ extern int have_clamjit; |
98 | 98 |
#ifdef __cplusplus |
99 | 99 |
} |
100 | 100 |
#endif |
101 |
-int cli_bytecode_init(struct cli_all_bc *allbc); |
|
101 |
+int cli_bytecode_init(struct cli_all_bc *allbc, unsigned dconfmask); |
|
102 | 102 |
int cli_bytecode_load(struct cli_bc *bc, FILE *f, struct cli_dbio *dbio, int security); |
103 |
-int cli_bytecode_prepare(struct cli_all_bc *allbc); |
|
103 |
+int cli_bytecode_prepare(struct cli_all_bc *allbc, unsigned dconfmask); |
|
104 | 104 |
int cli_bytecode_run(const struct cli_all_bc *bcs, const struct cli_bc *bc, struct cli_bc_ctx *ctx); |
105 | 105 |
void cli_bytecode_destroy(struct cli_bc *bc); |
106 | 106 |
int cli_bytecode_done(struct cli_all_bc *allbc); |
... | ... |
@@ -48,7 +48,7 @@ int cli_vm_execute_jit(const struct cli_all_bc *bcs, struct cli_bc_ctx *ctx, con |
48 | 48 |
return CL_EBYTECODE; |
49 | 49 |
} |
50 | 50 |
|
51 |
-int cli_bytecode_init_jit(struct cli_all_bc *allbc) |
|
51 |
+int cli_bytecode_init_jit(struct cli_all_bc *allbc, unsigned dconfmask) |
|
52 | 52 |
{ |
53 | 53 |
return CL_SUCCESS; |
54 | 54 |
} |
... | ... |
@@ -157,7 +157,7 @@ extern "C" { |
157 | 157 |
|
158 | 158 |
int cli_vm_execute_jit(const struct cli_all_bc *bcs, struct cli_bc_ctx *ctx, const struct cli_bc_func *func); |
159 | 159 |
int cli_bytecode_prepare_jit(struct cli_all_bc *bc); |
160 |
-int cli_bytecode_init_jit(struct cli_all_bc *bc); |
|
160 |
+int cli_bytecode_init_jit(struct cli_all_bc *bc, unsigned dconfmask); |
|
161 | 161 |
int cli_bytecode_done_jit(struct cli_all_bc *bc); |
162 | 162 |
|
163 | 163 |
#ifdef __cplusplus |
... | ... |
@@ -25,6 +25,7 @@ |
25 | 25 |
#include "llvm/ADT/BitVector.h" |
26 | 26 |
#include "llvm/ADT/StringMap.h" |
27 | 27 |
#include "llvm/ADT/StringSwitch.h" |
28 |
+#include "llvm/ADT/Triple.h" |
|
28 | 29 |
#include "llvm/CallingConv.h" |
29 | 30 |
#include "llvm/DerivedTypes.h" |
30 | 31 |
#include "llvm/Function.h" |
... | ... |
@@ -57,6 +58,7 @@ |
57 | 57 |
#include "llvm/Analysis/Verifier.h" |
58 | 58 |
#include "llvm/Transforms/Scalar.h" |
59 | 59 |
#include "llvm/System/ThreadLocal.h" |
60 |
+#include "dconf.h" |
|
60 | 61 |
#include <cstdlib> |
61 | 62 |
#include <csetjmp> |
62 | 63 |
#include <new> |
... | ... |
@@ -1480,12 +1482,47 @@ int bytecode_init(void) |
1480 | 1480 |
return 0; |
1481 | 1481 |
} |
1482 | 1482 |
|
1483 |
+extern "C" uint8_t cli_debug_flag; |
|
1483 | 1484 |
// Called once when loading a new set of BC files |
1484 |
-int cli_bytecode_init_jit(struct cli_all_bc *bcs) |
|
1485 |
+int cli_bytecode_init_jit(struct cli_all_bc *bcs, unsigned dconfmask) |
|
1485 | 1486 |
{ |
1486 | 1487 |
LLVMApiScopedLock scopedLock; |
1488 |
+ Triple triple(sys::getHostTriple()); |
|
1489 |
+ if (cli_debug_flag) |
|
1490 |
+ errs() << "host triple is: " << sys::getHostTriple() << "\n"; |
|
1491 |
+ enum Triple::ArchType arch = triple.getArch(); |
|
1492 |
+ switch (arch) { |
|
1493 |
+ case Triple::arm: |
|
1494 |
+ if (!(dconfmask & BYTECODE_JIT_ARM)) { |
|
1495 |
+ if (cli_debug_flag) |
|
1496 |
+ errs() << "host triple is: " << sys::getHostTriple() << "\n"; |
|
1497 |
+ return 0; |
|
1498 |
+ } |
|
1499 |
+ break; |
|
1500 |
+ case Triple::ppc: |
|
1501 |
+ case Triple::ppc64: |
|
1502 |
+ if (!(dconfmask & BYTECODE_JIT_PPC)) { |
|
1503 |
+ if (cli_debug_flag) |
|
1504 |
+ errs() << "JIT disabled for ppc\n"; |
|
1505 |
+ return 0; |
|
1506 |
+ } |
|
1507 |
+ break; |
|
1508 |
+ case Triple::x86: |
|
1509 |
+ case Triple::x86_64: |
|
1510 |
+ if (!(dconfmask & BYTECODE_JIT_X86)) { |
|
1511 |
+ if (cli_debug_flag) |
|
1512 |
+ errs() << "JIT disabled for x86\n"; |
|
1513 |
+ return 0; |
|
1514 |
+ } |
|
1515 |
+ break; |
|
1516 |
+ default: |
|
1517 |
+ errs() << "Not supported architecture for " << triple.str() << "\n"; |
|
1518 |
+ return CL_EBYTECODE; |
|
1519 |
+ } |
|
1520 |
+ |
|
1487 | 1521 |
std::string cpu = sys::getHostCPUName(); |
1488 |
- DEBUG(errs() << "host cpu is: " << cpu << "\n"); |
|
1522 |
+ if (cli_debug_flag) |
|
1523 |
+ errs() << "host cpu is: " << cpu << "\n"; |
|
1489 | 1524 |
if (!cpu.compare("i386") || |
1490 | 1525 |
!cpu.compare("i486")) { |
1491 | 1526 |
bcs->engine = 0; |
... | ... |
@@ -2564,7 +2564,7 @@ int cl_load(const char *path, struct cl_engine *engine, unsigned int *signo, uns |
2564 | 2564 |
return ret; |
2565 | 2565 |
|
2566 | 2566 |
if((dboptions & CL_DB_BYTECODE) && !engine->bcs.engine && (engine->dconf->bytecode & BYTECODE_ENGINE_MASK)) { |
2567 |
- if((ret = cli_bytecode_init(&engine->bcs))) |
|
2567 |
+ if((ret = cli_bytecode_init(&engine->bcs, engine->dconf->bytecode))) |
|
2568 | 2568 |
return ret; |
2569 | 2569 |
} else { |
2570 | 2570 |
cli_dbgmsg("Bytecode engine disabled\n"); |
... | ... |
@@ -2996,7 +2996,7 @@ int cl_engine_compile(struct cl_engine *engine) |
2996 | 2996 |
mpool_flush(engine->mempool); |
2997 | 2997 |
|
2998 | 2998 |
/* Compile bytecode */ |
2999 |
- if((ret = cli_bytecode_prepare(&engine->bcs))) { |
|
2999 |
+ if((ret = cli_bytecode_prepare(&engine->bcs, engine->dconf->bytecode))) { |
|
3000 | 3000 |
cli_errmsg("Unable to compile/load bytecode: %s\n", cl_strerror(ret)); |
3001 | 3001 |
return ret; |
3002 | 3002 |
} |
... | ... |
@@ -33,6 +33,7 @@ |
33 | 33 |
#include "../libclamav/others.h" |
34 | 34 |
#include "../libclamav/bytecode.h" |
35 | 35 |
#include "checks.h" |
36 |
+#include "../libclamav/dconf.h" |
|
36 | 37 |
|
37 | 38 |
static void runtest(const char *file, uint64_t expected, int fail, int nojit) |
38 | 39 |
{ |
... | ... |
@@ -51,7 +52,7 @@ static void runtest(const char *file, uint64_t expected, int fail, int nojit) |
51 | 51 |
cl_debug(); |
52 | 52 |
|
53 | 53 |
if (!nojit) { |
54 |
- rc = cli_bytecode_init(&bcs); |
|
54 |
+ rc = cli_bytecode_init(&bcs, BYTECODE_ENGINE_MASK); |
|
55 | 55 |
fail_unless(rc == CL_SUCCESS, "cli_bytecode_init failed"); |
56 | 56 |
} else { |
57 | 57 |
bcs.engine = NULL; |
... | ... |
@@ -64,7 +65,7 @@ static void runtest(const char *file, uint64_t expected, int fail, int nojit) |
64 | 64 |
fail_unless(rc == CL_SUCCESS, "cli_bytecode_load failed"); |
65 | 65 |
fclose(f); |
66 | 66 |
|
67 |
- rc = cli_bytecode_prepare(&bcs); |
|
67 |
+ rc = cli_bytecode_prepare(&bcs, BYTECODE_ENGINE_MASK); |
|
68 | 68 |
fail_unless(rc == CL_SUCCESS, "cli_bytecode_prepare failed"); |
69 | 69 |
|
70 | 70 |
if (have_clamjit && !nojit && nojit != -1) { |