#include <assert.h>
#include <gpxe/umalloc.h>
#include <gpxe/efi/efi.h>
Go to the source code of this file.
Defines | |
| #define | UNOWHERE ( ~UNULL ) |
| Equivalent of NOWHERE for user pointers. | |
Functions | |
| FILE_LICENCE (GPL2_OR_LATER) | |
| static userptr_t | efi_urealloc (userptr_t old_ptr, size_t new_size) |
| Reallocate external memory. | |
| PROVIDE_UMALLOC (efi, urealloc, efi_urealloc) | |
Definition in file efi_umalloc.c.
| #define UNOWHERE ( ~UNULL ) |
Equivalent of NOWHERE for user pointers.
Definition at line 32 of file efi_umalloc.c.
Referenced by efi_urealloc(), and memtop_urealloc().
| FILE_LICENCE | ( | GPL2_OR_LATER | ) |
Reallocate external memory.
| old_ptr | Memory previously allocated by umalloc(), or UNULL | |
| new_size | Requested size |
| new_ptr | Allocated memory, or UNULL |
Definition at line 44 of file efi_umalloc.c.
References AllocateAnyPages, EFI_BOOT_SERVICES::AllocatePages, assert, _EFI_SYSTEM_TABLE::BootServices, copy_from_user(), copy_to_user(), DBG, EFI_PAGE_SIZE, EFI_SIZE_TO_PAGES, efi_strerror(), efi_systab, EfiBootServicesData, EFI_BOOT_SERVICES::FreePages, memcpy_user(), phys_to_user(), UNOWHERE, UNULL, and user_to_phys().
00044 { 00045 EFI_BOOT_SERVICES *bs = efi_systab->BootServices; 00046 EFI_PHYSICAL_ADDRESS phys_addr; 00047 unsigned int new_pages, old_pages; 00048 userptr_t new_ptr = UNOWHERE; 00049 size_t old_size; 00050 EFI_STATUS efirc; 00051 00052 /* Allocate new memory if necessary. If allocation fails, 00053 * return without touching the old block. 00054 */ 00055 if ( new_size ) { 00056 new_pages = ( EFI_SIZE_TO_PAGES ( new_size ) + 1 ); 00057 if ( ( efirc = bs->AllocatePages ( AllocateAnyPages, 00058 EfiBootServicesData, 00059 new_pages, 00060 &phys_addr ) ) != 0 ) { 00061 DBG ( "EFI could not allocate %d pages: %s\n", 00062 new_pages, efi_strerror ( efirc ) ); 00063 return UNULL; 00064 } 00065 assert ( phys_addr != 0 ); 00066 new_ptr = phys_to_user ( phys_addr + EFI_PAGE_SIZE ); 00067 copy_to_user ( new_ptr, -EFI_PAGE_SIZE, 00068 &new_size, sizeof ( new_size ) ); 00069 DBG ( "EFI allocated %d pages at %llx\n", 00070 new_pages, phys_addr ); 00071 } 00072 00073 /* Copy across relevant part of the old data region (if any), 00074 * then free it. Note that at this point either (a) new_ptr 00075 * is valid, or (b) new_size is 0; either way, the memcpy() is 00076 * valid. 00077 */ 00078 if ( old_ptr && ( old_ptr != UNOWHERE ) ) { 00079 copy_from_user ( &old_size, old_ptr, -EFI_PAGE_SIZE, 00080 sizeof ( old_size ) ); 00081 memcpy_user ( new_ptr, 0, old_ptr, 0, 00082 ( (old_size < new_size) ? old_size : new_size )); 00083 old_pages = ( EFI_SIZE_TO_PAGES ( old_size ) + 1 ); 00084 phys_addr = user_to_phys ( old_ptr, -EFI_PAGE_SIZE ); 00085 if ( ( efirc = bs->FreePages ( phys_addr, old_pages ) ) != 0 ){ 00086 DBG ( "EFI could not free %d pages at %llx: %s\n", 00087 old_pages, phys_addr, efi_strerror ( efirc ) ); 00088 /* Not fatal; we have leaked memory but successfully 00089 * allocated (if asked to do so). 00090 */ 00091 } 00092 DBG ( "EFI freed %d pages at %llx\n", old_pages, phys_addr ); 00093 } 00094 00095 return new_ptr; 00096 }
| PROVIDE_UMALLOC | ( | efi | , | |
| urealloc | , | |||
| efi_urealloc | ||||
| ) |
1.5.7.1