[PATCH] ntdll: Use VALGRIND_RESIZEINPLACE_BLOCK when available

Maarten Lankhorst m.b.lankhorst at gmail.com
Fri Nov 11 15:12:25 CST 2011


I'm not a valgrind expert, but seems valgrind can finally do realloc in place..
Use this capability, since the other thing is wrong, and won't work if --free-fill
or --malloc-fill is set.

Signed-off-by: Maarten Lankhorst <m.b.lankhorst at gmail.com>

---
diff --git a/dlls/ntdll/heap.c b/dlls/ntdll/heap.c
index 022045f..4f180cc 100644
--- a/dlls/ntdll/heap.c
+++ b/dlls/ntdll/heap.c
@@ -263,6 +263,13 @@ static inline void notify_free( void const *ptr )
 #endif
 }
 
+static inline void notify_realloc( void const *ptr, SIZE_T size_old, SIZE_T size_new )
+{
+#ifdef VALGRIND_RESIZEINPLACE_BLOCK
+    VALGRIND_RESIZEINPLACE_BLOCK( ptr, size_old, size_new, 0 );
+#endif
+}
+
 static void subheap_notify_free_all(SUBHEAP const *subheap)
 {
 #ifdef VALGRIND_FREELIKE_BLOCK
@@ -753,6 +759,11 @@ static void *realloc_large_block( HEAP *heap, DWORD flags, void *ptr, SIZE_T siz
         SIZE_T unused = arena->block_size - sizeof(*arena) - size;
 
         /* FIXME: we could remap zero-pages instead */
+#ifdef VALGRIND_RESIZEINPLACE_BLOCK
+        if (RUNNING_ON_VALGRIND) {
+            notify_realloc( arena + 1, arena->data_size, size );
+        } else
+#endif
         if (size > arena->data_size)
             initialize_block( (char *)ptr + arena->data_size, size - arena->data_size, unused, flags );
         else
@@ -1844,11 +1855,8 @@ PVOID WINAPI RtlReAllocateHeap( HANDLE heap, ULONG flags, PVOID ptr, SIZE_T size
             list_remove( &pFree->entry );
             pArena->size += (pFree->size & ARENA_SIZE_MASK) + sizeof(*pFree);
             if (!HEAP_Commit( subheap, pArena, rounded_size )) goto oom;
-            notify_free( pArena + 1 );
+            notify_realloc( pArena + 1, oldActualSize, size );
             HEAP_ShrinkBlock( subheap, pArena, rounded_size );
-            notify_alloc( pArena + 1, size, FALSE );
-            /* FIXME: this is wrong as we may lose old VBits settings */
-            mark_block_initialized( pArena + 1, oldActualSize );
         }
         else  /* Do it the hard way */
         {
@@ -1883,12 +1891,8 @@ PVOID WINAPI RtlReAllocateHeap( HANDLE heap, ULONG flags, PVOID ptr, SIZE_T size
     }
     else
     {
-        /* Shrink the block */
-        notify_free( pArena + 1 );
         HEAP_ShrinkBlock( subheap, pArena, rounded_size );
-        notify_alloc( pArena + 1, size, FALSE );
-        /* FIXME: this is wrong as we may lose old VBits settings */
-        mark_block_initialized( pArena + 1, size );
+        notify_realloc( pArena + 1, oldActualSize, size );
     }
 
     pArena->unused_bytes = (pArena->size & ARENA_SIZE_MASK) - size;





More information about the wine-patches mailing list