mem.c

Go to the documentation of this file.
00001 /*
00002  * $Id: mem.c 5721 2009-03-18 17:23:00Z henningw $
00003  *
00004  * Copyright (C) 2001-2003 FhG Fokus
00005  *
00006  * This file is part of Kamailio, a free SIP server.
00007  *
00008  * Kamailio is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version
00012  *
00013  * Kamailio is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License 
00019  * along with this program; if not, write to the Free Software 
00020  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  *
00022  *
00023  * History:
00024  * --------
00025  *  2003-04-08  init_mallocs split into init_{pkg,shm}_malloc (andrei)
00026  * 
00027  */
00028 
00029 
00030 #include <stdio.h>
00031 #include "../config.h"
00032 #include "../dprint.h"
00033 #include "../globals.h"
00034 #include "mem.h"
00035 
00036 #ifdef PKG_MALLOC
00037    #include "q_malloc.h"
00038 #endif
00039 
00040 #include "shm_mem.h"
00041 
00042 #ifdef PKG_MALLOC
00043    char mem_pool[PKG_MEM_POOL_SIZE];
00044    #ifdef F_MALLOC
00045       struct fm_block* mem_block;
00046    #else
00047       struct qm_block* mem_block;
00048    #endif
00049 #endif
00050 
00051 
00052 int init_pkg_mallocs(void)
00053 {
00054 #ifdef PKG_MALLOC
00055    /*init mem*/
00056    #ifdef F_MALLOC
00057       mem_block=fm_malloc_init(mem_pool, PKG_MEM_POOL_SIZE);
00058    #else
00059       mem_block=qm_malloc_init(mem_pool, PKG_MEM_POOL_SIZE);
00060    #endif
00061    if (mem_block==0){
00062       LM_CRIT("could not initialize memory pool\n");
00063       fprintf(stderr, "Too much pkg memory demanded: %d\n",
00064          PKG_MEM_POOL_SIZE );
00065       return -1;
00066    }
00067 #endif
00068    return 0;
00069 }
00070 
00071 
00072 
00073 int init_shm_mallocs(void)
00074 {
00075    if (shm_mem_init()<0) {
00076       LM_CRIT("could not initialize shared memory pool, exiting...\n");
00077        fprintf(stderr, "Too much shared memory demanded: %lu\n",
00078          shm_mem_size );
00079       return -1;
00080    }
00081    return 0;
00082 }
00083 
00084 #ifdef SYSTEM_MALLOC
00085 void *
00086 sys_malloc(size_t s, const char *file, const char *function, int line)
00087 {
00088    void *v;
00089 
00090    v = malloc(s);
00091    LM_DBG("%s:%s:%d: malloc %p size %lu end %p\n", file, function, line,
00092        v, (unsigned long)s, (char *)v + s);
00093    return v;
00094 }
00095 
00096 void *
00097 sys_realloc(void *p, size_t s, const char *file, const char *function, int line)
00098 {
00099    void *v;
00100 
00101    v = realloc(p, s);
00102    LM_DBG("%s:%s:%d: realloc old %p to %p size %lu end %p\n", file,
00103        function, line, p, v, (unsigned long)s, (char *)v + s);
00104    return v;
00105 }
00106 
00107 void
00108 sys_free(void *p, const char *file, const char *function, int line)
00109 {
00110 
00111    LM_DBG("%s:%s:%d: free %p\n", file, function, line, p);
00112    free(p);
00113 }
00114 #endif

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