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.

umalloc.h 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #ifndef _GPXE_UMALLOC_H
  2. #define _GPXE_UMALLOC_H
  3. /**
  4. * @file
  5. *
  6. * User memory allocation
  7. *
  8. */
  9. #include <gpxe/api.h>
  10. #include <config/umalloc.h>
  11. #include <gpxe/uaccess.h>
  12. /**
  13. * Provide a user memory allocation API implementation
  14. *
  15. * @v _prefix Subsystem prefix
  16. * @v _api_func API function
  17. * @v _func Implementing function
  18. */
  19. #define PROVIDE_UMALLOC( _subsys, _api_func, _func ) \
  20. PROVIDE_SINGLE_API ( UMALLOC_PREFIX_ ## _subsys, _api_func, _func )
  21. /* Include all architecture-independent I/O API headers */
  22. #include <gpxe/efi/efi_umalloc.h>
  23. /* Include all architecture-dependent I/O API headers */
  24. #include <bits/umalloc.h>
  25. /**
  26. * Reallocate external memory
  27. *
  28. * @v userptr Memory previously allocated by umalloc(), or UNULL
  29. * @v new_size Requested size
  30. * @ret userptr Allocated memory, or UNULL
  31. *
  32. * Calling realloc() with a new size of zero is a valid way to free a
  33. * memory block.
  34. */
  35. userptr_t urealloc ( userptr_t userptr, size_t new_size );
  36. /**
  37. * Allocate external memory
  38. *
  39. * @v size Requested size
  40. * @ret userptr Memory, or UNULL
  41. *
  42. * Memory is guaranteed to be aligned to a page boundary.
  43. */
  44. static inline __always_inline userptr_t umalloc ( size_t size ) {
  45. return urealloc ( UNULL, size );
  46. }
  47. /**
  48. * Free external memory
  49. *
  50. * @v userptr Memory allocated by umalloc(), or UNULL
  51. *
  52. * If @c ptr is UNULL, no action is taken.
  53. */
  54. static inline __always_inline void ufree ( userptr_t userptr ) {
  55. urealloc ( userptr, 0 );
  56. }
  57. #endif /* _GPXE_UMALLOC_H */