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. struct TopLevel {
  9. struct FreeSpace *root_freespace;
  10. struct TreeAlloc *root_treealloc;
  11. };
  12. // All three of these types should be memory-compatible with each other
  13. typedef struct TreeAlloc {
  14. char type; // Should be RT_TREE_NODE
  15. struct TreeAlloc *parent;
  16. struct TreeAlloc *left;
  17. struct TreeAlloc *right;
  18. struct TreeAlloc *before;
  19. struct TreeAlloc *after;
  20. uintptr_t size;
  21. } TreeAlloc;
  22. typedef struct FreeSpace {
  23. char type; // Should be RT_FREESPACE
  24. struct FreeSpace *parent;
  25. struct FreeSpace *left;
  26. struct FreeSpace *right;
  27. struct TreeAlloc *before;
  28. struct TreeAlloc *after;
  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. struct TreeAlloc *before;
  37. struct TreeAlloc *after;
  38. uintptr_t size;
  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