MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / mmap_alloc

Function mmap_alloc

system/lib/dlmalloc.c:3907–3936  ·  view source on GitHub ↗

Malloc using mmap */

Source from the content-addressed store, hash-verified

3905
3906/* Malloc using mmap */
3907static void* mmap_alloc(mstate m, size_t nb) {
3908 size_t mmsize = mmap_align(nb + SIX_SIZE_T_SIZES + CHUNK_ALIGN_MASK);
3909 if (m->footprint_limit != 0) {
3910 size_t fp = m->footprint + mmsize;
3911 if (fp <= m->footprint || fp > m->footprint_limit)
3912 return 0;
3913 }
3914 if (mmsize > nb) { /* Check for wrap around 0 */
3915 char* mm = (char*)(CALL_DIRECT_MMAP(mmsize));
3916 if (mm != CMFAIL) {
3917 size_t offset = align_offset(chunk2mem(mm));
3918 size_t psize = mmsize - offset - MMAP_FOOT_PAD;
3919 mchunkptr p = (mchunkptr)(mm + offset);
3920 p->prev_foot = offset;
3921 p->head = psize;
3922 mark_inuse_foot(m, p, psize);
3923 chunk_plus_offset(p, psize)->head = FENCEPOST_HEAD;
3924 chunk_plus_offset(p, psize+SIZE_T_SIZE)->head = 0;
3925
3926 if (m->least_addr == 0 || mm < m->least_addr)
3927 m->least_addr = mm;
3928 if ((m->footprint += mmsize) > m->max_footprint)
3929 m->max_footprint = m->footprint;
3930 assert(is_aligned(chunk2mem(p)));
3931 check_mmapped_chunk(m, p);
3932 return chunk2mem(p);
3933 }
3934 }
3935 return 0;
3936}
3937
3938/* Realloc using mmap */
3939static mchunkptr mmap_resize(mstate m, mchunkptr oldp, size_t nb, int flags) {

Callers 1

sys_allocFunction · 0.85

Calls 1

assertFunction · 0.50

Tested by

no test coverage detected