From 56c1d7e5078ca6b79bb286f458956b5f49c83e81 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Sat, 24 Feb 2007 12:40:43 +0000 Subject: r21525: Go ahead and checkin the mlock() & memalign() fixes so others don't get stuck with the winbindd hang. Still waiting on additional confirmation from Guenther that this fixes thes issues he was observing as well. But it's been running in my local tree for a day without problems. (This used to be commit 0d2b80c6c4a744b05a0efdec352cddccc430e0c4) --- source3/lib/system.c | 21 +++++++++++++++++++++ source3/lib/util.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) (limited to 'source3/lib') diff --git a/source3/lib/system.c b/source3/lib/system.c index 9ee3f7cc26..5e70fb8ac5 100644 --- a/source3/lib/system.c +++ b/source3/lib/system.c @@ -43,6 +43,27 @@ +/******************************************************************* + A wrapper for memalign +********************************************************************/ + +void* sys_memalign( size_t align, size_t size ) +{ +#if defined(HAVE_MEMALIGN) + return memalign( align, size ); +#elif defined(HAVE_POSIX_MEMALIGN) + char *p = NULL; + int ret = posix_memalign( &p, align, size ); + if ( ret == 0 ) + return p; + + return NULL; +#else + DEBUG(0,("memalign functionalaity not available on this platform!\n")); + return NULL; +#endif +} + /******************************************************************* A wrapper for usleep in case we don't have one. ********************************************************************/ diff --git a/source3/lib/util.c b/source3/lib/util.c index 7d41a14292..5f9eb4fc45 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -912,6 +912,17 @@ void *malloc_(size_t size) #define malloc(s) __ERROR_DONT_USE_MALLOC_DIRECTLY } +/**************************************************************************** + Internal malloc wrapper. Externally visible. +****************************************************************************/ + +void *memalign_(size_t align, size_t size) +{ +#undef memalign + return memalign(align, size); +#define memalign(align, s) __ERROR_DONT_USE_MEMALIGN_DIRECTLY +} + /**************************************************************************** Internal calloc wrapper. Not externally visible. ****************************************************************************/ @@ -953,6 +964,23 @@ void *malloc_array(size_t el_size, unsigned int count) #endif } +/**************************************************************************** + Type-safe memalign +****************************************************************************/ + +void *memalign_array(size_t el_size, size_t align, unsigned int count) +{ + if (count >= MAX_ALLOC_SIZE/el_size) { + return NULL; + } + +#if defined(PARANOID_MALLOC_CHECKER) + return memalign_(align, el_size*count); +#else + return sys_memalign(align, el_size*count); +#endif +} + /**************************************************************************** Type-safe calloc. ****************************************************************************/ -- cgit