summaryrefslogtreecommitdiffstats
path: root/src/interface/efi/efi_umalloc.c
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/efi/efi_umalloc.c
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/efi/efi_umalloc.c')
-rw-r--r--src/interface/efi/efi_umalloc.c25
1 files changed, 12 insertions, 13 deletions
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 );