heap.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * heap.h
  3. *
  4. * Copyright (C) 2013 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as
  8. * published by the Free Software Foundation, either version 3 of the
  9. * License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef _HEAP_H_
  20. #define _HEAP_H_
  21. #include <common.h>
  22. #include <lock.h>
  23. #include <libraries/mlcrt/include/malloc.h>
  24. #define SYSTEM_HEAP_START 0x90000000
  25. #define SYSTEM_HEAP_END (EVICTABLE_HEAP_START - 1)
  26. #define EVICTABLE_HEAP_START 0xA0000000
  27. #define EVICTABLE_HEAP_END KERNEL_POOL_END
  28. #define SYSTEM_HEAP_MAGIC 0x74737953 // Syst
  29. #define EVICTABLE_HEAP_MAGIC 0x63697645 // Evic
  30. #define HEAP_ZEROFILL (1 << 0)
  31. #define HEAP_EVICTABLE (1 << 1)
  32. typedef struct _heap_header_t
  33. {
  34. dword_t length;
  35. bool_t free;
  36. dword_t magic;
  37. } heap_header_t;
  38. typedef struct
  39. {
  40. __crt_heap_t crt;
  41. lock_t lock;
  42. } heap_t;
  43. extern heap_t system_heap;
  44. extern heap_t evictable_heap;
  45. void *heap_alloc(heap_t *heap, uintptr_t size);
  46. void heap_free(heap_t *heap, void *ptr);
  47. void *heap_realloc(heap_t *heap, void *ptr, uintptr_t size);
  48. dword_t heap_create(heap_t *heap, uintptr_t start, uintptr_t end, dword_t flags, dword_t magic);
  49. dword_t heap_destroy(heap_t *heap);
  50. void heap_init(void);
  51. #endif