svn commit: samba r21525 - in branches: SAMBA_3_0/source SAMBA_3_0/source/include SAMBA_3_0/source/lib SAMBA_3_0/source/nsswitch SAMBA_3_0_25/source SAMBA_3_0_25/source/include SAMBA_3_0_25/source/lib SAMBA_3_0_25/source/nsswitch

jerry at samba.org jerry at samba.org
Sat Feb 24 12:40:45 GMT 2007


Author: jerry
Date: 2007-02-24 12:40:43 +0000 (Sat, 24 Feb 2007)
New Revision: 21525

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=21525

Log:
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.



Modified:
   branches/SAMBA_3_0/source/configure.in
   branches/SAMBA_3_0/source/include/smb_macros.h
   branches/SAMBA_3_0/source/lib/system.c
   branches/SAMBA_3_0/source/lib/util.c
   branches/SAMBA_3_0/source/nsswitch/winbindd_cred_cache.c
   branches/SAMBA_3_0/source/nsswitch/winbindd_nss.h
   branches/SAMBA_3_0_25/source/configure.in
   branches/SAMBA_3_0_25/source/include/smb_macros.h
   branches/SAMBA_3_0_25/source/lib/system.c
   branches/SAMBA_3_0_25/source/lib/util.c
   branches/SAMBA_3_0_25/source/nsswitch/winbindd_cred_cache.c
   branches/SAMBA_3_0_25/source/nsswitch/winbindd_nss.h


Changeset:
Modified: branches/SAMBA_3_0/source/configure.in
===================================================================
--- branches/SAMBA_3_0/source/configure.in	2007-02-24 09:16:04 UTC (rev 21524)
+++ branches/SAMBA_3_0/source/configure.in	2007-02-24 12:40:43 UTC (rev 21525)
@@ -1240,6 +1240,7 @@
 AC_CHECK_FUNCS(setlocale nl_langinfo)
 AC_CHECK_FUNCS(nanosleep)
 AC_CHECK_FUNCS(mlock munlock mlockall munlockall)
+AC_CHECK_FUNCS(memalign posix_memalign)
 AC_CHECK_HEADERS(sys/mman.h)
 # setbuffer, shmget, shm_open are needed for smbtorture
 AC_CHECK_FUNCS(setbuffer shmget shm_open)

Modified: branches/SAMBA_3_0/source/include/smb_macros.h
===================================================================
--- branches/SAMBA_3_0/source/include/smb_macros.h	2007-02-24 09:16:04 UTC (rev 21524)
+++ branches/SAMBA_3_0/source/include/smb_macros.h	2007-02-24 12:40:43 UTC (rev 21525)
@@ -276,6 +276,7 @@
 *****************************************************************************/
 
 #define SMB_MALLOC_ARRAY(type,count) (type *)malloc_array(sizeof(type),(count))
+#define SMB_MEMALIGN_ARRAY(type,align,count) (type *)memalign_array(sizeof(type),align,(count))
 #define SMB_REALLOC(p,s) Realloc((p),(s),True)	/* Always frees p on error or s == 0 */
 #define SMB_REALLOC_KEEP_OLD_ON_ERROR(p,s) Realloc((p),(s),False) /* Never frees p on error or s == 0 */
 #define SMB_REALLOC_ARRAY(p,type,count) (type *)realloc_array((p),sizeof(type),(count),True) /* Always frees p on error or s == 0 */

Modified: branches/SAMBA_3_0/source/lib/system.c
===================================================================
--- branches/SAMBA_3_0/source/lib/system.c	2007-02-24 09:16:04 UTC (rev 21524)
+++ branches/SAMBA_3_0/source/lib/system.c	2007-02-24 12:40:43 UTC (rev 21525)
@@ -44,6 +44,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.
 ********************************************************************/
 

Modified: branches/SAMBA_3_0/source/lib/util.c
===================================================================
--- branches/SAMBA_3_0/source/lib/util.c	2007-02-24 09:16:04 UTC (rev 21524)
+++ branches/SAMBA_3_0/source/lib/util.c	2007-02-24 12:40:43 UTC (rev 21525)
@@ -913,6 +913,17 @@
 }
 
 /****************************************************************************
+ 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.
 ****************************************************************************/
 
@@ -954,6 +965,23 @@
 }
 
 /****************************************************************************
+ 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.
 ****************************************************************************/
 

Modified: branches/SAMBA_3_0/source/nsswitch/winbindd_cred_cache.c
===================================================================
--- branches/SAMBA_3_0/source/nsswitch/winbindd_cred_cache.c	2007-02-24 09:16:04 UTC (rev 21524)
+++ branches/SAMBA_3_0/source/nsswitch/winbindd_cred_cache.c	2007-02-24 12:40:43 UTC (rev 21525)
@@ -482,29 +482,21 @@
 		memcredp->len += strlen(pass)+1;
 	}
 
-	/* On non-linux platforms, mlock()'d memory must be aligned on
-	   a page boundary so allocate a bit more so we can offset
-	   enough */
+	/* On non-linux platforms, mlock()'d memory must be aligned */
 
-	memcredp->len += psize;
-			  
-	memcredp->buffer = (unsigned char*)TALLOC_ZERO(memcredp, memcredp->len);
-				  
-	if (!memcredp->buffer) {
+	memcredp->nt_hash = SMB_MEMALIGN_ARRAY(unsigned char*, psize, 
+					       memcredp->len);
+	if (!memcredp->nt_hash) {
 		return NT_STATUS_NO_MEMORY;
 	}
-				  
+	memset( memcredp->nt_hash, 0x0, memcredp->len );
 
-	/* point the nt_hash at the page boundary in the buffer */
-
-	memcredp->nt_hash = memcredp->buffer +
-		(psize - ((uint32)memcredp->buffer % psize));
 	memcredp->lm_hash = memcredp->nt_hash + NT_HASH_LEN;
 
 #ifdef DEBUG_PASSWORD
 	DEBUG(10,("mlocking memory: %p\n", memcredp->nt_hash));
 #endif		
-	if ((mlock(memcredp->nt_hash, memcredp->len-psize)) == -1) {
+	if ((mlock(memcredp->nt_hash, memcredp->len)) == -1) {
 		DEBUG(0,("failed to mlock memory: %s (%d)\n", 
 			strerror(errno), errno));
 		return map_nt_error_from_unix(errno);
@@ -536,15 +528,13 @@
 #if !defined(HAVE_MUNLOCK)
 	return NT_STATUS_OK;
 #else
-	int psize = getpagesize();	
-
-	if (munlock(memcredp->buffer, memcredp->len - psize) == -1) {
+	if (munlock(memcredp->nt_hash, memcredp->len) == -1) {
 		DEBUG(0,("failed to munlock memory: %s (%d)\n", 
 			strerror(errno), errno));
 		return map_nt_error_from_unix(errno);
 	}
-	memset(memcredp->buffer, '\0', memcredp->len);
-	TALLOC_FREE(memcredp->buffer);
+	memset(memcredp->nt_hash, '\0', memcredp->len);
+	SAFE_FREE(memcredp->nt_hash);
 	memcredp->nt_hash = NULL;
 	memcredp->lm_hash = NULL;
 	memcredp->pass = NULL;

Modified: branches/SAMBA_3_0/source/nsswitch/winbindd_nss.h
===================================================================
--- branches/SAMBA_3_0/source/nsswitch/winbindd_nss.h	2007-02-24 09:16:04 UTC (rev 21524)
+++ branches/SAMBA_3_0/source/nsswitch/winbindd_nss.h	2007-02-24 12:40:43 UTC (rev 21525)
@@ -469,8 +469,6 @@
 	uid_t uid;
 	int ref_count;
 	size_t len;
-	unsigned char *buffer;  /* buffer block containing the
-				   following 3 */
 	unsigned char *nt_hash; /* Base pointer for the following 2 */
 	unsigned char *lm_hash;
 	char *pass;

Modified: branches/SAMBA_3_0_25/source/configure.in
===================================================================
--- branches/SAMBA_3_0_25/source/configure.in	2007-02-24 09:16:04 UTC (rev 21524)
+++ branches/SAMBA_3_0_25/source/configure.in	2007-02-24 12:40:43 UTC (rev 21525)
@@ -1236,6 +1236,7 @@
 AC_CHECK_FUNCS(setlocale nl_langinfo)
 AC_CHECK_FUNCS(nanosleep)
 AC_CHECK_FUNCS(mlock munlock mlockall munlockall)
+AC_CHECK_FUNCS(memalign posix_memalign)
 AC_CHECK_HEADERS(sys/mman.h)
 # setbuffer, shmget, shm_open are needed for smbtorture
 AC_CHECK_FUNCS(setbuffer shmget shm_open)

Modified: branches/SAMBA_3_0_25/source/include/smb_macros.h
===================================================================
--- branches/SAMBA_3_0_25/source/include/smb_macros.h	2007-02-24 09:16:04 UTC (rev 21524)
+++ branches/SAMBA_3_0_25/source/include/smb_macros.h	2007-02-24 12:40:43 UTC (rev 21525)
@@ -276,6 +276,7 @@
 *****************************************************************************/
 
 #define SMB_MALLOC_ARRAY(type,count) (type *)malloc_array(sizeof(type),(count))
+#define SMB_MEMALIGN_ARRAY(type,align,count) (type *)memalign_array(sizeof(type),align,(count))
 #define SMB_REALLOC(p,s) Realloc((p),(s),True)	/* Always frees p on error or s == 0 */
 #define SMB_REALLOC_KEEP_OLD_ON_ERROR(p,s) Realloc((p),(s),False) /* Never frees p on error or s == 0 */
 #define SMB_REALLOC_ARRAY(p,type,count) (type *)realloc_array((p),sizeof(type),(count),True) /* Always frees p on error or s == 0 */

Modified: branches/SAMBA_3_0_25/source/lib/system.c
===================================================================
--- branches/SAMBA_3_0_25/source/lib/system.c	2007-02-24 09:16:04 UTC (rev 21524)
+++ branches/SAMBA_3_0_25/source/lib/system.c	2007-02-24 12:40:43 UTC (rev 21525)
@@ -44,6 +44,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.
 ********************************************************************/
 

Modified: branches/SAMBA_3_0_25/source/lib/util.c
===================================================================
--- branches/SAMBA_3_0_25/source/lib/util.c	2007-02-24 09:16:04 UTC (rev 21524)
+++ branches/SAMBA_3_0_25/source/lib/util.c	2007-02-24 12:40:43 UTC (rev 21525)
@@ -913,6 +913,17 @@
 }
 
 /****************************************************************************
+ 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.
 ****************************************************************************/
 
@@ -954,6 +965,23 @@
 }
 
 /****************************************************************************
+ 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.
 ****************************************************************************/
 

Modified: branches/SAMBA_3_0_25/source/nsswitch/winbindd_cred_cache.c
===================================================================
--- branches/SAMBA_3_0_25/source/nsswitch/winbindd_cred_cache.c	2007-02-24 09:16:04 UTC (rev 21524)
+++ branches/SAMBA_3_0_25/source/nsswitch/winbindd_cred_cache.c	2007-02-24 12:40:43 UTC (rev 21525)
@@ -482,29 +482,21 @@
 		memcredp->len += strlen(pass)+1;
 	}
 
-	/* On non-linux platforms, mlock()'d memory must be aligned on
-	   a page boundary so allocate a bit more so we can offset
-	   enough */
+	/* On non-linux platforms, mlock()'d memory must be aligned */
 
-	memcredp->len += psize;
-			  
-	memcredp->buffer = (unsigned char*)TALLOC_ZERO(memcredp, memcredp->len);
-				  
-	if (!memcredp->buffer) {
+	memcredp->nt_hash = SMB_MEMALIGN_ARRAY(unsigned char*, psize, 
+					       memcredp->len);
+	if (!memcredp->nt_hash) {
 		return NT_STATUS_NO_MEMORY;
 	}
-				  
+	memset( memcredp->nt_hash, 0x0, memcredp->len );
 
-	/* point the nt_hash at the page boundary in the buffer */
-
-	memcredp->nt_hash = memcredp->buffer +
-		(psize - ((uint32)memcredp->buffer % psize));
 	memcredp->lm_hash = memcredp->nt_hash + NT_HASH_LEN;
 
 #ifdef DEBUG_PASSWORD
 	DEBUG(10,("mlocking memory: %p\n", memcredp->nt_hash));
 #endif		
-	if ((mlock(memcredp->nt_hash, memcredp->len-psize)) == -1) {
+	if ((mlock(memcredp->nt_hash, memcredp->len)) == -1) {
 		DEBUG(0,("failed to mlock memory: %s (%d)\n", 
 			strerror(errno), errno));
 		return map_nt_error_from_unix(errno);
@@ -536,15 +528,13 @@
 #if !defined(HAVE_MUNLOCK)
 	return NT_STATUS_OK;
 #else
-	int psize = getpagesize();	
-
-	if (munlock(memcredp->buffer, memcredp->len - psize) == -1) {
+	if (munlock(memcredp->nt_hash, memcredp->len) == -1) {
 		DEBUG(0,("failed to munlock memory: %s (%d)\n", 
 			strerror(errno), errno));
 		return map_nt_error_from_unix(errno);
 	}
-	memset(memcredp->buffer, '\0', memcredp->len);
-	TALLOC_FREE(memcredp->buffer);
+	memset(memcredp->nt_hash, '\0', memcredp->len);
+	SAFE_FREE(memcredp->nt_hash);
 	memcredp->nt_hash = NULL;
 	memcredp->lm_hash = NULL;
 	memcredp->pass = NULL;

Modified: branches/SAMBA_3_0_25/source/nsswitch/winbindd_nss.h
===================================================================
--- branches/SAMBA_3_0_25/source/nsswitch/winbindd_nss.h	2007-02-24 09:16:04 UTC (rev 21524)
+++ branches/SAMBA_3_0_25/source/nsswitch/winbindd_nss.h	2007-02-24 12:40:43 UTC (rev 21525)
@@ -469,8 +469,6 @@
 	uid_t uid;
 	int ref_count;
 	size_t len;
-	unsigned char *buffer;  /* buffer block containing the
-				   following 3 */
 	unsigned char *nt_hash; /* Base pointer for the following 2 */
 	unsigned char *lm_hash;
 	char *pass;



More information about the samba-cvs mailing list