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.

malloc.h 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #ifndef _MALLOC_H
  2. #define _MALLOC_H
  3. #include <stdint.h>
  4. /** @file
  5. *
  6. * Dynamic memory allocation
  7. *
  8. */
  9. extern void * alloc_memblock ( size_t size, size_t align );
  10. extern void free_memblock ( void *ptr, size_t size );
  11. extern void * malloc ( size_t size );
  12. extern void free ( void *ptr );
  13. extern void mpopulate ( void *start, size_t len );
  14. extern void mdumpfree ( void );
  15. /**
  16. * Allocate memory for DMA
  17. *
  18. * @v size Requested size
  19. * @v align Physical alignment
  20. * @ret ptr Memory, or NULL
  21. *
  22. * Allocates physically-aligned memory for DMA.
  23. *
  24. * @c align must be a power of two. @c size may not be zero.
  25. */
  26. static inline void * malloc_dma ( size_t size, size_t phys_align ) {
  27. return alloc_memblock ( size, phys_align );
  28. }
  29. /**
  30. * Free memory allocated with malloc_dma()
  31. *
  32. * @v ptr Memory allocated by malloc_dma(), or NULL
  33. * @v size Size of memory, as passed to malloc_dma()
  34. *
  35. * Memory allocated with malloc_dma() can only be freed with
  36. * free_dma(); it cannot be freed with the standard free().
  37. *
  38. * If @c ptr is NULL, no action is taken.
  39. */
  40. static inline void free_dma ( void *ptr, size_t size ) {
  41. free_memblock ( ptr, size );
  42. }
  43. /**
  44. * Allocate cleared memory
  45. *
  46. * @v nmemb Number of members
  47. * @v size Size of each member
  48. * @ret ptr Allocated memory
  49. *
  50. * Allocate memory as per malloc(), and zero it.
  51. *
  52. * Note that malloc() and calloc() are identical, in the interests of
  53. * reducing code size. Callers should not, however, rely on malloc()
  54. * clearing memory, since this behaviour may change in future.
  55. */
  56. static inline void * calloc ( size_t nmemb, size_t size ) {
  57. return malloc ( nmemb * size );
  58. }
  59. #endif /* _MALLOC_H */