mirror of
https://github.com/ipxe/ipxe
synced 2026-02-02 17:40:24 +03:00
[umalloc] Remove userptr_t from user memory allocations
Use standard void pointers for umalloc(), urealloc(), and ufree(),
with the "u" prefix retained to indicate that these allocations are
made from external ("user") memory rather than from the internal heap.
Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -106,9 +106,9 @@ struct dma_operations {
|
||||
* @v align Physical alignment
|
||||
* @ret addr Buffer address, or NULL on error
|
||||
*/
|
||||
userptr_t ( * umalloc ) ( struct dma_device *dma,
|
||||
struct dma_mapping *map,
|
||||
size_t len, size_t align );
|
||||
void * ( * umalloc ) ( struct dma_device *dma,
|
||||
struct dma_mapping *map,
|
||||
size_t len, size_t align );
|
||||
/**
|
||||
* Unmap and free DMA-coherent buffer from external (user) memory
|
||||
*
|
||||
@@ -118,7 +118,7 @@ struct dma_operations {
|
||||
* @v len Length of buffer
|
||||
*/
|
||||
void ( * ufree ) ( struct dma_device *dma, struct dma_mapping *map,
|
||||
userptr_t addr, size_t len );
|
||||
void *addr, size_t len );
|
||||
/**
|
||||
* Set addressable space mask
|
||||
*
|
||||
@@ -265,11 +265,11 @@ DMAAPI_INLINE ( flat, dma_free ) ( struct dma_mapping *map,
|
||||
* @v align Physical alignment
|
||||
* @ret addr Buffer address, or NULL on error
|
||||
*/
|
||||
static inline __always_inline userptr_t
|
||||
static inline __always_inline void *
|
||||
DMAAPI_INLINE ( flat, dma_umalloc ) ( struct dma_device *dma,
|
||||
struct dma_mapping *map,
|
||||
size_t len, size_t align __unused ) {
|
||||
userptr_t addr;
|
||||
void *addr;
|
||||
|
||||
/* Allocate buffer */
|
||||
addr = umalloc ( len );
|
||||
@@ -292,7 +292,7 @@ DMAAPI_INLINE ( flat, dma_umalloc ) ( struct dma_device *dma,
|
||||
*/
|
||||
static inline __always_inline void
|
||||
DMAAPI_INLINE ( flat, dma_ufree ) ( struct dma_mapping *map,
|
||||
userptr_t addr, size_t len __unused ) {
|
||||
void *addr, size_t len __unused ) {
|
||||
|
||||
/* Free buffer */
|
||||
ufree ( addr );
|
||||
@@ -397,8 +397,8 @@ void dma_free ( struct dma_mapping *map, void *addr, size_t len );
|
||||
* @v align Physical alignment
|
||||
* @ret addr Buffer address, or NULL on error
|
||||
*/
|
||||
userptr_t dma_umalloc ( struct dma_device *dma, struct dma_mapping *map,
|
||||
size_t len, size_t align );
|
||||
void * dma_umalloc ( struct dma_device *dma, struct dma_mapping *map,
|
||||
size_t len, size_t align );
|
||||
|
||||
/**
|
||||
* Unmap and free DMA-coherent buffer from external (user) memory
|
||||
@@ -407,7 +407,7 @@ userptr_t dma_umalloc ( struct dma_device *dma, struct dma_mapping *map,
|
||||
* @v addr Buffer address
|
||||
* @v len Length of buffer
|
||||
*/
|
||||
void dma_ufree ( struct dma_mapping *map, userptr_t addr, size_t len );
|
||||
void dma_ufree ( struct dma_mapping *map, void *addr, size_t len );
|
||||
|
||||
/**
|
||||
* Set addressable space mask
|
||||
|
||||
@@ -21,6 +21,24 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
#include <ipxe/tables.h>
|
||||
#include <valgrind/memcheck.h>
|
||||
|
||||
/**
|
||||
* Address for zero-length memory blocks
|
||||
*
|
||||
* @c malloc(0) or @c realloc(ptr,0) will return the special value @c
|
||||
* NOWHERE. Calling @c free(NOWHERE) will have no effect.
|
||||
*
|
||||
* This is consistent with the ANSI C standards, which state that
|
||||
* "either NULL or a pointer suitable to be passed to free()" must be
|
||||
* returned in these cases. Using a special non-NULL value means that
|
||||
* the caller can take a NULL return value to indicate failure,
|
||||
* without first having to check for a requested size of zero.
|
||||
*
|
||||
* Code outside of the memory allocators themselves does not ever need
|
||||
* to refer to the actual value of @c NOWHERE; this is an internal
|
||||
* definition.
|
||||
*/
|
||||
#define NOWHERE ( ( void * ) ~( ( intptr_t ) 0 ) )
|
||||
|
||||
extern size_t freemem;
|
||||
extern size_t usedmem;
|
||||
extern size_t maxusedmem;
|
||||
|
||||
@@ -10,9 +10,10 @@
|
||||
|
||||
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
|
||||
#include <stddef.h>
|
||||
#include <ipxe/api.h>
|
||||
#include <ipxe/malloc.h>
|
||||
#include <config/umalloc.h>
|
||||
#include <ipxe/uaccess.h>
|
||||
|
||||
/**
|
||||
* Provide a user memory allocation API implementation
|
||||
@@ -34,36 +35,36 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
/**
|
||||
* Reallocate external memory
|
||||
*
|
||||
* @v userptr Memory previously allocated by umalloc(), or UNULL
|
||||
* @v old_ptr Memory previously allocated by umalloc(), or NULL
|
||||
* @v new_size Requested size
|
||||
* @ret userptr Allocated memory, or UNULL
|
||||
* @ret new_ptr Allocated memory, or NULL
|
||||
*
|
||||
* 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 );
|
||||
void * urealloc ( void *ptr, size_t new_size );
|
||||
|
||||
/**
|
||||
* Allocate external memory
|
||||
*
|
||||
* @v size Requested size
|
||||
* @ret userptr Memory, or UNULL
|
||||
* @ret ptr Memory, or NULL
|
||||
*
|
||||
* Memory is guaranteed to be aligned to a page boundary.
|
||||
*/
|
||||
static inline __always_inline userptr_t umalloc ( size_t size ) {
|
||||
return urealloc ( UNULL, size );
|
||||
static inline __always_inline void * umalloc ( size_t size ) {
|
||||
return urealloc ( NULL, size );
|
||||
}
|
||||
|
||||
/**
|
||||
* Free external memory
|
||||
*
|
||||
* @v userptr Memory allocated by umalloc(), or UNULL
|
||||
* @v ptr Memory allocated by umalloc(), or NULL
|
||||
*
|
||||
* If @c ptr is UNULL, no action is taken.
|
||||
* If @c ptr is NULL, no action is taken.
|
||||
*/
|
||||
static inline __always_inline void ufree ( userptr_t userptr ) {
|
||||
urealloc ( userptr, 0 );
|
||||
static inline __always_inline void ufree ( void *ptr ) {
|
||||
urealloc ( ptr, 0 );
|
||||
}
|
||||
|
||||
#endif /* _IPXE_UMALLOC_H */
|
||||
|
||||
@@ -11,7 +11,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
|
||||
#include <stdint.h>
|
||||
#include <ipxe/iobuf.h>
|
||||
#include <ipxe/uaccess.h>
|
||||
#include <ipxe/interface.h>
|
||||
#include <ipxe/xfer.h>
|
||||
|
||||
@@ -84,7 +83,7 @@ xferbuf_malloc_init ( struct xfer_buffer *xferbuf ) {
|
||||
* @v data User pointer
|
||||
*/
|
||||
static inline __attribute__ (( always_inline )) void
|
||||
xferbuf_umalloc_init ( struct xfer_buffer *xferbuf, userptr_t *data ) {
|
||||
xferbuf_umalloc_init ( struct xfer_buffer *xferbuf, void **data ) {
|
||||
xferbuf->data = data;
|
||||
xferbuf->op = &xferbuf_umalloc_operations;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user