MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / create_mspace

Function create_mspace

dlmalloc/dlmalloc.c:4736–4767  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4734}
4735
4736mspace create_mspace(size_t capacity, int locked) {
4737 mstate m = 0;
4738 size_t msize = pad_request(sizeof(struct malloc_state));
4739 init_mparams(); /* Ensure pagesize etc initialized */
4740
4741 if (capacity < (size_t) -(msize + TOP_FOOT_SIZE + mparams.page_size)) {
4742 size_t rs = (capacity + TOP_FOOT_SIZE + msize);
4743 size_t tsize = granularity_align(rs);
4744 char* tbase = (char*)(CALL_MMAP(tsize));
4745 if (tbase == CMFAIL) {
4746 tbase = malloc(tsize);
4747 if (tbase == NULL)
4748 tbase = CMFAIL;
4749 }
4750 if (tbase != CMFAIL) {
4751 m = init_user_mstate(tbase, tsize);
4752 m->seg.sflags = IS_MMAPPED_BIT;
4753 set_lock(m, locked);
4754 }
4755 }
4756
4757 if (m != NULL) {
4758 m->allocfunc = 0;
4759 m->alloc0func = 0;
4760 m->destfunc = 0;
4761 m->reallocfunc = 0;
4762 m->nallocs = 0;
4763 ZERO_HIST(m);
4764 }
4765
4766 return (mspace) m;
4767}
4768
4769void mspace_setmorecore(mspace msp, void*(*allocfunc)(size_t)) {
4770 mstate m = (mstate) msp;

Callers 2

comdb2ma_initFunction · 0.85
comdb2ma_create_intFunction · 0.85

Calls 3

init_mparamsFunction · 0.85
mallocFunction · 0.85
init_user_mstateFunction · 0.85

Tested by

no test coverage detected