#include #include #include #include #include "dmm_config.h" #ifdef HAVE_LOCKS #include "posix_lock.h" #endif /* HAVE_LOCKS */ #include "other.h" #include "sys_alloc.h" #include "block_header.h" #include "heap.h" void *sys_alloc(heap_t *heap, size_t size) { size_t allocation_size; void *ptr; #ifdef HAVE_LOCKS sbrk_lock(); #endif /* HAVE_LOCKS */ allocation_size = req_padding(size) + HEADER_SIZE; ptr = sbrk((int) allocation_size); if(ptr == (void *) -1) { printf("sbrk problem for size of: %zu\n", allocation_size); printf( "Error on sbrk: %s\n", strerror( errno ) ); } ptr = (void *) ((char *) ptr + HEADER_SIZE); set_size(ptr, req_padding(size)); heap->dmm_stats.mem_allocated += req_padding(size); heap->dmm_stats.mem_requested += size; #ifdef HAVE_LOCKS sbrk_unlock(); #endif /* HAVE_LOCKS */ return ptr; }