summaryrefslogtreecommitdiffstats
path: root/src/interface/efi/efi_umalloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/interface/efi/efi_umalloc.c')
-rw-r--r--src/interface/efi/efi_umalloc.c34
1 files changed, 17 insertions, 17 deletions
diff --git a/src/interface/efi/efi_umalloc.c b/src/interface/efi/efi_umalloc.c
index e3f1dacc2..257b27bec 100644
--- a/src/interface/efi/efi_umalloc.c
+++ b/src/interface/efi/efi_umalloc.c
@@ -22,10 +22,12 @@
*/
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+FILE_SECBOOT ( PERMITTED );
#include <string.h>
#include <errno.h>
#include <assert.h>
+#include <ipxe/uaccess.h>
#include <ipxe/umalloc.h>
#include <ipxe/efi/efi.h>
@@ -35,25 +37,23 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
*
*/
-/** Equivalent of NOWHERE for user pointers */
-#define UNOWHERE ( ~UNULL )
-
/**
* 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 +69,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_user ( phys_addr + EFI_PAGE_SIZE );
- copy_to_user ( new_ptr, -EFI_PAGE_SIZE,
- &new_size, sizeof ( new_size ) );
+ new_ptr = phys_to_virt ( phys_addr + EFI_PAGE_SIZE );
+ info = ( new_ptr - EFI_PAGE_SIZE );
+ *info = new_size;
DBG ( "EFI allocated %d pages at %llx\n",
new_pages, phys_addr );
}
@@ -84,13 +84,13 @@ 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 ) );
- memcpy_user ( new_ptr, 0, old_ptr, 0,
- ( (old_size < new_size) ? old_size : new_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 );
- phys_addr = user_to_phys ( old_ptr, -EFI_PAGE_SIZE );
+ phys_addr = virt_to_phys ( old_ptr - EFI_PAGE_SIZE );
if ( ( efirc = bs->FreePages ( phys_addr, old_pages ) ) != 0 ){
rc = -EEFI ( efirc );
DBG ( "EFI could not free %d pages at %llx: %s\n",