#include #include #include #include #include "posix_lock.h" #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; sbrk_lock(); 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; sbrk_unlock(); return ptr; }