summaryrefslogtreecommitdiffstats
path: root/src/interface
diff options
context:
space:
mode:
authorMichael Brown2025-04-23 13:47:53 +0200
committerMichael Brown2025-04-23 15:43:04 +0200
commit839540cb95a310ebf96d6302afecc3ac97ccf746 (patch)
tree67c13ca2d9a48e3d63b5e739492646ee69c9e6cb /src/interface
parent[smbios] Remove userptr_t from SMBIOS structure parsing (diff)
downloadipxe-839540cb95a310ebf96d6302afecc3ac97ccf746.tar.gz
ipxe-839540cb95a310ebf96d6302afecc3ac97ccf746.tar.xz
ipxe-839540cb95a310ebf96d6302afecc3ac97ccf746.zip
[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>
Diffstat (limited to 'src/interface')
-rw-r--r--src/interface/efi/efi_pci.c36
-rw-r--r--src/interface/efi/efi_umalloc.c25
-rw-r--r--src/interface/linux/linux_umalloc.c31
3 files changed, 25 insertions, 67 deletions
diff --git a/src/interface/efi/efi_pci.c b/src/interface/efi/efi_pci.c
index 01351df51..b8c7df38d 100644
--- a/src/interface/efi/efi_pci.c
+++ b/src/interface/efi/efi_pci.c
@@ -641,38 +641,6 @@ static void efipci_dma_free ( struct dma_device *dma, struct dma_mapping *map,
}
/**
- * Allocate and map DMA-coherent buffer from external (user) memory
- *
- * @v dma DMA device
- * @v map DMA mapping to fill in
- * @v len Length of buffer
- * @v align Physical alignment
- * @ret addr Buffer address, or NULL on error
- */
-static userptr_t efipci_dma_umalloc ( struct dma_device *dma,
- struct dma_mapping *map,
- size_t len, size_t align ) {
- void *addr;
-
- addr = efipci_dma_alloc ( dma, map, len, align );
- return virt_to_user ( addr );
-}
-
-/**
- * Unmap and free DMA-coherent buffer from external (user) memory
- *
- * @v dma DMA device
- * @v map DMA mapping
- * @v addr Buffer address
- * @v len Length of buffer
- */
-static void efipci_dma_ufree ( struct dma_device *dma, struct dma_mapping *map,
- userptr_t addr, size_t len ) {
-
- efipci_dma_free ( dma, map, addr, len );
-}
-
-/**
* Set addressable space mask
*
* @v dma DMA device
@@ -710,8 +678,8 @@ static struct dma_operations efipci_dma_operations = {
.unmap = efipci_dma_unmap,
.alloc = efipci_dma_alloc,
.free = efipci_dma_free,
- .umalloc = efipci_dma_umalloc,
- .ufree = efipci_dma_ufree,
+ .umalloc = efipci_dma_alloc,
+ .ufree = efipci_dma_free,
.set_mask = efipci_dma_set_mask,
};
diff --git a/src/interface/efi/efi_umalloc.c b/src/interface/efi/efi_umalloc.c
index 0636cb7fd..419d9b294 100644
--- a/src/interface/efi/efi_umalloc.c
+++ b/src/interface/efi/efi_umalloc.c
@@ -26,6 +26,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <string.h>
#include <errno.h>
#include <assert.h>
+#include <ipxe/uaccess.h>
#include <ipxe/umalloc.h>
#include <ipxe/efi/efi.h>
@@ -35,25 +36,23 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
*
*/
-/** Equivalent of NOWHERE for user pointers */
-#define UNOWHERE ( ( userptr_t ) ~( ( intptr_t ) 0 ) )
-
/**
* Reallocate external memory
*
- * @v old_ptr Memory previously allocated by umalloc(), or UNULL
+ * @v old_ptr Memory previously allocated by umalloc(), or NULL
* @v new_size Requested size
- * @ret new_ptr 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.
*/
-static userptr_t efi_urealloc ( userptr_t old_ptr, size_t new_size ) {
+static void * efi_urealloc ( void *old_ptr, size_t new_size ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
EFI_PHYSICAL_ADDRESS phys_addr;
unsigned int new_pages, old_pages;
- userptr_t new_ptr = UNOWHERE;
+ void *new_ptr = NOWHERE;
size_t old_size;
+ size_t *info;
EFI_STATUS efirc;
int rc;
@@ -69,12 +68,12 @@ static userptr_t efi_urealloc ( userptr_t old_ptr, size_t new_size ) {
rc = -EEFI ( efirc );
DBG ( "EFI could not allocate %d pages: %s\n",
new_pages, strerror ( rc ) );
- return UNULL;
+ return NULL;
}
assert ( phys_addr != 0 );
new_ptr = phys_to_virt ( phys_addr + EFI_PAGE_SIZE );
- copy_to_user ( new_ptr, -EFI_PAGE_SIZE,
- &new_size, sizeof ( new_size ) );
+ info = ( new_ptr - EFI_PAGE_SIZE );
+ *info = new_size;
DBG ( "EFI allocated %d pages at %llx\n",
new_pages, phys_addr );
}
@@ -84,9 +83,9 @@ static userptr_t efi_urealloc ( userptr_t old_ptr, size_t new_size ) {
* is valid, or (b) new_size is 0; either way, the memcpy() is
* valid.
*/
- if ( old_ptr && ( old_ptr != UNOWHERE ) ) {
- copy_from_user ( &old_size, old_ptr, -EFI_PAGE_SIZE,
- sizeof ( old_size ) );
+ if ( old_ptr && ( old_ptr != NOWHERE ) ) {
+ info = ( old_ptr - EFI_PAGE_SIZE );
+ old_size = *info;
memcpy ( new_ptr, old_ptr,
( (old_size < new_size) ? old_size : new_size ) );
old_pages = ( EFI_SIZE_TO_PAGES ( old_size ) + 1 );
diff --git a/src/interface/linux/linux_umalloc.c b/src/interface/linux/linux_umalloc.c
index a7250fa5b..ab5770e9c 100644
--- a/src/interface/linux/linux_umalloc.c
+++ b/src/interface/linux/linux_umalloc.c
@@ -31,9 +31,6 @@ FILE_LICENCE(GPL2_OR_LATER);
#include <ipxe/linux_api.h>
-/** Special address returned for empty allocations */
-#define NOWHERE ((void *)-1)
-
/** Poison to make the metadata more unique */
#define POISON 0xa5a5a5a5
#define min(a,b) (((a)<(b))?(a):(b))
@@ -47,7 +44,16 @@ struct metadata
#define SIZE_MD (sizeof(struct metadata))
-/** Simple realloc which passes most of the work to mmap(), mremap() and munmap() */
+/**
+ * Reallocate external memory
+ *
+ * @v old_ptr Memory previously allocated by umalloc(), or NULL
+ * @v new_size Requested size
+ * @ret new_ptr Allocated memory, or NULL
+ *
+ * Calling realloc() with a new size of zero is a valid way to free a
+ * memory block.
+ */
static void * linux_realloc(void *ptr, size_t size)
{
struct metadata md = {0, 0};
@@ -136,19 +142,4 @@ static void * linux_realloc(void *ptr, size_t size)
return ptr;
}
-/**
- * Reallocate external memory
- *
- * @v old_ptr Memory previously allocated by umalloc(), or UNULL
- * @v new_size Requested size
- * @ret new_ptr Allocated memory, or UNULL
- *
- * Calling realloc() with a new size of zero is a valid way to free a
- * memory block.
- */
-static userptr_t linux_urealloc(userptr_t old_ptr, size_t new_size)
-{
- return (userptr_t)linux_realloc((void *)old_ptr, new_size);
-}
-
-PROVIDE_UMALLOC(linux, urealloc, linux_urealloc);
+PROVIDE_UMALLOC(linux, urealloc, linux_realloc);