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

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