mem.h

Go to the documentation of this file.
00001 /* $Id: mem.h 5154 2008-11-03 09:46:48Z henningw $
00002  *
00003  * memory related stuff (malloc & friends)
00004  *
00005  * Copyright (C) 2001-2003 FhG Fokus
00006  *
00007  * This file is part of Kamailio, a free SIP server.
00008  *
00009  * Kamailio is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version
00013  *
00014  * Kamailio is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License 
00020  * along with this program; if not, write to the Free Software 
00021  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022  *
00023  * History:
00024  * --------
00025  *  2003-03-10  __FUNCTION__ is a gcc-ism, defined it to "" for sun cc
00026  *               (andrei)
00027  *  2003-03-07  split init_malloc into init_pkg_mallocs & init_shm_mallocs 
00028  *               (andrei)
00029  */
00030 
00031 
00032 
00033 #ifndef mem_h
00034 #define mem_h
00035 #include "../config.h"
00036 #include "../dprint.h"
00037 
00038 /* fix debug defines, DBG_F_MALLOC <=> DBG_QM_MALLOC */
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__ ""  /* gcc specific */
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 /*! generic logging helper for allocation errors in private memory pool/ system */
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 /*! generic logging helper for allocation errors in shared memory pool */
00126 #define SHM_MEM_ERROR LM_ERR("could not allocate shared memory from available pool")
00127 
00128 #endif

Generated on Wed May 23 20:00:27 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6