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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #ifndef _IPXE_UMALLOC_H
  2. #define _IPXE_UMALLOC_H
  3. /**
  4. * @file
  5. *
  6. * User memory allocation
  7. *
  8. */
  9. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  10. #include <ipxe/api.h>
  11. #include <config/umalloc.h>
  12. #include <ipxe/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 <ipxe/efi/efi_umalloc.h>
  24. #include <ipxe/linux/linux_umalloc.h>
  25. /* Include all architecture-dependent I/O API headers */
  26. #include <bits/umalloc.h>
  27. /**
  28. * Reallocate external memory
  29. *
  30. * @v userptr Memory previously allocated by umalloc(), or UNULL
  31. * @v new_size Requested size
  32. * @ret userptr Allocated memory, or UNULL
  33. *
  34. * Calling realloc() with a new size of zero is a valid way to free a
  35. * memory block.
  36. */
  37. userptr_t urealloc ( userptr_t userptr, size_t new_size );
  38. /**
  39. * Allocate external memory
  40. *
  41. * @v size Requested size
  42. * @ret userptr Memory, or UNULL
  43. *
  44. * Memory is guaranteed to be aligned to a page boundary.
  45. */
  46. static inline __always_inline userptr_t umalloc ( size_t size ) {
  47. return urealloc ( UNULL, size );
  48. }
  49. /**
  50. * Free external memory
  51. *
  52. * @v userptr Memory allocated by umalloc(), or UNULL
  53. *
  54. * If @c ptr is UNULL, no action is taken.
  55. */
  56. static inline __always_inline void ufree ( userptr_t userptr ) {
  57. urealloc ( userptr, 0 );
  58. }
  59. #endif /* _IPXE_UMALLOC_H */