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.

61 lines
1.5 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. const char COLOR_RED = 0;
  9. const char COLOR_BLACK = 1;
  10. typedef struct Arena {
  11. struct FreeSpace *root_freespace;
  12. struct TreeAlloc *root_treealloc;
  13. void *(*get_new_region)(uintptr_t);
  14. void (*error)(char*);
  15. } Arena;
  16. // All three of these types should be memory-compatible with each other
  17. typedef struct TreeAlloc {
  18. char type; // Should be RT_TREE_NODE
  19. char color;
  20. struct TreeAlloc *parent;
  21. struct TreeAlloc *left;
  22. struct TreeAlloc *right;
  23. uintptr_t size;
  24. struct TreeAlloc *before;
  25. struct TreeAlloc *after;
  26. } TreeAlloc;
  27. typedef struct FreeSpace {
  28. char type; // Should be RT_FREESPACE
  29. char color;
  30. struct FreeSpace *parent;
  31. struct FreeSpace *left;
  32. struct FreeSpace *right;
  33. uintptr_t size;
  34. } FreeSpace;
  35. typedef struct WatermarkAlloc {
  36. char type; // Should be RT_WATERMARK
  37. char color;
  38. struct TreeAlloc *parent;
  39. struct TreeAlloc *left;
  40. struct TreeAlloc *right;
  41. uintptr_t size;
  42. struct TreeAlloc *before;
  43. struct TreeAlloc *after;
  44. int num_allocs;
  45. void *next_alloc;
  46. } WatermarkAlloc;
  47. void* align_after(void* address, uintptr_t align);
  48. TreeAlloc *insert_node_at(void *address, uintptr_t padding, uintptr_t align, uintptr_t size);
  49. TreeAlloc *search_by_address(TreeAlloc *root, void *address);
  50. TreeAlloc *search_by_size(TreeAlloc *root, uintptr_t padding, uintptr_t align, uintptr_t size);
  51. #endif