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