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.

heap.h 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #ifndef HEAP_H
  2. #define HEAP_H
  3. /*
  4. * Allocate a block with specified (physical) alignment
  5. *
  6. * "align" must be a power of 2.
  7. *
  8. * Note that "align" affects the alignment of the physical address,
  9. * not the virtual address. This is almost certainly what you want.
  10. *
  11. */
  12. extern void * emalloc ( size_t size, unsigned int align );
  13. /*
  14. * Allocate all remaining space on the heap
  15. *
  16. */
  17. extern void * emalloc_all ( size_t *size );
  18. /*
  19. * Free a block.
  20. *
  21. * The caller must ensure that the block being freed is the last (most
  22. * recent) block allocated on the heap, otherwise heap corruption will
  23. * occur.
  24. *
  25. */
  26. extern void efree ( void *ptr );
  27. /*
  28. * Free all allocated blocks on the heap
  29. *
  30. */
  31. extern void efree_all ( void );
  32. /*
  33. * Resize a block.
  34. *
  35. * The caller must ensure that the block being resized is the last
  36. * (most recent) block allocated on the heap, otherwise heap
  37. * corruption will occur.
  38. *
  39. */
  40. extern void * erealloc ( void *ptr, size_t size );
  41. /*
  42. * Allocate, free, and resize blocks without caring about alignment
  43. *
  44. */
  45. static inline void * malloc ( size_t size ) {
  46. return emalloc ( size, sizeof ( void * ) );
  47. }
  48. static inline void free ( void *ptr ) {
  49. efree ( ptr );
  50. }
  51. static inline void * realloc ( void *ptr, size_t size ) {
  52. return erealloc ( ptr, size );
  53. }
  54. /*
  55. * Legacy API calls
  56. *
  57. */
  58. static inline void * allot ( size_t size ) {
  59. return emalloc ( size, sizeof ( void * ) );
  60. }
  61. static inline void forget ( void *ptr ) {
  62. efree ( ptr );
  63. }
  64. static inline void * allot2 ( size_t size, uint32_t mask ) {
  65. return emalloc ( size, mask + 1 );
  66. }
  67. static inline void forget2 ( void *ptr ) {
  68. efree ( ptr );
  69. }
  70. /*
  71. * Heap markers. osloader.c and other code may wish to know the heap
  72. * location, without necessarily wanting to drag in heap.o. We
  73. * therefore declare these as shared (i.e. common) symbols.
  74. *
  75. */
  76. physaddr_t heap_ptr __asm__ ( "_shared_heap_ptr" );
  77. physaddr_t heap_end __asm__ ( "_shared_heap_end" );
  78. #endif /* HEAP_H */