Fixed a problem in the JIT memory allocator where
authorSean Callanan <scallanan@apple.com>
Wed, 15 Aug 2012 20:53:52 +0000 (20:53 +0000)
committerSean Callanan <scallanan@apple.com>
Wed, 15 Aug 2012 20:53:52 +0000 (20:53 +0000)
allocations of executable memory would not be padded
to account for the size of the allocation header.
This resulted in undersized allocations, meaning that
when the allocation was written to later the next
allocation's header would be corrupted.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@161984 91177308-0d34-0410-b5e6-96231b3b80d8

lib/ExecutionEngine/JIT/JITMemoryManager.cpp

index 7be6ef8cba937fd10b0dd8bd521023ec2cfcc95f..61bc119d305bafb760bc5f27164bda4a5440ad73 100644 (file)
@@ -461,6 +461,9 @@ namespace {
     /// allocateCodeSection - Allocate memory for a code section.
     uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment,
                                  unsigned SectionID) {
+      // Grow the required block size to account for the block header
+      Size += sizeof(*CurBlock);
+
       // FIXME: Alignement handling.
       FreeRangeHeader* candidateBlock = FreeMemoryList;
       FreeRangeHeader* head = FreeMemoryList;