aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/Core/MemoryManager.cpp
diff options
context:
space:
mode:
authorMartin Nowack <martin@se.inf.tu-dresden.de>2016-03-22 17:16:38 +0100
committerMartin Nowack <martin@se.inf.tu-dresden.de>2016-07-08 22:54:54 +0200
commitea0c6724dc992a5358d6da3d50d9f60472d66d64 (patch)
tree63c186ee950792fb475dfda71db861d359c16efb /lib/Core/MemoryManager.cpp
parentf4363713c97769f392b7d85c4782f6e1aeb1a137 (diff)
downloadklee-ea0c6724dc992a5358d6da3d50d9f60472d66d64.tar.gz
Handle aligned varargs allignment correctly
For vararg handling, arguments of size bigger than 64 bit need to be handled 128bit aligned according to AMD calling conventions AMD64-ABI 3.5.7p5. To handle that case correctly, we do: 1) make sure that every argument is aligned correctly in an allocation for function arguments 2) the allocation itself is aligned correctly
Diffstat (limited to 'lib/Core/MemoryManager.cpp')
-rw-r--r--lib/Core/MemoryManager.cpp22
1 files changed, 17 insertions, 5 deletions
diff --git a/lib/Core/MemoryManager.cpp b/lib/Core/MemoryManager.cpp
index 7c76d480..02bbe678 100644
--- a/lib/Core/MemoryManager.cpp
+++ b/lib/Core/MemoryManager.cpp
@@ -32,13 +32,25 @@ MemoryManager::~MemoryManager() {
}
}
-MemoryObject *MemoryManager::allocate(uint64_t size, bool isLocal,
+MemoryObject *MemoryManager::allocate(uint64_t size, bool isLocal,
bool isGlobal,
- const llvm::Value *allocSite) {
+ const llvm::Value *allocSite,
+ size_t alignment) {
if (size>10*1024*1024)
- klee_warning_once(0, "Large alloc: %u bytes. KLEE may run out of memory.", (unsigned) size);
-
- uint64_t address = (uint64_t) (unsigned long) malloc((unsigned) size);
+ klee_warning_once(0, "Large alloc: %lu bytes. KLEE may run out of memory.",
+ size);
+
+ uint64_t address = 0;
+ // Use malloc for the standard case
+ if (alignment <= 8)
+ address = (uint64_t)malloc(size);
+ else {
+ int res = posix_memalign((void **)&address, alignment, size);
+ if (res < 0) {
+ klee_warning("Allocating aligned memory failed.");
+ address = 0;
+ }
+ }
if (!address)
return 0;