00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef mem_h
00034 #define mem_h
00035 #include "../config.h"
00036 #include "../dprint.h"
00037
00038
00039 #ifdef F_MALLOC
00040 #ifdef DBG_F_MALLOC
00041 #ifndef DBG_QM_MALLOC
00042 #define DBG_QM_MALLOC
00043 #endif
00044 #elif defined(DBG_QM_MALLOC)
00045 #define DBG_F_MALLOC
00046 #endif
00047 #endif
00048
00049 #ifdef PKG_MALLOC
00050 # ifdef F_MALLOC
00051 # include "f_malloc.h"
00052 extern struct fm_block* mem_block;
00053 # else
00054 # include "q_malloc.h"
00055 extern struct qm_block* mem_block;
00056 # endif
00057
00058 extern char mem_pool[PKG_MEM_POOL_SIZE];
00059
00060
00061 # ifdef DBG_QM_MALLOC
00062 #ifdef __SUNPRO_C
00063 #define __FUNCTION__ ""
00064 #endif
00065 # ifdef F_MALLOC
00066 # define pkg_malloc(s) fm_malloc(mem_block, (s),__FILE__, \
00067 __FUNCTION__, __LINE__)
00068 # define pkg_free(p) fm_free(mem_block, (p), __FILE__, \
00069 __FUNCTION__, __LINE__)
00070 # define pkg_realloc(p, s) fm_realloc(mem_block, (p), (s),__FILE__, \
00071 __FUNCTION__, __LINE__)
00072 # else
00073 # define pkg_malloc(s) qm_malloc(mem_block, (s),__FILE__, \
00074 __FUNCTION__, __LINE__)
00075 # define pkg_realloc(p, s) qm_realloc(mem_block, (p), (s),__FILE__, \
00076 __FUNCTION__, __LINE__)
00077 # define pkg_free(p) qm_free(mem_block, (p), __FILE__, \
00078 __FUNCTION__, __LINE__)
00079 # endif
00080 # else
00081 # ifdef F_MALLOC
00082 # define pkg_malloc(s) fm_malloc(mem_block, (s))
00083 # define pkg_realloc(p, s) fm_realloc(mem_block, (p), (s))
00084 # define pkg_free(p) fm_free(mem_block, (p))
00085 # else
00086 # define pkg_malloc(s) qm_malloc(mem_block, (s))
00087 # define pkg_realloc(p, s) qm_realloc(mem_block, (p), (s))
00088 # define pkg_free(p) qm_free(mem_block, (p))
00089 # endif
00090 # endif
00091 # ifdef F_MALLOC
00092 # define pkg_status() fm_status(mem_block)
00093 # else
00094 # define pkg_status() qm_status(mem_block)
00095 # endif
00096 #elif defined(USE_SHM_MEM)
00097 # include "shm_mem.h"
00098 # define pkg_malloc(s) shm_malloc((s))
00099 # define pkg_free(p) shm_free((p))
00100 # define pkg_status() shm_status()
00101 #else
00102 # include <stdlib.h>
00103
00104 void *sys_malloc(size_t, const char *, const char *, int);
00105 void *sys_realloc(void *, size_t, const char *, const char *, int);
00106 void sys_free(void *, const char *, const char *, int);
00107
00108 # define SYSTEM_MALLOC
00109 # define pkg_malloc(s) sys_malloc((s), __FILE__, __FUNCTION__, __LINE__)
00110 # define pkg_realloc(ptr, s) sys_realloc((ptr), (s), __FILE__, __FUNCTION__, __LINE__)
00111 # define pkg_free(p) sys_free((p), __FILE__, __FUNCTION__, __LINE__)
00112 # define pkg_status()
00113 #endif
00114
00115 int init_pkg_mallocs(void);
00116 int init_shm_mallocs(void);
00117
00118
00119
00120 #ifdef SYSTEM_MALLOC
00121 #define PKG_MEM_ERROR LM_ERR("could not allocate private memory from system")
00122 #else
00123 #define PKG_MEM_ERROR LM_ERR("could not allocate private memory from available pool")
00124 #endif
00125
00126 #define SHM_MEM_ERROR LM_ERR("could not allocate shared memory from available pool")
00127
00128 #endif