[Lldb-commits] [lldb] r180614 - Change Malloc to request an aligned memory size.

Matt Kopec Matt.Kopec at intel.com
Fri Apr 26 10:48:01 PDT 2013


Author: mkopec
Date: Fri Apr 26 12:48:01 2013
New Revision: 180614

URL: http://llvm.org/viewvc/llvm-project?rev=180614&view=rev
Log:
Change Malloc to request an aligned memory size.

This fixes a problem on Linux where allocated memory would get overun in some use cases (ie. in TestExprs2.py).

Modified:
    lldb/trunk/source/Expression/IRMemoryMap.cpp

Modified: lldb/trunk/source/Expression/IRMemoryMap.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRMemoryMap.cpp?rev=180614&r1=180613&r2=180614&view=diff
==============================================================================
--- lldb/trunk/source/Expression/IRMemoryMap.cpp (original)
+++ lldb/trunk/source/Expression/IRMemoryMap.cpp Fri Apr 26 12:48:01 2013
@@ -235,8 +235,14 @@ IRMemoryMap::Malloc (size_t size, uint8_
     lldb::ProcessSP process_sp;
     lldb::addr_t    allocation_address  = LLDB_INVALID_ADDRESS;
     lldb::addr_t    aligned_address     = LLDB_INVALID_ADDRESS;
-    
-    size_t          allocation_size = (size ? size : 1) + alignment - 1;
+
+    size_t          alignment_mask = alignment - 1;
+    size_t          allocation_size;
+
+    if (size == 0)
+        allocation_size = alignment;
+    else
+        allocation_size = (size & alignment_mask) ? ((size + alignment) & (~alignment_mask)) : size;
     
     switch (policy)
     {
@@ -305,7 +311,7 @@ IRMemoryMap::Malloc (size_t size, uint8_
 
     m_allocations[aligned_address] = Allocation(allocation_address,
                                                 aligned_address,
-                                                size,
+                                                allocation_size,
                                                 permissions,
                                                 alignment,
                                                 policy);
@@ -331,7 +337,7 @@ IRMemoryMap::Malloc (size_t size, uint8_
         }
         
         log->Printf("IRMemoryMap::Malloc (%llu, 0x%llx, 0x%llx, %s) -> 0x%llx",
-                    (uint64_t)size,
+                    (uint64_t)allocation_size,
                     (uint64_t)alignment,
                     (uint64_t)permissions,
                     policy_string,





More information about the lldb-commits mailing list