Malloc using mmap */
| 3819 | |
| 3820 | /* Malloc using mmap */ |
| 3821 | static void* mmap_alloc(mstate m, size_t nb) { |
| 3822 | size_t mmsize = mmap_align(nb + SIX_SIZE_T_SIZES + CHUNK_ALIGN_MASK); |
| 3823 | if (m->footprint_limit != 0) { |
| 3824 | size_t fp = m->footprint + mmsize; |
| 3825 | if (fp <= m->footprint || fp > m->footprint_limit) |
| 3826 | return 0; |
| 3827 | } |
| 3828 | if (mmsize > nb) { /* Check for wrap around 0 */ |
| 3829 | char* mm = (char*)(CALL_DIRECT_MMAP(mmsize)); |
| 3830 | if (mm != CMFAIL) { |
| 3831 | size_t offset = align_offset(chunk2mem(mm)); |
| 3832 | size_t psize = mmsize - offset - MMAP_FOOT_PAD; |
| 3833 | mchunkptr p = (mchunkptr)(mm + offset); |
| 3834 | p->prev_foot = offset; |
| 3835 | p->head = psize; |
| 3836 | mark_inuse_foot(m, p, psize); |
| 3837 | chunk_plus_offset(p, psize)->head = FENCEPOST_HEAD; |
| 3838 | chunk_plus_offset(p, psize+SIZE_T_SIZE)->head = 0; |
| 3839 | |
| 3840 | if (m->least_addr == 0 || mm < m->least_addr) |
| 3841 | m->least_addr = mm; |
| 3842 | if ((m->footprint += mmsize) > m->max_footprint) |
| 3843 | m->max_footprint = m->footprint; |
| 3844 | assert(is_aligned(chunk2mem(p))); |
| 3845 | check_mmapped_chunk(m, p); |
| 3846 | return chunk2mem(p); |
| 3847 | } |
| 3848 | } |
| 3849 | return 0; |
| 3850 | } |
| 3851 | |
| 3852 | /* Realloc using mmap */ |
| 3853 | static mchunkptr mmap_resize(mstate m, mchunkptr oldp, size_t nb, int flags) { |