1234567891011121314151617181920212223242526272829 |
- #include <unistd.h>
- #include <stdio.h>
- #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);
- 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;
- }
|