void* chpl_pvalloc(size_t size) { size_t page_size = chpl_getHeapPageSize(); size_t num_pages = (size + page_size - 1) / page_size; size_t rounded_up = num_pages * page_size; return chpl_memalign(chpl_getHeapPageSize(), rounded_up); }
/* We have to see if the thread stacks should be allocated in * the chapel heap and if we need to add a guard page for catch * a stack overflow */ void chpl_init_heap_stack(void){ // We don't want a guard page, but we want the stack in the heap if (CHPL_STACK_CHECKS == 0) { chpl_alloc_stack_in_heap = true; chpl_use_guard_page = false; return; } /* Special case: we want a guard page, but we can't add it. So * we use a pthread stack that provides a guard page. */ #if defined(CHPL_USING_CSTDLIB_MALLOC) && defined(__APPLE__) chpl_alloc_stack_in_heap = false; chpl_use_guard_page = false; return; #else if (chpl_getHeapPageSize() != chpl_getSysPageSize()) { chpl_alloc_stack_in_heap = false; chpl_use_guard_page = false; return; } // We want a guard page and we can add it chpl_alloc_stack_in_heap = true; chpl_use_guard_page = true; #endif }
static inline void alignAddrSize(void* p, size_t size, chpl_bool onlyInside, size_t* p_pgSize, unsigned char** p_pPgLo, size_t* p_nPages) { unsigned char* pCh = (unsigned char*) p; size_t pgSize = chpl_getHeapPageSize(); size_t pgMask = pgSize - 1; unsigned char* pPgLo; size_t nPages; if (onlyInside) { pPgLo = round_up_to_mask_ptr(pCh, pgMask); if (size < pPgLo - pCh) nPages = 0; else nPages = round_down_to_mask(size - (pPgLo - pCh), pgMask) / pgSize; } else { pPgLo = round_down_to_mask_ptr(pCh, pgMask); nPages = round_up_to_mask(size + (pCh - pPgLo), pgMask) / pgSize; } *p_pgSize = pgSize; *p_pPgLo = pPgLo; *p_nPages = nPages; }
void* chpl_valloc(size_t size) { return chpl_memalign(chpl_getHeapPageSize(), size); }