diff options
| author | Michael Brown | 2008-10-13 05:32:11 +0200 |
|---|---|---|
| committer | Michael Brown | 2008-10-13 06:33:14 +0200 |
| commit | 831e4cfc2718b0784bc22c2d00045481ab3c65b5 (patch) | |
| tree | 34d26c6b88381b490d71c020bc9e72b0e90eca37 /src/include | |
| parent | [uaccess] Formalise the uaccess API (diff) | |
| download | ipxe-831e4cfc2718b0784bc22c2d00045481ab3c65b5.tar.gz ipxe-831e4cfc2718b0784bc22c2d00045481ab3c65b5.tar.xz ipxe-831e4cfc2718b0784bc22c2d00045481ab3c65b5.zip | |
[umalloc] Formalise the user memory allocation API
Diffstat (limited to 'src/include')
| -rw-r--r-- | src/include/gpxe/umalloc.h | 54 |
1 files changed, 51 insertions, 3 deletions
diff --git a/src/include/gpxe/umalloc.h b/src/include/gpxe/umalloc.h index 49ec22b47..ffa0c0c49 100644 --- a/src/include/gpxe/umalloc.h +++ b/src/include/gpxe/umalloc.h @@ -8,10 +8,58 @@ * */ +#include <gpxe/api.h> +#include <config/umalloc.h> #include <gpxe/uaccess.h> -extern userptr_t umalloc ( size_t size ); -extern userptr_t urealloc ( userptr_t ptr, size_t new_size ); -extern void ufree ( userptr_t ptr ); +/** + * Provide a user memory allocation API implementation + * + * @v _prefix Subsystem prefix + * @v _api_func API function + * @v _func Implementing function + */ +#define PROVIDE_UMALLOC( _subsys, _api_func, _func ) \ + PROVIDE_SINGLE_API ( UMALLOC_PREFIX_ ## _subsys, _api_func, _func ) + +/* Include all architecture-independent I/O API headers */ + +/* Include all architecture-dependent I/O API headers */ +#include <bits/umalloc.h> + +/** + * Reallocate external memory + * + * @v userptr Memory previously allocated by umalloc(), or UNULL + * @v new_size Requested size + * @ret userptr Allocated memory, or UNULL + * + * Calling realloc() with a new size of zero is a valid way to free a + * memory block. + */ +userptr_t urealloc ( userptr_t userptr, size_t new_size ); + +/** + * Allocate external memory + * + * @v size Requested size + * @ret userptr Memory, or UNULL + * + * Memory is guaranteed to be aligned to a page boundary. + */ +static inline __always_inline userptr_t umalloc ( size_t size ) { + return urealloc ( UNULL, size ); +} + +/** + * Free external memory + * + * @v userptr Memory allocated by umalloc(), or UNULL + * + * If @c ptr is UNULL, no action is taken. + */ +static inline __always_inline void ufree ( userptr_t userptr ) { + urealloc ( userptr, 0 ); +} #endif /* _GPXE_UMALLOC_H */ |
