#include #include #include #include #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)); set_requested_size(ptr, size); set_next(ptr, heap->used_blocks_head); heap->used_blocks_head = ptr; #ifdef HAVE_LOCKS sbrk_unlock(); #endif /* HAVE_LOCKS */ return ptr; }