[Lldb-commits] [lldb] r154697 - /lldb/trunk/source/Target/Memory.cpp

Greg Clayton gclayton at apple.com
Fri Apr 13 13:37:20 PDT 2012


Author: gclayton
Date: Fri Apr 13 15:37:20 2012
New Revision: 154697

URL: http://llvm.org/viewvc/llvm-project?rev=154697&view=rev
Log:
<rdar://problem/11193466>

Fixed an error where lldb would hang when writing memory near the end of the addres space due to an unsigned overflow.


Modified:
    lldb/trunk/source/Target/Memory.cpp

Modified: lldb/trunk/source/Target/Memory.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Memory.cpp?rev=154697&r1=154696&r2=154697&view=diff
==============================================================================
--- lldb/trunk/source/Target/Memory.cpp (original)
+++ lldb/trunk/source/Target/Memory.cpp Fri Apr 13 15:37:20 2012
@@ -51,20 +51,31 @@
 {
     if (size == 0)
         return;
-    
-    const uint32_t cache_line_byte_size = m_cache_line_byte_size;
-    const addr_t end_addr = (addr + size - 1);
-    const addr_t flush_start_addr = addr - (addr % cache_line_byte_size);
-    const addr_t flush_end_addr = end_addr - (end_addr % cache_line_byte_size);
-    
+
     Mutex::Locker locker (m_mutex);
     if (m_cache.empty())
         return;
-    
-    assert ((flush_start_addr % cache_line_byte_size) == 0);
-    
-    for (addr_t curr_addr = flush_start_addr; curr_addr <= flush_end_addr; curr_addr += cache_line_byte_size)
+
+    const uint32_t cache_line_byte_size = m_cache_line_byte_size;
+    const addr_t end_addr = (addr + size - 1);
+    const addr_t first_cache_line_addr = addr - (addr % cache_line_byte_size);
+    const addr_t last_cache_line_addr = end_addr - (end_addr % cache_line_byte_size);
+    // Watch for overflow where size will cause us to go off the end of the
+    // 64 bit address space
+    uint32_t num_cache_lines;
+    if (last_cache_line_addr >= first_cache_line_addr)
+        num_cache_lines = ((last_cache_line_addr - first_cache_line_addr)/cache_line_byte_size) + 1;
+    else
+        num_cache_lines = (UINT64_MAX - first_cache_line_addr + 1)/cache_line_byte_size;
+
+    //printf ("MemoryCache::Flush (0x%16.16llx, %zu (0x%zx))\n", addr, size, size);
+
+    uint32_t cache_idx = 0;
+    for (addr_t curr_addr = first_cache_line_addr;
+         cache_idx < num_cache_lines;
+         curr_addr += cache_line_byte_size, ++cache_idx)
     {
+        //printf ("flushing: 0x%16.16llx\n", curr_addr); /// REMOVE THIS PRIOR TO CHECKIN!!!!
         BlockMap::iterator pos = m_cache.find (curr_addr);
         if (pos != m_cache.end())
             m_cache.erase(pos);





More information about the lldb-commits mailing list