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.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #ifndef _GPXE_MALLOC_H
  2. #define _GPXE_MALLOC_H
  3. #include <stdint.h>
  4. /** @file
  5. *
  6. * Dynamic memory allocation
  7. *
  8. */
  9. /*
  10. * Prototypes for the standard functions (malloc() et al) are in
  11. * stdlib.h. Include <gpxe/malloc.h> only if you need the
  12. * non-standard functions, such as malloc_dma().
  13. *
  14. */
  15. #include <stdlib.h>
  16. extern size_t freemem;
  17. extern void * __malloc alloc_memblock ( size_t size, size_t align );
  18. extern void free_memblock ( void *ptr, size_t size );
  19. extern void mpopulate ( void *start, size_t len );
  20. extern void mdumpfree ( void );
  21. /**
  22. * Allocate memory for DMA
  23. *
  24. * @v size Requested size
  25. * @v align Physical alignment
  26. * @ret ptr Memory, or NULL
  27. *
  28. * Allocates physically-aligned memory for DMA.
  29. *
  30. * @c align must be a power of two. @c size may not be zero.
  31. */
  32. static inline void * __malloc malloc_dma ( size_t size, size_t phys_align ) {
  33. return alloc_memblock ( size, phys_align );
  34. }
  35. /**
  36. * Free memory allocated with malloc_dma()
  37. *
  38. * @v ptr Memory allocated by malloc_dma(), or NULL
  39. * @v size Size of memory, as passed to malloc_dma()
  40. *
  41. * Memory allocated with malloc_dma() can only be freed with
  42. * free_dma(); it cannot be freed with the standard free().
  43. *
  44. * If @c ptr is NULL, no action is taken.
  45. */
  46. static inline void free_dma ( void *ptr, size_t size ) {
  47. free_memblock ( ptr, size );
  48. }
  49. #endif /* _GPXE_MALLOC_H */