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 <stddef.h>
14 #include <ipxe/api.h>
15 #include <ipxe/malloc.h>
16 #include <config/umalloc.h>
17 
18 /**
19  * Provide a user memory allocation API implementation
20  *
21  * @v _prefix Subsystem prefix
22  * @v _api_func API function
23  * @v _func Implementing function
24  */
25 #define PROVIDE_UMALLOC( _subsys, _api_func, _func ) \
26  PROVIDE_SINGLE_API ( UMALLOC_PREFIX_ ## _subsys, _api_func, _func )
27 
28 /* Include all architecture-independent I/O API headers */
29 #include <ipxe/uheap.h>
30 #include <ipxe/efi/efi_umalloc.h>
32 
33 /* Include all architecture-dependent I/O API headers */
34 #include <bits/umalloc.h>
35 
36 /**
37  * Reallocate external memory
38  *
39  * @v old_ptr Memory previously allocated by umalloc(), or NULL
40  * @v new_size Requested size
41  * @ret new_ptr Allocated memory, or NULL
42  *
43  * Calling realloc() with a new size of zero is a valid way to free a
44  * memory block.
45  */
46 void * urealloc ( void *ptr, size_t new_size );
47 
48 /**
49  * Allocate external memory
50  *
51  * @v size Requested size
52  * @ret ptr Memory, or NULL
53  *
54  * Memory is guaranteed to be aligned to a page boundary.
55  */
56 static inline __always_inline void * umalloc ( size_t size ) {
57  return urealloc ( NULL, size );
58 }
59 
60 /**
61  * Free external memory
62  *
63  * @v ptr Memory allocated by umalloc(), or NULL
64  *
65  * If @c ptr is NULL, no action is taken.
66  */
67 static inline __always_inline void ufree ( void *ptr ) {
68  urealloc ( ptr, 0 );
69 }
70 
71 #endif /* _IPXE_UMALLOC_H */
static __always_inline void ufree(void *ptr)
Free external memory.
Definition: umalloc.h:67
Dummy architecture-specific user memory allocation API implementations.
iPXE internal APIs
uint16_t size
Buffer size.
Definition: dwmac.h:14
User memory allocation API configuration.
Dynamic memory allocation.
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
External ("user") heap.
static __always_inline void * umalloc(size_t size)
Allocate external memory.
Definition: umalloc.h:56
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
void * urealloc(void *ptr, size_t new_size)
Reallocate external memory.
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321