diff options
author | Daniel Schemmel <daniel@schemmel.net> | 2023-03-15 00:13:28 +0000 |
---|---|---|
committer | Frank Busse <f.busse@imperial.ac.uk> | 2023-03-16 11:57:59 +0000 |
commit | 9d0e072e3b40b720a26265f0d9b2b99f2d3a954e (patch) | |
tree | 23bbe4dca4432acbe1b52ae0861310ad1eec818f /lib/Core/ExecutionState.cpp | |
parent | 51655c601b3246457e27cf296284c049641c470c (diff) | |
download | klee-9d0e072e3b40b720a26265f0d9b2b99f2d3a954e.tar.gz |
Integrate KDAlloc into KLEE
Diffstat (limited to 'lib/Core/ExecutionState.cpp')
-rw-r--r-- | lib/Core/ExecutionState.cpp | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/lib/Core/ExecutionState.cpp b/lib/Core/ExecutionState.cpp index 5231f7fb..1c1f477c 100644 --- a/lib/Core/ExecutionState.cpp +++ b/lib/Core/ExecutionState.cpp @@ -70,10 +70,14 @@ StackFrame::~StackFrame() { /***/ -ExecutionState::ExecutionState(KFunction *kf) +ExecutionState::ExecutionState(KFunction *kf, MemoryManager *mm) : pc(kf->instructions), prevPC(pc) { pushFrame(nullptr, kf); setID(); + if (mm->stackFactory && mm->heapFactory) { + stackAllocator = mm->stackFactory.makeAllocator(); + heapAllocator = mm->heapFactory.makeAllocator(); + } } ExecutionState::~ExecutionState() { @@ -91,6 +95,8 @@ ExecutionState::ExecutionState(const ExecutionState& state): incomingBBIndex(state.incomingBBIndex), depth(state.depth), addressSpace(state.addressSpace), + stackAllocator(state.stackAllocator), + heapAllocator(state.heapAllocator), constraints(state.constraints), pathOS(state.pathOS), symPathOS(state.symPathOS), @@ -127,11 +133,25 @@ void ExecutionState::pushFrame(KInstIterator caller, KFunction *kf) { void ExecutionState::popFrame() { const StackFrame &sf = stack.back(); - for (const auto * memoryObject : sf.allocas) + for (const auto *memoryObject : sf.allocas) { + deallocate(memoryObject); addressSpace.unbindObject(memoryObject); + } stack.pop_back(); } +void ExecutionState::deallocate(const MemoryObject *mo) { + if (!stackAllocator || !heapAllocator) + return; + + auto address = reinterpret_cast<void *>(mo->address); + if (mo->isLocal) { + stackAllocator.free(address, std::max(mo->size, mo->alignment)); + } else { + heapAllocator.free(address, std::max(mo->size, mo->alignment)); + } +} + void ExecutionState::addSymbolic(const MemoryObject *mo, const Array *array) { symbolics.emplace_back(ref<const MemoryObject>(mo), array); } |