You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

53 lines
1.4 KiB

#ifndef ALLOCATOR_INTERNAL_H
#define ALLOCATOR_INTERNAL_H
#include <stdint.h>
// No enum because these need to be 1 byte
const char RT_FREESPACE = 0;
const char RT_TREE_NODE = 1;
const char RT_WATERMARK = 2;
struct TopLevel {
struct FreeSpace *root_freespace;
struct TreeAlloc *root_treealloc;
};
// All three of these types should be memory-compatible with each other
typedef struct TreeAlloc {
char type; // Should be RT_TREE_NODE
struct TreeAlloc *parent;
struct TreeAlloc *left;
struct TreeAlloc *right;
uintptr_t size;
struct TreeAlloc *before;
struct TreeAlloc *after;
} TreeAlloc;
typedef struct FreeSpace {
char type; // Should be RT_FREESPACE
struct FreeSpace *parent;
struct FreeSpace *left;
struct FreeSpace *right;
uintptr_t size;
} FreeSpace;
typedef struct WatermarkAlloc {
char type; // Should be RT_WATERMARK
struct TreeAlloc *parent;
struct TreeAlloc *left;
struct TreeAlloc *right;
uintptr_t size;
struct TreeAlloc *before;
struct TreeAlloc *after;
int num_allocs;
void *next_alloc;
} WatermarkAlloc;
void* align_after(void* address, uintptr_t align);
TreeAlloc *insert_node_at(void *address, uintptr_t padding, uintptr_t align, uintptr_t size);
TreeAlloc *search_by_address(TreeAlloc *root, void *address);
TreeAlloc *search_by_size(TreeAlloc *root, uintptr_t padding, uintptr_t align, uintptr_t size);
#endif