#include <malloc.h>
#include <bool.h>
#include <as.h>
#include <align.h>
#include <macros.h>
#include <assert.h>
#include <errno.h>
#include <bitops.h>
#include <mem.h>
#include <futex.h>
#include <stdlib.h>
#include <adt/gcdlcm.h>
#include "private/malloc.h"
Go to the source code of this file.
Data Structures | |
struct | heap_area |
Heap area. More... | |
struct | heap_block_foot_t |
Footer of a heap block. More... | |
struct | heap_block_head_t |
Header of a heap block. More... | |
Defines | |
#define | AREA_FIRST_BLOCK_HEAD(area) (ALIGN_UP(((uintptr_t) (area)) + sizeof(heap_area_t), BASE_ALIGN)) |
Get first block in heap area. | |
#define | AREA_LAST_BLOCK_FOOT(area) (((uintptr_t) (area)->end) - sizeof(heap_block_foot_t)) |
Get last block in heap area. | |
#define | AREA_OVERHEAD(size) (ALIGN_UP(size + sizeof(heap_area_t), BASE_ALIGN)) |
Overhead of each area. | |
#define | BASE_ALIGN 16 |
Allocation alignment. | |
#define | BLOCK_FOOT(head) |
Get footer in heap block. | |
#define | BLOCK_HEAD(foot) |
Get header in heap block. | |
#define | GROSS_SIZE(size) ((size) + STRUCT_OVERHEAD) |
Calculate real size of a heap block. | |
#define | HEAP_AREA_MAGIC UINT32_C(0xBEEFCAFE) |
Magic used in heap descriptor. | |
#define | HEAP_BLOCK_FOOT_MAGIC UINT32_C(0xBEEF0202) |
Magic used in heap footers. | |
#define | HEAP_BLOCK_HEAD_MAGIC UINT32_C(0xBEEF0101) |
Magic used in heap headers. | |
#define | malloc_assert(expr) |
#define | NET_SIZE(size) ((size) - STRUCT_OVERHEAD) |
Calculate net size of a heap block. | |
#define | SHRINK_GRANULARITY (64 * PAGE_SIZE) |
Heap shrink granularity. | |
#define | STRUCT_OVERHEAD (sizeof(heap_block_head_t) + sizeof(heap_block_foot_t)) |
Overhead of each heap block. | |
Typedefs | |
typedef heap_area | heap_area_t |
Heap area. | |
Functions | |
void | __malloc_init (void) |
Initialize the heap allocator. | |
static void | area_check (void *addr) |
Check a heap area structure. | |
static bool | area_create (size_t size) |
Create new heap area. | |
static bool | area_grow (heap_area_t *area, size_t size) |
Try to enlarge a heap area. | |
static void | block_check (void *addr) |
Check a heap block. | |
static void | block_init (void *addr, size_t size, bool free, heap_area_t *area) |
Initialize a heap block. | |
void * | calloc (const size_t nmemb, const size_t size) |
Allocate memory by number of elements. | |
void | free (const void *addr) |
Free a memory block. | |
void * | heap_check (void) |
static bool | heap_grow (size_t size) |
Try to enlarge any of the heap areas. | |
static void | heap_shrink (heap_area_t *area) |
Try to shrink heap. | |
void * | malloc (const size_t size) |
Allocate memory. | |
static void * | malloc_area (heap_area_t *area, heap_block_head_t *first_block, heap_block_head_t *final_block, size_t real_size, size_t falign) |
Allocate memory from heap area starting from given block. | |
static void * | malloc_internal (const size_t size, const size_t align) |
Allocate a memory block. | |
void * | memalign (const size_t align, const size_t size) |
Allocate memory with specified alignment. | |
void * | realloc (const void *addr, const size_t size) |
Reallocate memory block. | |
static void | split_mark (heap_block_head_t *cur, const size_t size) |
Split heap block and mark it as used. | |
Variables | |
static heap_area_t * | first_heap_area = NULL |
First heap area. | |
static heap_area_t * | last_heap_area = NULL |
Last heap area. | |
static futex_t | malloc_futex = FUTEX_INITIALIZER |
Futex for thread-safe heap manipulation. | |
static heap_block_head_t * | next_fit = NULL |
Next heap block to examine (next fit algorithm). |
Definition in file malloc.c.