mem.c
Go to the documentation of this file.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 #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
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