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