diff options
author | Matthias Huetsch [mhu] <matthias.huetsch@oracle.com> | 2010-12-13 10:17:38 +0100 |
---|---|---|
committer | Matthias Huetsch [mhu] <matthias.huetsch@oracle.com> | 2010-12-13 10:17:38 +0100 |
commit | 340b22a09175abb796dc7df234962ef958b1ad6f (patch) | |
tree | 663b4034dc46444356b5466c686806dc4ca44338 /sal/rtl | |
parent | 232c0fb700efd31eff8cfee896437c481582ed0f (diff) |
#115784# sal/rtl/alloc: add support for valgrind(memcheck).
Diffstat (limited to 'sal/rtl')
-rw-r--r-- | sal/rtl/source/alloc_arena.c | 22 | ||||
-rw-r--r-- | sal/rtl/source/alloc_cache.c | 21 | ||||
-rw-r--r-- | sal/rtl/source/alloc_impl.h | 20 |
3 files changed, 53 insertions, 10 deletions
diff --git a/sal/rtl/source/alloc_arena.c b/sal/rtl/source/alloc_arena.c index 1a74c7e36cae..e2735cc014e4 100644 --- a/sal/rtl/source/alloc_arena.c +++ b/sal/rtl/source/alloc_arena.c @@ -28,22 +28,13 @@ #define _BSD_SOURCE /* sys/mman.h: MAP_ANON */ #include "alloc_arena.h" -#ifndef INCLUDED_RTL_ARENA_IMPL_H #include "alloc_impl.h" -#endif #include "internal/once.h" #include "sal/macros.h" #include "osl/diagnose.h" -#ifndef INCLUDED_STRING_H #include <string.h> -#endif - -#ifndef INCLUDED_STDIO_H #include <stdio.h> -#endif - -#include "sal/types.h" #ifdef OS2 #undef OSL_TRACE @@ -967,6 +958,7 @@ try_alloc: if (result != 0) { rtl_arena_type * arena = result; + VALGRIND_CREATE_MEMPOOL(arena, 0, 0); rtl_arena_constructor (arena); if (!source_arena) @@ -989,6 +981,7 @@ try_alloc: { rtl_arena_deactivate (arena); rtl_arena_destructor (arena); + VALGRIND_DESTROY_MEMPOOL(arena); rtl_arena_free (gp_arena_arena, arena, size); } } @@ -1014,6 +1007,7 @@ SAL_CALL rtl_arena_destroy ( { rtl_arena_deactivate (arena); rtl_arena_destructor (arena); + VALGRIND_DESTROY_MEMPOOL(arena); rtl_arena_free (gp_arena_arena, arena, sizeof(rtl_arena_type)); } } @@ -1069,6 +1063,9 @@ SAL_CALL rtl_arena_alloc ( rtl_arena_hash_insert (arena, segment); + OSL_DEBUG_ONLY(memset((void*)(segment->m_addr), 0x77777777, segment->m_size)); + VALGRIND_MEMPOOL_ALLOC(arena, segment->m_addr, segment->m_size); + (*pSize) = segment->m_size; addr = (void*)(segment->m_addr); } @@ -1112,6 +1109,10 @@ SAL_CALL rtl_arena_free ( { rtl_arena_segment_type *next, *prev; + /* DEBUG ONLY: mark undefined, unallocated */ + OSL_DEBUG_ONLY(memset((void*)(segment->m_addr), 0x33333333, segment->m_size)); + VALGRIND_MEMPOOL_FREE(arena, segment->m_addr); + /* coalesce w/ adjacent free segment(s) */ rtl_arena_segment_coalesce (arena, segment); @@ -1303,6 +1304,7 @@ rtl_arena_once_init (void) static rtl_arena_type g_machdep_arena; OSL_ASSERT(gp_machdep_arena == 0); + VALGRIND_CREATE_MEMPOOL(&g_machdep_arena, 0, 0); rtl_arena_constructor (&g_machdep_arena); gp_machdep_arena = rtl_arena_activate ( @@ -1319,6 +1321,7 @@ rtl_arena_once_init (void) static rtl_arena_type g_default_arena; OSL_ASSERT(gp_default_arena == 0); + VALGRIND_CREATE_MEMPOOL(&g_default_arena, 0, 0); rtl_arena_constructor (&g_default_arena); gp_default_arena = rtl_arena_activate ( @@ -1337,6 +1340,7 @@ rtl_arena_once_init (void) static rtl_arena_type g_arena_arena; OSL_ASSERT(gp_arena_arena == 0); + VALGRIND_CREATE_MEMPOOL(&g_arena_arena, 0, 0); rtl_arena_constructor (&g_arena_arena); gp_arena_arena = rtl_arena_activate ( diff --git a/sal/rtl/source/alloc_cache.c b/sal/rtl/source/alloc_cache.c index 629d19224522..db02c79d5ba7 100644 --- a/sal/rtl/source/alloc_cache.c +++ b/sal/rtl/source/alloc_cache.c @@ -507,6 +507,10 @@ rtl_cache_slab_alloc ( addr = (void*)rtl_cache_hash_insert (cache, bufctl); else addr = bufctl; + + /* DEBUG ONLY: mark undefined, allocated */ + OSL_DEBUG_ONLY(memset(addr, 0x77777777, cache->m_type_size)); + VALGRIND_MEMPOOL_ALLOC(cache, addr, cache->m_type_size); } RTL_MEMORY_LOCK_RELEASE(&(cache->m_slab_lock)); @@ -529,6 +533,11 @@ rtl_cache_slab_free ( RTL_MEMORY_LOCK_ACQUIRE(&(cache->m_slab_lock)); + /* DEBUG ONLY: mark unallocated, undefined */ + OSL_DEBUG_ONLY(memset(addr, 0x33333333, cache->m_type_size)); + VALGRIND_MEMPOOL_FREE(cache, addr); + VALGRIND_MAKE_MEM_UNDEFINED(addr, cache->m_type_size); + /* determine slab from addr */ if (cache->m_features & RTL_CACHE_FEATURE_HASH) { @@ -1126,6 +1135,7 @@ try_alloc: if (result != 0) { rtl_cache_type * cache = result; + VALGRIND_CREATE_MEMPOOL(cache, 0, 0); (void) rtl_cache_constructor (cache); if (!source) @@ -1153,6 +1163,7 @@ try_alloc: /* activation failed */ rtl_cache_deactivate (cache); rtl_cache_destructor (cache); + VALGRIND_DESTROY_MEMPOOL(cache); rtl_arena_free (gp_cache_arena, cache, size); } } @@ -1177,6 +1188,7 @@ void SAL_CALL rtl_cache_destroy ( { rtl_cache_deactivate (cache); rtl_cache_destructor (cache); + VALGRIND_DESTROY_MEMPOOL(cache); rtl_arena_free (gp_cache_arena, cache, sizeof(rtl_cache_type)); } } @@ -1206,6 +1218,7 @@ SAL_CALL rtl_cache_alloc ( if ((curr != 0) && (curr->m_mag_used > 0)) { obj = curr->m_objects[--curr->m_mag_used]; + VALGRIND_MEMPOOL_ALLOC(cache, obj, cache->m_type_size); cache->m_cpu_stats.m_alloc += 1; RTL_MEMORY_LOCK_RELEASE(&(cache->m_depot_lock)); @@ -1249,7 +1262,6 @@ SAL_CALL rtl_cache_alloc ( rtl_cache_slab_free (cache, obj), obj = 0; } } - return (obj); } @@ -1274,6 +1286,7 @@ SAL_CALL rtl_cache_free ( if ((curr != 0) && (curr->m_mag_used < curr->m_mag_size)) { curr->m_objects[curr->m_mag_used++] = obj; + VALGRIND_MEMPOOL_FREE(cache, obj); cache->m_cpu_stats.m_free += 1; RTL_MEMORY_LOCK_RELEASE(&(cache->m_depot_lock)); @@ -1587,6 +1600,7 @@ rtl_cache_once_init (void) static rtl_cache_type g_cache_magazine_cache; OSL_ASSERT(gp_cache_magazine_cache == 0); + VALGRIND_CREATE_MEMPOOL(&g_cache_magazine_cache, 0, 0); (void) rtl_cache_constructor (&g_cache_magazine_cache); gp_cache_magazine_cache = rtl_cache_activate ( @@ -1611,6 +1625,7 @@ rtl_cache_once_init (void) static rtl_cache_type g_cache_slab_cache; OSL_ASSERT(gp_cache_slab_cache == 0); + VALGRIND_CREATE_MEMPOOL(&g_cache_slab_cache, 0, 0); (void) rtl_cache_constructor (&g_cache_slab_cache); gp_cache_slab_cache = rtl_cache_activate ( @@ -1632,6 +1647,7 @@ rtl_cache_once_init (void) static rtl_cache_type g_cache_bufctl_cache; OSL_ASSERT(gp_cache_bufctl_cache == 0); + VALGRIND_CREATE_MEMPOOL(&g_cache_bufctl_cache, 0, 0); (void) rtl_cache_constructor (&g_cache_bufctl_cache); gp_cache_bufctl_cache = rtl_cache_activate ( @@ -1683,18 +1699,21 @@ rtl_cache_fini (void) cache = gp_cache_bufctl_cache, gp_cache_bufctl_cache = 0; rtl_cache_deactivate (cache); rtl_cache_destructor (cache); + VALGRIND_DESTROY_MEMPOOL(cache); } if (gp_cache_slab_cache != 0) { cache = gp_cache_slab_cache, gp_cache_slab_cache = 0; rtl_cache_deactivate (cache); rtl_cache_destructor (cache); + VALGRIND_DESTROY_MEMPOOL(cache); } if (gp_cache_magazine_cache != 0) { cache = gp_cache_magazine_cache, gp_cache_magazine_cache = 0; rtl_cache_deactivate (cache); rtl_cache_destructor (cache); + VALGRIND_DESTROY_MEMPOOL(cache); } if (gp_cache_arena != 0) { diff --git a/sal/rtl/source/alloc_impl.h b/sal/rtl/source/alloc_impl.h index d3d1924ddf91..fcebdf4369cc 100644 --- a/sal/rtl/source/alloc_impl.h +++ b/sal/rtl/source/alloc_impl.h @@ -240,6 +240,26 @@ typedef CRITICAL_SECTION rtl_memory_lock_type; #define RTL_CACHE_FLAG_QUANTUMCACHE (2 << 13) /* used as arena quantum cache */ +/** Valgrind support macros. + */ +#if !defined(HAVE_VALGRIND_MEMCHECK_H) || (OSL_DEBUG_LEVEL == 0) +#if !defined(NVALGRIND) +#define NVALGRIND 1 +#endif /* ! NVALGRIND */ +#endif /* ! HAVE_VALGRIND_MEMCHECK_H || (OSL_DEBUG_LEVEL == 0) */ + +#if defined(NVALGRIND) +#define VALGRIND_MAKE_MEM_UNDEFINED(addr, size) +#define VALGRIND_MALLOCLIKE_BLOCK(addr, sizeB, rzB, is_zeroed) +#define VALGRIND_FREELIKE_BLOCK(addr, rzB) +#define VALGRIND_CREATE_MEMPOOL(pool, rzB, is_zeroed) +#define VALGRIND_DESTROY_MEMPOOL(pool) +#define VALGRIND_MEMPOOL_ALLOC(pool, addr, size) +#define VALGRIND_MEMPOOL_FREE(pool, addr) +#elif defined(HAVE_VALGRIND_MEMCHECK_H) +#include <valgrind/memcheck.h> +#endif /* NVALGRIND || HAVE_VALGRIND_MEMCHECK_H */ + #ifdef __cplusplus } #endif |