iPXE
efi_debug.c File Reference

EFI debugging utilities. More...

Go to the source code of this file.

Data Structures

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.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 EFI_REQUEST_PROTOCOL (EFI_DEVICE_PATH_TO_TEXT_PROTOCOL, &efidpt)
const char * efi_tpl_name (EFI_TPL tpl)
 Name EFI TPL.
const char * efi_locate_search_type_name (EFI_LOCATE_SEARCH_TYPE search_type)
 Name locate search type.
const char * efi_open_attributes_name (unsigned int attributes)
 Name protocol open attributes.
void dbg_efi_opener (EFI_HANDLE handle, EFI_GUID *protocol, EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *opener)
 Print opened protocol information.
void dbg_efi_openers (EFI_HANDLE handle, EFI_GUID *protocol)
 Print list of openers of a given protocol on a given handle.
void dbg_efi_protocol (EFI_HANDLE handle, EFI_GUID *protocol)
 Print protocol information on a given handle.
void dbg_efi_protocols (EFI_HANDLE handle)
 Print list of protocol handlers attached to a handle.
const char * efi_devpath_text (EFI_DEVICE_PATH_PROTOCOL *path)
 Get textual representation of device path.
static const char * efi_driver_name (EFI_COMPONENT_NAME_PROTOCOL *wtf)
 Get driver name.
static const char * efi_driver_name2 (EFI_COMPONENT_NAME2_PROTOCOL *wtf)
 Get driver name.
static const char * efi_binding_name (EFI_DRIVER_BINDING_PROTOCOL *binding)
 Get driver binding name.
static const char * efi_binding_name2 (EFI_DRIVER_BINDING_PROTOCOL *binding)
 Get driver binding name.
static const char * efi_pecoff_debug_name (EFI_LOADED_IMAGE_PROTOCOL *loaded)
 Get PE/COFF debug filename.
static const char * efi_first_loaded_image_name (EFI_LOADED_IMAGE_PROTOCOL *loaded)
 Get initial loaded image name.
static const char * efi_loaded_image_filepath_name (EFI_LOADED_IMAGE_PROTOCOL *loaded)
 Get loaded image name from file path.
static const char * efi_conin_name (EFI_SIMPLE_TEXT_INPUT_PROTOCOL *input)
 Get console input handle name.
static const char * efi_conout_name (EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *output)
 Get console output handle name.
const char * efi_handle_name (EFI_HANDLE handle)
 Get name of an EFI handle.

Variables

static EFI_DEVICE_PATH_TO_TEXT_PROTOCOLefidpt
 Device path to text protocol.
static struct efi_handle_name_type efi_handle_name_types []
 EFI handle name types.

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:1986
uint16_t protocol
Protocol ID.
Definition stp.h:7

Define an EFI handle name type.

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

Definition at line 610 of file efi_debug.c.

610#define EFI_HANDLE_NAME_TYPE( protocol, name ) { \
611 (protocol), \
612 ( const char * ( * ) ( void * ) ) (name), \
613 }

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ EFI_REQUEST_PROTOCOL()

EFI_REQUEST_PROTOCOL ( EFI_DEVICE_PATH_TO_TEXT_PROTOCOL ,
& efidpt )

References efidpt.

◆ efi_tpl_name()

const char * efi_tpl_name ( EFI_TPL tpl)

Name EFI TPL.

Parameters
tplTask priority level
Return values
textTask priority level as text

Definition at line 55 of file efi_debug.c.

55 {
56 static char buf[ 19 /* "0xXXXXXXXXXXXXXXXX" + NUL */ ];
57
58 switch ( tpl ) {
59 case TPL_APPLICATION: return "Application";
60 case TPL_CALLBACK: return "Callback";
61 case TPL_NOTIFY: return "Notify";
62 case TPL_HIGH_LEVEL: return "HighLevel";
63 default:
64 snprintf ( buf, sizeof ( buf ), "%#lx",
65 ( unsigned long ) tpl );
66 return buf;
67 }
68}
#define TPL_CALLBACK
Definition UefiSpec.h:649
#define TPL_HIGH_LEVEL
Definition UefiSpec.h:651
#define TPL_APPLICATION
Definition UefiSpec.h:648
#define TPL_NOTIFY
Definition UefiSpec.h:650
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition vsprintf.c:383

References snprintf(), TPL_APPLICATION, TPL_CALLBACK, TPL_HIGH_LEVEL, and TPL_NOTIFY.

Referenced by efi_connect(), efi_create_event_ex_wrapper(), efi_create_event_wrapper(), efi_disconnect(), efi_raise_tpl_wrapper(), and efi_restore_tpl_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 77 of file efi_debug.c.

77 {
78 static char buf[16];
79
80 switch ( search_type ) {
81 case AllHandles : return "AllHandles";
82 case ByRegisterNotify: return "ByRegisterNotify";
83 case ByProtocol: return "ByProtocol";
84 default:
85 snprintf ( buf, sizeof ( buf ), "UNKNOWN<%d>", search_type );
86 return buf;
87 }
88}
@ ByProtocol
Retrieve the set of handles from the handle database that support a specified protocol.
Definition UefiSpec.h:1531
@ ByRegisterNotify
Retrieve the next handle fron a RegisterProtocolNotify() event.
Definition UefiSpec.h:1526
@ AllHandles
Retrieve all the handles in the handle database.
Definition UefiSpec.h:1522

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 102 of file efi_debug.c.

102 {
103 static char attribute_chars[] = "HGTCDX";
104 static char name[ sizeof ( attribute_chars ) ];
105 char *tmp = name;
106 unsigned int i;
107
108 for ( i = 0 ; i < ( sizeof ( attribute_chars ) - 1 ) ; i++ ) {
109 if ( attributes & ( 1 << i ) )
110 *(tmp++) = attribute_chars[i];
111 }
112 *tmp = '\0';
113
114 return name;
115}
unsigned long tmp
Definition linux_pci.h:65

References name, and tmp.

Referenced by dbg_efi_opener(), and efi_open_protocol_wrapper().

◆ dbg_efi_opener()

void dbg_efi_opener ( EFI_HANDLE handle,
EFI_GUID * protocol,
EFI_OPEN_PROTOCOL_INFORMATION_ENTRY * opener )

Print opened protocol information.

Parameters
handleEFI handle @V protocol Protocol GUID
openerOpened protocol information

Definition at line 124 of file efi_debug.c.

125 {
126
127 printf ( "HANDLE %s %s opened %dx (%s)", efi_handle_name ( handle ),
128 efi_guid_ntoa ( protocol ), opener->OpenCount,
130 printf ( " by %s", efi_handle_name ( opener->AgentHandle ) );
131 if ( opener->ControllerHandle == handle ) {
132 printf ( "\n" );
133 } else {
134 printf ( " for %s\n",
135 efi_handle_name ( opener->ControllerHandle ) );
136 }
137}
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition efi_debug.c:652
const char * efi_open_attributes_name(unsigned int attributes)
Name protocol open attributes.
Definition efi_debug.c:102
const char * efi_guid_ntoa(CONST EFI_GUID *guid)
Convert GUID to a printable string.
Definition efi_guid.c:726
uint16_t handle
Handle.
Definition smbios.h:5
EFI_HANDLE AgentHandle
Definition UefiSpec.h:1433
UINT32 OpenCount
Definition UefiSpec.h:1436
UINT32 Attributes
Definition UefiSpec.h:1435
EFI_HANDLE ControllerHandle
Definition UefiSpec.h:1434
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition vsprintf.c:465

References EFI_OPEN_PROTOCOL_INFORMATION_ENTRY::AgentHandle, EFI_OPEN_PROTOCOL_INFORMATION_ENTRY::Attributes, EFI_OPEN_PROTOCOL_INFORMATION_ENTRY::ControllerHandle, efi_guid_ntoa(), EFI_HANDLE, efi_handle_name(), efi_open_attributes_name(), handle, EFI_OPEN_PROTOCOL_INFORMATION_ENTRY::OpenCount, printf(), and protocol.

Referenced by dbg_efi_openers().

◆ 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 145 of file efi_debug.c.

145 {
146 EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
148 UINTN count;
149 unsigned int i;
150 EFI_STATUS efirc;
151 int rc;
152
153 /* Sanity check */
154 if ( ( ! handle ) || ( ! protocol ) ) {
155 printf ( "HANDLE %s could not retrieve openers for %s\n",
158 return;
159 }
160
161 /* Retrieve list of openers */
162 if ( ( efirc = bs->OpenProtocolInformation ( handle, protocol, &openers,
163 &count ) ) != 0 ) {
164 rc = -EEFI ( efirc );
165 printf ( "HANDLE %s could not retrieve openers for %s: %s\n",
168 return;
169 }
170
171 /* Dump list of openers */
172 for ( i = 0 ; i < count ; i++ )
173 dbg_efi_opener ( handle, protocol, &openers[i] );
174
175 /* Free list */
176 bs->FreePool ( openers );
177}
UINT64 UINTN
Unsigned value of native width.
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
void dbg_efi_opener(EFI_HANDLE handle, EFI_GUID *protocol, EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *opener)
Print opened protocol information.
Definition efi_debug.c:124
static unsigned int count
Number of entries.
Definition dwmac.h:220
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition efi.h:175
EFI_SYSTEM_TABLE * efi_systab
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
EFI Boot Services Table.
Definition UefiSpec.h:1931
EFI_FREE_POOL FreePool
Definition UefiSpec.h:1950
EFI_OPEN_PROTOCOL_INFORMATION OpenProtocolInformation
Definition UefiSpec.h:2002
EFI Oprn Protocol Information Entry.
Definition UefiSpec.h:1432

References count, dbg_efi_opener(), EEFI, efi_guid_ntoa(), EFI_HANDLE, efi_handle_name(), efi_systab, EFI_BOOT_SERVICES::FreePool, handle, EFI_BOOT_SERVICES::OpenProtocolInformation, printf(), protocol, rc, and strerror().

Referenced by dbg_efi_protocol().

◆ dbg_efi_protocol()

void dbg_efi_protocol ( EFI_HANDLE handle,
EFI_GUID * protocol )

Print protocol information on a given handle.

Parameters
handleEFI handle
protocolProtocol GUID

Definition at line 185 of file efi_debug.c.

185 {
187 int rc;
188
189 /* Get protocol instance */
190 if ( ( rc = efi_open ( handle, protocol, &interface ) ) != 0 ) {
191 printf ( "HANDLE %s could not identify %s: %s\n",
194 return;
195 }
196 printf ( "HANDLE %s %s at %p\n", efi_handle_name ( handle ),
198
199 /* Dump list of openers */
201}
#define VOID
Undeclared type.
Definition Base.h:272
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:145
#define efi_open(handle, protocol, interface)
Open protocol for ephemeral use.
Definition efi.h:444
An object interface.
Definition interface.h:125

References dbg_efi_openers(), efi_guid_ntoa(), EFI_HANDLE, efi_handle_name(), efi_open, handle, printf(), protocol, rc, strerror(), and VOID.

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 208 of file efi_debug.c.

208 {
209 EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
210 EFI_GUID **protocols;
211 UINTN count;
212 unsigned int i;
213 EFI_STATUS efirc;
214 int rc;
215
216 /* Sanity check */
217 if ( ! handle ) {
218 printf ( "HANDLE %p could not retrieve protocols\n", handle );
219 return;
220 }
221
222 /* Retrieve list of protocols */
223 if ( ( efirc = bs->ProtocolsPerHandle ( handle, &protocols,
224 &count ) ) != 0 ) {
225 rc = -EEFI ( efirc );
226 printf ( "HANDLE %s could not retrieve protocols: %s\n",
228 return;
229 }
230
231 /* Dump list of protocols */
232 for ( i = 0 ; i < count ; i++ ) {
233 dbg_efi_protocol ( handle, protocols[i] );
234 }
235
236 /* Free list */
237 bs->FreePool ( protocols );
238}
GUID EFI_GUID
128-bit buffer containing a unique identifier value.
void dbg_efi_protocol(EFI_HANDLE handle, EFI_GUID *protocol)
Print protocol information on a given handle.
Definition efi_debug.c:185
EFI_PROTOCOLS_PER_HANDLE ProtocolsPerHandle
Definition UefiSpec.h:2007

References count, dbg_efi_protocol(), EEFI, EFI_HANDLE, efi_handle_name(), efi_systab, EFI_BOOT_SERVICES::FreePool, handle, printf(), 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 247 of file efi_debug.c.

247 {
248 EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
249 static char text[512];
250 size_t len;
251 CHAR16 *wtext;
252
253 /* Sanity checks */
254 if ( ! path ) {
255 DBG ( "[NULL DevicePath]" );
256 return NULL;
257 }
258
259 /* If we have no DevicePathToText protocol then use a raw hex string */
260 if ( ! efidpt ) {
261 DBG ( "[No DevicePathToText]" );
262 len = efi_path_len ( path );
263 base16_encode ( path, len, text, sizeof ( text ) );
264 return text;
265 }
266
267 /* Convert path to a textual representation */
268 wtext = efidpt->ConvertDevicePathToText ( path, FALSE, FALSE );
269 if ( ! wtext )
270 return NULL;
271
272 /* Store path in buffer */
273 snprintf ( text, sizeof ( text ), "%ls", wtext );
274
275 /* Free path */
276 bs->FreePool ( wtext );
277
278 return text;
279}
unsigned short CHAR16
2-byte Character.
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
ring len
Length.
Definition dwmac.h:226
static EFI_DEVICE_PATH_TO_TEXT_PROTOCOL * efidpt
Device path to text protocol.
Definition efi_debug.c:46
size_t efi_path_len(EFI_DEVICE_PATH_PROTOCOL *path)
Find length of device path (excluding terminator)
Definition efi_path.c:174
#define DBG(...)
Print a debugging message.
Definition compiler.h:498
#define FALSE
Definition tlan.h:45

References DBG, efi_path_len(), efi_systab, efidpt, FALSE, EFI_BOOT_SERVICES::FreePool, len, NULL, and snprintf().

Referenced by efi_block_exec(), efi_block_hook(), efi_block_match(), efi_connect_controller_wrapper(), efi_driver_start(), efi_driver_supported(), efi_dump_image(), efi_file_path_claim(), efi_file_path_install(), efi_file_path_uninstall(), efi_init(), efi_init_application(), efi_load_image_wrapper(), efi_loaded_image_filepath_name(), efi_local_open_volume(), efi_locate_device(), efi_locate_device_path_wrapper(), efi_path_net_probe(), usbio_open(), and usbio_path().

◆ efi_driver_name()

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 287 of file efi_debug.c.

287 {
288 static char name[64];
289 CHAR16 *driver_name;
290 EFI_STATUS efirc;
291
292 /* Sanity check */
293 if ( ! wtf ) {
294 DBG ( "[NULL ComponentName]" );
295 return NULL;
296 }
297
298 /* Try "eng" first; if that fails then try the first language */
299 if ( ( ( efirc = wtf->GetDriverName ( wtf, "eng",
300 &driver_name ) ) != 0 ) &&
301 ( ( efirc = wtf->GetDriverName ( wtf, wtf->SupportedLanguages,
302 &driver_name ) ) != 0 ) ) {
303 return NULL;
304 }
305
306 /* Convert name from CHAR16 to char */
307 snprintf ( name, sizeof ( name ), "%ls", driver_name );
308 return name;
309}
char wtf[42]
Authenticator response string.
Definition mschapv2.h:7

References DBG, name, NULL, snprintf(), and wtf.

Referenced by efi_binding_name().

◆ efi_driver_name2()

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 317 of file efi_debug.c.

317 {
318 static char name[64];
319 CHAR16 *driver_name;
320 EFI_STATUS efirc;
321
322 /* Sanity check */
323 if ( ! wtf ) {
324 DBG ( "[NULL ComponentName2]" );
325 return NULL;
326 }
327
328 /* Try "en" first; if that fails then try the first language */
329 if ( ( ( efirc = wtf->GetDriverName ( wtf, "en",
330 &driver_name ) ) != 0 ) &&
331 ( ( efirc = wtf->GetDriverName ( wtf, wtf->SupportedLanguages,
332 &driver_name ) ) != 0 ) ) {
333 return NULL;
334 }
335
336 /* Convert name from CHAR16 to char */
337 snprintf ( name, sizeof ( name ), "%ls", driver_name );
338 return name;
339}

References DBG, name, NULL, snprintf(), and wtf.

Referenced by efi_binding_name2().

◆ efi_binding_name()

const char * efi_binding_name ( EFI_DRIVER_BINDING_PROTOCOL * binding)
static

Get driver binding name.

Parameters
bindingDriver binding protocol
Return values
nameDriver name, or NULL

Definition at line 347 of file efi_debug.c.

347 {
350 int rc;
351
352 /* Sanity check */
353 if ( ! binding ) {
354 DBG ( "[NULL DriverBinding]" );
355 return NULL;
356 }
357
358 /* Try to open component name protocol on image handle */
359 image = binding->ImageHandle;
361 &name ) ) != 0 ) {
362 DBG ( "[DriverBinding no ComponentName]" );
363 return NULL;
364 }
365
366 /* Try to get name from component name protocol */
367 return efi_driver_name ( name );
368}
struct _EFI_COMPONENT_NAME_PROTOCOL EFI_COMPONENT_NAME_PROTOCOL
static const char * efi_driver_name(EFI_COMPONENT_NAME_PROTOCOL *wtf)
Get driver name.
Definition efi_debug.c:287
EFI_GUID efi_component_name_protocol_guid
Component name protocol GUID.
Definition efi_guid.c:157
#define EFI_HANDLE
Definition efi.h:53
EFI_HANDLE ImageHandle
The image handle of the UEFI driver that produced this instance of the EFI_DRIVER_BINDING_PROTOCOL.
An executable image.
Definition image.h:24

References DBG, efi_component_name_protocol_guid, efi_driver_name(), EFI_HANDLE, efi_open, _EFI_DRIVER_BINDING_PROTOCOL::ImageHandle, name, NULL, and rc.

◆ efi_binding_name2()

const char * efi_binding_name2 ( EFI_DRIVER_BINDING_PROTOCOL * binding)
static

Get driver binding name.

Parameters
bindingDriver binding protocol
Return values
nameDriver name, or NULL

Definition at line 376 of file efi_debug.c.

376 {
379 int rc;
380
381 /* Sanity check */
382 if ( ! binding ) {
383 DBG ( "[NULL DriverBinding]" );
384 return NULL;
385 }
386
387 /* Try to open component name protocol on image handle */
388 image = binding->ImageHandle;
390 &name2 ) ) != 0 ) {
391 DBG ( "[DriverBinding no ComponentName2]" );
392 return NULL;
393 }
394
395 /* Try to get name from component name protocol */
396 return efi_driver_name2 ( name2 );
397}
struct _EFI_COMPONENT_NAME2_PROTOCOL EFI_COMPONENT_NAME2_PROTOCOL
static const char * efi_driver_name2(EFI_COMPONENT_NAME2_PROTOCOL *wtf)
Get driver name.
Definition efi_debug.c:317
EFI_GUID efi_component_name2_protocol_guid
Component name 2 protocol GUID.
Definition efi_guid.c:161

References DBG, efi_component_name2_protocol_guid, efi_driver_name2(), EFI_HANDLE, efi_open, _EFI_DRIVER_BINDING_PROTOCOL::ImageHandle, NULL, and rc.

◆ efi_pecoff_debug_name()

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 406 of file efi_debug.c.

406 {
407 static char buf[32];
417 uint16_t dos_magic;
418 uint32_t pe_magic;
419 uint16_t opt_magic;
420 uint32_t codeview_magic;
421 size_t max_len;
422 char *name;
423 char *tmp;
424
425 /* Sanity check */
426 if ( ! loaded ) {
427 DBG ( "[NULL LoadedImage]" );
428 return NULL;
429 }
430
431 /* Parse DOS header */
432 dos = loaded->ImageBase;
433 if ( ! dos ) {
434 DBG ( "[Missing DOS header]" );
435 return NULL;
436 }
437 dos_magic = dos->e_magic;
438 if ( dos_magic != EFI_IMAGE_DOS_SIGNATURE ) {
439 DBG ( "[Bad DOS signature %#04x]", dos_magic );
440 return NULL;
441 }
442 pe = ( loaded->ImageBase + dos->e_lfanew );
443
444 /* Parse PE header */
445 pe_magic = pe->Pe32.Signature;
446 if ( pe_magic != EFI_IMAGE_NT_SIGNATURE ) {
447 DBG ( "[Bad PE signature %#08x]", pe_magic );
448 return NULL;
449 }
450 opt32 = &pe->Pe32.OptionalHeader;
451 opt64 = &pe->Pe32Plus.OptionalHeader;
452 opt_magic = opt32->Magic;
453 if ( opt_magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC ) {
454 datadir = opt32->DataDirectory;
455 } else if ( opt_magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC ) {
456 datadir = opt64->DataDirectory;
457 } else {
458 DBG ( "[Bad optional header signature %#04x]", opt_magic );
459 return NULL;
460 }
461
462 /* Parse data directory entry */
463 if ( ! datadir[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress ) {
464 DBG ( "[Empty debug directory entry]" );
465 return NULL;
466 }
467 debug = ( loaded->ImageBase +
469
470 /* Parse debug directory entry */
471 if ( debug->Type != EFI_IMAGE_DEBUG_TYPE_CODEVIEW ) {
472 DBG ( "[Not a CodeView debug directory entry (type %d)]",
473 debug->Type );
474 return NULL;
475 }
476 codeview_nb10 = ( loaded->ImageBase + debug->RVA );
477 codeview_rsds = ( loaded->ImageBase + debug->RVA );
478 codeview_mtoc = ( loaded->ImageBase + debug->RVA );
479 codeview_magic = codeview_nb10->Signature;
480
481 /* Parse CodeView entry */
482 if ( codeview_magic == CODEVIEW_SIGNATURE_NB10 ) {
483 name = ( ( void * ) ( codeview_nb10 + 1 ) );
484 } else if ( codeview_magic == CODEVIEW_SIGNATURE_RSDS ) {
485 name = ( ( void * ) ( codeview_rsds + 1 ) );
486 } else if ( codeview_magic == CODEVIEW_SIGNATURE_MTOC ) {
487 name = ( ( void * ) ( codeview_mtoc + 1 ) );
488 } else {
489 DBG ( "[Bad CodeView signature %#08x]", codeview_magic );
490 return NULL;
491 }
492
493 /* Sanity check - avoid scanning endlessly through memory */
494 max_len = EFI_PAGE_SIZE; /* Reasonably sane */
495 if ( strnlen ( name, max_len ) == max_len ) {
496 DBG ( "[Excessively long or invalid CodeView name]" );
497 return NULL;
498 }
499
500 /* Skip any directory components. We cannot modify this data
501 * or create a temporary buffer, so do not use basename().
502 */
503 while ( ( ( tmp = strchr ( name, '/' ) ) != NULL ) ||
504 ( ( tmp = strchr ( name, '\\' ) ) != NULL ) ) {
505 name = ( tmp + 1 );
506 }
507
508 /* Copy base name to buffer */
509 snprintf ( buf, sizeof ( buf ), "%s", name );
510
511 /* Strip file suffix, if present */
512 if ( ( tmp = strrchr ( buf, '.' ) ) != NULL )
513 *tmp = '\0';
514
515 return buf;
516}
#define CODEVIEW_SIGNATURE_NB10
Debug Data Structure defined in Microsoft C++.
Definition PeImage.h:659
#define EFI_IMAGE_DEBUG_TYPE_CODEVIEW
The Visual C++ debug information.
Definition PeImage.h:653
#define CODEVIEW_SIGNATURE_RSDS
Debug Data Structure defined in Microsoft C++.
Definition PeImage.h:673
#define EFI_IMAGE_NT_SIGNATURE
Definition PeImage.h:53
#define EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC
Definition PeImage.h:145
#define EFI_IMAGE_DOS_SIGNATURE
Definition PeImage.h:50
#define EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC
Definition PeImage.h:196
#define CODEVIEW_SIGNATURE_MTOC
Debug Data Structure defined by Apple Mach-O to Coff utility.
Definition PeImage.h:689
#define EFI_IMAGE_DIRECTORY_ENTRY_DEBUG
Definition PeImage.h:131
#define EFI_PAGE_SIZE
unsigned short uint16_t
Definition stdint.h:11
unsigned int uint32_t
Definition stdint.h:12
uint64_t debug
Debug area base address.
Definition ena.h:3
char * strchr(const char *src, int character)
Find character within a string.
Definition string.c:272
size_t strnlen(const char *src, size_t max)
Get length of string.
Definition string.c:256
char * strrchr(const char *src, int character)
Find rightmost character within a string.
Definition string.c:290
Header Data Directories.
Definition PeImage.h:117
Definition PeImage.h:690
Definition PeImage.h:660
UINT32 Signature
"NB10"
Definition PeImage.h:661
Definition PeImage.h:674
Debug Directory Format.
Definition PeImage.h:642
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:59
UINT32 e_lfanew
File address of new exe header.
Definition PeImage.h:78
UINT16 e_magic
Magic number.
Definition PeImage.h:60
EFI_IMAGE_OPTIONAL_HEADER32 OptionalHeader
Definition PeImage.h:247
EFI_IMAGE_OPTIONAL_HEADER64 OptionalHeader
Definition PeImage.h:259
Optional Header Standard Fields for PE32.
Definition PeImage.h:150
EFI_IMAGE_DATA_DIRECTORY DataDirectory[EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES]
Definition PeImage.h:187
UINT16 Magic
Standard fields.
Definition PeImage.h:154
Optional Header Standard Fields for PE32+.
Definition PeImage.h:201
EFI_IMAGE_DATA_DIRECTORY DataDirectory[EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES]
Definition PeImage.h:237
VOID * ImageBase
The base address at which the image was loaded.
Definition LoadedImage.h:70
Union of PE32, PE32+, and TE headers.
Definition PeImage.h:805
EFI_IMAGE_NT_HEADERS64 Pe32Plus
Definition PeImage.h:807
EFI_IMAGE_NT_HEADERS32 Pe32
Definition PeImage.h:806

References CODEVIEW_SIGNATURE_MTOC, CODEVIEW_SIGNATURE_NB10, CODEVIEW_SIGNATURE_RSDS, EFI_IMAGE_OPTIONAL_HEADER32::DataDirectory, EFI_IMAGE_OPTIONAL_HEADER64::DataDirectory, DBG, debug, 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, 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_CODEVIEW_NB10_ENTRY::Signature, EFI_IMAGE_NT_HEADERS32::Signature, snprintf(), strchr(), strnlen(), strrchr(), tmp, and EFI_IMAGE_DATA_DIRECTORY::VirtualAddress.

◆ efi_first_loaded_image_name()

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 525 of file efi_debug.c.

525 {
526
527 /* Sanity check */
528 if ( ! loaded ) {
529 DBG ( "[NULL LoadedImage]" );
530 return NULL;
531 }
532
533 return ( ( loaded->ParentHandle == NULL ) ? "DxeCore(?)" : NULL );
534}
EFI_HANDLE ParentHandle
Parent image's image handle.
Definition LoadedImage.h:49

References DBG, NULL, and EFI_LOADED_IMAGE_PROTOCOL::ParentHandle.

◆ efi_loaded_image_filepath_name()

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 543 of file efi_debug.c.

543 {
544
545 /* Sanity check */
546 if ( ! loaded ) {
547 DBG ( "[NULL LoadedImage]" );
548 return NULL;
549 }
550
551 return efi_devpath_text ( loaded->FilePath );
552}
const char * efi_devpath_text(EFI_DEVICE_PATH_PROTOCOL *path)
Get textual representation of device path.
Definition efi_debug.c:247
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:57

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

◆ efi_conin_name()

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 561 of file efi_debug.c.

561 {
562
563 /* Check for match against ConIn */
564 if ( input == efi_systab->ConIn )
565 return "ConIn";
566
567 return NULL;
568}

References efi_systab, and NULL.

◆ efi_conout_name()

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 577 of file efi_debug.c.

577 {
578
579 /* Check for match against ConOut */
580 if ( output == efi_systab->ConOut )
581 return "ConOut";
582
583 /* Check for match against StdErr (if different from ConOut) */
584 if ( output == efi_systab->StdErr )
585 return "StdErr";
586
587 return NULL;
588}

References efi_systab, and NULL.

◆ 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 652 of file efi_debug.c.

652 {
653 EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
655 static char buf[256];
656 size_t used = 0;
657 EFI_GUID **protocols;
658 UINTN count;
659 unsigned int i;
660 void *interface;
661 const char *name;
662 EFI_STATUS efirc;
663 int rc;
664
665 /* Fail immediately for NULL handles */
666 if ( ! handle )
667 return NULL;
668
669 /* Try each name type in turn */
670 for ( i = 0 ; i < ( sizeof ( efi_handle_name_types ) /
671 sizeof ( efi_handle_name_types[0] ) ) ; i++ ) {
673 DBG2 ( "<%d", i );
674
675 /* Try to open the applicable protocol */
676 if ( ( rc = efi_open ( handle, type->protocol,
677 &interface ) ) != 0 ) {
678 DBG2 ( ">" );
679 continue;
680 }
681
682 /* Try to get name from this protocol */
683 DBG2 ( "-" );
684 name = type->name ( interface );
685 DBG2 ( "%c>", ( name ? ( name[0] ? 'Y' : 'E' ) : 'N' ) );
686
687 /* Use this name, if possible */
688 if ( name && name[0] )
689 return name;
690 }
691
692 /* If no name is found, then use the raw handle value and a
693 * list of installed protocols.
694 */
695 used = ssnprintf ( buf, sizeof ( buf ), "UNKNOWN<%p", handle );
696 if ( ( efirc = bs->ProtocolsPerHandle ( handle, &protocols,
697 &count ) ) == 0 ) {
698 for ( i = 0 ; i < count ; i++ ) {
699 used += ssnprintf ( ( buf + used ),
700 ( sizeof ( buf ) - used ), ",%s",
701 efi_guid_ntoa ( protocols[i] ) );
702 }
703 bs->FreePool ( protocols );
704 }
705 used += ssnprintf ( ( buf + used ), ( sizeof ( buf ) - used ), ">" );
706 return buf;
707}
static struct efi_handle_name_type efi_handle_name_types[]
EFI handle name types.
Definition efi_debug.c:616
uint32_t type
Operating system type.
Definition ena.h:1
#define DBG2(...)
Definition compiler.h:515
An EFI handle name type.
Definition efi_debug.c:591
int ssnprintf(char *buf, ssize_t ssize, const char *fmt,...)
Version of vsnprintf() that accepts a signed buffer size.
Definition vsprintf.c:421

References count, DBG2, efi_guid_ntoa(), EFI_HANDLE, efi_handle_name_types, efi_open, efi_systab, EFI_BOOT_SERVICES::FreePool, handle, name, NULL, EFI_BOOT_SERVICES::ProtocolsPerHandle, rc, ssnprintf(), and type.

Referenced by chained_locate(), chained_supported(), dbg_efi_opener(), dbg_efi_openers(), dbg_efi_protocol(), dbg_efi_protocols(), efi_autoexec_filesystem(), efi_autoexec_load(), efi_autoexec_network(), efi_block_boot(), efi_block_filename(), efi_block_hook(), efi_block_local(), efi_block_match(), efi_block_root(), efi_bofm_start(), efi_bofm_supported(), efi_cachedhcp_record(), efi_child_add(), efi_child_del(), efi_close_protocol_wrapper(), efi_connect(), efi_connect_controller_wrapper(), efi_device_info(), efi_device_info_pci(), efi_disconnect(), efi_disconnect_controller_wrapper(), efi_driver_connect(), efi_driver_exclude(), efi_driver_start(), efi_driver_stop(), efi_driver_supported(), efi_dump_image(), efi_exit_boot_services_wrapper(), efi_exit_wrapper(), efi_file_path_claim(), efi_handle_protocol_wrapper(), efi_install_multiple_protocol_interfaces_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_information_wrapper(), efi_open_protocol_wrapper(), efi_protocols_per_handle_wrapper(), efi_pxe_install(), efi_pxe_uninstall(), efi_reinstall_protocol_interface_wrapper(), efi_service_add(), efi_service_del(), efi_set_autoboot_ll_addr(), efi_snp_probe(), efi_start_image_wrapper(), efi_uninstall_multiple_protocol_interfaces_wrapper(), efi_uninstall_protocol_interface_wrapper(), efi_unload_image_wrapper(), efi_usb_install(), efi_usb_uninstall(), efi_veto(), efi_veto_close(), efi_veto_close_handle(), efi_veto_close_protocol(), efi_veto_destroy(), efi_veto_disconnect(), efi_veto_find(), efi_veto_uninstall(), efi_veto_unload(), efidev_alloc(), efipci_discover_one(), efipci_exclude(), efipci_info(), efipci_root_open(), efipci_start(), mnpnet_start(), mnptemp_create(), nii_exclude(), nii_start(), snpnet_exclude(), snpnet_insomniac_patch(), snpnet_insomniac_restore(), snpnet_is_insomniac(), snpnet_start(), snpnet_stop(), snpnet_supported(), usbio_bulk_in_poll(), usbio_bulk_out_poll(), usbio_config(), usbio_control_poll(), usbio_endpoint_open(), usbio_exclude(), 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 46 of file efi_debug.c.

Referenced by efi_devpath_text(), and EFI_REQUEST_PROTOCOL().

◆ efi_handle_name_types

struct efi_handle_name_type efi_handle_name_types[]
static
Initial value:
= {
}
static const char * efi_conin_name(EFI_SIMPLE_TEXT_INPUT_PROTOCOL *input)
Get console input handle name.
Definition efi_debug.c:561
#define EFI_HANDLE_NAME_TYPE(protocol, name)
Define an EFI handle name type.
Definition efi_debug.c:610
static const char * efi_loaded_image_filepath_name(EFI_LOADED_IMAGE_PROTOCOL *loaded)
Get loaded image name from file path.
Definition efi_debug.c:543
static const char * efi_pecoff_debug_name(EFI_LOADED_IMAGE_PROTOCOL *loaded)
Get PE/COFF debug filename.
Definition efi_debug.c:406
static const char * efi_binding_name2(EFI_DRIVER_BINDING_PROTOCOL *binding)
Get driver binding name.
Definition efi_debug.c:376
static const char * efi_binding_name(EFI_DRIVER_BINDING_PROTOCOL *binding)
Get driver binding name.
Definition efi_debug.c:347
static const char * efi_conout_name(EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *output)
Get console output handle name.
Definition efi_debug.c:577
static const char * efi_first_loaded_image_name(EFI_LOADED_IMAGE_PROTOCOL *loaded)
Get initial loaded image name.
Definition efi_debug.c:525
EFI_GUID efi_loaded_image_protocol_guid
Loaded image protocol GUID.
Definition efi_guid.c:273
EFI_GUID efi_loaded_image_device_path_protocol_guid
Loaded image device path protocol GUID.
Definition efi_guid.c:277
EFI_GUID efi_device_path_protocol_guid
Device path protocol GUID.
Definition efi_guid.c:169
EFI_GUID efi_simple_text_output_protocol_guid
Simple text output protocol GUID.
Definition efi_guid.c:357
EFI_GUID efi_driver_binding_protocol_guid
Driver binding protocol GUID.
Definition efi_guid.c:209
EFI_GUID efi_simple_text_input_protocol_guid
Simple text input protocol GUID.
Definition efi_guid.c:349

EFI handle name types.

Definition at line 616 of file efi_debug.c.

616 {
617 /* Driver name (for driver binding handles) */
620 /* Driver name (via obsolete original ComponentName protocol) */
623 /* PE/COFF debug filename (for image handles) */
626 /* Loaded image device path (for image handles) */
629 /* First loaded image name (for the DxeCore image) */
632 /* Handle's loaded image file path (for image handles) */
635 /* Device path */
638 /* Our standard input file handle */
641 /* Our standard output and standard error file handles */
644};

Referenced by efi_handle_name().