iPXE
umalloc.h
Go to the documentation of this file.
1 #ifndef _IPXE_UMALLOC_H
2 #define _IPXE_UMALLOC_H
3 
4 /**
5  * @file
6  *
7  * User memory allocation
8  *
9  */
10 
11 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
12 
13 #include <ipxe/api.h>
14 #include <config/umalloc.h>
15 #include <ipxe/uaccess.h>
16 
17 /**
18  * Provide a user memory allocation API implementation
19  *
20  * @v _prefix Subsystem prefix
21  * @v _api_func API function
22  * @v _func Implementing function
23  */
24 #define PROVIDE_UMALLOC( _subsys, _api_func, _func ) \
25  PROVIDE_SINGLE_API ( UMALLOC_PREFIX_ ## _subsys, _api_func, _func )
26 
27 /* Include all architecture-independent I/O API headers */
28 #include <ipxe/efi/efi_umalloc.h>
30 
31 /* Include all architecture-dependent I/O API headers */
32 #include <bits/umalloc.h>
33 
34 /**
35  * Reallocate external memory
36  *
37  * @v userptr Memory previously allocated by umalloc(), or UNULL
38  * @v new_size Requested size
39  * @ret userptr Allocated memory, or UNULL
40  *
41  * Calling realloc() with a new size of zero is a valid way to free a
42  * memory block.
43  */
44 userptr_t urealloc ( userptr_t userptr, size_t new_size );
45 
46 /**
47  * Allocate external memory
48  *
49  * @v size Requested size
50  * @ret userptr Memory, or UNULL
51  *
52  * Memory is guaranteed to be aligned to a page boundary.
53  */
54 static inline __always_inline userptr_t umalloc ( size_t size ) {
55  return urealloc ( UNULL, size );
56 }
57 
58 /**
59  * Free external memory
60  *
61  * @v userptr Memory allocated by umalloc(), or UNULL
62  *
63  * If @c ptr is UNULL, no action is taken.
64  */
65 static inline __always_inline void ufree ( userptr_t userptr ) {
66  urealloc ( userptr, 0 );
67 }
68 
69 #endif /* _IPXE_UMALLOC_H */
iPXE internal APIs
x86-specific user memory allocation API implementations
User memory allocation API configuration.
Access to external ("user") memory.
userptr_t urealloc(userptr_t userptr, size_t new_size)
Reallocate external memory.
iPXE user memory allocation API for Linux
#define __always_inline
Declare a function to be always inline.
Definition: compiler.h:611
iPXE user memory allocation API for EFI
#define UNULL
Equivalent of NULL for user pointers.
Definition: uaccess.h:36
static __always_inline void ufree(userptr_t userptr)
Free external memory.
Definition: umalloc.h:65
static __always_inline userptr_t umalloc(size_t size)
Allocate external memory.
Definition: umalloc.h:54
uint8_t size
Entry size (in 32-bit words)
Definition: ena.h:16
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
unsigned long userptr_t
A pointer to a user buffer.
Definition: uaccess.h:33