* Pool init. */
| 1794 | * Pool init. |
| 1795 | */ |
| 1796 | static 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). |
no test coverage detected