diff options
-rw-r--r-- | sal/prj/d.lst | 2 | ||||
-rw-r--r-- | sal/rtl/source/alloc.c | 157 | ||||
-rw-r--r-- | sal/rtl/source/makefile.mk | 19 | ||||
-rw-r--r-- | sal/util/makefile.mk | 24 | ||||
-rw-r--r-- | sal/util/salalloc.list | 7 | ||||
-rw-r--r-- | sal/util/salalloc.map | 10 |
6 files changed, 132 insertions, 87 deletions
diff --git a/sal/prj/d.lst b/sal/prj/d.lst index 3ce270bbb..d73af4a71 100644 --- a/sal/prj/d.lst +++ b/sal/prj/d.lst @@ -14,8 +14,6 @@ mkdir: %_DEST%\inc%_EXT%\systools\win32 ..\inc\systools\win32\*.h %_DEST%\inc%_EXT%\systools\win32\*.h ..\inc\systools\win32\*.hxx %_DEST%\inc%_EXT%\systools\win32\*.hxx -..\%__SRC%\lib\libsalalloc_malloc.so.3 %_DEST%\lib%_EXT%\libsalalloc_malloc.so.3 -symlink: %_DEST%\lib%_EXT%\libsalalloc_malloc.so.3 %_DEST%\lib%_EXT%\libsalalloc_malloc.so ..\%__SRC%\lib\libuno_sal.so.3 %_DEST%\lib%_EXT%\libuno_sal.so.3 symlink: %_DEST%\lib%_EXT%\libuno_sal.so.3 %_DEST%\lib%_EXT%\libuno_sal.so ..\%__SRC%\lib\libuno_sal.dylib.3 %_DEST%\lib%_EXT%\libuno_sal.dylib.3 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 -------------------------------------------- diff --git a/sal/util/makefile.mk b/sal/util/makefile.mk index 82ebbc811..1eab39a56 100644 --- a/sal/util/makefile.mk +++ b/sal/util/makefile.mk @@ -156,12 +156,6 @@ SHL1STDLIBS+=-lcrypt .ENDIF .ENDIF -# #i105898# required for LD_PRELOAD libsalalloc_malloc.so -# if sal is linked with -Bsymbolic-functions -.IF "$(HAVE_LD_BSYMBOLIC_FUNCTIONS)" == "TRUE" -SHL1LINKFLAGS+=-Wl,--dynamic-list=salalloc.list -.ENDIF # .IF "$(HAVE_LD_BSYMBOLIC_FUNCTIONS)" == "TRUE" - SHL1LIBS+=$(SLB)$/$(TARGET).lib .IF "$(linkinc)" != "" @@ -182,24 +176,6 @@ SHL1DEF= $(MISC)$/$(SHL1TARGET).def DEF1NAME= $(SHL1TARGET) -# -# This part builds a tiny extra lib, -# containing an alloc.c which uses system -# heap instead of our own mem management. -# This is e.g. useful for proper valgrinding -# the office. -# -.IF "$(OS)"=="LINUX" - -TARGET2 = salalloc_malloc -SHL2TARGET= $(TARGET2) -SHL2IMPLIB= i$(TARGET2) -SHL2VERSIONMAP= salalloc.map - -SHL2LIBS+=$(SLB)$/SYSALLOC_cpprtl.lib - -.ENDIF # .IF "$(OS)"=="LINUX" - # --- Coverage ----------------------------------------------------- # LLA: 20040304 The follows lines are an additional which is only need if we run # coverage tests. For normal test runs this feature is not used. diff --git a/sal/util/salalloc.list b/sal/util/salalloc.list deleted file mode 100644 index 303d225dd..000000000 --- a/sal/util/salalloc.list +++ /dev/null @@ -1,7 +0,0 @@ -{ - rtl_allocateMemory; - rtl_reallocateMemory; - rtl_freeMemory; - rtl_allocateZeroMemory; - rtl_freeZeroMemory; -}; diff --git a/sal/util/salalloc.map b/sal/util/salalloc.map deleted file mode 100644 index 3cd098b83..000000000 --- a/sal/util/salalloc.map +++ /dev/null @@ -1,10 +0,0 @@ -UDK_3_0_0 { - global: - rtl_allocateMemory; - rtl_reallocateMemory; - rtl_freeMemory; - rtl_allocateZeroMemory; - rtl_freeZeroMemory; - local: - *; -}; |