MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / fm_malloc_init

Function fm_malloc_init

mem/f_malloc.c:194–257  ·  view source on GitHub ↗

init malloc and return a fm_block*/

Source from the content-addressed store, hash-verified

192
193/* init malloc and return a fm_block*/
194struct fm_block *fm_malloc_init(char *address, unsigned long size, char *name)
195
196{
197 char *start;
198 char *end;
199 struct fm_block *fm;
200 unsigned long init_overhead;
201
202 /* make address and size multiple of 8*/
203 start=(char*)ROUNDUP((unsigned long) address);
204 LM_DBG("F_OPTIMIZE=%lu, /ROUNDTO=%lu, %lu-bytes aligned\n",
205 F_MALLOC_OPTIMIZE, F_MALLOC_OPTIMIZE/ROUNDTO,
206 (unsigned long)ROUNDTO);
207 LM_DBG("F_HASH_SIZE=%lu, fm_block size=%zu, frag_size=%zu\n",
208 F_HASH_SIZE, sizeof(struct fm_block), sizeof(struct fm_frag));
209 LM_DBG("params (%p, %lu), start=%p\n", address, size, start);
210
211 if (size<(unsigned long)(start-address)) return 0;
212 size-=(start-address);
213 if (size <(MIN_FRAG_SIZE+FRAG_OVERHEAD)) return 0;
214 size=ROUNDDOWN(size);
215
216 init_overhead=(ROUNDUP(sizeof(struct fm_block))+ 2 * FRAG_OVERHEAD);
217
218
219 if (size < init_overhead)
220 {
221 /* not enough mem to create our control structures !!!*/
222 return 0;
223 }
224 end=start+size;
225 fm=(struct fm_block *)(void *)start;
226 memset(fm, 0, sizeof(struct fm_block));
227 fm->name = name;
228 fm->size=size;
229
230 #if defined(DBG_MALLOC) || defined(STATISTICS)
231 fm->used=size-init_overhead;
232 fm->real_used=size;
233 fm->max_real_used=init_overhead;
234 fm->fragments = 0;
235 #endif
236
237 fm->first_frag=(struct fm_frag *)(void *)(start+ROUNDUP(sizeof(struct fm_block)));
238 fm->last_frag=(struct fm_frag *)(void *)end - 1;
239
240 /* init initial fragments */
241 fm->first_frag->size=size-init_overhead;
242 fm->first_frag->pf=NULL;
243 fm->last_frag->size=0;
244 fm->last_frag->pf=fm->first_frag;
245
246 fm->last_frag->prev=NULL;
247 fm->first_frag->prev=NULL;
248
249 assert(((char *)fm->first_frag + sizeof *fm->first_frag + fm->first_frag->size)
250 == (char *)fm->last_frag);
251

Callers 4

init_pkg_mallocsFunction · 0.85
rpm_mem_init_mallocsFunction · 0.85
shm_mem_init_mallocsFunction · 0.85
shm_dbg_mem_init_mallocsFunction · 0.85

Calls 1

fm_insert_freeFunction · 0.85

Tested by

no test coverage detected