123456789101112131415161718192021222324252627282930313233343536373839404142 |
- #include <unistd.h>
- #include <stdio.h>
- #include <errno.h>
- #include <string.h>
- #include <dmmlib/heap.h>
- #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"
- 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;
- }
|