mirror of
https://github.com/ipxe/ipxe
synced 2025-12-24 06:22:59 +03:00
[efi] Perform meaningful error code conversions
Exploit the redefinition of iPXE error codes to include a "platform error code" to allow for meaningful conversion of EFI_STATUS values to iPXE errors and vice versa. Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -19,6 +19,8 @@
|
||||
|
||||
FILE_LICENCE ( GPL2_OR_LATER );
|
||||
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <ipxe/umalloc.h>
|
||||
#include <ipxe/efi/efi.h>
|
||||
@@ -49,6 +51,7 @@ static userptr_t efi_urealloc ( userptr_t old_ptr, size_t new_size ) {
|
||||
userptr_t new_ptr = UNOWHERE;
|
||||
size_t old_size;
|
||||
EFI_STATUS efirc;
|
||||
int rc;
|
||||
|
||||
/* Allocate new memory if necessary. If allocation fails,
|
||||
* return without touching the old block.
|
||||
@@ -59,8 +62,9 @@ static userptr_t efi_urealloc ( userptr_t old_ptr, size_t new_size ) {
|
||||
EfiBootServicesData,
|
||||
new_pages,
|
||||
&phys_addr ) ) != 0 ) {
|
||||
rc = -EEFI ( efirc );
|
||||
DBG ( "EFI could not allocate %d pages: %s\n",
|
||||
new_pages, efi_strerror ( efirc ) );
|
||||
new_pages, strerror ( rc ) );
|
||||
return UNULL;
|
||||
}
|
||||
assert ( phys_addr != 0 );
|
||||
@@ -84,8 +88,9 @@ static userptr_t efi_urealloc ( userptr_t old_ptr, size_t new_size ) {
|
||||
old_pages = ( EFI_SIZE_TO_PAGES ( old_size ) + 1 );
|
||||
phys_addr = user_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",
|
||||
old_pages, phys_addr, efi_strerror ( efirc ) );
|
||||
old_pages, phys_addr, strerror ( rc ) );
|
||||
/* Not fatal; we have leaked memory but successfully
|
||||
* allocated (if asked to do so).
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user