diff options
author | Michael Meeks <michael.meeks@novell.com> | 2010-10-08 16:36:18 +0100 |
---|---|---|
committer | Michael Meeks <michael.meeks@novell.com> | 2010-10-08 16:36:18 +0100 |
commit | c2b3d165d828353d97d90fbaa1fce74eb432d5bb (patch) | |
tree | 57ab9b953d5d7848043a64b1053c62d0791098c5 /sal/rtl | |
parent | 7eacf3ea5fe2efb92039301d687533fa042915ff (diff) |
Enable valgrind-ability with G_SLICE env. var
Dung out old, awful and pretty pointless valgrind solution involving
unpleasant LD_PRELOAD thing that doesn't ship, and/or work easily.
Diffstat (limited to 'sal/rtl')
-rw-r--r-- | sal/rtl/source/alloc.c | 157 | ||||
-rw-r--r-- | sal/rtl/source/makefile.mk | 19 |
2 files changed, 132 insertions, 44 deletions
diff --git a/sal/rtl/source/alloc.c b/sal/rtl/source/alloc.c index a694c6c34..5fdbec594 100644 --- a/sal/rtl/source/alloc.c +++ b/sal/rtl/source/alloc.c @@ -287,6 +287,38 @@ static sal_Size __rtl_memory_vmpagesize (void) /*=========================================================================== * + * Determine allocation mode (debug/release) by examining unix + * environment variable "G_SLICE" + * + *=========================================================================*/ + +#include <stdlib.h> /* getenv */ +#include <stdio.h> /* stderr */ + +typedef + enum { AMode_CUSTOM, AMode_SYSTEM, AMode_UNSET } + AllocMode; + +static AllocMode alloc_mode = AMode_UNSET; + +static void determine_alloc_mode ( void ) +{ + /* This shouldn't happen, but still ... */ + if (alloc_mode != AMode_UNSET) + return; + + if (getenv("G_SLICE") != NULL) { + alloc_mode = AMode_SYSTEM; + fprintf(stderr, "OOo: Using system memory allocator.\n"); + fprintf(stderr, "OOo: This is for debugging only. To disable,\n"); + fprintf(stderr, "OOo: unset the environment variable G_SLICE.\n"); + } else { + alloc_mode = AMode_CUSTOM; + } +} + +/*=========================================================================== + * * rtl_memory (global) internals. * *=========================================================================*/ @@ -1233,8 +1265,8 @@ static void __rtl_memory_enqueue (memory_type **ppMemory) /* * rtl_reallocateMemory. */ -#ifndef FORCE_SYSALLOC -void* SAL_CALL rtl_reallocateMemory (void * p, sal_Size n) SAL_THROW_EXTERN_C() +static +void* SAL_CALL rtl_reallocateMemory_CUSTOM (void * p, sal_Size n) SAL_THROW_EXTERN_C() { memory_type * memory; if (!(!p || !n)) @@ -1390,18 +1422,33 @@ void* SAL_CALL rtl_reallocateMemory (void * p, sal_Size n) SAL_THROW_EXTERN_C() } return (p); } -#else /* FORCE_SYSALLOC */ -void* SAL_CALL rtl_reallocateMemory (void * p, sal_Size n) SAL_THROW_EXTERN_C() + +static +void* SAL_CALL rtl_reallocateMemory_SYSTEM (void * p, sal_Size n) SAL_THROW_EXTERN_C() { return realloc(p, (sal_Size)(n)); } -#endif /* FORCE_SYSALLOC */ + +void* SAL_CALL rtl_reallocateMemory (void * p, sal_Size n) SAL_THROW_EXTERN_C() +{ + while (1) { + if (alloc_mode == AMode_CUSTOM) { + return rtl_reallocateMemory_CUSTOM(p,n); + } + if (alloc_mode == AMode_SYSTEM) { + return rtl_reallocateMemory_SYSTEM(p,n); + } + determine_alloc_mode(); + } +} + + /* * rtl_allocateMemory. */ -#ifndef FORCE_SYSALLOC -void* SAL_CALL rtl_allocateMemory (sal_Size n) SAL_THROW_EXTERN_C() +static +void* SAL_CALL rtl_allocateMemory_CUSTOM (sal_Size n) SAL_THROW_EXTERN_C() { void * p = 0; if (n > 0) @@ -1423,18 +1470,33 @@ void* SAL_CALL rtl_allocateMemory (sal_Size n) SAL_THROW_EXTERN_C() } return (p); } -#else /* FORCE_SYSALLOC */ -void* SAL_CALL rtl_allocateMemory (sal_Size n) SAL_THROW_EXTERN_C() + +static +void* SAL_CALL rtl_allocateMemory_SYSTEM (sal_Size n) SAL_THROW_EXTERN_C() { return malloc((sal_Size)(n)); } -#endif /* FORCE_SYSALLOC */ + +void* SAL_CALL rtl_allocateMemory (sal_Size n) SAL_THROW_EXTERN_C() +{ + while (1) { + if (alloc_mode == AMode_CUSTOM) { + return rtl_allocateMemory_CUSTOM(n); + } + if (alloc_mode == AMode_SYSTEM) { + return rtl_allocateMemory_SYSTEM(n); + } + determine_alloc_mode(); + } +} + + /* * rtl_freeMemory. */ -#ifndef FORCE_SYSALLOC -void SAL_CALL rtl_freeMemory (void * p) SAL_THROW_EXTERN_C() +static +void SAL_CALL rtl_freeMemory_CUSTOM (void * p) SAL_THROW_EXTERN_C() { if (p) { @@ -1455,18 +1517,34 @@ void SAL_CALL rtl_freeMemory (void * p) SAL_THROW_EXTERN_C() RTL_MEMORY_LEAVE(); } } -#else /* FORCE_SYSALLOC */ -void SAL_CALL rtl_freeMemory (void * p) SAL_THROW_EXTERN_C() + +static +void SAL_CALL rtl_freeMemory_SYSTEM (void * p) SAL_THROW_EXTERN_C() { free(p); } -#endif /* FORCE_SYSALLOC */ + +void SAL_CALL rtl_freeMemory (void * p) SAL_THROW_EXTERN_C() +{ + while (1) { + if (alloc_mode == AMode_CUSTOM) { + rtl_freeMemory_CUSTOM(p); + return; + } + if (alloc_mode == AMode_SYSTEM) { + rtl_freeMemory_SYSTEM(p); + return; + } + determine_alloc_mode(); + } +} + /* * rtl_allocateZeroMemory. */ -#ifndef FORCE_SYSALLOC -void* SAL_CALL rtl_allocateZeroMemory (sal_Size n) SAL_THROW_EXTERN_C() +static +void* SAL_CALL rtl_allocateZeroMemory_CUSTOM (sal_Size n) SAL_THROW_EXTERN_C() { void * p = 0; if (n > 0) @@ -1489,18 +1567,32 @@ void* SAL_CALL rtl_allocateZeroMemory (sal_Size n) SAL_THROW_EXTERN_C() } return (p); } -#else /* FORCE_SYSALLOC */ -void* SAL_CALL rtl_allocateZeroMemory (sal_Size n) SAL_THROW_EXTERN_C() + +static +void* SAL_CALL rtl_allocateZeroMemory_SYSTEM (sal_Size n) SAL_THROW_EXTERN_C() { return calloc((sal_Size)(n), 1); } -#endif /* FORCE_SYSALLOC */ + +void* SAL_CALL rtl_allocateZeroMemory (sal_Size n) SAL_THROW_EXTERN_C() +{ + while (1) { + if (alloc_mode == AMode_CUSTOM) { + return rtl_allocateZeroMemory_CUSTOM(n); + } + if (alloc_mode == AMode_SYSTEM) { + return rtl_allocateZeroMemory_SYSTEM(n); + } + determine_alloc_mode(); + } +} + /* * rtl_freeZeroMemory. */ -#ifndef FORCE_SYSALLOC -void SAL_CALL rtl_freeZeroMemory (void * p, sal_Size n) SAL_THROW_EXTERN_C() +static +void SAL_CALL rtl_freeZeroMemory_CUSTOM (void * p, sal_Size n) SAL_THROW_EXTERN_C() { (void) n; /* unused */ if (p) @@ -1523,8 +1615,9 @@ void SAL_CALL rtl_freeZeroMemory (void * p, sal_Size n) SAL_THROW_EXTERN_C() RTL_MEMORY_LEAVE(); } } -#else /* FORCE_SYSALLOC */ -void SAL_CALL rtl_freeZeroMemory (void * p, sal_Size n) SAL_THROW_EXTERN_C() + +static +void SAL_CALL rtl_freeZeroMemory_SYSTEM (void * p, sal_Size n) SAL_THROW_EXTERN_C() { if (p) { @@ -1532,7 +1625,21 @@ void SAL_CALL rtl_freeZeroMemory (void * p, sal_Size n) SAL_THROW_EXTERN_C() free(p); } } -#endif /* FORCE_SYSALLOC */ + +void SAL_CALL rtl_freeZeroMemory (void * p, sal_Size n) SAL_THROW_EXTERN_C() +{ + while (1) { + if (alloc_mode == AMode_CUSTOM) { + rtl_freeZeroMemory_CUSTOM(p,n); + return; + } + if (alloc_mode == AMode_SYSTEM) { + rtl_freeZeroMemory_SYSTEM(p,n); + return; + } + determine_alloc_mode(); + } +} /*=========================================================================== * diff --git a/sal/rtl/source/makefile.mk b/sal/rtl/source/makefile.mk index 9968d8992..517d2c2df 100644 --- a/sal/rtl/source/makefile.mk +++ b/sal/rtl/source/makefile.mk @@ -138,25 +138,6 @@ APP1OBJS=$(SLO)$/gen_makefile.obj APP1LIBSALCPPRT= APP1RPATH=NONE -# --- Extra objs ---------------------------------------------------- - -.IF "$(OS)"=="LINUX" || "$(OS)"=="OS2" - -# -# This part builds a second version of alloc.c, with -# FORCE_SYSALLOC defined. Is later used in util/makefile.mk -# to build a tiny replacement lib to LD_PRELOAD into the -# office, enabling e.g. proper valgrinding. -# - -SECOND_BUILD=SYSALLOC -SYSALLOC_SLOFILES= $(SLO)$/alloc_global.obj -SYSALLOCCDEFS+=-DFORCE_SYSALLOC - -.ENDIF # .IF "$(OS)"=="LINUX" - -#.ENDIF - .ENDIF # --- Makefile snippet -------------------------------------------- |