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

Function pool_init

examples/stdlib.c:1796–1822  ·  view source on GitHub ↗

* Pool init. */

Source from the content-addressed store, hash-verified

1794 * Pool init.
1795 */
1796static struct malloc_pool_s *pool_init(struct malloc_pool_s *pool)
1797{
1798 pool = (pool == NULL? &malloc_pool: pool);
1799 if (pool->base != NULL)
1800 return pool;
1801 if (mutex_lock(&pool->mutex) < 0)
1802 return pool;
1803 if (pool->base != NULL)
1804 {
1805 mutex_unlock(&pool->mutex);
1806 return pool;
1807 }
1808 uintptr_t hint = 0xaaa00000000ull;
1809 (void)getrandom(&hint, sizeof(uint32_t), 0);
1810 hint &= ~(MA_PAGE_SIZE-1);
1811 void *ptr = mmap((void *)hint, MA_MAX_SIZE, PROT_NONE,
1812 MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0);
1813 if (ptr == MAP_FAILED)
1814 panic("mmap() failed");
1815 pool->base = (uint8_t *)ptr;
1816 pool->mmap = 0;
1817 pool->end = UINT32_MAX;
1818 pool->root = MA_NIL;
1819 pool->flags = MAP_PRIVATE | MAP_ANONYMOUS;
1820 mutex_unlock(&pool->mutex);
1821 return pool;
1822}
1823
1824/*
1825 * Fix the interval-tree invariant (RB-tree augmentation).

Callers 3

malloc_implFunction · 0.85
free_implFunction · 0.85
realloc_implFunction · 0.85

Calls 4

mutex_lockFunction · 0.85
mutex_unlockFunction · 0.85
getrandomFunction · 0.85
mmapFunction · 0.85

Tested by

no test coverage detected