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.

55 lines
1.4 KiB

  1. #ifndef ALLOCATOR_INTERNAL_H
  2. #define ALLOCATOR_INTERNAL_H
  3. #include <stdint.h>
  4. // No enum because these need to be 1 byte
  5. const char RT_FREESPACE = 0;
  6. const char RT_TREE_NODE = 1;
  7. const char RT_WATERMARK = 2;
  8. typedef struct Arena {
  9. struct FreeSpace *root_freespace;
  10. struct TreeAlloc *root_treealloc;
  11. void *(*get_new_region)(uintptr_t);
  12. void (*error)(char*);
  13. } Arena;
  14. // All three of these types should be memory-compatible with each other
  15. typedef struct TreeAlloc {
  16. char type; // Should be RT_TREE_NODE
  17. struct TreeAlloc *parent;
  18. struct TreeAlloc *left;
  19. struct TreeAlloc *right;
  20. uintptr_t size;
  21. struct TreeAlloc *before;
  22. struct TreeAlloc *after;
  23. } TreeAlloc;
  24. typedef struct FreeSpace {
  25. char type; // Should be RT_FREESPACE
  26. struct FreeSpace *parent;
  27. struct FreeSpace *left;
  28. struct FreeSpace *right;
  29. uintptr_t size;
  30. } FreeSpace;
  31. typedef struct WatermarkAlloc {
  32. char type; // Should be RT_WATERMARK
  33. struct TreeAlloc *parent;
  34. struct TreeAlloc *left;
  35. struct TreeAlloc *right;
  36. uintptr_t size;
  37. struct TreeAlloc *before;
  38. struct TreeAlloc *after;
  39. int num_allocs;
  40. void *next_alloc;
  41. } WatermarkAlloc;
  42. void* align_after(void* address, uintptr_t align);
  43. TreeAlloc *insert_node_at(void *address, uintptr_t padding, uintptr_t align, uintptr_t size);
  44. TreeAlloc *search_by_address(TreeAlloc *root, void *address);
  45. TreeAlloc *search_by_size(TreeAlloc *root, uintptr_t padding, uintptr_t align, uintptr_t size);
  46. #endif