MCPcopy Create free account
hub / github.com/QBDI/QBDI / comparedExec

Method comparedExec

test/TestSetup/ShellcodeTester.cpp:37–85  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35}
36
37void ShellcodeTester::comparedExec(const char *source, QBDI::Context &inputCtx,
38 QBDI::rword stackSize) {
39 InMemoryObject object = compileWithContextSwitch(source);
40
41 QBDI::Context realCtx, jitCtx;
42 llvm::sys::MemoryBlock realStack = allocateStack(stackSize);
43 llvm::sys::MemoryBlock jitStack = allocateStack(stackSize);
44 REQUIRE(realStack.allocatedSize() == jitStack.allocatedSize());
45
46 const llvm::ArrayRef<uint8_t> &code = object.getCode();
47 llvm::sys::Memory::InvalidateInstructionCache(code.data(), code.size());
48
49 // use the same stack for the 2 executions
50 memset(jitStack.base(), 0, jitStack.allocatedSize());
51 realCtx = realExec(code, inputCtx, jitStack);
52 memcpy(realStack.base(), jitStack.base(), jitStack.allocatedSize());
53
54 memset(jitStack.base(), 0, jitStack.allocatedSize());
55 jitCtx = jitExec(code, inputCtx, jitStack);
56
57 for (uint32_t i = 0; i < QBDI::AVAILABLE_GPR; i++) {
58 INFO("The offset is " << i);
59 CHECK(QBDI_GPR_GET(&realCtx.gprState, i) ==
60 QBDI_GPR_GET(&jitCtx.gprState, i));
61 }
62
63#if defined(QBDI_ARCH_AARCH64)
64 for (uint32_t i = 0; i < QBDI_NUM_FPR; i++) {
65 INFO("The offset is " << i);
66 CHECK(((__uint128_t *)&realCtx.fprState)[i] ==
67 ((__uint128_t *)&jitCtx.fprState)[i]);
68 }
69#elif !defined(_QBDI_ASAN_ENABLED_) || !defined(QBDI_ARCH_X86_64)
70 for (uint32_t i = 0; i < sizeof(QBDI::FPRState); i++) {
71 INFO("The offset is " << i);
72 CHECK(((char *)&realCtx.fprState)[i] == ((char *)&jitCtx.fprState)[i]);
73 }
74#endif
75 for (uint32_t i = 0; i < realStack.allocatedSize() - sizeof(QBDI::rword);
76 i++) {
77 INFO("The offset is " << i << " / " << realStack.allocatedSize());
78 CHECK(((char *)realStack.base())[i] == ((char *)jitStack.base())[i]);
79 }
80
81 inputCtx = jitCtx;
82
83 freeStack(realStack);
84 freeStack(jitStack);
85}

Callers

nothing calls this directly

Calls 2

getCodeMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected