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
11FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
12FILE_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>
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 */
47void * 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 */
57static 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 */
68static inline __always_inline void ufree ( void *ptr ) {
69 urealloc ( ptr, 0 );
70}
71
72#endif /* _IPXE_UMALLOC_H */
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
iPXE internal APIs
User memory allocation API configuration.
iPXE user memory allocation API for EFI
#define __always_inline
Declare a function to be always inline.
Definition compiler.h:611
uint16_t size
Buffer size.
Definition dwmac.h:3
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:926
Dummy architecture-specific user memory allocation API implementations.
void * urealloc(void *ptr, size_t new_size)
Reallocate external memory.
static __always_inline void * umalloc(size_t size)
Allocate external memory.
Definition umalloc.h:57
static __always_inline void ufree(void *ptr)
Free external memory.
Definition umalloc.h:68
iPXE user memory allocation API for Linux
Dynamic memory allocation.
External ("user") heap.