head 1.33; access; symbols MM_1_4_2:1.32 MM_1_4_1:1.32 MM_1_4_0:1.30 MM_1_3_1:1.29 MM_1_3_0:1.28 MM_1_2_2:1.27 MM_1_2_1:1.25 MM_1_2_0:1.25 MM_1_1_3:1.19 MM_1_1_2:1.19 MM_1_1_1:1.19 MM_1_1_0:1.18 MM_1_0_12:1.13 MM_1_0_11:1.13 MM_1_0_10:1.13 MM_1_0_9:1.11 MM_1_0_8:1.11 MM_1_0_7:1.11 MM_1_0_6:1.11 MM_1_0_5:1.10 MM_1_0_4:1.10 MM_1_0_3:1.9 MM_1_0_1:1.8 MM_1_0_0:1.7 MM_1_0b6:1.7 MM_1_0b5:1.6 MM_1_0b4:1.3 MM_1_0b3:1.3 MM_1_0b2plus:1.1.1.1 RSE:1.1.1; locks; strict; comment @ * @; 1.33 date 2007.01.01.18.26.34; author rse; state Exp; branches; next 1.32; commitid xbmVq17WhC8zJP0s; 1.32 date 2006.08.10.19.00.33; author rse; state Exp; branches; next 1.31; commitid zS8gipIRuG1bykIr; 1.31 date 2006.06.10.21.25.54; author rse; state Exp; branches; next 1.30; commitid MFCthRi9H63BjvAr; 1.30 date 2005.09.02.20.00.46; author rse; state Exp; branches; next 1.29; 1.29 date 2004.09.12.18.35.01; author rse; state Exp; branches; next 1.28; 1.28 date 2003.03.07.14.59.15; author rse; state Exp; branches; next 1.27; 1.27 date 2002.12.19.09.25.23; author rse; state Exp; branches; next 1.26; 1.26 date 2002.12.19.09.14.58; author rse; state Exp; branches; next 1.25; 1.25 date 2002.07.26.13.21.31; author rse; state Exp; branches; next 1.24; 1.24 date 2002.07.26.13.04.40; author rse; state Exp; branches; next 1.23; 1.23 date 2002.07.26.09.59.34; author rse; state Exp; branches; next 1.22; 1.22 date 2001.01.29.20.31.50; author rse; state Exp; branches; next 1.21; 1.21 date 2001.01.29.20.27.22; author rse; state Exp; branches; next 1.20; 1.20 date 2000.12.03.19.56.39; author rse; state Exp; branches; next 1.19; 1.19 date 2000.04.30.18.33.07; author rse; state Exp; branches; next 1.18; 1.18 date 2000.04.30.09.22.11; author rse; state Exp; branches; next 1.17; 1.17 date 2000.04.30.08.58.57; author rse; state Exp; branches; next 1.16; 1.16 date 2000.04.26.19.08.27; author rse; state Exp; branches; next 1.15; 1.15 date 2000.03.17.16.54.08; author rse; state Exp; branches; next 1.14; 1.14 date 2000.01.09.20.19.40; author rse; state Exp; branches; next 1.13; 1.13 date 99.08.27.09.34.18; author rse; state Exp; branches; next 1.12; 1.12 date 99.07.16.06.27.50; author rse; state Exp; branches; next 1.11; 1.11 date 99.06.06.11.03.21; author rse; state Exp; branches; next 1.10; 1.10 date 99.05.21.21.20.09; author rse; state Exp; branches; next 1.9; 1.9 date 99.05.15.11.45.22; author rse; state Exp; branches; next 1.8; 1.8 date 99.04.18.10.39.50; author rse; state Exp; branches; next 1.7; 1.7 date 99.03.18.14.47.38; author rse; state Exp; branches; next 1.6; 1.6 date 99.03.18.09.02.13; author rse; state Exp; branches; next 1.5; 1.5 date 99.03.18.07.55.19; author rse; state Exp; branches; next 1.4; 1.4 date 99.03.15.17.17.55; author rse; state Exp; branches; next 1.3; 1.3 date 99.03.15.13.25.47; author rse; state Exp; branches; next 1.2; 1.2 date 99.03.15.12.58.49; author rse; state Exp; branches; next 1.1; 1.1 date 99.03.15.11.12.50; author rse; state Exp; branches 1.1.1.1; next ; 1.1.1.1 date 99.03.15.11.12.50; author rse; state Exp; branches; next ; desc @@ 1.33 log @Updated all copyright messages for year 2007 @ text @/* ==================================================================== * Copyright (c) 1999-2007 Ralf S. Engelschall * Copyright (c) 1999-2007 The OSSP Project * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. All advertising materials mentioning features or use of this * software must display the following acknowledgment: * "This product includes software developed by * Ralf S. Engelschall ." * * 4. Redistributions of any form whatsoever must retain the following * acknowledgment: * "This product includes software developed by * Ralf S. Engelschall ." * * THIS SOFTWARE IS PROVIDED BY RALF S. ENGELSCHALL ``AS IS'' AND ANY * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RALF S. ENGELSCHALL OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * ==================================================================== */ /* ** ** mm.h -- Shared Memory library API header ** */ #ifndef _MM_H_ #define _MM_H_ #ifdef __cplusplus extern "C" { #endif /* ** ____ Public Part (I) of the API ________________________ */ #include #include #include #include #include #include typedef enum { MM_LOCK_RD, MM_LOCK_RW } mm_lock_mode; /* ** ____ Private Part of the API ___________________________ */ #if defined(MM_PRIVATE) #include "config.h" #include #include #include #include #include #include #ifdef HAVE_SYS_PARAM_H #include #endif #ifdef MM_OS_SUNOS #include /* SunOS4 lacks prototypes */ extern int getpagesize(void); extern int munmap(caddr_t, int); extern int ftruncate(int, off_t); extern int flock(int, int); extern char *strerror(int); #endif #if !defined(FALSE) #define FALSE 0 #endif #if !defined(TRUE) #define TRUE !FALSE #endif #if !defined(NULL) #define NULL (void *)0 #endif #if !defined(NUL) #define NUL '\0' #endif #if !defined(min_of) #define min_of(a,b) ((a) < (b) ? (a) : (b)) #endif #if !defined(max_of) #define max_of(a,b) ((a) > (b) ? (a) : (b)) #endif #if !defined(absof) #define abs_of(a) ((a) < 0 ? -(a) : (a)) #endif #if !defined(offset_of) #define offset_of(type,member) ((size_t)(&((type *)0)->member)) #endif #if !defined(HAVE_MEMCPY) #if defined(HAVE_BCOPY) #define memcpy(to,from,len) bcopy(from,to,len) #else #define memcpy(to,from,len) \ { int i; for (i = 0; i < (len); i++) *(((char *)(to))+i) = *(((char *)(from))+i); } #endif #endif #if !defined(HAVE_MEMSET) #define memset(to,ch,len) \ { int i; for (i = 0; i < (len); i++) *(((char *)(to))+i) = (ch); } #endif #define ERR(type,str) mm_lib_error_set(type,str) #define FAIL(type,str) { ERR(type,str); goto cus; } #define BEGIN_FAILURE cus: #define END_FAILURE #if defined(HAVE_PATH_MAX) #define MM_MAXPATH PATH_MAX #elif defined(HAVE__POSIX_PATH_MAX) #define MM_MAXPATH _POSIX_PATH_MAX #elif defined(HAVE_MAXPATHLEN) #define MM_MAXPATH MAXPATHLEN #else #define MM_MAXPATH 2048 #endif #if defined(HAVE_CHILD_MAX) #define MM_MAXCHILD CHILD_MAX #elif defined(HAVE__POSIX_CHILD_MAX) #define MM_MAXCHILD _POSIX_CHILD_MAX #else #define MM_MAXCHILD 512 #endif #if defined(MM_SHMT_MMANON) || defined(MM_SHMT_MMPOSX) ||\ defined(MM_SHMT_MMZERO) || defined(MM_SHMT_MMFILE) #include #if !defined(MAP_ANON) && defined(MAP_ANONYMOUS) #define MAP_ANON MAP_ANONYMOUS #endif #if !defined(MAP_FAILED) #define MAP_FAILED ((void *)-1) #endif #endif #if defined(MM_SHMT_IPCSHM) || defined(MM_SEMT_IPCSEM) #include #endif #if defined(MM_SHMT_IPCSHM) #ifdef MM_OS_SUNOS #define KERNEL 1 #endif #ifdef MM_OS_BS2000 #define _KMEMUSER #endif #include #ifdef MM_OS_SUNOS #undef KERNEL #endif #ifdef MM_OS_BS2000 #undef _KMEMUSER #endif #if !defined(SHM_R) #define SHM_R 0400 #endif #if !defined(SHM_W) #define SHM_W 0200 #endif #endif #ifdef MM_SHMT_BEOS #include #endif #if defined(MM_SEMT_IPCSEM) #include #ifndef HAVE_UNION_SEMUN union semun { int val; struct semid_ds *buf; u_short *array; }; #endif #endif #ifdef MM_SEMT_FLOCK #include #endif #define MM_ALLOC_MINSIZE (1024*8) #define MM_CORE_FILEMODE (S_IRUSR|S_IWUSR) #define MM_CORE_DEFAULT_PAGESIZE (1024*8) #define MM_CORE_DEFAULT_FILE "/tmp/mm.core.%d" /* %d is PID */ #define MM_ERR_ALLOC 1 #define MM_ERR_CORE 2 #define MM_ERR_SYSTEM 4 /* * Define a union with types which are likely to have the longest * *relevant* CPU-specific memory word alignment restrictions... */ union mem_word { void *mw_vp; void (*mw_fp)(void); char *mw_cp; long mw_l; double mw_d; }; typedef union mem_word mem_word; #define SIZEOF_mem_word (sizeof(mem_word)) /* * Define the structure used for memory chunks */ union mem_chunk_mc_u { struct mem_chunk *mc_next; /* really used when it's free */ mem_word mc_base; /* virtually used when it's allocated */ }; struct mem_chunk { size_t mc_size; /* physical size */ size_t mc_usize; /* user known size */ union mem_chunk_mc_u mc_u; }; typedef struct mem_chunk mem_chunk; #define SIZEOF_mem_chunk (sizeof(mem_chunk)-sizeof(union mem_chunk_mc_u)) /* * Define the structure describing a memory pool */ struct mem_pool { size_t mp_size; size_t mp_offset; mem_chunk mp_freechunks; mem_word mp_base; }; typedef struct mem_pool mem_pool; #define SIZEOF_mem_pool (sizeof(mem_pool)-SIZEOF_mem_word) /* * Define the structure holding per-process filedescriptors */ #if defined(MM_SEMT_FLOCK) struct mem_core_fd { pid_t pid; int fd; }; typedef struct mem_core_fd mem_core_fd; #define SIZEOF_mem_core_fd (sizeof(mem_core_fd)) #endif /* * Define the structure describing a shared memory core area * (the actual contents depends on the shared memory and * semaphore/mutex type and is stripped down to a minimum * required) */ struct mem_core { size_t mc_size; size_t mc_usize; pid_t mc_pid; #if defined(MM_SHMT_IPCSHM) int mc_fdmem; #endif #if defined(MM_SHMT_MMFILE) char mc_fnmem[MM_MAXPATH]; #endif #if defined(MM_SHMT_BEOS) area_id mc_areaid; #endif #if !defined(MM_SEMT_FLOCK) int mc_fdsem; #endif #if defined(MM_SEMT_FLOCK) mem_core_fd mc_fdsem[MM_MAXCHILD]; #endif #if defined(MM_SEMT_IPCSEM) int mc_fdsem_rd; int mc_readers; mm_lock_mode mc_lockmode; #endif #if defined(MM_SEMT_FLOCK) || defined(MM_SEMT_FCNTL) char mc_fnsem[MM_MAXPATH]; #endif #if defined(MM_SEMT_BEOS) sem_id mc_semid; int32 mc_ben; #endif mem_word mc_base; }; typedef struct mem_core mem_core; #define SIZEOF_mem_core (sizeof(mem_core)-SIZEOF_mem_word) #endif /* MM_PRIVATE */ /* ** ____ Public Part (II) of the API _______________________ */ #if defined(MM_PRIVATE) typedef mem_pool MM; #else typedef void MM; #endif /* Global Malloc-Replacement API */ int MM_create(size_t, const char *); int MM_permission(mode_t, uid_t, gid_t); void MM_reset(void); void MM_destroy(void); int MM_lock(mm_lock_mode); int MM_unlock(void); void *MM_malloc(size_t); void *MM_realloc(void *, size_t); void MM_free(void *); void *MM_calloc(size_t, size_t); char *MM_strdup(const char *); size_t MM_sizeof(const void *); size_t MM_maxsize(void); size_t MM_available(void); char *MM_error(void); /* Standard Malloc-Style API */ MM *mm_create(size_t, const char *); int mm_permission(MM *, mode_t, uid_t, gid_t); void mm_reset(MM *); void mm_destroy(MM *); int mm_lock(MM *, mm_lock_mode); int mm_unlock(MM *); void *mm_malloc(MM *, size_t); void *mm_realloc(MM *, void *, size_t); void mm_free(MM *, void *); void *mm_calloc(MM *, size_t, size_t); char *mm_strdup(MM *, const char *); size_t mm_sizeof(MM *, const void *); size_t mm_maxsize(void); size_t mm_available(MM *); char *mm_error(void); void mm_display_info(MM *); /* Low-Level Shared Memory API */ void *mm_core_create(size_t, const char *); int mm_core_permission(void *, mode_t, uid_t, gid_t); void mm_core_delete(void *); size_t mm_core_size(const void *); int mm_core_lock(const void *, mm_lock_mode); int mm_core_unlock(const void *); size_t mm_core_maxsegsize(void); size_t mm_core_align2page(size_t); size_t mm_core_align2word(size_t); /* Internal Library API */ void mm_lib_error_set(unsigned int, const char *); char *mm_lib_error_get(void); int mm_lib_version(void); #ifdef __cplusplus } #endif #endif /* _MM_H_ */ @ 1.32 log @bump copyright for year 2006 @ text @d2 2 a3 2 * Copyright (c) 1999-2006 Ralf S. Engelschall * Copyright (c) 1999-2006 The OSSP Project @ 1.31 log @Add new API function MM_reset() and mm_reset(). Submitted by: Neil Conway @ text @d2 2 a3 2 * Copyright (c) 1999-2005 Ralf S. Engelschall * Copyright (c) 1999-2005 The OSSP Project @ 1.30 log @adjust copyright year @ text @d334 1 d351 1 @ 1.29 log @adjust year in copyright messages @ text @d2 2 a3 2 * Copyright (c) 1999-2004 Ralf S. Engelschall * Copyright (c) 1999-2004 The OSSP Project @ 1.28 log @1. Correctly cleanup under MM_SHMT_MMZERO in case of a shared memory segment creation error. 2. Close the filedescriptor of the underlying object immediately after mmap(2)'ing it in case of MM_SHMT_MMPOSX, MM_SHMT_MMZERO and MM_SHMT_MMFILE. Hints by: Joe Orton @ text @d2 2 a3 2 * Copyright (c) 1999-2003 Ralf S. Engelschall * Copyright (c) 1999-2003 The OSSP Project @ 1.27 log @Updated all copyright messages with forthcoming year 2003, added OSSP project as secondary copyright holder, added standard OSSP ASCII-art logo to documents, etc. @ text @d287 1 d289 1 @ 1.26 log @Stripped trailing whitespaces from all files in source tree. @ text @d2 2 a3 1 * Copyright (c) 1999-2002 Ralf S. Engelschall. All rights reserved. @ 1.25 log @Add support for IRIX 6.5 and other Unix flavors which have MAXPATHLEN in Submitted by: Joe Orton @ text @d9 1 a9 1 * notice, this list of conditions and the following disclaimer. d65 1 a65 1 typedef enum { d122 1 a122 1 #if !defined(HAVE_MEMCPY) d138 1 a138 1 #define END_FAILURE d178 1 a178 1 #define _KMEMUSER d214 1 a214 1 #define MM_ALLOC_MINSIZE (1024*8) d223 1 a223 1 /* @ 1.24 log @major source tree overhauling @ text @d83 3 @ 1.23 log @bump copyright year @ text @d75 1 a75 1 #include "mm_conf.h" @ 1.22 log @*** empty log message *** @ text @d2 1 a2 1 * Copyright (c) 1999-2001 Ralf S. Engelschall. All rights reserved. @ 1.21 log @*** empty log message *** @ text @d326 2 a327 2 int MM_create(size_t size, const char *file); int MM_permission(mode_t mode, uid_t owner, gid_t group); d329 1 a329 1 int MM_lock(mm_lock_mode mode); d331 6 a336 6 void *MM_malloc(size_t size); void *MM_realloc(void *ptr, size_t size); void MM_free(void *ptr); void *MM_calloc(size_t number, size_t size); char *MM_strdup(const char *str); size_t MM_sizeof(const void *ptr); d342 11 a352 11 MM *mm_create(size_t size, const char *file); int mm_permission(MM *mm, mode_t mode, uid_t owner, gid_t group); void mm_destroy(MM *mm); int mm_lock(MM *mm, mm_lock_mode mode); int mm_unlock(MM *mm); void *mm_malloc(MM *mm, size_t size); void *mm_realloc(MM *mm, void *ptr, size_t size); void mm_free(MM *mm, void *ptr); void *mm_calloc(MM *mm, size_t number, size_t size); char *mm_strdup(MM *mm, const char *str); size_t mm_sizeof(MM *mm, const void *ptr); d354 1 a354 1 size_t mm_available(MM *mm); d356 1 a356 1 void mm_display_info(MM *mm); d359 6 a364 6 void *mm_core_create(size_t size, const char *file); int mm_core_permission(void *core, mode_t mode, uid_t owner, gid_t group); void mm_core_delete(void *core); size_t mm_core_size(const void *core); int mm_core_lock(const void *core, mm_lock_mode mode); int mm_core_unlock(const void *core); d366 2 a367 2 size_t mm_core_align2page(size_t size); size_t mm_core_align2word(size_t size); d370 1 a370 1 void mm_lib_error_set(unsigned int, const char *str); @ 1.20 log @*** empty log message *** @ text @d2 1 a2 1 * Copyright (c) 1999-2000 Ralf S. Engelschall. All rights reserved. @ 1.19 log @*** empty log message *** @ text @d270 1 a270 1 #define SIZEOF_mem_core_fd (sizeof(mem_core_fd) @ 1.18 log @*** empty log message *** @ text @d171 6 a176 2 #define KERNEL 1 /* For SunOS4 */ #define _KMEMUSER /* For BS2000 to enable SHM_[RW] */ d178 1 d180 2 d183 1 @ 1.17 log @*** empty log message *** @ text @d47 2 a48 2 #ifndef MM_H #define MM_H 1 d370 2 a371 1 #endif /* MM_H */ @ 1.16 log @*** empty log message *** @ text @d124 1 a124 1 { int i; for (i = 0; i < (len); i++) *((to)+i) = *((from)+i); } d129 1 a129 1 { int i; for (i = 0; i < (len); i++) *((to)+i) = (ch); } @ 1.15 log @*** empty log message *** @ text @a84 1 #define KERNEL 1 d86 1 a86 1 /* SunOS lacks prototypes */ d171 2 d174 2 @ 1.14 log @*** empty log message *** @ text @d173 10 d276 3 d292 4 @ 1.13 log @*** empty log message *** @ text @d2 1 a2 1 * Copyright (c) 1999 Ralf S. Engelschall. All rights reserved. @ 1.12 log @*** empty log message *** @ text @d85 1 @ 1.11 log @*** empty log message *** @ text @d65 4 d87 5 a91 5 extern int getpagesize(void); extern int munmap(caddr_t addr, int len); extern int ftruncate(int fd, off_t length); extern int flock(int fd, int operation); extern char *strerror (int err); a294 4 typedef enum { MM_LOCK_RD, MM_LOCK_RW } mm_lock_mode; @ 1.10 log @*** empty log message *** @ text @a64 13 #if !defined(FALSE) #define FALSE 0 #endif #if !defined(TRUE) #define TRUE !FALSE #endif #if !defined(NULL) #define NULL (void *)0 #endif #if !defined(NUL) #define NUL '\0' #endif d90 23 a112 2 #if !defined(offsetof) #define offsetof(type,member) ((size_t)(&((type *)0)->member)) @ 1.9 log @*** empty log message *** @ text @a177 1 #define MM_ALLOC_MAXSIZE (MM_SHM_MAXSEGSIZE-SIZEOF_mem_pool) @ 1.8 log @*** empty log message *** @ text @d61 3 d291 1 d307 1 d324 1 @ 1.7 log @*** empty log message *** @ text @d287 1 a287 1 int MM_create(size_t size, char *file); d296 1 a296 1 size_t MM_sizeof(void *ptr); d302 1 a302 1 MM *mm_create(size_t size, char *file); d311 1 a311 1 size_t mm_sizeof(MM *mm, void *ptr); d318 1 a318 1 void *mm_core_create(size_t size, char *file); d320 3 a322 3 size_t mm_core_size(void *core); int mm_core_lock(void *core, mm_lock_mode mode); int mm_core_unlock(void *core); @ 1.6 log @*** empty log message *** @ text @d287 1 a287 1 int MM_create(void); @ 1.5 log @*** empty log message *** @ text @d297 1 d312 1 @ 1.4 log @*** empty log message *** @ text @d175 1 a175 1 #define MM_ALLOC_MAXSIZE MM_SHM_MAXSEGSIZE @ 1.3 log @*** empty log message *** @ text @d289 1 a289 1 int MM_lock(mm_lock_mode); d303 1 a303 1 int mm_lock(MM *mm, mm_lock_mode); d319 1 a319 1 int mm_core_lock(void *core, mm_lock_mode); @ 1.2 log @*** empty log message *** @ text @d244 4 a247 4 size_t mc_size; size_t mc_usize; pid_t mc_pid; int mc_fdmem; d249 1 a249 1 char mc_fnmem[MM_MAXPATH]; d252 1 a252 1 int mc_fdsem; d255 1 a255 1 mem_core_fd mc_fdsem[MM_MAXCHILD]; d258 3 a260 3 int mc_fdsem_rd; int mc_readers; int mc_lockmode; d263 1 a263 1 char mc_fnsem[MM_MAXPATH]; d265 1 a265 1 mem_word mc_base; d282 3 a284 2 #define MM_LOCK_RD 1 #define MM_LOCK_RW 2 d289 1 a289 1 int MM_lock(unsigned int mode); d303 1 a303 1 int mm_lock(MM *mm, unsigned int mode); d319 1 a319 1 int mm_core_lock(void *core, unsigned int mode); @ 1.1 log @Initial revision @ text @d257 5 d282 3 d288 1 a288 1 int MM_lock(void); d302 1 a302 1 int mm_lock(MM *mm); d318 1 a318 1 int mm_core_lock(void *core); @ 1.1.1.1 log @Import into CVS @ text @@