iPXE
Data Structures | Macros | Functions | Variables
efi_debug.c File Reference

EFI debugging utilities. More...

#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <ipxe/uuid.h>
#include <ipxe/base16.h>
#include <ipxe/vsprintf.h>
#include <ipxe/efi/efi.h>
#include <ipxe/efi/efi_utils.h>
#include <ipxe/efi/Protocol/ComponentName.h>
#include <ipxe/efi/Protocol/ComponentName2.h>
#include <ipxe/efi/Protocol/DevicePathToText.h>
#include <ipxe/efi/IndustryStandard/PeImage.h>

Go to the source code of this file.

Data Structures

struct  efi_well_known_guid
 A well-known GUID. More...
 
struct  efi_handle_name_type
 An EFI handle name type. More...
 

Macros

#define EFI_HANDLE_NAME_TYPE(protocol, name)
 Define an EFI handle name type. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
 EFI_REQUEST_PROTOCOL (EFI_DEVICE_PATH_TO_TEXT_PROTOCOL, &efidpt)
 
const char * efi_guid_ntoa (EFI_GUID *guid)
 Convert GUID to a printable string. More...
 
const char * efi_locate_search_type_name (EFI_LOCATE_SEARCH_TYPE search_type)
 Name locate search type. More...
 
const char * efi_open_attributes_name (unsigned int attributes)
 Name protocol open attributes. More...
 
void dbg_efi_openers (EFI_HANDLE handle, EFI_GUID *protocol)
 Print list of openers of a given protocol on a given handle. More...
 
void dbg_efi_protocols (EFI_HANDLE handle)
 Print list of protocol handlers attached to a handle. More...
 
const char * efi_devpath_text (EFI_DEVICE_PATH_PROTOCOL *path)
 Get textual representation of device path. More...
 
static const char * efi_driver_name (EFI_COMPONENT_NAME_PROTOCOL *wtf)
 Get driver name. More...
 
static const char * efi_driver_name2 (EFI_COMPONENT_NAME2_PROTOCOL *wtf)
 Get driver name. More...
 
static const char * efi_pecoff_debug_name (EFI_LOADED_IMAGE_PROTOCOL *loaded)
 Get PE/COFF debug filename. More...
 
static const char * efi_first_loaded_image_name (EFI_LOADED_IMAGE_PROTOCOL *loaded)
 Get initial loaded image name. More...
 
static const char * efi_loaded_image_filepath_name (EFI_LOADED_IMAGE_PROTOCOL *loaded)
 Get loaded image name from file path. More...
 
static const char * efi_conin_name (EFI_SIMPLE_TEXT_INPUT_PROTOCOL *input)
 Get console input handle name. More...
 
static const char * efi_conout_name (EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *output)
 Get console output handle name. More...
 
const char * efi_handle_name (EFI_HANDLE handle)
 Get name of an EFI handle. More...
 

Variables

static EFI_DEVICE_PATH_TO_TEXT_PROTOCOLefidpt
 Device path to text protocol. More...
 
static EFI_GUID efi_iscsi4_dxe_guid
 Iscsi4Dxe module GUID. More...
 
static EFI_GUID efi_vlan_config_dxe_guid
 VlanConfigDxe module GUID. More...
 
static struct efi_well_known_guid efi_well_known_guids []
 Well-known GUIDs. More...
 
static struct efi_handle_name_type efi_handle_name_types []
 EFI handle name types. More...
 

Detailed Description

EFI debugging utilities.

Definition in file efi_debug.c.

Macro Definition Documentation

◆ EFI_HANDLE_NAME_TYPE

#define EFI_HANDLE_NAME_TYPE (   protocol,
  name 
)
Value:
{ \
(protocol), \
( const char * ( * ) ( void * ) ) (name), \
}
const char * name
Definition: ath9k_hw.c:1984
uint16_t protocol
Protocol ID.
Definition: stp.h:18

Define an EFI handle name type.

Parameters
protocolProtocol interface
nameMethod to get name
Return values
typeEFI handle name type

Definition at line 671 of file efi_debug.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ EFI_REQUEST_PROTOCOL()

EFI_REQUEST_PROTOCOL ( EFI_DEVICE_PATH_TO_TEXT_PROTOCOL  ,
efidpt 
)

◆ efi_guid_ntoa()

const char* efi_guid_ntoa ( EFI_GUID guid)

Convert GUID to a printable string.

Parameters
guidGUID
Return values
stringPrintable string

Definition at line 192 of file efi_debug.c.

192  {
193  union {
194  union uuid uuid;
195  EFI_GUID guid;
196  } u;
197  unsigned int i;
198 
199  /* Sanity check */
200  if ( ! guid )
201  return NULL;
202 
203  /* Check for a match against well-known GUIDs */
204  for ( i = 0 ; i < ( sizeof ( efi_well_known_guids ) /
205  sizeof ( efi_well_known_guids[0] ) ) ; i++ ) {
207  sizeof ( *guid ) ) == 0 ) {
208  return efi_well_known_guids[i].name;
209  }
210  }
211 
212  /* Convert GUID to standard endianness */
213  memcpy ( &u.guid, guid, sizeof ( u.guid ) );
214  uuid_mangle ( &u.uuid );
215  return uuid_ntoa ( &u.uuid );
216 }
const char * name
Name.
Definition: efi_debug.c:67
128 bit buffer containing a unique identifier value.
Definition: Base.h:263
A universally unique ID.
Definition: uuid.h:15
static struct efi_well_known_guid efi_well_known_guids[]
Well-known GUIDs.
Definition: efi_debug.c:71
static void uuid_mangle(union uuid *uuid)
Change UUID endianness.
Definition: uuid.h:43
void * memcpy(void *dest, const void *src, size_t len) __nonnull
const char * uuid_ntoa(const union uuid *uuid)
Convert UUID to printable string.
Definition: uuid.c:43
uint64_t guid
GUID.
Definition: edd.h:30
union @16 u
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition: string.c:98
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References efi_well_known_guids, guid, efi_well_known_guid::guid, memcmp(), memcpy(), efi_well_known_guid::name, NULL, u, uuid_mangle(), and uuid_ntoa().

Referenced by chained_locate(), chained_supported(), dbg_efi_openers(), dbg_efi_protocols(), efi_close_protocol_wrapper(), efi_file_get_info(), efi_file_set_info(), efi_handle_name(), efi_handle_protocol_wrapper(), efi_init(), efi_install_protocol_interface_wrapper(), efi_locate_device(), efi_locate_device_path_wrapper(), efi_locate_handle_buffer_wrapper(), efi_locate_handle_wrapper(), efi_locate_protocol_wrapper(), efi_open_protocol_wrapper(), efi_protocols_per_handle_wrapper(), efi_reinstall_protocol_interface_wrapper(), and efi_uninstall_protocol_interface_wrapper().

◆ efi_locate_search_type_name()

const char* efi_locate_search_type_name ( EFI_LOCATE_SEARCH_TYPE  search_type)

Name locate search type.

Parameters
search_typeLocate search type
Return values
nameLocate search type name

Definition at line 225 of file efi_debug.c.

225  {
226  static char buf[16];
227 
228  switch ( search_type ) {
229  case AllHandles : return "AllHandles";
230  case ByRegisterNotify: return "ByRegisterNotify";
231  case ByProtocol: return "ByProtocol";
232  default:
233  snprintf ( buf, sizeof ( buf ), "UNKNOWN<%d>", search_type );
234  return buf;
235  }
236 }
Retrieve all the handles in the handle database.
Definition: UefiSpec.h:1439
Retrieve the next handle fron a RegisterProtocolNotify() event.
Definition: UefiSpec.h:1443
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:382
Retrieve the set of handles from the handle database that support a specified protocol.
Definition: UefiSpec.h:1448

References AllHandles, ByProtocol, ByRegisterNotify, and snprintf().

Referenced by efi_locate_handle_buffer_wrapper(), and efi_locate_handle_wrapper().

◆ efi_open_attributes_name()

const char* efi_open_attributes_name ( unsigned int  attributes)

Name protocol open attributes.

Parameters
attributesProtocol open attributes
Return values
nameProtocol open attributes name

Returns a (static) string with characters for each set bit corresponding to BY_(H)ANDLE_PROTOCOL, (G)ET_PROTOCOL, (T)EST_PROTOCOL, BY_(C)HILD_CONTROLLER, BY_(D)RIVER, and E(X)CLUSIVE.

Definition at line 250 of file efi_debug.c.

250  {
251  static char attribute_chars[] = "HGTCDX";
252  static char name[ sizeof ( attribute_chars ) ];
253  char *tmp = name;
254  unsigned int i;
255 
256  for ( i = 0 ; i < ( sizeof ( attribute_chars ) - 1 ) ; i++ ) {
257  if ( attributes & ( 1 << i ) )
258  *(tmp++) = attribute_chars[i];
259  }
260  *tmp = '\0';
261 
262  return name;
263 }
const char * name
Definition: ath9k_hw.c:1984
uint8_t * tmp
Definition: entropy.h:156

References name, and tmp.

Referenced by dbg_efi_openers(), and efi_open_protocol_wrapper().

◆ dbg_efi_openers()

void dbg_efi_openers ( EFI_HANDLE  handle,
EFI_GUID protocol 
)

Print list of openers of a given protocol on a given handle.

Parameters
handleEFI handle
protocolProtocol GUID

Definition at line 271 of file efi_debug.c.

271  {
275  UINTN count;
276  unsigned int i;
277  EFI_STATUS efirc;
278  int rc;
279 
280  /* Sanity check */
281  if ( ( ! handle ) || ( ! protocol ) ) {
282  printf ( "HANDLE %s could not retrieve openers for %s\n",
284  efi_guid_ntoa ( protocol ) );
285  return;
286  }
287 
288  /* Retrieve list of openers */
289  if ( ( efirc = bs->OpenProtocolInformation ( handle, protocol, &openers,
290  &count ) ) != 0 ) {
291  rc = -EEFI ( efirc );
292  printf ( "HANDLE %s could not retrieve openers for %s: %s\n",
294  efi_guid_ntoa ( protocol ), strerror ( rc ) );
295  return;
296  }
297 
298  /* Dump list of openers */
299  for ( i = 0 ; i < count ; i++ ) {
300  opener = &openers[i];
301  printf ( "HANDLE %s %s opened %dx (%s)",
303  efi_guid_ntoa ( protocol ), opener->OpenCount,
304  efi_open_attributes_name ( opener->Attributes ) );
305  printf ( " by %s", efi_handle_name ( opener->AgentHandle ) );
306  if ( opener->ControllerHandle == handle ) {
307  printf ( "\n" );
308  } else {
309  printf ( " for %s\n",
310  efi_handle_name ( opener->ControllerHandle ) );
311  }
312  }
313 
314  /* Free list */
315  bs->FreePool ( openers );
316 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
EFI Oprn Protocol Information Entry.
Definition: UefiSpec.h:1349
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:159
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
EFI_HANDLE ControllerHandle
Definition: UefiSpec.h:1351
EFI_HANDLE AgentHandle
Definition: UefiSpec.h:1350
UINT32 OpenCount
Definition: UefiSpec.h:1353
UINT32 Attributes
Definition: UefiSpec.h:1352
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:713
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1836
UINT64 UINTN
Unsigned value of native width.
Definition: ProcessorBind.h:71
EFI_FREE_POOL FreePool
Definition: UefiSpec.h:1855
EFI_OPEN_PROTOCOL_INFORMATION OpenProtocolInformation
Definition: UefiSpec.h:1907
const char * efi_guid_ntoa(EFI_GUID *guid)
Convert GUID to a printable string.
Definition: efi_debug.c:192
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
uint16_t count
Number of entries.
Definition: ena.h:22
const char * efi_open_attributes_name(unsigned int attributes)
Name protocol open attributes.
Definition: efi_debug.c:250
EFI_SYSTEM_TABLE * efi_systab
uint16_t protocol
Protocol ID.
Definition: stp.h:18
uint16_t handle
Handle.
Definition: smbios.h:16

References EFI_OPEN_PROTOCOL_INFORMATION_ENTRY::AgentHandle, EFI_OPEN_PROTOCOL_INFORMATION_ENTRY::Attributes, EFI_SYSTEM_TABLE::BootServices, EFI_OPEN_PROTOCOL_INFORMATION_ENTRY::ControllerHandle, count, EEFI, efi_guid_ntoa(), efi_handle_name(), efi_open_attributes_name(), efi_systab, EFI_BOOT_SERVICES::FreePool, handle, EFI_OPEN_PROTOCOL_INFORMATION_ENTRY::OpenCount, EFI_BOOT_SERVICES::OpenProtocolInformation, printf(), protocol, rc, and strerror().

Referenced by dbg_efi_protocols().

◆ dbg_efi_protocols()

void dbg_efi_protocols ( EFI_HANDLE  handle)

Print list of protocol handlers attached to a handle.

Parameters
handleEFI handle

Definition at line 323 of file efi_debug.c.

323  {
325  EFI_GUID **protocols;
327  UINTN count;
328  unsigned int i;
329  EFI_STATUS efirc;
330  int rc;
331 
332  /* Sanity check */
333  if ( ! handle ) {
334  printf ( "HANDLE %p could not retrieve protocols\n", handle );
335  return;
336  }
337 
338  /* Retrieve list of protocols */
339  if ( ( efirc = bs->ProtocolsPerHandle ( handle, &protocols,
340  &count ) ) != 0 ) {
341  rc = -EEFI ( efirc );
342  printf ( "HANDLE %s could not retrieve protocols: %s\n",
343  efi_handle_name ( handle ), strerror ( rc ) );
344  return;
345  }
346 
347  /* Dump list of protocols */
348  for ( i = 0 ; i < count ; i++ ) {
349  protocol = protocols[i];
350  printf ( "HANDLE %s %s supported\n", efi_handle_name ( handle ),
351  efi_guid_ntoa ( protocol ) );
353  }
354 
355  /* Free list */
356  bs->FreePool ( protocols );
357 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:159
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
void dbg_efi_openers(EFI_HANDLE handle, EFI_GUID *protocol)
Print list of openers of a given protocol on a given handle.
Definition: efi_debug.c:271
128 bit buffer containing a unique identifier value.
Definition: Base.h:263
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:713
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1836
UINT64 UINTN
Unsigned value of native width.
Definition: ProcessorBind.h:71
EFI_FREE_POOL FreePool
Definition: UefiSpec.h:1855
const char * efi_guid_ntoa(EFI_GUID *guid)
Convert GUID to a printable string.
Definition: efi_debug.c:192
EFI_PROTOCOLS_PER_HANDLE ProtocolsPerHandle
Definition: UefiSpec.h:1912
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
uint16_t count
Number of entries.
Definition: ena.h:22
EFI_SYSTEM_TABLE * efi_systab
uint16_t protocol
Protocol ID.
Definition: stp.h:18
uint16_t handle
Handle.
Definition: smbios.h:16

References EFI_SYSTEM_TABLE::BootServices, count, dbg_efi_openers(), EEFI, efi_guid_ntoa(), efi_handle_name(), efi_systab, EFI_BOOT_SERVICES::FreePool, handle, printf(), protocol, EFI_BOOT_SERVICES::ProtocolsPerHandle, rc, and strerror().

◆ efi_devpath_text()

const char* efi_devpath_text ( EFI_DEVICE_PATH_PROTOCOL path)

Get textual representation of device path.

Parameters
pathDevice path
Return values
textTextual representation of device path, or NULL

Definition at line 366 of file efi_debug.c.

366  {
368  static char text[256];
369  size_t len;
370  CHAR16 *wtext;
371 
372  /* Sanity checks */
373  if ( ! path ) {
374  DBG ( "[NULL DevicePath]" );
375  return NULL;
376  }
377 
378  /* If we have no DevicePathToText protocol then use a raw hex string */
379  if ( ! efidpt ) {
380  DBG ( "[No DevicePathToText]" );
381  len = efi_devpath_len ( path );
382  base16_encode ( path, len, text, sizeof ( text ) );
383  return text;
384  }
385 
386  /* Convert path to a textual representation */
387  wtext = efidpt->ConvertDevicePathToText ( path, TRUE, FALSE );
388  if ( ! wtext )
389  return NULL;
390 
391  /* Store path in buffer */
392  snprintf ( text, sizeof ( text ), "%ls", wtext );
393 
394  /* Free path */
395  bs->FreePool ( wtext );
396 
397  return text;
398 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
size_t efi_devpath_len(EFI_DEVICE_PATH_PROTOCOL *path)
Find length of device path (excluding terminator)
Definition: efi_utils.c:59
unsigned short CHAR16
Definition: ProcessorBind.h:59
static EFI_DEVICE_PATH_TO_TEXT_PROTOCOL * efidpt
Device path to text protocol.
Definition: efi_debug.c:47
EFI Boot Services Table.
Definition: UefiSpec.h:1836
EFI_FREE_POOL FreePool
Definition: UefiSpec.h:1855
#define TRUE
Definition: tlan.h:46
uint32_t len
Length.
Definition: ena.h:14
#define FALSE
Definition: tlan.h:45
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:382
EFI_SYSTEM_TABLE * efi_systab
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
EFI_DEVICE_PATH_TO_TEXT_PATH ConvertDevicePathToText
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References EFI_SYSTEM_TABLE::BootServices, EFI_DEVICE_PATH_TO_TEXT_PROTOCOL::ConvertDevicePathToText, DBG, efi_devpath_len(), efi_systab, efidpt, FALSE, EFI_BOOT_SERVICES::FreePool, len, NULL, snprintf(), and TRUE.

Referenced by efi_block_boot_image(), efi_block_hook(), efi_connect_controller_wrapper(), efi_driver_start(), efi_driver_supported(), efi_load_image_wrapper(), efi_loaded_image_filepath_name(), efi_locate_device_path_wrapper(), efi_wrap(), usbio_open(), and usbio_path().

◆ efi_driver_name()

static const char* efi_driver_name ( EFI_COMPONENT_NAME_PROTOCOL wtf)
static

Get driver name.

Parameters
wtfComponent name protocol
Return values
nameDriver name, or NULL

Definition at line 406 of file efi_debug.c.

406  {
407  static char name[64];
408  CHAR16 *driver_name;
409  EFI_STATUS efirc;
410 
411  /* Sanity check */
412  if ( ! wtf ) {
413  DBG ( "[NULL ComponentName]" );
414  return NULL;
415  }
416 
417  /* Try "eng" first; if that fails then try the first language */
418  if ( ( ( efirc = wtf->GetDriverName ( wtf, "eng",
419  &driver_name ) ) != 0 ) &&
420  ( ( efirc = wtf->GetDriverName ( wtf, wtf->SupportedLanguages,
421  &driver_name ) ) != 0 ) ) {
422  return NULL;
423  }
424 
425  /* Convert name from CHAR16 to char */
426  snprintf ( name, sizeof ( name ), "%ls", driver_name );
427  return name;
428 }
const char * name
Definition: ath9k_hw.c:1984
EFI_COMPONENT_NAME_GET_DRIVER_NAME GetDriverName
unsigned short CHAR16
Definition: ProcessorBind.h:59
CHAR8 * SupportedLanguages
A Null-terminated ASCII string that contains one or more ISO 639-2 language codes.
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:382
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References DBG, _EFI_COMPONENT_NAME_PROTOCOL::GetDriverName, name, NULL, snprintf(), and _EFI_COMPONENT_NAME_PROTOCOL::SupportedLanguages.

◆ efi_driver_name2()

static const char* efi_driver_name2 ( EFI_COMPONENT_NAME2_PROTOCOL wtf)
static

Get driver name.

Parameters
wtfComponent name protocol
Return values
nameDriver name, or NULL

Definition at line 436 of file efi_debug.c.

436  {
437  static char name[64];
438  CHAR16 *driver_name;
439  EFI_STATUS efirc;
440 
441  /* Sanity check */
442  if ( ! wtf ) {
443  DBG ( "[NULL ComponentName2]" );
444  return NULL;
445  }
446 
447  /* Try "en" first; if that fails then try the first language */
448  if ( ( ( efirc = wtf->GetDriverName ( wtf, "en",
449  &driver_name ) ) != 0 ) &&
450  ( ( efirc = wtf->GetDriverName ( wtf, wtf->SupportedLanguages,
451  &driver_name ) ) != 0 ) ) {
452  return NULL;
453  }
454 
455  /* Convert name from CHAR16 to char */
456  snprintf ( name, sizeof ( name ), "%ls", driver_name );
457  return name;
458 }
const char * name
Definition: ath9k_hw.c:1984
unsigned short CHAR16
Definition: ProcessorBind.h:59
EFI_COMPONENT_NAME2_GET_DRIVER_NAME GetDriverName
CHAR8 * SupportedLanguages
A Null-terminated ASCII string array that contains one or more supported language codes.
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:382
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References DBG, _EFI_COMPONENT_NAME2_PROTOCOL::GetDriverName, name, NULL, snprintf(), and _EFI_COMPONENT_NAME2_PROTOCOL::SupportedLanguages.

◆ efi_pecoff_debug_name()

static const char* efi_pecoff_debug_name ( EFI_LOADED_IMAGE_PROTOCOL loaded)
static

Get PE/COFF debug filename.

Parameters
loadedLoaded image
Return values
namePE/COFF debug filename, or NULL

Definition at line 467 of file efi_debug.c.

467  {
468  static char buf[32];
473  EFI_IMAGE_DATA_DIRECTORY *datadir;
478  uint16_t dos_magic;
479  uint32_t pe_magic;
480  uint16_t opt_magic;
481  uint32_t codeview_magic;
482  size_t max_len;
483  char *name;
484  char *tmp;
485 
486  /* Sanity check */
487  if ( ! loaded ) {
488  DBG ( "[NULL LoadedImage]" );
489  return NULL;
490  }
491 
492  /* Parse DOS header */
493  dos = loaded->ImageBase;
494  if ( ! dos ) {
495  DBG ( "[Missing DOS header]" );
496  return NULL;
497  }
498  dos_magic = dos->e_magic;
499  if ( dos_magic != EFI_IMAGE_DOS_SIGNATURE ) {
500  DBG ( "[Bad DOS signature %#04x]", dos_magic );
501  return NULL;
502  }
503  pe = ( loaded->ImageBase + dos->e_lfanew );
504 
505  /* Parse PE header */
506  pe_magic = pe->Pe32.Signature;
507  if ( pe_magic != EFI_IMAGE_NT_SIGNATURE ) {
508  DBG ( "[Bad PE signature %#08x]", pe_magic );
509  return NULL;
510  }
511  opt32 = &pe->Pe32.OptionalHeader;
512  opt64 = &pe->Pe32Plus.OptionalHeader;
513  opt_magic = opt32->Magic;
514  if ( opt_magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC ) {
515  datadir = opt32->DataDirectory;
516  } else if ( opt_magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC ) {
517  datadir = opt64->DataDirectory;
518  } else {
519  DBG ( "[Bad optional header signature %#04x]", opt_magic );
520  return NULL;
521  }
522 
523  /* Parse data directory entry */
524  if ( ! datadir[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress ) {
525  DBG ( "[Empty debug directory entry]" );
526  return NULL;
527  }
528  debug = ( loaded->ImageBase +
530 
531  /* Parse debug directory entry */
532  if ( debug->Type != EFI_IMAGE_DEBUG_TYPE_CODEVIEW ) {
533  DBG ( "[Not a CodeView debug directory entry (type %d)]",
534  debug->Type );
535  return NULL;
536  }
537  codeview_nb10 = ( loaded->ImageBase + debug->RVA );
538  codeview_rsds = ( loaded->ImageBase + debug->RVA );
539  codeview_mtoc = ( loaded->ImageBase + debug->RVA );
540  codeview_magic = codeview_nb10->Signature;
541 
542  /* Parse CodeView entry */
543  if ( codeview_magic == CODEVIEW_SIGNATURE_NB10 ) {
544  name = ( ( void * ) ( codeview_nb10 + 1 ) );
545  } else if ( codeview_magic == CODEVIEW_SIGNATURE_RSDS ) {
546  name = ( ( void * ) ( codeview_rsds + 1 ) );
547  } else if ( codeview_magic == CODEVIEW_SIGNATURE_MTOC ) {
548  name = ( ( void * ) ( codeview_mtoc + 1 ) );
549  } else {
550  DBG ( "[Bad CodeView signature %#08x]", codeview_magic );
551  return NULL;
552  }
553 
554  /* Sanity check - avoid scanning endlessly through memory */
555  max_len = EFI_PAGE_SIZE; /* Reasonably sane */
556  if ( strnlen ( name, max_len ) == max_len ) {
557  DBG ( "[Excessively long or invalid CodeView name]" );
558  return NULL;
559  }
560 
561  /* Skip any directory components. We cannot modify this data
562  * or create a temporary buffer, so do not use basename().
563  */
564  while ( ( ( tmp = strchr ( name, '/' ) ) != NULL ) ||
565  ( ( tmp = strchr ( name, '\\' ) ) != NULL ) ) {
566  name = ( tmp + 1 );
567  }
568 
569  /* Copy base name to buffer */
570  snprintf ( buf, sizeof ( buf ), "%s", name );
571 
572  /* Strip file suffix, if present */
573  if ( ( tmp = strrchr ( name, '.' ) ) != NULL )
574  *tmp = '\0';
575 
576  return name;
577 }
#define EFI_PAGE_SIZE
Definition: UefiBaseType.h:191
const char * name
Definition: ath9k_hw.c:1984
unsigned short uint16_t
Definition: stdint.h:11
char * strrchr(const char *src, int character)
Find rightmost character within a string.
Definition: string.c:259
static void size_t size_t max_len
Definition: entropy.h:153
Union of PE32, PE32+, and TE headers.
Definition: PeImage.h:745
Definition: PeImage.h:625
#define EFI_IMAGE_DOS_SIGNATURE
Definition: PeImage.h:49
Optional Header Standard Fields for PE32+.
Definition: PeImage.h:199
Optional Header Standard Fields for PE32.
Definition: PeImage.h:148
VOID * ImageBase
The base address at which the image was loaded.
Definition: LoadedImage.h:75
EFI_IMAGE_NT_HEADERS32 Pe32
Definition: PeImage.h:746
#define EFI_IMAGE_NT_SIGNATURE
Definition: PeImage.h:52
Definition: PeImage.h:656
UINT32 Type
Definition: PeImage.h:613
#define EFI_IMAGE_DIRECTORY_ENTRY_DEBUG
Definition: PeImage.h:129
#define CODEVIEW_SIGNATURE_RSDS
Debug Data Structure defined in Microsoft C++.
Definition: PeImage.h:638
UINT16 Magic
Standard fields.
Definition: PeImage.h:152
char * strchr(const char *src, int character)
Find character within a string.
Definition: string.c:241
UINT32 Signature
"NB10"
Definition: PeImage.h:626
#define CODEVIEW_SIGNATURE_MTOC
Debug Data Structure defined by Apple Mach-O to Coff utility.
Definition: PeImage.h:655
uint8_t * tmp
Definition: entropy.h:156
Header Data Directories.
Definition: PeImage.h:115
EFI_IMAGE_DATA_DIRECTORY DataDirectory[EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES]
Definition: PeImage.h:235
size_t strnlen(const char *src, size_t max)
Get length of string.
Definition: string.c:225
EFI_IMAGE_OPTIONAL_HEADER64 OptionalHeader
Definition: PeImage.h:258
Definition: PeImage.h:639
unsigned int uint32_t
Definition: stdint.h:12
Debug Directory Format.
Definition: PeImage.h:608
#define CODEVIEW_SIGNATURE_NB10
Debug Data Structure defined in Microsoft C++.
Definition: PeImage.h:624
UINT32 e_lfanew
File address of new exe header.
Definition: PeImage.h:77
UINT16 e_magic
Magic number.
Definition: PeImage.h:59
EFI_IMAGE_DATA_DIRECTORY DataDirectory[EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES]
Definition: PeImage.h:185
PE images can start with an optional DOS header, so if an image is run under DOS it can print an erro...
Definition: PeImage.h:58
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:382
EFI_IMAGE_NT_HEADERS64 Pe32Plus
Definition: PeImage.h:747
#define EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC
Definition: PeImage.h:143
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
UINT32 RVA
The address of the debug data when loaded, relative to the image base.
Definition: PeImage.h:615
#define EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC
Definition: PeImage.h:194
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
#define EFI_IMAGE_DEBUG_TYPE_CODEVIEW
The Visual C++ debug information.
Definition: PeImage.h:619
EFI_IMAGE_OPTIONAL_HEADER32 OptionalHeader
Definition: PeImage.h:246

References CODEVIEW_SIGNATURE_MTOC, CODEVIEW_SIGNATURE_NB10, CODEVIEW_SIGNATURE_RSDS, EFI_IMAGE_OPTIONAL_HEADER32::DataDirectory, EFI_IMAGE_OPTIONAL_HEADER64::DataDirectory, DBG, EFI_IMAGE_DOS_HEADER::e_lfanew, EFI_IMAGE_DOS_HEADER::e_magic, EFI_IMAGE_DEBUG_TYPE_CODEVIEW, EFI_IMAGE_DIRECTORY_ENTRY_DEBUG, EFI_IMAGE_DOS_SIGNATURE, EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC, EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC, EFI_IMAGE_NT_SIGNATURE, EFI_PAGE_SIZE, EFI_LOADED_IMAGE_PROTOCOL::ImageBase, EFI_IMAGE_OPTIONAL_HEADER32::Magic, max_len, name, NULL, EFI_IMAGE_NT_HEADERS32::OptionalHeader, EFI_IMAGE_NT_HEADERS64::OptionalHeader, EFI_IMAGE_OPTIONAL_HEADER_UNION::Pe32, EFI_IMAGE_OPTIONAL_HEADER_UNION::Pe32Plus, EFI_IMAGE_DEBUG_DIRECTORY_ENTRY::RVA, EFI_IMAGE_NT_HEADERS32::Signature, EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY::Signature, snprintf(), strchr(), strnlen(), strrchr(), tmp, EFI_IMAGE_DEBUG_DIRECTORY_ENTRY::Type, and EFI_IMAGE_DATA_DIRECTORY::VirtualAddress.

◆ efi_first_loaded_image_name()

static const char* efi_first_loaded_image_name ( EFI_LOADED_IMAGE_PROTOCOL loaded)
static

Get initial loaded image name.

Parameters
loadedLoaded image
Return values
nameInitial loaded image name, or NULL

Definition at line 586 of file efi_debug.c.

586  {
587 
588  /* Sanity check */
589  if ( ! loaded ) {
590  DBG ( "[NULL LoadedImage]" );
591  return NULL;
592  }
593 
594  return ( ( loaded->ParentHandle == NULL ) ? "DxeCore(?)" : NULL );
595 }
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
EFI_HANDLE ParentHandle
Parent image's image handle.
Definition: LoadedImage.h:54

References DBG, NULL, and EFI_LOADED_IMAGE_PROTOCOL::ParentHandle.

◆ efi_loaded_image_filepath_name()

static const char* efi_loaded_image_filepath_name ( EFI_LOADED_IMAGE_PROTOCOL loaded)
static

Get loaded image name from file path.

Parameters
loadedLoaded image
Return values
nameLoaded image name, or NULL

Definition at line 604 of file efi_debug.c.

604  {
605 
606  /* Sanity check */
607  if ( ! loaded ) {
608  DBG ( "[NULL LoadedImage]" );
609  return NULL;
610  }
611 
612  return efi_devpath_text ( loaded->FilePath );
613 }
EFI_DEVICE_PATH_PROTOCOL * FilePath
A pointer to the file path portion specific to DeviceHandle that the EFI Image was loaded from.
Definition: LoadedImage.h:62
const char * efi_devpath_text(EFI_DEVICE_PATH_PROTOCOL *path)
Get textual representation of device path.
Definition: efi_debug.c:366
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References DBG, efi_devpath_text(), EFI_LOADED_IMAGE_PROTOCOL::FilePath, and NULL.

◆ efi_conin_name()

static const char* efi_conin_name ( EFI_SIMPLE_TEXT_INPUT_PROTOCOL input)
static

Get console input handle name.

Parameters
inputSimple text input protocol
Return values
nameConsole input handle name, or NULL

Definition at line 622 of file efi_debug.c.

622  {
623 
624  /* Check for match against ConIn */
625  if ( input == efi_systab->ConIn )
626  return "ConIn";
627 
628  return NULL;
629 }
Definition: bnxt_hsi.h:68
EFI_SIMPLE_TEXT_INPUT_PROTOCOL * ConIn
A pointer to the EFI_SIMPLE_TEXT_INPUT_PROTOCOL interface that is associated with ConsoleInHandle.
Definition: UefiSpec.h:1973
EFI_SYSTEM_TABLE * efi_systab
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References EFI_SYSTEM_TABLE::ConIn, efi_systab, and NULL.

◆ efi_conout_name()

static const char* efi_conout_name ( EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL output)
static

Get console output handle name.

Parameters
outputSimple text output protocol
Return values
nameConsole output handle name, or NULL

Definition at line 638 of file efi_debug.c.

638  {
639 
640  /* Check for match against ConOut */
641  if ( output == efi_systab->ConOut )
642  return "ConOut";
643 
644  /* Check for match against StdErr (if different from ConOut) */
645  if ( output == efi_systab->StdErr )
646  return "StdErr";
647 
648  return NULL;
649 }
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL * ConOut
A pointer to the EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL interface that is associated with ConsoleOutHandle.
Definition: UefiSpec.h:1982
EFI_SYSTEM_TABLE * efi_systab
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL * StdErr
A pointer to the EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL interface that is associated with StandardErrorHandl...
Definition: UefiSpec.h:1992

References EFI_SYSTEM_TABLE::ConOut, efi_systab, NULL, and EFI_SYSTEM_TABLE::StdErr.

◆ efi_handle_name()

const char* efi_handle_name ( EFI_HANDLE  handle)

Get name of an EFI handle.

Parameters
handleEFI handle
Return values
textName of handle, or NULL

Definition at line 713 of file efi_debug.c.

713  {
715  struct efi_handle_name_type *type;
716  static char buf[256];
717  size_t used = 0;
718  EFI_GUID **protocols;
719  UINTN count;
720  unsigned int i;
721  void *interface;
722  const char *name;
723  EFI_STATUS efirc;
724 
725  /* Fail immediately for NULL handles */
726  if ( ! handle )
727  return NULL;
728 
729  /* Try each name type in turn */
730  for ( i = 0 ; i < ( sizeof ( efi_handle_name_types ) /
731  sizeof ( efi_handle_name_types[0] ) ) ; i++ ) {
733  DBG2 ( "<%d", i );
734 
735  /* Try to open the applicable protocol */
736  efirc = bs->OpenProtocol ( handle, type->protocol, &interface,
739  if ( efirc != 0 ) {
740  DBG2 ( ">" );
741  continue;
742  }
743 
744  /* Try to get name from this protocol */
745  DBG2 ( "-" );
746  name = type->name ( interface );
747  DBG2 ( "%c", ( name ? ( name[0] ? 'Y' : 'E' ) : 'N' ) );
748 
749  /* Close protocol */
750  bs->CloseProtocol ( handle, type->protocol,
752  DBG2 ( ">" );
753 
754  /* Use this name, if possible */
755  if ( name && name[0] )
756  return name;
757  }
758 
759  /* If no name is found, then use the raw handle value and a
760  * list of installed protocols.
761  */
762  used = ssnprintf ( buf, sizeof ( buf ), "UNKNOWN<%p", handle );
763  if ( ( efirc = bs->ProtocolsPerHandle ( handle, &protocols,
764  &count ) ) == 0 ) {
765  for ( i = 0 ; i < count ; i++ ) {
766  used += ssnprintf ( ( buf + used ),
767  ( sizeof ( buf ) - used ), ",%s",
768  efi_guid_ntoa ( protocols[i] ) );
769  }
770  bs->FreePool ( protocols );
771  }
772  used += ssnprintf ( ( buf + used ), ( sizeof ( buf ) - used ), ">" );
773  return buf;
774 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
const char * name
Definition: ath9k_hw.c:1984
128 bit buffer containing a unique identifier value.
Definition: Base.h:263
uint8_t type
Type.
Definition: ena.h:16
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:1906
int ssnprintf(char *buf, ssize_t ssize, const char *fmt,...)
Version of vsnprintf() that accepts a signed buffer size.
Definition: vsprintf.c:420
An object interface.
Definition: interface.h:109
#define EFI_OPEN_PROTOCOL_GET_PROTOCOL
Definition: UefiSpec.h:1271
static struct efi_handle_name_type efi_handle_name_types[]
EFI handle name types.
Definition: efi_debug.c:677
EFI Boot Services Table.
Definition: UefiSpec.h:1836
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:30
UINT64 UINTN
Unsigned value of native width.
Definition: ProcessorBind.h:71
EFI_FREE_POOL FreePool
Definition: UefiSpec.h:1855
const char * efi_guid_ntoa(EFI_GUID *guid)
Convert GUID to a printable string.
Definition: efi_debug.c:192
EFI_PROTOCOLS_PER_HANDLE ProtocolsPerHandle
Definition: UefiSpec.h:1912
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
uint16_t count
Number of entries.
Definition: ena.h:22
An EFI handle name type.
Definition: efi_debug.c:652
EFI_SYSTEM_TABLE * efi_systab
EFI_OPEN_PROTOCOL OpenProtocol
Definition: UefiSpec.h:1905
uint16_t handle
Handle.
Definition: smbios.h:16
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
#define DBG2(...)
Definition: compiler.h:515

References EFI_SYSTEM_TABLE::BootServices, EFI_BOOT_SERVICES::CloseProtocol, count, DBG2, efi_guid_ntoa(), efi_handle_name_types, efi_image_handle, EFI_OPEN_PROTOCOL_GET_PROTOCOL, efi_systab, EFI_BOOT_SERVICES::FreePool, handle, name, NULL, EFI_BOOT_SERVICES::OpenProtocol, EFI_BOOT_SERVICES::ProtocolsPerHandle, ssnprintf(), and type.

Referenced by chained_locate(), chained_supported(), dbg_efi_openers(), dbg_efi_protocols(), efi_blacklist(), efi_bofm_start(), efi_bofm_supported(), efi_child_add(), efi_child_del(), efi_close_protocol_wrapper(), efi_connect_controller_wrapper(), efi_device_info(), efi_disconnect_controller_wrapper(), efi_driver_connect(), efi_driver_start(), efi_driver_stop(), efi_driver_supported(), efi_exit_boot_services_wrapper(), efi_exit_wrapper(), efi_handle_protocol_wrapper(), efi_install_protocol_interface_wrapper(), efi_load_image_wrapper(), efi_local_check_volume_name(), efi_local_open_root(), efi_local_open_volume(), efi_locate_device(), efi_locate_device_path_wrapper(), efi_locate_handle_buffer_wrapper(), efi_locate_handle_wrapper(), efi_open_protocol_wrapper(), efi_pci_info(), efi_protocols_per_handle_wrapper(), efi_pxe_install(), efi_pxe_uninstall(), efi_reinstall_protocol_interface_wrapper(), efi_snp_probe(), efi_start_image_wrapper(), efi_uninstall_protocol_interface_wrapper(), efi_unload_blacklist(), efi_unload_image_wrapper(), efi_usb_install(), efi_wrap(), efipci_open(), efipci_root(), efipci_start(), nii_start(), nii_supported(), snp_supported(), snpnet_start(), snpnet_stop(), usbio_bulk_in_poll(), usbio_bulk_out_poll(), usbio_config(), usbio_control_poll(), usbio_endpoint_open(), usbio_interface(), usbio_interfaces(), usbio_interrupt_callback(), usbio_interrupt_open(), usbio_open(), usbio_path(), usbio_start(), and usbio_supported().

Variable Documentation

◆ efidpt

Device path to text protocol.

Definition at line 47 of file efi_debug.c.

Referenced by efi_devpath_text().

◆ efi_iscsi4_dxe_guid

EFI_GUID efi_iscsi4_dxe_guid
static
Initial value:
= {
0x4579b72d, 0x7ec4, 0x4dd4,
{ 0x84, 0x86, 0x08, 0x3c, 0x86, 0xb1, 0x82, 0xa7 }
}

Iscsi4Dxe module GUID.

Definition at line 51 of file efi_debug.c.

◆ efi_vlan_config_dxe_guid

EFI_GUID efi_vlan_config_dxe_guid
static
Initial value:
= {
0xe4f61863, 0xfe2c, 0x4b56,
{ 0xa8, 0xf4, 0x08, 0x51, 0x9b, 0xc4, 0x39, 0xdf }
}

VlanConfigDxe module GUID.

Definition at line 57 of file efi_debug.c.

◆ efi_well_known_guids

struct efi_well_known_guid efi_well_known_guids[]
static

Well-known GUIDs.

Definition at line 71 of file efi_debug.c.

Referenced by efi_guid_ntoa().

◆ efi_handle_name_types

struct efi_handle_name_type efi_handle_name_types[]
static
Initial value:
= {
}
static const char * efi_loaded_image_filepath_name(EFI_LOADED_IMAGE_PROTOCOL *loaded)
Get loaded image name from file path.
Definition: efi_debug.c:604
static const char * efi_conin_name(EFI_SIMPLE_TEXT_INPUT_PROTOCOL *input)
Get console input handle name.
Definition: efi_debug.c:622
static const char * efi_driver_name(EFI_COMPONENT_NAME_PROTOCOL *wtf)
Get driver name.
Definition: efi_debug.c:406
EFI_GUID efi_loaded_image_device_path_protocol_guid
Loaded image device path protocol GUID.
Definition: efi_guid.c:188
EFI_GUID efi_loaded_image_protocol_guid
Loaded image protocol GUID.
Definition: efi_guid.c:184
#define EFI_HANDLE_NAME_TYPE(protocol, name)
Define an EFI handle name type.
Definition: efi_debug.c:671
static const char * efi_driver_name2(EFI_COMPONENT_NAME2_PROTOCOL *wtf)
Get driver name.
Definition: efi_debug.c:436
EFI_GUID efi_simple_text_output_protocol_guid
Simple text output protocol GUID.
Definition: efi_guid.c:252
const char * efi_devpath_text(EFI_DEVICE_PATH_PROTOCOL *path)
Get textual representation of device path.
Definition: efi_debug.c:366
static const char * efi_pecoff_debug_name(EFI_LOADED_IMAGE_PROTOCOL *loaded)
Get PE/COFF debug filename.
Definition: efi_debug.c:467
EFI_GUID efi_device_path_protocol_guid
Device path protocol GUID.
Definition: efi_guid.c:132
EFI_GUID efi_component_name2_protocol_guid
Component name 2 protocol GUID.
Definition: efi_guid.c:124
EFI_GUID efi_simple_text_input_protocol_guid
Simple text input protocol GUID.
Definition: efi_guid.c:244
static const char * efi_conout_name(EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *output)
Get console output handle name.
Definition: efi_debug.c:638
static const char * efi_first_loaded_image_name(EFI_LOADED_IMAGE_PROTOCOL *loaded)
Get initial loaded image name.
Definition: efi_debug.c:586
EFI_GUID efi_component_name_protocol_guid
Component name protocol GUID.
Definition: efi_guid.c:120

EFI handle name types.

Definition at line 677 of file efi_debug.c.

Referenced by efi_handle_name().