iPXE
umalloc.h
Go to the documentation of this file.
00001 #ifndef _IPXE_UMALLOC_H
00002 #define _IPXE_UMALLOC_H
00003 
00004 /**
00005  * @file
00006  *
00007  * User memory allocation
00008  *
00009  */
00010 
00011 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00012 
00013 #include <ipxe/api.h>
00014 #include <config/umalloc.h>
00015 #include <ipxe/uaccess.h>
00016 
00017 /**
00018  * Provide a user memory allocation API implementation
00019  *
00020  * @v _prefix           Subsystem prefix
00021  * @v _api_func         API function
00022  * @v _func             Implementing function
00023  */
00024 #define PROVIDE_UMALLOC( _subsys, _api_func, _func ) \
00025         PROVIDE_SINGLE_API ( UMALLOC_PREFIX_ ## _subsys, _api_func, _func )
00026 
00027 /* Include all architecture-independent I/O API headers */
00028 #include <ipxe/efi/efi_umalloc.h>
00029 #include <ipxe/linux/linux_umalloc.h>
00030 
00031 /* Include all architecture-dependent I/O API headers */
00032 #include <bits/umalloc.h>
00033 
00034 /**
00035  * Reallocate external memory
00036  *
00037  * @v userptr           Memory previously allocated by umalloc(), or UNULL
00038  * @v new_size          Requested size
00039  * @ret userptr         Allocated memory, or UNULL
00040  *
00041  * Calling realloc() with a new size of zero is a valid way to free a
00042  * memory block.
00043  */
00044 userptr_t urealloc ( userptr_t userptr, size_t new_size );
00045 
00046 /**
00047  * Allocate external memory
00048  *
00049  * @v size              Requested size
00050  * @ret userptr         Memory, or UNULL
00051  *
00052  * Memory is guaranteed to be aligned to a page boundary.
00053  */
00054 static inline __always_inline userptr_t umalloc ( size_t size ) {
00055         return urealloc ( UNULL, size );
00056 }
00057 
00058 /**
00059  * Free external memory
00060  *
00061  * @v userptr           Memory allocated by umalloc(), or UNULL
00062  *
00063  * If @c ptr is UNULL, no action is taken.
00064  */
00065 static inline __always_inline void ufree ( userptr_t userptr ) {
00066         urealloc ( userptr, 0 );
00067 }
00068 
00069 #endif /* _IPXE_UMALLOC_H */