mem/mem.h
dda9dab1
 /* $Id$
  *
  * memory related stuff (malloc & friends)
  * 
7dd0b342
  *
84d8e165
  * Copyright (C) 2001-2003 FhG Fokus
7dd0b342
  *
  * This file is part of ser, a free SIP server.
  *
  * ser 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 2 of the License, or
  * (at your option) any later version
  *
  * For a license to use the ser software under conditions
  * other than those described here, or to purchase support for this
  * software, please contact iptel.org by e-mail at the following addresses:
  *    info@iptel.org
  *
  * ser 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, write to the Free Software 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
dda9dab1
  */
6419a43f
 /*
  * History:
  * --------
  *  2003-03-10  __FUNCTION__ is a gcc-ism, defined it to "" for sun cc
  *               (andrei)
90907c3f
  *  2003-03-07  split init_malloc into init_pkg_mallocs & init_shm_mallocs 
  *               (andrei)
6419a43f
  */
dda9dab1
 
 
7dd0b342
 
dda9dab1
 #ifndef mem_h
 #define mem_h
 #include "../config.h"
 #include "../dprint.h"
 
9c01c860
 /* fix debug defines, DBG_F_MALLOC <=> DBG_QM_MALLOC */
 #ifdef F_MALLOC
 	#ifdef DBG_F_MALLOC
 		#ifndef DBG_QM_MALLOC
 			#define DBG_QM_MALLOC
 		#endif
 	#elif defined(DBG_QM_MALLOC)
 		#define DBG_F_MALLOC
 	#endif
 #endif
 
dda9dab1
 #ifdef PKG_MALLOC
 #	ifdef VQ_MALLOC
 #		include "vq_malloc.h"
 		extern struct vqm_block* mem_block;
b2dec9c6
 #	elif defined F_MALLOC
 #		include "f_malloc.h"
 		extern struct fm_block* mem_block;
 #   else
dda9dab1
 #		include "q_malloc.h"
 		extern struct qm_block* mem_block;
 #	endif
 
 	extern char mem_pool[PKG_MEM_POOL_SIZE];
 
 
 #	ifdef DBG_QM_MALLOC
6419a43f
 #ifdef __SUNPRO_C
 		#define __FUNCTION__ ""  /* gcc specific */
 #endif
dda9dab1
 #		ifdef VQ_MALLOC
 #			define pkg_malloc(s) vqm_malloc(mem_block, (s),__FILE__, \
65097752
 				__FUNCTION__, __LINE__)
dda9dab1
 #			define pkg_free(p)   vqm_free(mem_block, (p), __FILE__,  \
65097752
 				__FUNCTION__, __LINE__)
9c01c860
 #			warn "no proper realloc implementation, use another mem. alloc"
b2dec9c6
 #		elif defined F_MALLOC
 #			define pkg_malloc(s) fm_malloc(mem_block, (s),__FILE__, \
a768ee68
 				__FUNCTION__, __LINE__)
b2dec9c6
 #			define pkg_free(p)   fm_free(mem_block, (p), __FILE__,  \
a768ee68
 				__FUNCTION__, __LINE__)
9c01c860
 #			define pkg_realloc(p, s) fm_realloc(mem_block, (p), (s),__FILE__, \
 				__FUNCTION__, __LINE__)
dda9dab1
 #		else
 #			define pkg_malloc(s) qm_malloc(mem_block, (s),__FILE__, \
a768ee68
 				__FUNCTION__, __LINE__)
f22b996b
 #			define pkg_realloc(p, s) qm_realloc(mem_block, (p), (s),__FILE__, \
 				__FUNCTION__, __LINE__)
dda9dab1
 #			define pkg_free(p)   qm_free(mem_block, (p), __FILE__,  \
a768ee68
 				__FUNCTION__, __LINE__)
dda9dab1
 #		endif
 #	else
 #		ifdef VQ_MALLOC
 #			define pkg_malloc(s) vqm_malloc(mem_block, (s))
 #			define pkg_free(p)   vqm_free(mem_block, (p))
b2dec9c6
 #		elif defined F_MALLOC
 #			define pkg_malloc(s) fm_malloc(mem_block, (s))
9c01c860
 #			define pkg_realloc(p, s) fm_realloc(mem_block, (p), (s))
b2dec9c6
 #			define pkg_free(p)   fm_free(mem_block, (p))
dda9dab1
 #		else
 #			define pkg_malloc(s) qm_malloc(mem_block, (s))
f22b996b
 #			define pkg_realloc(p, s) qm_realloc(mem_block, (p), (s))
dda9dab1
 #			define pkg_free(p)   qm_free(mem_block, (p))
 #		endif
 #	endif
 #	ifdef VQ_MALLOC
 #		define pkg_status()  vqm_status(mem_block)
b2dec9c6
 #	elif defined F_MALLOC
 #		define pkg_status()  fm_status(mem_block)
dda9dab1
 #	else
 #		define pkg_status()  qm_status(mem_block)
 #	endif
 #elif defined(SHM_MEM) && defined(USE_SHM_MEM)
 #	include "shm_mem.h"
 #	define pkg_malloc(s) shm_malloc((s))
 #	define pkg_free(p)   shm_free((p))
 #	define pkg_status()  shm_status()
 #else
 #	include <stdlib.h>
 #	define pkg_malloc(s) \
 	(  { void *v; v=malloc((s)); \
9f4c52ce
 	   DBG("malloc %p size %d end %p\n", v, s, (char*)v+(s));\
dda9dab1
 	   v; } )
9f4c52ce
 #	define pkg_free(p)  do{ DBG("free %p\n", (p)); free((p)); }while(0);
dda9dab1
 #	define pkg_status()
 #endif
 
90907c3f
 int init_pkg_mallocs();
 int init_shm_mallocs();
dda9dab1
 
 #endif