MCPcopy Create free account
hub / github.com/GJDuck/e9patch / malloc_mem_grow

Function malloc_mem_grow

examples/stdlib.c:2119–2137  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2117}
2118
2119static bool malloc_mem_grow(struct malloc_pool_s *pool, uint32_t hi)
2120{
2121 if (hi <= pool->mmap)
2122 return true;
2123 uint8_t *base = pool->base + (size_t)pool->mmap * MA_UNIT;
2124 size_t extension = (size_t)(hi - pool->mmap) * MA_UNIT;
2125 extension -= extension % MA_PAGE_SIZE;
2126 extension += 4 * MA_PAGE_SIZE; // Extra padding
2127 uint8_t *ptr = (uint8_t *)mmap(base, extension, PROT_READ | PROT_WRITE,
2128 pool->flags | MAP_FIXED, -1, 0);
2129 if (ptr != base)
2130 {
2131 (void)munmap(ptr, extension);
2132 errno = ENOMEM;
2133 return false;
2134 }
2135 pool->mmap += extension / MA_UNIT;
2136 return true;
2137}
2138
2139static uint32_t malloc_mem_alloc(struct malloc_pool_s *pool, uint32_t size,
2140 uint32_t lb, uint32_t ub)

Callers 2

malloc_mem_allocFunction · 0.85
malloc_mem_reallocFunction · 0.85

Calls 2

mmapFunction · 0.85
munmapFunction · 0.85

Tested by

no test coverage detected