The branch, master has been updated via 7e56602 s3-build Put memcache in a standalone library via 8c8ff2c s3-lib Move source3-specific malloc replacements into a seperate file via 52399f3 lib/util Move sys_memalign into lib/util/system.c via 38fee2b s3-smbd Fix conn_msg.c: Cannot return in a void function via 9d5b539 s3-lib Improve indentation of errmap_unix via 159fad9 s4-libcli Merge error map order with source3 errmap_unix.c via aa848c1 s3-lib: Use ARRAY_SIZE() to walk the error mapping tables from 8a75d73 winbindd.8: Fix typo
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master - Log ----------------------------------------------------------------- commit 7e5660282e94c969ac049eca5da7439982414010 Author: Andrew Bartlett <abart...@samba.org> Date: Tue May 31 10:45:08 2011 +1000 s3-build Put memcache in a standalone library Autobuild-User: Andrew Bartlett <abart...@samba.org> Autobuild-Date: Tue May 31 04:08:08 CEST 2011 on sn-devel-104 commit 8c8ff2cd6b597f7c4759cfaf178857ac533cc9ba Author: Andrew Bartlett <abart...@samba.org> Date: Tue May 31 10:42:30 2011 +1000 s3-lib Move source3-specific malloc replacements into a seperate file This will make it easier to create a dep tree for otherwise simple libraries. Andrew Bartlett commit 52399f3177515fce777d85288650ff89f9028dc9 Author: Andrew Bartlett <abart...@samba.org> Date: Tue May 31 10:41:42 2011 +1000 lib/util Move sys_memalign into lib/util/system.c commit 38fee2b521e1109e08510b286fccd056689ad33f Author: Andrew Bartlett <abart...@samba.org> Date: Tue May 31 10:23:42 2011 +1000 s3-smbd Fix conn_msg.c: Cannot return in a void function commit 9d5b53921d8d1f83f5456192bc4e0662d7e6a6bf Author: Andrew Bartlett <abart...@samba.org> Date: Tue May 31 09:16:35 2011 +1000 s3-lib Improve indentation of errmap_unix This also makes it easier to compare and contrast with the source4 version, because the differences here matter, and need to be resolved with care. Andrew Bartlett commit 159fad92d9f46acf41e9be35b8fa42ea51610426 Author: Andrew Bartlett <abart...@samba.org> Date: Tue May 31 09:08:43 2011 +1000 s4-libcli Merge error map order with source3 errmap_unix.c This makes it easier to see what the actual differences here are. Andrew Bartlett commit aa848c12eba441700557af78cb2ad23661d56f21 Author: Andrew Bartlett <abart...@samba.org> Date: Tue May 31 08:44:02 2011 +1000 s3-lib: Use ARRAY_SIZE() to walk the error mapping tables This gives a constant termination condition, and may help the compiler. Andrew Bartlett ----------------------------------------------------------------------- Summary of changes: lib/util/system.c | 39 +++++++++ lib/util/util.h | 2 + source3/Makefile.in | 2 +- source3/include/proto.h | 1 - source3/lib/errmap_unix.c | 82 +++++++++---------- source3/lib/system.c | 36 --------- source3/lib/util.c | 143 --------------------------------- source3/lib/util_malloc.c | 171 ++++++++++++++++++++++++++++++++++++++++ source3/smbd/conn_msg.c | 2 +- source3/wscript_build | 15 +++- source4/libcli/util/errormap.c | 54 +++++++------ 11 files changed, 295 insertions(+), 252 deletions(-) create mode 100644 source3/lib/util_malloc.c Changeset truncated at 500 lines: diff --git a/lib/util/system.c b/lib/util/system.c index 17c0553..1e80f1a 100644 --- a/lib/util/system.c +++ b/lib/util/system.c @@ -22,6 +22,8 @@ #include "system/network.h" #include "system/filesys.h" +#undef malloc + /* The idea is that this file will eventually have wrappers around all important system calls in samba. The aims are: @@ -37,6 +39,42 @@ expansions/etc make sense to the OS should be acceptable to Samba. */ +/******************************************************************* + A wrapper for memalign +********************************************************************/ + +void *sys_memalign( size_t align, size_t size ) +{ +#if defined(HAVE_POSIX_MEMALIGN) + void *p = NULL; + int ret = posix_memalign( &p, align, size ); + if ( ret == 0 ) + return p; + + return NULL; +#elif defined(HAVE_MEMALIGN) + return memalign( align, size ); +#else + /* On *BSD systems memaligns doesn't exist, but memory will + * be aligned on allocations of > pagesize. */ +#if defined(SYSCONF_SC_PAGESIZE) + size_t pagesize = (size_t)sysconf(_SC_PAGESIZE); +#elif defined(HAVE_GETPAGESIZE) + size_t pagesize = (size_t)getpagesize(); +#else + size_t pagesize = (size_t)-1; +#endif + if (pagesize == (size_t)-1) { + DEBUG(0,("memalign functionalaity not available on this platform!\n")); + return NULL; + } + if (size < pagesize) { + size = pagesize; + } + return malloc(size); +#endif +} + /************************************************************************** A wrapper for gethostbyname() that tries avoids looking up hostnames in the root domain, which can cause dial-on-demand links to come up for no @@ -189,3 +227,4 @@ _PUBLIC_ int sys_connect(int fd, const struct sockaddr * addr) return connect(fd, addr, salen); } + diff --git a/lib/util/util.h b/lib/util/util.h index 93b181b..d1c5e82 100644 --- a/lib/util/util.h +++ b/lib/util/util.h @@ -115,6 +115,8 @@ void CatchChildLeaveStatus(void); /* The following definitions come from lib/util/system.c */ +void *sys_memalign( size_t align, size_t size ); + /************************************************************************** A wrapper for gethostbyname() that tries avoids looking up hostnames in the root domain, which can cause dial-on-demand links to come up for no diff --git a/source3/Makefile.in b/source3/Makefile.in index 7fbefda..c768a40 100644 --- a/source3/Makefile.in +++ b/source3/Makefile.in @@ -462,7 +462,7 @@ LIB_OBJ = $(LIBSAMBAUTIL_OBJ) $(UTIL_OBJ) $(CRYPTO_OBJ) \ ../lib/util/base64.o lib/util_sid.o \ ../lib/util/charset/util_unistr.o \ ../lib/util/charset/util_unistr_w.o ../lib/util/charset/codepoints.o ../lib/util/charset/util_str.o lib/util_file.o \ - lib/util.o lib/namearray.o lib/util_cmdline.o lib/util_names.o \ + lib/util.o lib/util_malloc.o lib/namearray.o lib/util_cmdline.o lib/util_names.o \ lib/util_sock.o lib/sock_exec.o lib/util_sec.o \ lib/substitute.o lib/substitute_generic.o ../lib/util/substitute.o lib/dbwrap_util.o \ lib/ms_fnmatch.o ../lib/util/ms_fnmatch.o lib/errmap_unix.o \ diff --git a/source3/include/proto.h b/source3/include/proto.h index 1f09461..23654e1 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -352,7 +352,6 @@ int sys_set_nfs_quota(const char *path, const char *bdev, /* The following definitions come from lib/system.c */ -void *sys_memalign( size_t align, size_t size ); int sys_usleep(long usecs); ssize_t sys_read(int fd, void *buf, size_t count); ssize_t sys_write(int fd, const void *buf, size_t count); diff --git a/source3/lib/errmap_unix.c b/source3/lib/errmap_unix.c index f0ae217..8de397c 100644 --- a/source3/lib/errmap_unix.c +++ b/source3/lib/errmap_unix.c @@ -28,90 +28,89 @@ static const struct { int unix_error; NTSTATUS nt_error; } unix_nt_errmap[] = { - { EPERM, NT_STATUS_ACCESS_DENIED }, - { EACCES, NT_STATUS_ACCESS_DENIED }, - { ENOENT, NT_STATUS_OBJECT_NAME_NOT_FOUND }, - { ENOTDIR, NT_STATUS_NOT_A_DIRECTORY }, - { EIO, NT_STATUS_IO_DEVICE_ERROR }, - { EBADF, NT_STATUS_INVALID_HANDLE }, - { EINVAL, NT_STATUS_INVALID_PARAMETER }, - { EEXIST, NT_STATUS_OBJECT_NAME_COLLISION}, - { ENFILE, NT_STATUS_TOO_MANY_OPENED_FILES }, - { EMFILE, NT_STATUS_TOO_MANY_OPENED_FILES }, - { ENOSPC, NT_STATUS_DISK_FULL }, - { ENOMEM, NT_STATUS_NO_MEMORY }, - { EISDIR, NT_STATUS_FILE_IS_A_DIRECTORY}, - { EMLINK, NT_STATUS_TOO_MANY_LINKS }, - { EINTR, NT_STATUS_RETRY }, - { ENOSYS, NT_STATUS_NOT_SUPPORTED }, + { EPERM, NT_STATUS_ACCESS_DENIED }, + { EACCES, NT_STATUS_ACCESS_DENIED }, + { ENOENT, NT_STATUS_OBJECT_NAME_NOT_FOUND }, + { ENOTDIR, NT_STATUS_NOT_A_DIRECTORY }, + { EIO, NT_STATUS_IO_DEVICE_ERROR }, + { EBADF, NT_STATUS_INVALID_HANDLE }, + { EINVAL, NT_STATUS_INVALID_PARAMETER }, + { EEXIST, NT_STATUS_OBJECT_NAME_COLLISION}, + { ENFILE, NT_STATUS_TOO_MANY_OPENED_FILES }, + { EMFILE, NT_STATUS_TOO_MANY_OPENED_FILES }, + { ENOSPC, NT_STATUS_DISK_FULL }, + { ENOMEM, NT_STATUS_NO_MEMORY }, + { EISDIR, NT_STATUS_FILE_IS_A_DIRECTORY}, + { EMLINK, NT_STATUS_TOO_MANY_LINKS }, + { EINTR, NT_STATUS_RETRY }, + { ENOSYS, NT_STATUS_NOT_SUPPORTED }, #ifdef ELOOP - { ELOOP, NT_STATUS_OBJECT_PATH_NOT_FOUND }, + { ELOOP, NT_STATUS_OBJECT_PATH_NOT_FOUND }, #endif #ifdef EFTYPE - { EFTYPE, NT_STATUS_OBJECT_PATH_NOT_FOUND }, + { EFTYPE, NT_STATUS_OBJECT_PATH_NOT_FOUND }, #endif #ifdef EDQUOT - { EDQUOT, NT_STATUS_DISK_FULL }, /* Windows apps need this, not NT_STATUS_QUOTA_EXCEEDED */ + { EDQUOT, NT_STATUS_DISK_FULL }, /* Windows apps need this, not NT_STATUS_QUOTA_EXCEEDED */ #endif #ifdef ENOTEMPTY - { ENOTEMPTY, NT_STATUS_DIRECTORY_NOT_EMPTY }, + { ENOTEMPTY, NT_STATUS_DIRECTORY_NOT_EMPTY }, #endif #ifdef EXDEV - { EXDEV, NT_STATUS_NOT_SAME_DEVICE }, + { EXDEV, NT_STATUS_NOT_SAME_DEVICE }, #endif #ifdef EROFS - { EROFS, NT_STATUS_ACCESS_DENIED }, + { EROFS, NT_STATUS_ACCESS_DENIED }, #endif #ifdef ENAMETOOLONG { ENAMETOOLONG, NT_STATUS_OBJECT_NAME_INVALID }, #endif #ifdef EFBIG - { EFBIG, NT_STATUS_DISK_FULL }, + { EFBIG, NT_STATUS_DISK_FULL }, #endif #ifdef ENOBUFS - { ENOBUFS, NT_STATUS_INSUFFICIENT_RESOURCES }, + { ENOBUFS, NT_STATUS_INSUFFICIENT_RESOURCES }, #endif - { EAGAIN, NT_STATUS_NETWORK_BUSY }, + { EAGAIN, NT_STATUS_NETWORK_BUSY }, #ifdef EADDRINUSE - { EADDRINUSE, NT_STATUS_ADDRESS_ALREADY_ASSOCIATED}, + { EADDRINUSE, NT_STATUS_ADDRESS_ALREADY_ASSOCIATED}, #endif #ifdef ENETUNREACH - { ENETUNREACH, NT_STATUS_NETWORK_UNREACHABLE}, + { ENETUNREACH, NT_STATUS_NETWORK_UNREACHABLE}, #endif #ifdef EHOSTUNREACH - { EHOSTUNREACH, NT_STATUS_HOST_UNREACHABLE}, + { EHOSTUNREACH, NT_STATUS_HOST_UNREACHABLE}, #endif #ifdef ECONNREFUSED { ECONNREFUSED, NT_STATUS_CONNECTION_REFUSED}, #endif #ifdef ETIMEDOUT - { ETIMEDOUT, NT_STATUS_IO_TIMEOUT}, + { ETIMEDOUT, NT_STATUS_IO_TIMEOUT}, #endif #ifdef ECONNABORTED { ECONNABORTED, NT_STATUS_CONNECTION_ABORTED}, #endif #ifdef ECONNRESET - { ECONNRESET, NT_STATUS_CONNECTION_RESET}, + { ECONNRESET, NT_STATUS_CONNECTION_RESET}, #endif #ifdef ENODEV - { ENODEV, NT_STATUS_DEVICE_DOES_NOT_EXIST}, + { ENODEV, NT_STATUS_DEVICE_DOES_NOT_EXIST}, #endif #ifdef EPIPE - { EPIPE, NT_STATUS_PIPE_BROKEN}, + { EPIPE, NT_STATUS_PIPE_BROKEN}, #endif #ifdef EWOULDBLOCK - { EWOULDBLOCK, NT_STATUS_NETWORK_BUSY }, + { EWOULDBLOCK, NT_STATUS_NETWORK_BUSY }, #endif #ifdef ENOATTR - { ENOATTR, NT_STATUS_NOT_FOUND }, + { ENOATTR, NT_STATUS_NOT_FOUND }, #endif #ifdef ECANCELED - { ECANCELED, NT_STATUS_CANCELLED}, + { ECANCELED, NT_STATUS_CANCELLED}, #endif #ifdef ENOTSUP - { ENOTSUP, NT_STATUS_NOT_SUPPORTED}, + { ENOTSUP, NT_STATUS_NOT_SUPPORTED}, #endif - { 0, NT_STATUS_OK } }; /********************************************************************* @@ -134,10 +133,10 @@ NTSTATUS map_nt_error_from_unix(int unix_error) } /* Look through list */ - while(unix_nt_errmap[i].unix_error != 0) { - if (unix_nt_errmap[i].unix_error == unix_error) + for (i=0;i<ARRAY_SIZE(unix_nt_errmap);i++) { + if (unix_nt_errmap[i].unix_error == unix_error) { return unix_nt_errmap[i].nt_error; - i++; + } } /* Default return */ @@ -254,7 +253,6 @@ static const struct { #ifdef EXDEV {NT_STATUS_NOT_SAME_DEVICE, EXDEV}, #endif - {NT_STATUS(0), 0} }; int map_errno_from_nt_status(NTSTATUS status) @@ -269,7 +267,7 @@ int map_errno_from_nt_status(NTSTATUS status) return 0; } - for (i=0;nt_errno_map[i].error;i++) { + for (i=0;i<ARRAY_SIZE(nt_errno_map);i++) { if (NT_STATUS_V(nt_errno_map[i].status) == NT_STATUS_V(status)) { return nt_errno_map[i].error; diff --git a/source3/lib/system.c b/source3/lib/system.c index 292965f..0dd4b81 100644 --- a/source3/lib/system.c +++ b/source3/lib/system.c @@ -48,42 +48,6 @@ /******************************************************************* - A wrapper for memalign -********************************************************************/ - -void *sys_memalign( size_t align, size_t size ) -{ -#if defined(HAVE_POSIX_MEMALIGN) - void *p = NULL; - int ret = posix_memalign( &p, align, size ); - if ( ret == 0 ) - return p; - - return NULL; -#elif defined(HAVE_MEMALIGN) - return memalign( align, size ); -#else - /* On *BSD systems memaligns doesn't exist, but memory will - * be aligned on allocations of > pagesize. */ -#if defined(SYSCONF_SC_PAGESIZE) - size_t pagesize = (size_t)sysconf(_SC_PAGESIZE); -#elif defined(HAVE_GETPAGESIZE) - size_t pagesize = (size_t)getpagesize(); -#else - size_t pagesize = (size_t)-1; -#endif - if (pagesize == (size_t)-1) { - DEBUG(0,("memalign functionalaity not available on this platform!\n")); - return NULL; - } - if (size < pagesize) { - size = pagesize; - } - return SMB_MALLOC(size); -#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 f86f517..173e906 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -430,149 +430,6 @@ NTSTATUS reinit_after_fork(struct messaging_context *msg_ctx, return status; } -#if defined(PARANOID_MALLOC_CHECKER) - -/**************************************************************************** - Internal malloc wrapper. Externally visible. -****************************************************************************/ - -void *malloc_(size_t size) -{ - if (size == 0) { - return NULL; - } -#undef malloc - return malloc(size); -#define malloc(s) __ERROR_DONT_USE_MALLOC_DIRECTLY -} - -/**************************************************************************** - Internal calloc wrapper. Not externally visible. -****************************************************************************/ - -static void *calloc_(size_t count, size_t size) -{ - if (size == 0 || count == 0) { - return NULL; - } -#undef calloc - return calloc(count, size); -#define calloc(n,s) __ERROR_DONT_USE_CALLOC_DIRECTLY -} - -/**************************************************************************** - Internal realloc wrapper. Not externally visible. -****************************************************************************/ - -static void *realloc_(void *ptr, size_t size) -{ -#undef realloc - return realloc(ptr, size); -#define realloc(p,s) __ERROR_DONT_USE_RELLOC_DIRECTLY -} - -#endif /* PARANOID_MALLOC_CHECKER */ - -/**************************************************************************** - 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; - } - - return sys_memalign(align, el_size*count); -} - -/**************************************************************************** - Type-safe calloc. -****************************************************************************/ - -void *calloc_array(size_t size, size_t nmemb) -{ - if (nmemb >= MAX_ALLOC_SIZE/size) { - return NULL; - } - if (size == 0 || nmemb == 0) { - return NULL; - } -#if defined(PARANOID_MALLOC_CHECKER) - return calloc_(nmemb, size); -#else - return calloc(nmemb, size); -#endif -} - -/**************************************************************************** - Expand a pointer to be a particular size. - Note that this version of Realloc has an extra parameter that decides - whether to free the passed in storage on allocation failure or if the - new size is zero. - - This is designed for use in the typical idiom of : - - p = SMB_REALLOC(p, size) - if (!p) { - return error; - } - - and not to have to keep track of the old 'p' contents to free later, nor - to worry if the size parameter was zero. In the case where NULL is returned - we guarentee that p has been freed. - - If free later semantics are desired, then pass 'free_old_on_error' as False which - guarentees that the old contents are not freed on error, even if size == 0. To use - this idiom use : - - tmp = SMB_REALLOC_KEEP_OLD_ON_ERROR(p, size); - if (!tmp) { - SAFE_FREE(p); - return error; - } else { - p = tmp; - } - - Changes were instigated by Coverity error checking. JRA. -****************************************************************************/ - -void *Realloc(void *p, size_t size, bool free_old_on_error) -{ - void *ret=NULL; - - if (size == 0) { - if (free_old_on_error) { - SAFE_FREE(p); - } - DEBUG(2,("Realloc asked for 0 bytes\n")); - return NULL; - } - -#if defined(PARANOID_MALLOC_CHECKER) - if (!p) { - ret = (void *)malloc_(size); - } else { - ret = (void *)realloc_(p,size); - } -#else - if (!p) { - ret = (void *)malloc(size); - } else { - ret = (void *)realloc(p,size); - } -#endif - - if (!ret) { - if (free_old_on_error && p) { - SAFE_FREE(p); - } - DEBUG(0,("Memory allocation error: failed to expand to %d bytes\n",(int)size)); - } - - return(ret); -} - /**************************************************************************** (Hopefully) efficient array append. ****************************************************************************/ diff --git a/source3/lib/util_malloc.c b/source3/lib/util_malloc.c new file mode 100644 index 0000000..c052adc --- /dev/null +++ b/source3/lib/util_malloc.c @@ -0,0 +1,171 @@ +/* + Unix SMB/CIFS implementation. + Samba utility functions + Copyright (C) Andrew Tridgell 1992-1998 + Copyright (C) Jeremy Allison 2001-2007 + Copyright (C) Simo Sorce 2001 + Copyright (C) Jim McDonough <j...@us.ibm.com> 2003 + Copyright (C) James Peach 2006 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "includes.h" + +/* Max allowable allococation - 256mb - 0x10000000 */ +#define MAX_ALLOC_SIZE (1024*1024*256) + +#if defined(PARANOID_MALLOC_CHECKER) + +/**************************************************************************** + Internal malloc wrapper. Externally visible. -- Samba Shared Repository