mm.h   mm.h 
skipping to change at line 43 skipping to change at line 43
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE. * OF THE POSSIBILITY OF SUCH DAMAGE.
* ==================================================================== * ====================================================================
*/ */
/* /*
** **
** mm.h -- memory map library API header ** mm.h -- Shared Memory library API header
** **
*/ */
#ifndef MM_H #ifndef MM_H
#define MM_H 1 #define MM_H 1
#ifdef __cplusplus
extern "C" {
#endif
/* /*
** ____ Public Part (I) of the API ________________________ ** ____ Public Part (I) of the API ________________________
*/ */
#define MM_VERSION_STR "0.9.0"
#define MM_VERSION_NUM 0x000900
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#if !defined(FALSE) #if !defined(FALSE)
#define FALSE 0 #define FALSE 0
#endif #endif
#if !defined(TRUE) #if !defined(TRUE)
#define TRUE !FALSE #define TRUE !FALSE
#endif #endif
#if !defined(NULL) #if !defined(NULL)
#define NULL (void *)0 #define NULL (void *)0
#endif #endif
#if !defined(NUL)
#define NUL '\0'
#endif
/* /*
** ____ Private Part of the API ___________________________ ** ____ Private Part of the API ___________________________
*/ */
#if defined(MM_PRIVATE) #if defined(MM_PRIVATE)
#include "mm_conf.h" #include "mm_conf.h"
#include <errno.h> #include <errno.h>
#include <limits.h> #include <limits.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#if defined(MM_OS_SunOS) #ifdef MM_OS_SUNOS
#include <memory.h> #include <memory.h>
/* SunOS lacks prototypes */ /* SunOS lacks prototypes */
int getpagesize(void); extern int getpagesize(void);
int munmap(caddr_t addr, int len); extern int munmap(caddr_t addr, int len);
int ftruncate(int fd, off_t length); extern int ftruncate(int fd, off_t length);
int flock(int fd, int operation); extern int flock(int fd, int operation);
extern char *strerror (int err);
#endif #endif
#if !defined(offsetof) #if !defined(offsetof)
#define offsetof(type,member) ((size_t)(&((type *)0)->member)) #define offsetof(type,member) ((size_t)(&((type *)0)->member))
#endif #endif
#define FAIL goto cus #if !defined(HAVE_MEMCPY)
#define BEGIN_FAILURE cus: #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++) *((to)+i) = *((from)+i); }
#endif
#endif
#if !defined(HAVE_MEMSET)
#define memset(to,ch,len) \
{ int i; for (i = 0; i < (len); i++) *((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 #define END_FAILURE
#if defined(PATH_MAX) #if defined(HAVE_PATH_MAX)
#define MM_MAXPATH PATH_MAX #define MM_MAXPATH PATH_MAX
#elif defined(_POSIX_PATH_MAX) #elif defined(HAVE__POSIX_PATH_MAX)
#define MM_MAXPATH _POSIX_PATH_MAX #define MM_MAXPATH _POSIX_PATH_MAX
#elif defined(MAXPATHLEN) #elif defined(HAVE_MAXPATHLEN)
#define MM_MAXPATH MAXPATHLEN #define MM_MAXPATH MAXPATHLEN
#else #else
#define MM_MAXPATH 2048 #define MM_MAXPATH 2048
#endif #endif
#if defined(CHILD_MAX) #if defined(HAVE_CHILD_MAX)
#define MM_MAXCHILD CHILD_MAX #define MM_MAXCHILD CHILD_MAX
#elif defined(_POSIX_CHILD_MAX) #elif defined(HAVE__POSIX_CHILD_MAX)
#define MM_MAXCHILD _POSIX_CHILD_MAX #define MM_MAXCHILD _POSIX_CHILD_MAX
#else #else
#define MM_MAXCHILD 512 #define MM_MAXCHILD 512
#endif #endif
#if defined(MM_SHMT_MMANON) || defined(MM_SHMT_MMPOSX) ||\ #if defined(MM_SHMT_MMANON) || defined(MM_SHMT_MMPOSX) ||\
defined(MM_SHMT_MMZERO) || defined(MM_SHMT_MMFILE) defined(MM_SHMT_MMZERO) || defined(MM_SHMT_MMFILE)
#include <sys/mman.h> #include <sys/mman.h>
#if !defined(MAP_ANON) && defined(MAP_ANONYMOUS) #if !defined(MAP_ANON) && defined(MAP_ANONYMOUS)
#define MAP_ANON MAP_ANONYMOUS #define MAP_ANON MAP_ANONYMOUS
#endif #endif
#if !defined(MAP_FAILED)
#define MAP_FAILED ((void *)-1)
#endif
#endif #endif
#if defined(MM_SHMT_IPCSHM) || defined(MM_SEMT_IPCSEM) #if defined(MM_SHMT_IPCSHM) || defined(MM_SEMT_IPCSEM)
#include <sys/ipc.h> #include <sys/ipc.h>
#endif #endif
#if defined(MM_SHMT_IPCSHM) #if defined(MM_SHMT_IPCSHM)
#include <sys/shm.h> #include <sys/shm.h>
#endif #endif
#if defined(MM_SEMT_IPCSEM) #if defined(MM_SEMT_IPCSEM)
#include <sys/sem.h> #include <sys/sem.h>
#ifndef HAVE_UNION_SEMUN
union semun {
int val;
struct semid_ds *buf;
u_short *array;
};
#endif
#endif #endif
#ifdef MM_SEMT_FLOCK #ifdef MM_SEMT_FLOCK
#include <sys/file.h> #include <sys/file.h>
#endif #endif
#define MM_CORE_FILEMODE (S_IRUSR|S_IWUSR) #define MM_ALLOC_MINSIZE (1024*8)
#define MM_CORE_MINSIZE (1*1024) /* 1 KB */ #define MM_ALLOC_MAXSIZE (MM_SHM_MAXSEGSIZE-SIZEOF_mem_pool)
#define MM_CORE_MAXSIZE (16*1024*1024) /* 16 MB */ #define MM_CORE_FILEMODE (S_IRUSR|S_IWUSR)
#define MM_DEFAULT_PAGESIZE 8192 /* 8 KB */ #define MM_CORE_DEFAULT_PAGESIZE (1024*8)
#define MM_DEFAULT_SIZE (1*1024*1024) /* 1MB */ #define MM_CORE_DEFAULT_FILE "/tmp/mm.core.%d" /* %d is PID */
#define MM_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 * Define a union with types which are likely to have the longest
* *relevant* CPU-specific memory word alignment restrictions... * *relevant* CPU-specific memory word alignment restrictions...
*/ */
union mem_word { union mem_word {
void *mw_vp; void *mw_vp;
void (*mw_fp)(void); void (*mw_fp)(void);
char *mw_cp; char *mw_cp;
long mw_l; long mw_l;
double mw_d; double mw_d;
}; };
typedef union mem_word mem_word; typedef union mem_word mem_word;
#define SIZEOF_mem_word (sizeof(mem_word)) #define SIZEOF_mem_word (sizeof(mem_word))
/* /*
* Define the structure used for memory chunks * Define the structure used for memory chunks
*/ */
union mem_chunk_mc_u { union mem_chunk_mc_u {
struct mem_chunk *mc_next; /* really used when it's free */ struct mem_chunk *mc_next; /* really used when it's free */
mem_word mc_base; /* virtually used when it's allocated */ mem_word mc_base; /* virtually used when it's allocated */
}; };
struct mem_chunk { struct mem_chunk {
size_t mc_size; /* physical size */ size_t mc_size; /* physical size */
size_t mc_usize; /* user known size */ size_t mc_usize; /* user known size */
union mem_chunk_mc_u mc_u; union mem_chunk_mc_u mc_u;
}; };
typedef struct mem_chunk mem_chunk; typedef struct mem_chunk mem_chunk;
#define SIZEOF_mem_chunk (sizeof(mem_chunk)-sizeof(union mem_chunk_mc_u)) #define SIZEOF_mem_chunk (sizeof(mem_chunk)-sizeof(union mem_chunk_mc_u))
/* /*
* Define the structure describing a memory pool * Define the structure describing a memory pool
*/ */
struct mem_pool { struct mem_pool {
size_t mp_size; size_t mp_size;
size_t mp_offset; size_t mp_offset;
skipping to change at line 212 skipping to change at line 244
#define SIZEOF_mem_core_fd (sizeof(mem_core_fd) #define SIZEOF_mem_core_fd (sizeof(mem_core_fd)
#endif #endif
/* /*
* Define the structure describing a shared memory core area * Define the structure describing a shared memory core area
* (the actual contents depends on the shared memory and * (the actual contents depends on the shared memory and
* semaphore/mutex type and is stripped down to a minimum * semaphore/mutex type and is stripped down to a minimum
* required) * required)
*/ */
struct mem_core { struct mem_core {
size_t mc_size; size_t mc_size;
size_t mc_usize; size_t mc_usize;
pid_t mc_pid; pid_t mc_pid;
int mc_fdmem; int mc_fdmem;
#if defined(MM_SHMT_MMFILE) #if defined(MM_SHMT_MMFILE)
char mc_fnmem[MM_MAXPATH]; char mc_fnmem[MM_MAXPATH];
#endif #endif
#if !defined(MM_SEMT_FLOCK) #if !defined(MM_SEMT_FLOCK)
int mc_fdsem; int mc_fdsem;
#endif #endif
#if defined(MM_SEMT_FLOCK) #if defined(MM_SEMT_FLOCK)
mem_core_fd mc_fdsem[MM_MAXCHILD]; 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 #endif
#if defined(MM_SEMT_FLOCK) || defined(MM_SEMT_FCNTL) #if defined(MM_SEMT_FLOCK) || defined(MM_SEMT_FCNTL)
char mc_fnsem[MM_MAXPATH]; char mc_fnsem[MM_MAXPATH];
#endif #endif
mem_word mc_base; mem_word mc_base;
}; };
typedef struct mem_core mem_core; typedef struct mem_core mem_core;
#define SIZEOF_mem_core (sizeof(mem_core)-SIZEOF_mem_word) #define SIZEOF_mem_core (sizeof(mem_core)-SIZEOF_mem_word)
#endif /* MM_PRIVATE */ #endif /* MM_PRIVATE */
/* /*
** ____ Public Part (II) of the API _______________________ ** ____ Public Part (II) of the API _______________________
*/ */
#if defined(MM_PRIVATE) #if defined(MM_PRIVATE)
typedef mem_pool MM; typedef mem_pool MM;
#else #else
typedef void MM; typedef void MM;
#endif #endif
typedef enum {
MM_LOCK_RD, MM_LOCK_RW
} mm_lock_mode;
/* Global Malloc-Replacement API */ /* Global Malloc-Replacement API */
int MM_create(void); int MM_create(size_t size, char *file);
void MM_destroy(void); void MM_destroy(void);
int MM_lock(void); int MM_lock(mm_lock_mode mode);
int MM_unlock(void); int MM_unlock(void);
void *MM_malloc(size_t size); void *MM_malloc(size_t size);
void *MM_realloc(void *ptr, size_t size); void *MM_realloc(void *ptr, size_t size);
void MM_free(void *ptr); void MM_free(void *ptr);
void *MM_calloc(size_t number, size_t size); void *MM_calloc(size_t number, size_t size);
char *MM_strdup(const char *str); char *MM_strdup(const char *str);
size_t MM_sizeof(void *ptr); size_t MM_sizeof(void *ptr);
size_t MM_maxsize(void);
size_t MM_available(void);
char *MM_error(void);
/* Standard Malloc-Style API */ /* Standard Malloc-Style API */
MM *mm_create(size_t size, char *file); MM *mm_create(size_t size, char *file);
void mm_destroy(MM *mm); void mm_destroy(MM *mm);
int mm_lock(MM *mm); int mm_lock(MM *mm, mm_lock_mode mode);
int mm_unlock(MM *mm); int mm_unlock(MM *mm);
void *mm_malloc(MM *mm, size_t size); void *mm_malloc(MM *mm, size_t size);
void *mm_realloc(MM *mm, void *ptr, size_t size); void *mm_realloc(MM *mm, void *ptr, size_t size);
void mm_free(MM *mm, void *ptr); void mm_free(MM *mm, void *ptr);
void *mm_calloc(MM *mm, size_t number, size_t size); void *mm_calloc(MM *mm, size_t number, size_t size);
char *mm_strdup(MM *mm, const char *str); char *mm_strdup(MM *mm, const char *str);
size_t mm_sizeof(MM *mm, void *ptr); size_t mm_sizeof(MM *mm, void *ptr);
#ifdef MM_DEBUG size_t mm_maxsize(void);
size_t mm_available(MM *mm);
char *mm_error(void);
void mm_display_info(MM *mm); void mm_display_info(MM *mm);
#endif
/* Low-Level Shared Memory API */ /* Low-Level Shared Memory API */
size_t mm_core_align2page(size_t size);
size_t mm_core_align2word(size_t size);
void *mm_core_create(size_t size, char *file); void *mm_core_create(size_t size, char *file);
void mm_core_delete(void *core); void mm_core_delete(void *core);
size_t mm_core_size(void *core); size_t mm_core_size(void *core);
int mm_core_lock(void *core); int mm_core_lock(void *core, mm_lock_mode mode);
int mm_core_unlock(void *core); int mm_core_unlock(void *core);
size_t mm_core_maxsegsize(void);
size_t mm_core_align2page(size_t size);
size_t mm_core_align2word(size_t size);
/* Internal Library API */
void mm_lib_error_set(unsigned int, const char *str);
char *mm_lib_error_get(void);
int mm_lib_version(void);
#ifdef __cplusplus
}
#endif
#endif /* MM_H */ #endif /* MM_H */
 End of changes. 33 change blocks. 
42 lines changed or deleted 97 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/