Maarten Lankhorst : ntdll: Use VALGRIND_RESIZEINPLACE_BLOCK when available.

Alexandre Julliard julliard at winehq.org
Tue Nov 15 13:17:31 CST 2011


Module: wine
Branch: master
Commit: d9889cfd632b0ac27026fdd92b5cae879bce62fd
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=d9889cfd632b0ac27026fdd92b5cae879bce62fd

Author: Maarten Lankhorst <m.b.lankhorst at gmail.com>
Date:   Fri Nov 11 22:12:25 2011 +0100

ntdll: Use VALGRIND_RESIZEINPLACE_BLOCK when available.

---

 dlls/ntdll/heap.c |   23 ++++++++++++++---------
 1 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/dlls/ntdll/heap.c b/dlls/ntdll/heap.c
index 022045f..6ca509a 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 +760,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 +1856,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 +1892,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-cvs mailing list