iPXE
efi_wrap.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Michael Brown <mbrown@fensystems.co.uk>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  *
19  * You can also choose to distribute this program under the terms of
20  * the Unmodified Binary Distribution Licence (as given in the file
21  * COPYING.UBDL), provided that you have satisfied its requirements.
22  */
23 
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25 
26 /**
27  * @file
28  *
29  * EFI image wrapping
30  *
31  */
32 
33 #include <string.h>
34 #include <stdio.h>
35 #include <errno.h>
36 #include <ipxe/efi/efi.h>
38 #include <ipxe/efi/efi_wrap.h>
39 
40 /** Colour for debug messages */
41 #define colour &efi_systab
42 
43 /** Maximum size for hex dumps */
44 #define EFI_WRAP_DUMP_MAX 128
45 
46 /** Number of lines to prescroll when needed */
47 #define EFI_WRAP_PRESCROLL 16
48 
49 /** Public EFI system table pointer */
51 
52 /** Private EFI system table used while wrapping is active */
54 
55 /** Original EFI boot services table pointer */
57 
58 /** Backup of original EFI boot services table */
60 
61 /** Original EFI runtime services table pointer */
63 
64 /** Backup of original EFI runtime services table */
66 
67 /**
68  * Convert EFI status code to text
69  *
70  * @v efirc EFI status code
71  * @ret text EFI status code text
72  */
73 static const char * efi_status ( EFI_STATUS efirc ) {
74  static char buf[ 19 /* "0xXXXXXXXXXXXXXXXX" + NUL */ ];
75 
76  switch ( efirc ) {
77  case EFI_SUCCESS : return "0";
78  case EFI_LOAD_ERROR : return "LOAD_ERROR";
79  case EFI_INVALID_PARAMETER : return "INVALID_PARAMETER";
80  case EFI_UNSUPPORTED : return "UNSUPPORTED";
81  case EFI_BAD_BUFFER_SIZE : return "BAD_BUFFER_SIZE";
82  case EFI_BUFFER_TOO_SMALL : return "BUFFER_TOO_SMALL";
83  case EFI_NOT_READY : return "NOT_READY";
84  case EFI_DEVICE_ERROR : return "DEVICE_ERROR";
85  case EFI_WRITE_PROTECTED : return "WRITE_PROTECTED";
86  case EFI_OUT_OF_RESOURCES : return "OUT_OF_RESOURCES";
87  case EFI_VOLUME_CORRUPTED : return "VOLUME_CORRUPTED";
88  case EFI_VOLUME_FULL : return "VOLUME_FULL";
89  case EFI_NO_MEDIA : return "NO_MEDIA";
90  case EFI_MEDIA_CHANGED : return "MEDIA_CHANGED";
91  case EFI_NOT_FOUND : return "NOT_FOUND";
92  case EFI_ACCESS_DENIED : return "ACCESS_DENIED";
93  case EFI_NO_RESPONSE : return "NO_RESPONSE";
94  case EFI_NO_MAPPING : return "NO_MAPPING";
95  case EFI_TIMEOUT : return "TIMEOUT";
96  case EFI_NOT_STARTED : return "NOT_STARTED";
97  case EFI_ALREADY_STARTED : return "ALREADY_STARTED";
98  case EFI_ABORTED : return "ABORTED";
99  case EFI_ICMP_ERROR : return "ICMP_ERROR";
100  case EFI_TFTP_ERROR : return "TFTP_ERROR";
101  case EFI_PROTOCOL_ERROR : return "PROTOCOL_ERROR";
102  case EFI_INCOMPATIBLE_VERSION : return "INCOMPATIBLE_VERSION";
103  case EFI_SECURITY_VIOLATION : return "SECURITY_VIOLATION";
104  case EFI_CRC_ERROR : return "CRC_ERROR";
105  case EFI_END_OF_MEDIA : return "END_OF_MEDIA";
106  case EFI_END_OF_FILE : return "END_OF_FILE";
107  case EFI_INVALID_LANGUAGE : return "INVALID_LANGUAGE";
108  case EFI_COMPROMISED_DATA : return "COMPROMISED_DATA";
109  case EFI_WARN_UNKNOWN_GLYPH : return "WARN_UNKNOWN_GLYPH";
110  case EFI_WARN_DELETE_FAILURE : return "WARN_DELETE_FAILURE";
111  case EFI_WARN_WRITE_FAILURE : return "WARN_WRITE_FAILURE";
112  case EFI_WARN_BUFFER_TOO_SMALL : return "WARN_BUFFER_TOO_SMALL";
113  case EFI_WARN_STALE_DATA : return "WARN_STALE_DATA";
114  default:
115  snprintf ( buf, sizeof ( buf ), "%#lx",
116  ( unsigned long ) efirc );
117  return buf;
118  }
119 }
120 
121 /**
122  * Convert EFI boolean to text
123  *
124  * @v boolean Boolean value
125  * @ret text Boolean value text
126  */
127 static const char * efi_boolean ( BOOLEAN boolean ) {
128 
129  return ( boolean ? "TRUE" : "FALSE" );
130 }
131 
132 /**
133  * Convert EFI allocation type to text
134  *
135  * @v type Allocation type
136  * @ret text Allocation type as text
137  */
138 static const char * efi_allocate_type ( EFI_ALLOCATE_TYPE type ) {
139  static char buf[ 11 /* "0xXXXXXXXX" + NUL */ ];
140 
141  switch ( type ) {
142  case AllocateAnyPages: return "AnyPages";
143  case AllocateMaxAddress: return "MaxAddress";
144  case AllocateAddress: return "Address";
145  default:
146  snprintf ( buf, sizeof ( buf ), "%#x", type );
147  return buf;
148  }
149 }
150 
151 /**
152  * Convert EFI memory type to text
153  *
154  * @v type Memory type
155  * @ret text Memory type as text
156  */
157 static const char * efi_memory_type ( EFI_MEMORY_TYPE type ) {
158  static char buf[ 11 /* "0xXXXXXXXX" + NUL */ ];
159 
160  switch ( type ) {
161  case EfiReservedMemoryType: return "Reserved";
162  case EfiLoaderCode: return "LoaderCode";
163  case EfiLoaderData: return "LoaderData";
164  case EfiBootServicesCode: return "BootCode";
165  case EfiBootServicesData: return "BootData";
166  case EfiRuntimeServicesCode: return "RuntimeCode";
167  case EfiRuntimeServicesData: return "RuntimeData";
168  case EfiConventionalMemory: return "Conventional";
169  case EfiUnusableMemory: return "Unusable";
170  case EfiACPIReclaimMemory: return "ACPIReclaim";
171  case EfiACPIMemoryNVS: return "ACPINVS";
172  case EfiMemoryMappedIO: return "MMIO";
173  case EfiMemoryMappedIOPortSpace:return "PIO";
174  case EfiPalCode: return "PalCode";
175  case EfiPersistentMemory: return "Persistent";
176  default:
177  snprintf ( buf, sizeof ( buf ), "%#x", type );
178  return buf;
179  }
180 }
181 
182 /**
183  * Convert EFI timer delay type to text
184  *
185  * @v type Timer delay type
186  * @ret text Timer delay type as text
187  */
188 static const char * efi_timer_delay ( EFI_TIMER_DELAY type ) {
189  static char buf[ 11 /* "0xXXXXXXXX" + NUL */ ];
190 
191  switch ( type ) {
192  case TimerCancel: return "Cancel";
193  case TimerPeriodic: return "Periodic";
194  case TimerRelative: return "Relative";
195  default:
196  snprintf ( buf, sizeof ( buf ), "%#x", type );
197  return buf;
198  }
199 }
200 
201 /**
202  * Convert EFI time to text
203  *
204  * @v time Time, or NULL
205  * @ret text Time as text
206  */
207 static const char * efi_time ( EFI_TIME *time ) {
208  static char buf[ 20 /* "xxxx-xx-xx xx:xx:xx" + NUL */ ];
209 
210  if ( ! time )
211  return "<NULL>";
212  snprintf ( buf, sizeof ( buf ), "%04d-%02d-%02d %02d:%02d:%02d",
213  time->Year, time->Month, time->Day, time->Hour,
214  time->Minute, time->Second );
215  return buf;
216 }
217 
218 /**
219  * Convert EFI reset type to text
220  *
221  * @v type Reset type
222  * @ret text Reset type as text
223  */
224 static const char * efi_reset_type ( EFI_RESET_TYPE type ) {
225  static char buf[ 11 /* "0xXXXXXXXX" + NUL */ ];
226 
227  switch ( type ) {
228  case EfiResetCold: return "Cold";
229  case EfiResetWarm: return "Warm";
230  case EfiResetShutdown: return "Shutdown";
231  case EfiResetPlatformSpecific: return "PlatformSpecific";
232  default:
233  snprintf ( buf, sizeof ( buf ), "%#x", type );
234  return buf;
235  }
236 }
237 
238 /**
239  * Pre-scroll display to create space for output lines
240  *
241  * @v lines Number of lines required
242  * @ret efirc EFI status code
243  */
244 static int efi_prescroll ( unsigned int lines ) {
246  UINTN columns;
247  UINTN rows;
248  UINTN space;
249  EFI_STATUS efirc;
250 
251  /* Get number of rows and columns */
252  if ( ( efirc = conout->QueryMode ( conout, conout->Mode->Mode,
253  &columns, &rows ) ) != 0 )
254  return efirc;
255 
256  /* Calculate available space */
257  space = ( rows - conout->Mode->CursorRow - 1 );
258 
259  /* Scroll to create space */
260  while ( space++ < lines )
261  conout->OutputString ( conout, L"\n" );
262 
263  /* Move cursor to start of space */
264  conout->SetCursorPosition ( conout, 0,
265  ( conout->Mode->CursorRow - lines ) );
266 
267  return 0;
268 }
269 
270 /**
271  * Dump information about a loaded image
272  *
273  * @v handle Image handle
274  */
277  int rc;
278 
279  /* Open loaded image protocol */
281  &loaded ) ) != 0 ) {
282  DBGC ( colour, "WRAP %s could not get loaded image protocol: "
283  "%s\n", efi_handle_name ( handle ), strerror ( rc ) );
284  return;
285  }
286 
287  /* Dump image information */
288  DBGC ( colour, "WRAP %s at base %p has protocols:\n",
289  efi_handle_name ( handle ), loaded->ImageBase );
291  DBGC ( colour, "WRAP %s parent", efi_handle_name ( handle ) );
292  DBGC ( colour, " %s\n", efi_handle_name ( loaded->ParentHandle ) );
293  DBGC ( colour, "WRAP %s device", efi_handle_name ( handle ) );
294  DBGC ( colour, " %s\n", efi_handle_name ( loaded->DeviceHandle ) );
295  DBGC ( colour, "WRAP %s file", efi_handle_name ( handle ) );
296  DBGC ( colour, " %s\n", efi_devpath_text ( loaded->FilePath ) );
297 }
298 
299 /**
300  * Wrap RaiseTPL()
301  *
302  */
303 static EFI_TPL EFIAPI
306  void *retaddr = __builtin_return_address ( 0 );
307  EFI_TPL old_tpl;
308 
309  DBGCP ( colour, "RaiseTPL ( %s ) ", efi_tpl_name ( new_tpl ) );
310  old_tpl = bs->RaiseTPL ( new_tpl );
311  DBGCP ( colour, "= %s -> %p\n", efi_tpl_name ( old_tpl ), retaddr );
312  return old_tpl;
313 }
314 
315 /**
316  * Wrap RestoreTPL()
317  *
318  */
319 static VOID EFIAPI
322  void *retaddr = __builtin_return_address ( 0 );
323 
324  DBGCP ( colour, "RestoreTPL ( %s ) ", efi_tpl_name ( old_tpl ) );
325  bs->RestoreTPL ( old_tpl );
326  DBGCP ( colour, "-> %p\n", retaddr );
327 }
328 
329 /**
330  * Wrap AllocatePages()
331  *
332  */
333 static EFI_STATUS EFIAPI
335  EFI_MEMORY_TYPE memory_type, UINTN pages,
336  EFI_PHYSICAL_ADDRESS *memory ) {
338  void *retaddr = __builtin_return_address ( 0 );
339  EFI_STATUS efirc;
340 
341  DBGC2 ( colour, "AllocatePages ( %s, %s, %#llx, %#llx ) ",
342  efi_allocate_type ( type ), efi_memory_type ( memory_type ),
343  ( ( unsigned long long ) pages ),
344  ( ( unsigned long long ) *memory ) );
345  efirc = bs->AllocatePages ( type, memory_type, pages, memory );
346  DBGC2 ( colour, "= %s ( %#llx ) -> %p\n", efi_status ( efirc ),
347  ( ( unsigned long long ) *memory ), retaddr );
348  return efirc;
349 }
350 
351 /**
352  * Wrap FreePages()
353  *
354  */
355 static EFI_STATUS EFIAPI
358  void *retaddr = __builtin_return_address ( 0 );
359  EFI_STATUS efirc;
360 
361  DBGC2 ( colour, "FreePages ( %#llx, %#llx ) ",
362  ( ( unsigned long long ) memory ),
363  ( ( unsigned long long ) pages ) );
364  efirc = bs->FreePages ( memory, pages );
365  DBGC2 ( colour, "= %s -> %p\n", efi_status ( efirc ), retaddr );
366  return efirc;
367 }
368 
369 /**
370  * Wrap GetMemoryMap()
371  *
372  */
373 static EFI_STATUS EFIAPI
375  EFI_MEMORY_DESCRIPTOR *memory_map, UINTN *map_key,
376  UINTN *descriptor_size,
377  UINT32 *descriptor_version ) {
379  void *retaddr = __builtin_return_address ( 0 );
381  size_t remaining;
382  EFI_STATUS efirc;
383 
384  DBGC ( colour, "GetMemoryMap ( %#llx, %p ) ",
385  ( ( unsigned long long ) *memory_map_size ), memory_map );
386  efirc = bs->GetMemoryMap ( memory_map_size, memory_map, map_key,
387  descriptor_size, descriptor_version );
388  DBGC ( colour, "= %s ( %#llx, %#llx, %#llx, v%d",
389  efi_status ( efirc ),
390  ( ( unsigned long long ) *memory_map_size ),
391  ( ( unsigned long long ) *map_key ),
392  ( ( unsigned long long ) *descriptor_size ),
393  *descriptor_version );
394  if ( DBG_EXTRA && ( efirc == 0 ) ) {
395  DBGC2 ( colour, ",\n" );
396  for ( desc = memory_map, remaining = *memory_map_size ;
397  remaining >= *descriptor_size ;
398  desc = ( ( ( void * ) desc ) + *descriptor_size ),
399  remaining -= *descriptor_size ) {
400  DBGC2 ( colour, "%#016llx+%#08llx %#016llx "
401  "%s\n", desc->PhysicalStart,
402  ( desc->NumberOfPages * EFI_PAGE_SIZE ),
403  desc->Attribute,
404  efi_memory_type ( desc->Type ) );
405  }
406  } else {
407  DBGC ( colour, " " );
408  }
409  DBGC ( colour, ") -> %p\n", retaddr );
410  return efirc;
411 }
412 
413 /**
414  * Wrap AllocatePool()
415  *
416  */
417 static EFI_STATUS EFIAPI
419  VOID **buffer ) {
421  void *retaddr = __builtin_return_address ( 0 );
422  EFI_STATUS efirc;
423 
424  DBGC2 ( colour, "AllocatePool ( %s, %#llx ) ",
425  efi_memory_type ( pool_type ),
426  ( ( unsigned long long ) size ) );
427  efirc = bs->AllocatePool ( pool_type, size, buffer );
428  DBGC2 ( colour, "= %s ( %p ) -> %p\n",
429  efi_status ( efirc ), *buffer, retaddr );
430  return efirc;
431 }
432 
433 /**
434  * Wrap FreePool()
435  *
436  */
437 static EFI_STATUS EFIAPI
440  void *retaddr = __builtin_return_address ( 0 );
441  EFI_STATUS efirc;
442 
443  DBGC2 ( colour, "FreePool ( %p ) ", buffer );
444  efirc = bs->FreePool ( buffer );
445  DBGC2 ( colour, "= %s -> %p\n", efi_status ( efirc ), retaddr );
446  return efirc;
447 }
448 
449 /**
450  * Wrap CreateEvent()
451  *
452  */
453 static EFI_STATUS EFIAPI
455  EFI_EVENT_NOTIFY notify_function,
456  VOID *notify_context, EFI_EVENT *event ) {
458  void *retaddr = __builtin_return_address ( 0 );
459  EFI_STATUS efirc;
460 
461  DBGC ( colour, "CreateEvent ( %#x, %s, %p, %p ) ", type,
462  efi_tpl_name ( notify_tpl ), notify_function, notify_context );
463  efirc = bs->CreateEvent ( type, notify_tpl, notify_function,
464  notify_context, event );
465  DBGC ( colour, "= %s ( %p ) -> %p\n",
466  efi_status ( efirc ), *event, retaddr );
467  return efirc;
468 }
469 
470 /**
471  * Wrap SetTimer()
472  *
473  */
474 static EFI_STATUS EFIAPI
476  UINT64 trigger_time ) {
478  void *retaddr = __builtin_return_address ( 0 );
479  EFI_STATUS efirc;
480 
481  DBGC ( colour, "SetTimer ( %p, %s, %ld.%07ld00s ) ",
482  event, efi_timer_delay ( type ),
483  ( ( unsigned long ) ( trigger_time / 10000000 ) ),
484  ( ( unsigned long ) ( trigger_time % 10000000 ) ) );
485  efirc = bs->SetTimer ( event, type, trigger_time );
486  DBGC ( colour, "= %s -> %p\n", efi_status ( efirc ), retaddr );
487  return efirc;
488 }
489 
490 /**
491  * Wrap WaitForEvent()
492  *
493  */
494 static EFI_STATUS EFIAPI
495 efi_wait_for_event_wrapper ( UINTN number_of_events, EFI_EVENT *event,
496  UINTN *index ) {
498  void *retaddr = __builtin_return_address ( 0 );
499  unsigned int i;
500  EFI_STATUS efirc;
501 
502  DBGC ( colour, "WaitForEvent (" );
503  for ( i = 0 ; i < number_of_events ; i++ )
504  DBGC ( colour, " %p", event[i] );
505  DBGC ( colour, " ) " );
506  efirc = bs->WaitForEvent ( number_of_events, event, index );
507  DBGC ( colour, "= %s", efi_status ( efirc ) );
508  if ( efirc == 0 )
509  DBGC ( colour, " ( %p )", event[*index] );
510  DBGC ( colour, " -> %p\n", retaddr );
511  return efirc;
512 }
513 
514 /**
515  * Wrap SignalEvent()
516  *
517  */
518 static EFI_STATUS EFIAPI
521  void *retaddr = __builtin_return_address ( 0 );
522  EFI_STATUS efirc;
523 
524  DBGC2 ( colour, "SignalEvent ( %p ) ", event );
525  efirc = bs->SignalEvent ( event );
526  DBGC2 ( colour, "= %s -> %p\n", efi_status ( efirc ), retaddr );
527  return efirc;
528 }
529 
530 /**
531  * Wrap CloseEvent()
532  *
533  */
534 static EFI_STATUS EFIAPI
537  void *retaddr = __builtin_return_address ( 0 );
538  EFI_STATUS efirc;
539 
540  DBGC ( colour, "CloseEvent ( %p ) ", event );
541  efirc = bs->CloseEvent ( event );
542  DBGC ( colour, "= %s -> %p\n", efi_status ( efirc ), retaddr );
543  return efirc;
544 }
545 /**
546  * Wrap CheckEvent()
547  *
548  */
549 static EFI_STATUS EFIAPI
552  void *retaddr = __builtin_return_address ( 0 );
553  EFI_STATUS efirc;
554 
555  DBGCP ( colour, "CheckEvent ( %p ) ", event );
556  efirc = bs->CheckEvent ( event );
557  DBGCP ( colour, "= %s -> %p\n", efi_status ( efirc ), retaddr );
558  return efirc;
559 }
560 
561 /**
562  * Wrap InstallProtocolInterface()
563  *
564  */
565 static EFI_STATUS EFIAPI
568  VOID *interface ) {
570  void *retaddr = __builtin_return_address ( 0 );
571  EFI_STATUS efirc;
572 
573  DBGC ( colour, "InstallProtocolInterface ( %s, %s, %d, %p ) ",
577  interface );
578  DBGC ( colour, "= %s ( %s ) -> %p\n",
579  efi_status ( efirc ), efi_handle_name ( *handle ), retaddr );
580  return efirc;
581 }
582 
583 /**
584  * Wrap ReinstallProtocolInterface()
585  *
586  */
587 static EFI_STATUS EFIAPI
590  VOID *old_interface,
591  VOID *new_interface ) {
593  void *retaddr = __builtin_return_address ( 0 );
594  EFI_STATUS efirc;
595 
596  DBGC ( colour, "ReinstallProtocolInterface ( %s, %s, %p, %p ) ",
598  old_interface, new_interface );
600  old_interface, new_interface );
601  DBGC ( colour, "= %s -> %p\n", efi_status ( efirc ), retaddr );
602  return efirc;
603 }
604 
605 /**
606  * Wrap UninstallProtocolInterface()
607  *
608  */
609 static EFI_STATUS EFIAPI
612  VOID *interface ) {
614  void *retaddr = __builtin_return_address ( 0 );
615  EFI_STATUS efirc;
616 
617  DBGC ( colour, "UninstallProtocolInterface ( %s, %s, %p ) ",
619  interface );
621  DBGC ( colour, "= %s -> %p\n", efi_status ( efirc ), retaddr );
622  return efirc;
623 }
624 
625 /**
626  * Wrap HandleProtocol()
627  *
628  */
629 static EFI_STATUS EFIAPI
631  VOID **interface ) {
633  void *retaddr = __builtin_return_address ( 0 );
634  EFI_STATUS efirc;
635 
636  DBGC ( colour, "HandleProtocol ( %s, %s ) ",
638  efirc = bs->HandleProtocol ( handle, protocol, interface );
639  DBGC ( colour, "= %s ( %p ) -> %p\n",
640  efi_status ( efirc ), *interface, retaddr );
641  return efirc;
642 }
643 
644 /**
645  * Wrap RegisterProtocolNotify()
646  *
647  */
648 static EFI_STATUS EFIAPI
650  VOID **registration ) {
652  void *retaddr = __builtin_return_address ( 0 );
653  EFI_STATUS efirc;
654 
655  DBGC ( colour, "RegisterProtocolNotify ( %s, %p ) ",
656  efi_guid_ntoa ( protocol ), event );
657  efirc = bs->RegisterProtocolNotify ( protocol, event, registration );
658  DBGC ( colour, "= %s ( %p ) -> %p\n",
659  efi_status ( efirc ), *registration, retaddr );
660  return efirc;
661 }
662 
663 /**
664  * Wrap LocateHandle()
665  *
666  */
667 static EFI_STATUS EFIAPI
669  EFI_GUID *protocol, VOID *search_key,
672  void *retaddr = __builtin_return_address ( 0 );
673  unsigned int i;
674  EFI_STATUS efirc;
675 
676  DBGC ( colour, "LocateHandle ( %s, %s, %p, %zd ) ",
677  efi_locate_search_type_name ( search_type ),
678  efi_guid_ntoa ( protocol ), search_key,
679  ( ( size_t ) *buffer_size ) );
680  efirc = bs->LocateHandle ( search_type, protocol, search_key,
681  buffer_size, buffer );
682  DBGC ( colour, "= %s ( %zd", efi_status ( efirc ),
683  ( ( size_t ) *buffer_size ) );
684  if ( efirc == 0 ) {
685  DBGC ( colour, ", {" );
686  for ( i = 0; i < ( *buffer_size / sizeof ( buffer[0] ) ); i++ ){
687  DBGC ( colour, "%s%s", ( i ? ", " : " " ),
688  efi_handle_name ( buffer[i] ) );
689  }
690  DBGC ( colour, " }" );
691  }
692  DBGC ( colour, " ) -> %p\n", retaddr );
693  return efirc;
694 }
695 
696 /**
697  * Wrap LocateDevicePath()
698  *
699  */
700 static EFI_STATUS EFIAPI
703  EFI_HANDLE *device ) {
705  void *retaddr = __builtin_return_address ( 0 );
706  EFI_STATUS efirc;
707 
708  DBGC ( colour, "LocateDevicePath ( %s, %s ) ",
710  efirc = bs->LocateDevicePath ( protocol, device_path, device );
711  DBGC ( colour, "= %s ( %s, ",
712  efi_status ( efirc ), efi_devpath_text ( *device_path ) );
713  DBGC ( colour, "%s ) -> %p\n", efi_handle_name ( *device ), retaddr );
714  return efirc;
715 }
716 
717 /**
718  * Wrap InstallConfigurationTable()
719  *
720  */
721 static EFI_STATUS EFIAPI
724  void *retaddr = __builtin_return_address ( 0 );
725  EFI_STATUS efirc;
726 
727  DBGC ( colour, "InstallConfigurationTable ( %s, %p ) ",
728  efi_guid_ntoa ( guid ), table );
729  efirc = bs->InstallConfigurationTable ( guid, table );
730  DBGC ( colour, "= %s -> %p\n", efi_status ( efirc ), retaddr );
731  return efirc;
732 }
733 
734 /**
735  * Wrap LoadImage()
736  *
737  */
738 static EFI_STATUS EFIAPI
739 efi_load_image_wrapper ( BOOLEAN boot_policy, EFI_HANDLE parent_image_handle,
741  VOID *source_buffer, UINTN source_size,
742  EFI_HANDLE *image_handle ) {
744  void *retaddr = __builtin_return_address ( 0 );
745  EFI_STATUS efirc;
746 
747  DBGC ( colour, "LoadImage ( %s, %s, ", efi_boolean ( boot_policy ),
748  efi_handle_name ( parent_image_handle ) );
749  DBGC ( colour, "%s, %p, %#llx ) ",
750  efi_devpath_text ( device_path ), source_buffer,
751  ( ( unsigned long long ) source_size ) );
752  efirc = bs->LoadImage ( boot_policy, parent_image_handle, device_path,
753  source_buffer, source_size, image_handle );
754  DBGC ( colour, "= %s ( ", efi_status ( efirc ) );
755  if ( efirc == 0 )
756  DBGC ( colour, "%s ", efi_handle_name ( *image_handle ) );
757  DBGC ( colour, ") -> %p\n", retaddr );
758 
759  /* Dump information about loaded image */
760  if ( efirc == 0 )
761  efi_dump_image ( *image_handle );
762 
763  return efirc;
764 }
765 
766 /**
767  * Wrap StartImage()
768  *
769  */
770 static EFI_STATUS EFIAPI
771 efi_start_image_wrapper ( EFI_HANDLE image_handle, UINTN *exit_data_size,
772  CHAR16 **exit_data ) {
774  void *retaddr = __builtin_return_address ( 0 );
775  EFI_STATUS efirc;
776 
777  DBGC ( colour, "StartImage ( %s ) ", efi_handle_name ( image_handle ) );
778  efirc = bs->StartImage ( image_handle, exit_data_size, exit_data );
779  DBGC ( colour, "= %s", efi_status ( efirc ) );
780  if ( ( efirc != 0 ) && exit_data && *exit_data_size )
781  DBGC ( colour, " ( \"%ls\" )", *exit_data );
782  DBGC ( colour, " -> %p\n", retaddr );
783  if ( ( efirc != 0 ) && exit_data && *exit_data_size )
784  DBGC_HD ( colour, *exit_data, *exit_data_size );
785  return efirc;
786 }
787 
788 /**
789  * Wrap Exit()
790  *
791  */
792 static EFI_STATUS EFIAPI
793 efi_exit_wrapper ( EFI_HANDLE image_handle, EFI_STATUS exit_status,
794  UINTN exit_data_size, CHAR16 *exit_data ) {
796  void *retaddr = __builtin_return_address ( 0 );
797  EFI_STATUS efirc;
798 
799  if ( ( exit_status != 0 ) && exit_data && exit_data_size )
800  DBGC_HD ( colour, exit_data, exit_data_size );
801  DBGC ( colour, "Exit ( %s, %s",
802  efi_handle_name ( image_handle ), efi_status ( exit_status ) );
803  if ( ( exit_status != 0 ) && exit_data && exit_data_size )
804  DBGC ( colour, ", \"%ls\"", exit_data );
805  DBGC ( colour, " ) " );
806  efirc = bs->Exit ( image_handle, exit_status, exit_data_size,
807  exit_data );
808  DBGC ( colour, "= %s -> %p\n", efi_status ( efirc ), retaddr );
809  return efirc;
810 }
811 
812 /**
813  * Wrap UnloadImage()
814  *
815  */
816 static EFI_STATUS EFIAPI
819  void *retaddr = __builtin_return_address ( 0 );
820  EFI_STATUS efirc;
821 
822  DBGC ( colour, "UnloadImage ( %s ) ",
823  efi_handle_name ( image_handle ) );
824  efirc = bs->UnloadImage ( image_handle );
825  DBGC ( colour, "= %s -> %p\n", efi_status ( efirc ), retaddr );
826  return efirc;
827 }
828 
829 /**
830  * Wrap ExitBootServices()
831  *
832  */
833 static EFI_STATUS EFIAPI
836  void *retaddr = __builtin_return_address ( 0 );
837  EFI_STATUS efirc;
838 
839  DBGC ( colour, "ExitBootServices ( %s, %#llx ) -> %p\n",
840  efi_handle_name ( image_handle ),
841  ( ( unsigned long long ) map_key ), retaddr );
842  efirc = bs->ExitBootServices ( image_handle, map_key );
843  if ( efirc != 0 ) {
844  DBGC ( colour, "ExitBootServices ( ... ) = %s -> %p\n",
845  efi_status ( efirc ), retaddr );
846  /* On some systems, scrolling the output will cause
847  * the system memory map to change (and so cause
848  * ExitBootServices() to fail).
849  *
850  * After the first failed attempt, prescroll the
851  * screen to maximise the chance of the subsequent
852  * attempt succeeding.
853  */
855  }
856  return efirc;
857 }
858 
859 /**
860  * Wrap GetNextMonotonicCount()
861  *
862  */
863 static EFI_STATUS EFIAPI
866  void *retaddr = __builtin_return_address ( 0 );
867  EFI_STATUS efirc;
868 
869  DBGCP ( colour, "GetNextMonotonicCount() " );
870  efirc = bs->GetNextMonotonicCount ( count );
871  DBGCP ( colour, "= %s ( %#llx ) -> %p\n",
872  efi_status ( efirc ), *count, retaddr );
873  return efirc;
874 }
875 
876 /**
877  * Wrap Stall()
878  *
879  */
880 static EFI_STATUS EFIAPI
881 efi_stall_wrapper ( UINTN microseconds ) {
883  void *retaddr = __builtin_return_address ( 0 );
884  EFI_STATUS efirc;
885 
886  DBGCP ( colour, "Stall ( %ld.%06lds ) ",
887  ( ( unsigned long ) ( microseconds / 1000000 ) ),
888  ( ( unsigned long ) ( microseconds % 1000000 ) ) );
889  efirc = bs->Stall ( microseconds );
890  DBGCP ( colour, "= %s -> %p\n", efi_status ( efirc ), retaddr );
891  return efirc;
892 }
893 
894 /**
895  * Wrap SetWatchdogTimer()
896  *
897  */
898 static EFI_STATUS EFIAPI
900  UINTN data_size, CHAR16 *watchdog_data ) {
902  void *retaddr = __builtin_return_address ( 0 );
903  EFI_STATUS efirc;
904 
905  DBGC ( colour, "SetWatchdogTimer ( %lds, %#llx, %#llx, %p ) ",
906  ( ( unsigned long ) timeout ), watchdog_code,
907  ( ( unsigned long long ) data_size ), watchdog_data );
908  efirc = bs->SetWatchdogTimer ( timeout, watchdog_code, data_size,
909  watchdog_data );
910  DBGC ( colour, "= %s -> %p\n", efi_status ( efirc ), retaddr );
911  return efirc;
912 }
913 
914 /**
915  * Wrap ConnectController()
916  *
917  */
918 static EFI_STATUS EFIAPI
920  EFI_HANDLE *driver_image_handle,
921  EFI_DEVICE_PATH_PROTOCOL *remaining_path,
922  BOOLEAN recursive ) {
924  void *retaddr = __builtin_return_address ( 0 );
925  EFI_HANDLE *tmp;
926  EFI_STATUS efirc;
927 
928  DBGC ( colour, "ConnectController ( %s, {",
929  efi_handle_name ( controller_handle ) );
930  if ( driver_image_handle ) {
931  for ( tmp = driver_image_handle ; *tmp ; tmp++ ) {
932  DBGC ( colour, "%s%s",
933  ( ( tmp == driver_image_handle ) ? " " : ", " ),
934  efi_handle_name ( *tmp ) );
935  }
936  }
937  DBGC ( colour, " }, %s, %s ) ", efi_devpath_text ( remaining_path ),
938  efi_boolean ( recursive ) );
939  efirc = bs->ConnectController ( controller_handle, driver_image_handle,
940  remaining_path, recursive );
941  DBGC ( colour, "= %s -> %p\n", efi_status ( efirc ), retaddr );
942  return efirc;
943 }
944 
945 /**
946  * Wrap DisconnectController()
947  *
948  */
949 static EFI_STATUS EFIAPI
951  EFI_HANDLE driver_image_handle,
952  EFI_HANDLE child_handle ) {
954  void *retaddr = __builtin_return_address ( 0 );
955  EFI_STATUS efirc;
956 
957  DBGC ( colour, "DisconnectController ( %s",
958  efi_handle_name ( controller_handle ) );
959  DBGC ( colour, ", %s", efi_handle_name ( driver_image_handle ) );
960  DBGC ( colour, ", %s ) ", efi_handle_name ( child_handle ) );
961  efirc = bs->DisconnectController ( controller_handle,
962  driver_image_handle,
963  child_handle );
964  DBGC ( colour, "= %s -> %p\n", efi_status ( efirc ), retaddr );
965  return efirc;
966 }
967 
968 /**
969  * Wrap OpenProtocol()
970  *
971  */
972 static EFI_STATUS EFIAPI
974  VOID **interface, EFI_HANDLE agent_handle,
975  EFI_HANDLE controller_handle, UINT32 attributes ) {
977  void *retaddr = __builtin_return_address ( 0 );
978  EFI_STATUS efirc;
979 
980  DBGC ( colour, "OpenProtocol ( %s, %s, ",
982  DBGC ( colour, "%s, ", efi_handle_name ( agent_handle ) );
983  DBGC ( colour, "%s, %s ) ", efi_handle_name ( controller_handle ),
984  efi_open_attributes_name ( attributes ) );
985  efirc = bs->OpenProtocol ( handle, protocol, interface, agent_handle,
986  controller_handle, attributes );
987  DBGC ( colour, "= %s ( %p ) -> %p\n",
988  efi_status ( efirc ), *interface, retaddr );
989  return efirc;
990 }
991 
992 /**
993  * Wrap CloseProtocol()
994  *
995  */
996 static EFI_STATUS EFIAPI
998  EFI_HANDLE agent_handle,
999  EFI_HANDLE controller_handle ) {
1001  void *retaddr = __builtin_return_address ( 0 );
1002  EFI_STATUS efirc;
1003 
1004  DBGC ( colour, "CloseProtocol ( %s, %s, ",
1006  DBGC ( colour, "%s, ", efi_handle_name ( agent_handle ) );
1007  DBGC ( colour, "%s ) ", efi_handle_name ( controller_handle ) );
1008  efirc = bs->CloseProtocol ( handle, protocol, agent_handle,
1009  controller_handle );
1010  DBGC ( colour, "= %s -> %p\n",
1011  efi_status ( efirc ), retaddr );
1012  return efirc;
1013 }
1014 
1015 /**
1016  * Wrap OpenProtocolInformation()
1017  *
1018  */
1019 static EFI_STATUS EFIAPI
1022  **entry_buffer,
1023  UINTN *entry_count ) {
1025  void *retaddr = __builtin_return_address ( 0 );
1026  EFI_STATUS efirc;
1027 
1028  DBGC ( colour, "OpenProtocolInformation ( %s, %s ) ",
1030  efirc = bs->OpenProtocolInformation ( handle, protocol, entry_buffer,
1031  entry_count );
1032  DBGC ( colour, "= %s ( %p, %#llx ) -> %p\n",
1033  efi_status ( efirc ), *entry_buffer,
1034  ( ( unsigned long long ) *entry_count ), retaddr );
1035  return efirc;
1036 }
1037 
1038 /**
1039  * Wrap ProtocolsPerHandle()
1040  *
1041  */
1042 static EFI_STATUS EFIAPI
1044  EFI_GUID ***protocol_buffer,
1045  UINTN *protocol_buffer_count ) {
1047  void *retaddr = __builtin_return_address ( 0 );
1048  unsigned int i;
1049  EFI_STATUS efirc;
1050 
1051  DBGC ( colour, "ProtocolsPerHandle ( %s ) ",
1052  efi_handle_name ( handle ) );
1053  efirc = bs->ProtocolsPerHandle ( handle, protocol_buffer,
1054  protocol_buffer_count );
1055  DBGC ( colour, "= %s", efi_status ( efirc ) );
1056  if ( efirc == 0 ) {
1057  DBGC ( colour, " ( {" );
1058  for ( i = 0 ; i < *protocol_buffer_count ; i++ ) {
1059  DBGC ( colour, "%s%s", ( i ? ", " : " " ),
1060  efi_guid_ntoa ( (*protocol_buffer)[i] ) );
1061  }
1062  DBGC ( colour, " } )" );
1063  }
1064  DBGC ( colour, " -> %p\n", retaddr );
1065  return efirc;
1066 }
1067 
1068 /**
1069  * Wrap LocateHandleBuffer()
1070  *
1071  */
1072 static EFI_STATUS EFIAPI
1074  EFI_GUID *protocol, VOID *search_key,
1075  UINTN *no_handles, EFI_HANDLE **buffer ) {
1077  void *retaddr = __builtin_return_address ( 0 );
1078  unsigned int i;
1079  EFI_STATUS efirc;
1080 
1081  DBGC ( colour, "LocateHandleBuffer ( %s, %s, %p ) ",
1082  efi_locate_search_type_name ( search_type ),
1083  efi_guid_ntoa ( protocol ), search_key );
1084  efirc = bs->LocateHandleBuffer ( search_type, protocol, search_key,
1085  no_handles, buffer );
1086  DBGC ( colour, "= %s", efi_status ( efirc ) );
1087  if ( efirc == 0 ) {
1088  DBGC ( colour, " ( %d, {", ( ( unsigned int ) *no_handles ) );
1089  for ( i = 0 ; i < *no_handles ; i++ ) {
1090  DBGC ( colour, "%s%s", ( i ? ", " : " " ),
1091  efi_handle_name ( (*buffer)[i] ) );
1092  }
1093  DBGC ( colour, " } )" );
1094  }
1095  DBGC ( colour, " -> %p\n", retaddr );
1096  return efirc;
1097 }
1098 
1099 /**
1100  * Wrap LocateProtocol()
1101  *
1102  */
1103 static EFI_STATUS EFIAPI
1105  VOID **interface ) {
1107  void *retaddr = __builtin_return_address ( 0 );
1108  EFI_STATUS efirc;
1109 
1110  DBGC ( colour, "LocateProtocol ( %s, %p ) ",
1111  efi_guid_ntoa ( protocol ), registration );
1112  efirc = bs->LocateProtocol ( protocol, registration, interface );
1113  DBGC ( colour, "= %s ( %p ) -> %p\n",
1114  efi_status ( efirc ), *interface, retaddr );
1115  return efirc;
1116 }
1117 
1118 /** Maximum number of interfaces for wrapped ...MultipleProtocolInterfaces() */
1119 #define MAX_WRAP_MULTI 20
1120 
1121 /**
1122  * Wrap InstallMultipleProtocolInterfaces()
1123  *
1124  */
1125 static EFI_STATUS EFIAPI
1128  void *retaddr = __builtin_return_address ( 0 );
1131  VA_LIST ap;
1132  unsigned int i;
1133  EFI_STATUS efirc;
1134 
1135  DBGC ( colour, "InstallMultipleProtocolInterfaces ( %s",
1136  efi_handle_name ( *handle ) );
1137  memset ( protocol, 0, sizeof ( protocol ) );
1138  memset ( interface, 0, sizeof ( interface ) );
1139  VA_START ( ap, handle );
1140  for ( i = 0 ; ( protocol[i] = VA_ARG ( ap, EFI_GUID * ) ) ; i++ ) {
1141  if ( i == MAX_WRAP_MULTI ) {
1142  VA_END ( ap );
1143  efirc = EFI_OUT_OF_RESOURCES;
1144  DBGC ( colour, "<FATAL: too many arguments> ) = %s "
1145  "-> %p\n", efi_status ( efirc ), retaddr );
1146  return efirc;
1147  }
1148  interface[i] = VA_ARG ( ap, VOID * );
1149  DBGC ( colour, ", %s, %p",
1150  efi_guid_ntoa ( protocol[i] ), interface[i] );
1151  }
1152  VA_END ( ap );
1153  DBGC ( colour, " ) " );
1155  protocol[0], interface[0], protocol[1], interface[1],
1156  protocol[2], interface[2], protocol[3], interface[3],
1157  protocol[4], interface[4], protocol[5], interface[5],
1158  protocol[6], interface[6], protocol[7], interface[7],
1159  protocol[8], interface[8], protocol[9], interface[9],
1160  protocol[10], interface[10], protocol[11], interface[11],
1161  protocol[12], interface[12], protocol[13], interface[13],
1162  protocol[14], interface[14], protocol[15], interface[15],
1163  protocol[16], interface[16], protocol[17], interface[17],
1164  protocol[18], interface[18], protocol[19], interface[19],
1165  NULL );
1166  DBGC ( colour, "= %s ( %s ) -> %p\n",
1167  efi_status ( efirc ), efi_handle_name ( *handle ), retaddr );
1168  return efirc;
1169 }
1170 
1171 /**
1172  * Wrap UninstallMultipleProtocolInterfaces()
1173  *
1174  */
1175 static EFI_STATUS EFIAPI
1178  void *retaddr = __builtin_return_address ( 0 );
1181  VA_LIST ap;
1182  unsigned int i;
1183  EFI_STATUS efirc;
1184 
1185  DBGC ( colour, "UninstallMultipleProtocolInterfaces ( %s",
1186  efi_handle_name ( handle ) );
1187  memset ( protocol, 0, sizeof ( protocol ) );
1188  memset ( interface, 0, sizeof ( interface ) );
1189  VA_START ( ap, handle );
1190  for ( i = 0 ; ( protocol[i] = VA_ARG ( ap, EFI_GUID * ) ) ; i++ ) {
1191  if ( i == MAX_WRAP_MULTI ) {
1192  VA_END ( ap );
1193  efirc = EFI_OUT_OF_RESOURCES;
1194  DBGC ( colour, "<FATAL: too many arguments> ) = %s "
1195  "-> %p\n", efi_status ( efirc ), retaddr );
1196  return efirc;
1197  }
1198  interface[i] = VA_ARG ( ap, VOID * );
1199  DBGC ( colour, ", %s, %p",
1200  efi_guid_ntoa ( protocol[i] ), interface[i] );
1201  }
1202  VA_END ( ap );
1203  DBGC ( colour, " ) " );
1205  protocol[0], interface[0], protocol[1], interface[1],
1206  protocol[2], interface[2], protocol[3], interface[3],
1207  protocol[4], interface[4], protocol[5], interface[5],
1208  protocol[6], interface[6], protocol[7], interface[7],
1209  protocol[8], interface[8], protocol[9], interface[9],
1210  protocol[10], interface[10], protocol[11], interface[11],
1211  protocol[12], interface[12], protocol[13], interface[13],
1212  protocol[14], interface[14], protocol[15], interface[15],
1213  protocol[16], interface[16], protocol[17], interface[17],
1214  protocol[18], interface[18], protocol[19], interface[19],
1215  NULL );
1216  DBGC ( colour, "= %s -> %p\n",
1217  efi_status ( efirc ), retaddr );
1218  return efirc;
1219 }
1220 
1221 /**
1222  * Wrap CreateEventEx()
1223  *
1224  */
1225 static EFI_STATUS EFIAPI
1227  EFI_EVENT_NOTIFY notify_function,
1228  CONST VOID *notify_context,
1229  CONST EFI_GUID *event_group, EFI_EVENT *event ) {
1231  void *retaddr = __builtin_return_address ( 0 );
1232  EFI_STATUS efirc;
1233 
1234  DBGC ( colour, "CreateEventEx ( %#x, %s, %p, %p, %s ) ",
1235  type, efi_tpl_name ( notify_tpl ), notify_function,
1236  notify_context, efi_guid_ntoa ( event_group ) );
1237  efirc = bs->CreateEventEx ( type, notify_tpl, notify_function,
1238  notify_context, event_group, event );
1239  DBGC ( colour, "= %s ( %p ) -> %p\n",
1240  efi_status ( efirc ), *event, retaddr );
1241  return efirc;
1242 }
1243 
1244 /**
1245  * Wrap GetTime()
1246  *
1247  */
1248 static EFI_STATUS EFIAPI
1251  void *retaddr = __builtin_return_address ( 0 );
1252  EFI_STATUS efirc;
1253 
1254  DBGCP ( colour, "GetTime() " );
1255  efirc = rs->GetTime ( time, cap );
1256  DBGCP ( colour, "= %s ( %s ) -> %p\n",
1257  efi_status ( efirc ), efi_time ( time ), retaddr );
1258  return efirc;
1259 }
1260 
1261 /**
1262  * Wrap SetTime()
1263  *
1264  */
1265 static EFI_STATUS EFIAPI
1268  void *retaddr = __builtin_return_address ( 0 );
1269  EFI_STATUS efirc;
1270 
1271  DBGC ( colour, "SetTime ( %s ) ", efi_time ( time ) );
1272  efirc = rs->SetTime ( time );
1273  DBGC ( colour, "= %s -> %p\n", efi_status ( efirc ), retaddr );
1274  return efirc;
1275 }
1276 
1277 /**
1278  * Wrap GetWakeupTime()
1279  *
1280  */
1281 static EFI_STATUS EFIAPI
1283  EFI_TIME *time ) {
1285  void *retaddr = __builtin_return_address ( 0 );
1286  EFI_STATUS efirc;
1287 
1288  DBGC ( colour, "GetWakeupTime() " );
1289  efirc = rs->GetWakeupTime ( enabled, pending, time );
1290  DBGC ( colour, "= %s ( %s, %s, %s ) -> %p\n", efi_status ( efirc ),
1292  efi_time ( time ), retaddr );
1293  return efirc;
1294 }
1295 
1296 /**
1297  * Wrap SetWakeupTime()
1298  *
1299  */
1300 static EFI_STATUS EFIAPI
1303  void *retaddr = __builtin_return_address ( 0 );
1304  EFI_STATUS efirc;
1305 
1306  DBGC ( colour, "SetWakeupTime ( %s, %s ) ",
1307  efi_boolean ( enable ), efi_time ( time ) );
1308  efirc = rs->SetWakeupTime ( enable, time );
1309  DBGC ( colour, "= %s -> %p\n", efi_status ( efirc ), retaddr );
1310  return efirc;
1311 }
1312 
1313 /**
1314  * Wrap GetVariable()
1315  *
1316  */
1317 static EFI_STATUS EFIAPI
1319  UINTN *len, VOID *data ) {
1321  void *retaddr = __builtin_return_address ( 0 );
1322  size_t dumplen;
1323  EFI_STATUS efirc;
1324 
1325  DBGC ( colour, "GetVariable ( %s:%ls, %#llx ) ",
1326  efi_guid_ntoa ( guid ), name, ( ( unsigned long long ) *len ) );
1327  efirc = rs->GetVariable ( name, guid, attrs, len, data );
1328  DBGC ( colour, "= %s ( %#llx",
1329  efi_status ( efirc ), ( ( unsigned long long ) *len ) );
1330  if ( DBG_EXTRA && ( efirc == 0 ) ) {
1331  dumplen = *len;
1332  if ( dumplen > EFI_WRAP_DUMP_MAX )
1333  dumplen = EFI_WRAP_DUMP_MAX;
1334  DBGC2 ( colour, ",\n" );
1335  DBGC2_HD ( colour, data, dumplen );
1336  if ( dumplen != *len )
1337  DBGC2 ( colour, "... " );
1338  } else {
1339  DBGC ( colour, " " );
1340  }
1341  DBGC ( colour, ") -> %p\n", retaddr );
1342  return efirc;
1343 }
1344 
1345 /**
1346  * Wrap GetNextVariableName()
1347  *
1348  */
1349 static EFI_STATUS EFIAPI
1351  EFI_GUID *guid ) {
1353  void *retaddr = __builtin_return_address ( 0 );
1354  EFI_STATUS efirc;
1355 
1356  DBGC ( colour, "GetNextVariableName ( %#llx, %s:%ls ) ",
1357  ( ( unsigned long long ) *len ), efi_guid_ntoa ( guid ), name );
1358  efirc = rs->GetNextVariableName ( len, name, guid );
1359  DBGC ( colour, "= %s ( %#llx, %s:%ls ) -> %p\n", efi_status ( efirc ),
1360  ( ( unsigned long long ) *len ), efi_guid_ntoa ( guid ), name,
1361  retaddr );
1362  return efirc;
1363 }
1364 
1365 /**
1366  * Wrap SetVariable()
1367  *
1368  */
1369 static EFI_STATUS EFIAPI
1371  UINTN len, VOID *data ) {
1373  void *retaddr = __builtin_return_address ( 0 );
1374  EFI_STATUS efirc;
1375 
1376  DBGC ( colour, "SetVariable ( %s:%ls, %#02x",
1377  efi_guid_ntoa ( guid ), name, attrs );
1378  if ( len ) {
1379  DBGC ( colour, ",\n" );
1380  DBGC_HD ( colour, data, len );
1381  DBGC ( colour, ") " );
1382  } else {
1383  DBGC ( colour, ", %#llx, %p ) ",
1384  ( ( unsigned long long ) len ), data );
1385  }
1386  efirc = rs->SetVariable ( name, guid, attrs, len, data );
1387  DBGC ( colour, "= %s -> %p\n", efi_status ( efirc ), retaddr );
1388  return efirc;
1389 }
1390 
1391 /**
1392  * Wrap ResetSystem()
1393  *
1394  */
1395 static VOID EFIAPI
1397  UINTN len, VOID *data ) {
1399  void *retaddr = __builtin_return_address ( 0 );
1400 
1401  DBGC ( colour, "ResetSystem ( %s, %s, %#llx, %p ) -> %p\n",
1403  ( ( unsigned long long ) len ), data, retaddr );
1404  rs->ResetSystem ( type, status, len, data );
1405 }
1406 
1407 /**
1408  * Wrap a boot services table
1409  *
1410  * @v wrapper Boot services table to wrap
1411  */
1412 void efi_wrap_bs ( EFI_BOOT_SERVICES *wrapper ) {
1414 
1415  /* Do nothing unless debugging is enabled */
1416  if ( ! DBG_LOG )
1417  return;
1418 
1419  /* Build boot services table wrapper */
1420  memcpy ( wrapper, bs, sizeof ( *wrapper ) );
1421  wrapper->RaiseTPL = efi_raise_tpl_wrapper;
1424  wrapper->FreePages = efi_free_pages_wrapper;
1427  wrapper->FreePool = efi_free_pool_wrapper;
1429  wrapper->SetTimer = efi_set_timer_wrapper;
1434  wrapper->InstallProtocolInterface
1444  wrapper->InstallConfigurationTable
1446  wrapper->LoadImage = efi_load_image_wrapper;
1448  wrapper->Exit = efi_exit_wrapper;
1452  wrapper->Stall = efi_stall_wrapper;
1458  wrapper->OpenProtocolInformation
1468 }
1469 
1470 /**
1471  * Wrap a runtime services table
1472  *
1473  * @v wrapper Runtime services table to wrap
1474  */
1477 
1478  /* Do nothing unless debugging is enabled */
1479  if ( ! DBG_LOG )
1480  return;
1481 
1482  /* Build boot services table wrapper */
1483  memcpy ( wrapper, rs, sizeof ( *wrapper ) );
1484  wrapper->GetTime = efi_get_time_wrapper;
1485  wrapper->SetTime = efi_set_time_wrapper;
1492 }
1493 
1494 /**
1495  * Wrap the public EFI system table
1496  *
1497  * @v global Patch global boot services table in-place
1498  */
1499 void efi_wrap_systab ( int global ) {
1500  static EFI_BOOT_SERVICES local_bs;
1501  static EFI_RUNTIME_SERVICES local_rs;
1502  EFI_BOOT_SERVICES *bs;
1504 
1505  /* Do nothing unless debugging is enabled */
1506  if ( ! DBG_LOG )
1507  return;
1508 
1509  /* Preserve original system and boot services tables */
1510  if ( ! efi_systab_pub ) {
1514  memcpy ( &efi_bs_copy, efi_bs_orig, sizeof ( efi_bs_copy ) );
1515  memcpy ( &efi_rs_copy, efi_rs_orig, sizeof ( efi_rs_copy ) );
1516  }
1517 
1518  /* Construct and use private system table */
1519  if ( efi_systab != &efi_systab_priv ) {
1521  sizeof ( efi_systab_priv ) );
1525  }
1526 
1527  /* Wrap global or local boot services table as applicable */
1528  bs = ( global ? efi_bs_orig : &local_bs );
1529  rs = ( global ? efi_rs_orig : &local_rs );
1530  efi_wrap_bs ( bs );
1531  efi_wrap_rs ( rs );
1534  DBGC ( colour, "WRAP installed %s wrappers\n",
1535  ( global ? "global" : "local" ) );
1536 }
1537 
1538 /**
1539  * Remove boot services table wrapper
1540  *
1541  */
1542 void efi_unwrap ( void ) {
1543 
1544  /* Do nothing unless debugging is enabled */
1545  if ( ! DBG_LOG )
1546  return;
1547 
1548  /* Do nothing if wrapping was never enabled */
1549  if ( ! efi_systab_pub )
1550  return;
1551 
1552  /* Restore original system and boot services tables */
1553  memcpy ( efi_bs_orig, &efi_bs_copy, sizeof ( *efi_bs_orig ) );
1555 
1556  /* Switch back to using public system table */
1558  DBGC ( colour, "WRAP uninstalled wrappers\n" );
1559 }
1560 
1561 /**
1562  * Wrap calls made by a newly loaded image
1563  *
1564  * @v handle Image handle
1565  */
1567 
1568  /* Do nothing unless debugging is enabled */
1569  if ( ! DBG_LOG )
1570  return;
1571 
1572  /* Dump image information */
1573  efi_dump_image ( handle );
1574 
1575  /* Patch public system table */
1576  efi_wrap_systab ( 0 );
1577 }
static EFI_STATUS EFIAPI efi_set_wakeup_time_wrapper(BOOLEAN enable, EFI_TIME *time)
Wrap SetWakeupTime()
Definition: efi_wrap.c:1301
union edd_device_path device_path
Device path.
Definition: edd.h:24
void efi_wrap_bs(EFI_BOOT_SERVICES *wrapper)
Wrap a boot services table.
Definition: efi_wrap.c:1412
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
static const char * efi_boolean(BOOLEAN boolean)
Convert EFI boolean to text.
Definition: efi_wrap.c:127
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2098
#define EFI_PAGE_SIZE
Definition: UefiBaseType.h:187
#define EFI_UNSUPPORTED
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:117
#define EFI_VOLUME_CORRUPTED
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:124
static EFI_BOOT_SERVICES efi_bs_copy
Backup of original EFI boot services table.
Definition: efi_wrap.c:59
static EFI_STATUS EFIAPI efi_set_timer_wrapper(EFI_EVENT event, EFI_TIMER_DELAY type, UINT64 trigger_time)
Wrap SetTimer()
Definition: efi_wrap.c:475
static VOID EFIAPI efi_restore_tpl_wrapper(EFI_TPL old_tpl)
Wrap RestoreTPL()
Definition: efi_wrap.c:320
EFI_SET_TIME SetTime
Definition: UefiSpec.h:1889
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Definition: ath9k_hw.c:1984
EFI_SET_WATCHDOG_TIMER SetWatchdogTimer
Definition: UefiSpec.h:1988
#define EFI_WARN_BUFFER_TOO_SMALL
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:152
#define EFI_ICMP_ERROR
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:136
EFI_GET_WAKEUP_TIME GetWakeupTime
Definition: UefiSpec.h:1890
EFI Oprn Protocol Information Entry.
Definition: UefiSpec.h:1431
#define EFI_WRAP_DUMP_MAX
Maximum size for hex dumps.
Definition: efi_wrap.c:44
#define EFI_NO_RESPONSE
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:130
EFI_TEXT_SET_CURSOR_POSITION SetCursorPosition
EFI_RAISE_TPL RaiseTPL
Definition: UefiSpec.h:1939
An event is to be signaled periodically at a specified interval from the current time.
Definition: UefiSpec.h:547
#define VA_END(Marker)
Terminates the use of a variable argument list.
Definition: Base.h:693
#define EFI_ALREADY_STARTED
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:134
static const char * efi_status(EFI_STATUS efirc)
Convert EFI status code to text.
Definition: efi_wrap.c:73
static EFI_STATUS EFIAPI efi_set_time_wrapper(EFI_TIME *time)
Wrap SetTime()
Definition: efi_wrap.c:1266
EFI_LOCATE_PROTOCOL LocateProtocol
Definition: UefiSpec.h:2008
EFI_STALL Stall
Definition: UefiSpec.h:1987
An event is to be signaled once at a specified interval from the current time.
Definition: UefiSpec.h:551
static EFI_STATUS EFIAPI efi_reinstall_protocol_interface_wrapper(EFI_HANDLE handle, EFI_GUID *protocol, VOID *old_interface, VOID *new_interface)
Wrap ReinstallProtocolInterface()
Definition: efi_wrap.c:588
Definition of an EFI memory descriptor.
Definition: UefiSpec.h:155
#define EFI_CRC_ERROR
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:141
128 bit buffer containing a unique identifier value.
Definition: Base.h:215
#define EFI_BAD_BUFFER_SIZE
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:118
Error codes.
Definition: efi.h:62
static EFI_STATUS EFIAPI efi_locate_handle_wrapper(EFI_LOCATE_SEARCH_TYPE search_type, EFI_GUID *protocol, VOID *search_key, UINTN *buffer_size, EFI_HANDLE *buffer)
Wrap LocateHandle()
Definition: efi_wrap.c:668
static EFI_STATUS EFIAPI efi_register_protocol_notify_wrapper(EFI_GUID *protocol, EFI_EVENT event, VOID **registration)
Wrap RegisterProtocolNotify()
Definition: efi_wrap.c:649
#define DBGC_EFI_PROTOCOLS(...)
Definition: efi.h:348
EFI_REINSTALL_PROTOCOL_INTERFACE ReinstallProtocolInterface
Definition: UefiSpec.h:1965
EFI_EXIT_BOOT_SERVICES ExitBootServices
Definition: UefiSpec.h:1981
EFI_UNINSTALL_PROTOCOL_INTERFACE UninstallProtocolInterface
Definition: UefiSpec.h:1966
EFI_RESET_TYPE
Enumeration of reset types.
EFI_IMAGE_LOAD LoadImage
Definition: UefiSpec.h:1977
unsigned char BOOLEAN
uint32_t type
Operating system type.
Definition: ena.h:12
static EFI_STATUS EFIAPI efi_close_protocol_wrapper(EFI_HANDLE handle, EFI_GUID *protocol, EFI_HANDLE agent_handle, EFI_HANDLE controller_handle)
Wrap CloseProtocol()
Definition: efi_wrap.c:997
static EFI_STATUS EFIAPI efi_protocols_per_handle_wrapper(EFI_HANDLE handle, EFI_GUID ***protocol_buffer, UINTN *protocol_buffer_count)
Wrap ProtocolsPerHandle()
Definition: efi_wrap.c:1043
uint16_t size
Buffer size.
Definition: dwmac.h:14
#define EFI_PROTOCOL_ERROR
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:138
#define DBGC(...)
Definition: compiler.h:505
EFI_GUID efi_loaded_image_protocol_guid
Loaded image protocol GUID.
Definition: efi_guid.c:272
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:56
A memory region that operates as EfiConventionalMemory, however it happens to also support byte-addre...
long index
Definition: bigint.h:62
static EFI_STATUS EFIAPI efi_get_wakeup_time_wrapper(BOOLEAN *enabled, BOOLEAN *pending, EFI_TIME *time)
Wrap GetWakeupTime()
Definition: efi_wrap.c:1282
unsigned int UINT32
Definition: ProcessorBind.h:98
static EFI_STATUS EFIAPI efi_handle_protocol_wrapper(EFI_HANDLE handle, EFI_GUID *protocol, VOID **interface)
Wrap HandleProtocol()
Definition: efi_wrap.c:630
EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES InstallMultipleProtocolInterfaces
Definition: UefiSpec.h:2009
static EFI_STATUS EFIAPI efi_install_configuration_table_wrapper(EFI_GUID *guid, VOID *table)
Wrap InstallConfigurationTable()
Definition: efi_wrap.c:722
unsigned short CHAR16
EFI_CLOSE_EVENT CloseEvent
Definition: UefiSpec.h:1958
EFI_SET_TIMER SetTimer
Definition: UefiSpec.h:1955
static void efi_dump_image(EFI_HANDLE handle)
Dump information about a loaded image.
Definition: efi_wrap.c:275
static EFI_STATUS EFIAPI efi_signal_event_wrapper(EFI_EVENT event)
Wrap SignalEvent()
Definition: efi_wrap.c:519
uint32_t buffer
Buffer index (or NETVSC_RNDIS_NO_BUFFER)
Definition: netvsc.h:16
EFI_LOCATE_HANDLE LocateHandle
Definition: UefiSpec.h:1970
static EFI_STATUS EFIAPI efi_create_event_wrapper(UINT32 type, EFI_TPL notify_tpl, EFI_EVENT_NOTIFY notify_function, VOID *notify_context, EFI_EVENT *event)
Wrap CreateEvent()
Definition: efi_wrap.c:454
EFI_IMAGE_UNLOAD UnloadImage
Definition: UefiSpec.h:1980
VOID * ImageBase
The base address at which the image was loaded.
Definition: LoadedImage.h:69
This protocol can be used on any device handle to obtain generic path/location information concerning...
Definition: DevicePath.h:45
#define EFI_BUFFER_TOO_SMALL
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:119
VOID(EFIAPI * EFI_EVENT_NOTIFY)(IN EFI_EVENT Event, IN VOID *Context)
Invoke a notification event.
Definition: UefiSpec.h:475
static EFI_STATUS EFIAPI efi_get_next_monotonic_count_wrapper(UINT64 *count)
Wrap GetNextMonotonicCount()
Definition: efi_wrap.c:864
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:2000
EFI_CREATE_EVENT_EX CreateEventEx
Definition: UefiSpec.h:2022
UINT64 EFI_PHYSICAL_ADDRESS
64-bit physical memory address.
Definition: UefiBaseType.h:52
uint16_t enabled
Single-entry bitmask of the enabled option value.
Definition: ena.h:14
#define EFI_NO_MEDIA
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:126
#define EFI_OUT_OF_RESOURCES
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:123
static EFI_STATUS EFIAPI efi_get_time_wrapper(EFI_TIME *time, EFI_TIME_CAPABILITIES *cap)
Wrap GetTime()
Definition: efi_wrap.c:1249
The SIMPLE_TEXT_OUTPUT protocol is used to control text-based output devices.
static EFI_STATUS EFIAPI efi_create_event_ex_wrapper(UINT32 type, EFI_TPL notify_tpl, EFI_EVENT_NOTIFY notify_function, CONST VOID *notify_context, CONST EFI_GUID *event_group, EFI_EVENT *event)
Wrap CreateEventEx()
Definition: efi_wrap.c:1226
Used to induce a system-wide reset.
uint32_t pending
Pending events.
Definition: hyperv.h:12
#define EFI_DEVICE_ERROR
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:121
UEFI 2.0 Loaded image protocol definition.
The code portions of a loaded application.
unsigned long tmp
Definition: linux_pci.h:64
static EFI_STATUS EFIAPI efi_get_memory_map_wrapper(UINTN *memory_map_size, EFI_MEMORY_DESCRIPTOR *memory_map, UINTN *map_key, UINTN *descriptor_size, UINT32 *descriptor_version)
Wrap GetMemoryMap()
Definition: efi_wrap.c:374
#define EFI_LOAD_ERROR
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:115
struct ena_llq_option desc
Descriptor counts.
Definition: ena.h:20
A hardware device.
Definition: device.h:76
void * memcpy(void *dest, const void *src, size_t len) __nonnull
void efi_wrap_systab(int global)
Wrap the public EFI system table.
Definition: efi_wrap.c:1499
An event's timer settings is to be cancelled and not trigger time is to be set/.
Definition: UefiSpec.h:543
Can be used on any image handle to obtain information about the loaded image.
Definition: LoadedImage.h:45
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL * ConOut
A pointer to the EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL interface that is associated with ConsoleOutHandle.
Definition: UefiSpec.h:2079
Used to induce a system-wide reset.
Used to induce a system-wide initialization.
#define EFI_VOLUME_FULL
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:125
EFI_MEMORY_TYPE
Enumeration of memory types introduced in UEFI.
#define EFI_ACCESS_DENIED
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:129
UINT8 Day
Definition: UefiBaseType.h:73
An object interface.
Definition: interface.h:124
static EFI_RUNTIME_SERVICES efi_rs_copy
Backup of original EFI runtime services table.
Definition: efi_wrap.c:65
Address space reserved by the firmware for code that is part of the processor.
UINT8 Minute
Definition: UefiBaseType.h:75
Used by system firmware to request that a memory-mapped IO region be mapped by the OS to a virtual ad...
#define EFI_COMPROMISED_DATA
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:145
static EFI_STATUS EFIAPI efi_set_variable_wrapper(CHAR16 *name, EFI_GUID *guid, UINT32 attrs, UINTN len, VOID *data)
Wrap SetVariable()
Definition: efi_wrap.c:1370
ring len
Length.
Definition: dwmac.h:231
EFI_SET_VARIABLE SetVariable
Definition: UefiSpec.h:1904
UINT8 Second
Definition: UefiBaseType.h:76
Allocate pages at a specified address.
Definition: UefiSpec.h:44
EFI_INSTALL_PROTOCOL_INTERFACE InstallProtocolInterface
Definition: UefiSpec.h:1964
EFI_CREATE_EVENT CreateEvent
Definition: UefiSpec.h:1954
#define VA_ARG(Marker, TYPE)
Returns an argument of a specified type from a variable argument list and updates the pointer to the ...
Definition: Base.h:681
static unsigned int count
Number of entries.
Definition: dwmac.h:225
const char * efi_locate_search_type_name(EFI_LOCATE_SEARCH_TYPE search_type)
Name locate search type.
Definition: efi_debug.c:77
EFI_HANDLE_PROTOCOL HandleProtocol
Definition: UefiSpec.h:1967
EFI_REGISTER_PROTOCOL_NOTIFY RegisterProtocolNotify
Definition: UefiSpec.h:1969
UINT8 Hour
Definition: UefiBaseType.h:74
Memory that holds the ACPI tables.
void efi_wrap_rs(EFI_RUNTIME_SERVICES *wrapper)
Wrap a runtime services table.
Definition: efi_wrap.c:1475
EFI_GET_VARIABLE GetVariable
Definition: UefiSpec.h:1902
INT32 Mode
The text mode of the output device(s).
const char * efi_devpath_text(EFI_DEVICE_PATH_PROTOCOL *path)
Get textual representation of device path.
Definition: efi_debug.c:247
EFI_SIMPLE_TEXT_OUTPUT_MODE * Mode
Pointer to SIMPLE_TEXT_OUTPUT_MODE data.
static EFI_SYSTEM_TABLE efi_systab_priv
Private EFI system table used while wrapping is active.
Definition: efi_wrap.c:53
static EFI_STATUS EFIAPI efi_free_pages_wrapper(EFI_PHYSICAL_ADDRESS memory, UINTN pages)
Wrap FreePages()
Definition: efi_wrap.c:356
The code portions of a loaded Boot Services Driver.
#define EFI_NOT_STARTED
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:133
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:652
static EFI_STATUS EFIAPI efi_start_image_wrapper(EFI_HANDLE image_handle, UINTN *exit_data_size, CHAR16 **exit_data)
Wrap StartImage()
Definition: efi_wrap.c:771
EFI_SIGNAL_EVENT SignalEvent
Definition: UefiSpec.h:1957
#define EFI_WRITE_PROTECTED
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:122
Free (unallocated) memory.
EFI Runtime Services Table.
Definition: UefiSpec.h:1879
EFI_RESET_SYSTEM ResetSystem
Definition: UefiSpec.h:1910
Allocate any available range of pages whose uppermost address is less than or equal to a specified ma...
Definition: UefiSpec.h:40
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define EFIAPI
EFI Boot Services Table.
Definition: UefiSpec.h:1930
static EFI_STATUS EFIAPI efi_set_watchdog_timer_wrapper(UINTN timeout, UINT64 watchdog_code, UINTN data_size, CHAR16 *watchdog_data)
Wrap SetWatchdogTimer()
Definition: efi_wrap.c:899
EFI_GET_NEXT_MONOTONIC_COUNT GetNextMonotonicCount
Definition: UefiSpec.h:1986
#define DBGC2_HD(...)
Definition: compiler.h:524
static EFI_STATUS EFIAPI efi_install_protocol_interface_wrapper(EFI_HANDLE *handle, EFI_GUID *protocol, EFI_INTERFACE_TYPE interface_type, VOID *interface)
Wrap InstallProtocolInterface()
Definition: efi_wrap.c:566
Used to induce an entry into a power state equivalent to the ACPI G2/S5 or G3 state.
static EFI_STATUS EFIAPI efi_open_protocol_information_wrapper(EFI_HANDLE handle, EFI_GUID *protocol, EFI_OPEN_PROTOCOL_INFORMATION_ENTRY **entry_buffer, UINTN *entry_count)
Wrap OpenProtocolInformation()
Definition: efi_wrap.c:1020
static EFI_STATUS EFIAPI efi_wait_for_event_wrapper(UINTN number_of_events, EFI_EVENT *event, UINTN *index)
Wrap WaitForEvent()
Definition: efi_wrap.c:495
#define DBGC_HD(...)
Definition: compiler.h:507
UINT16 Year
Definition: UefiBaseType.h:71
static EFI_BOOT_SERVICES * efi_bs_orig
Original EFI boot services table pointer.
Definition: efi_wrap.c:56
EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES UninstallMultipleProtocolInterfaces
Definition: UefiSpec.h:2010
EFI_CONNECT_CONTROLLER ConnectController
Definition: UefiSpec.h:1993
EFI_GET_TIME GetTime
Definition: UefiSpec.h:1888
#define efi_open(handle, protocol, interface)
Open protocol for ephemeral use.
Definition: efi.h:443
static EFI_STATUS EFIAPI efi_connect_controller_wrapper(EFI_HANDLE controller_handle, EFI_HANDLE *driver_image_handle, EFI_DEVICE_PATH_PROTOCOL *remaining_path, BOOLEAN recursive)
Wrap ConnectController()
Definition: efi_wrap.c:919
static EFI_STATUS EFIAPI efi_locate_protocol_wrapper(EFI_GUID *protocol, VOID *registration, VOID **interface)
Wrap LocateProtocol()
Definition: efi_wrap.c:1104
static EFI_STATUS EFIAPI efi_allocate_pages_wrapper(EFI_ALLOCATE_TYPE type, EFI_MEMORY_TYPE memory_type, UINTN pages, EFI_PHYSICAL_ADDRESS *memory)
Wrap AllocatePages()
Definition: efi_wrap.c:334
EFI_IMAGE_START StartImage
Definition: UefiSpec.h:1978
UINT64 UINTN
Unsigned value of native width.
#define VA_START(Marker, Parameter)
Retrieves a pointer to the beginning of a variable argument list, based on the name of the parameter ...
Definition: Base.h:663
EFI System Table.
Definition: UefiSpec.h:2043
#define EFI_NOT_READY
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:120
static EFI_TPL EFIAPI efi_raise_tpl_wrapper(EFI_TPL new_tpl)
Wrap RaiseTPL()
Definition: efi_wrap.c:304
static EFI_STATUS EFIAPI efi_install_multiple_protocol_interfaces_wrapper(EFI_HANDLE *handle,...)
Wrap InstallMultipleProtocolInterfaces()
Definition: efi_wrap.c:1126
#define EFI_INVALID_PARAMETER
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:116
#define EFI_END_OF_FILE
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:143
static EFI_STATUS EFIAPI efi_unload_image_wrapper(EFI_HANDLE image_handle)
Wrap UnloadImage()
Definition: efi_wrap.c:817
const char * efi_guid_ntoa(CONST EFI_GUID *guid)
Convert GUID to a printable string.
Definition: efi_guid.c:725
#define VOID
Undeclared type.
Definition: Base.h:271
unsigned long long UINT64
Definition: ProcessorBind.h:96
System memory-mapped IO region that is used to translate memory cycles to IO cycles by the processor.
EFI_WAIT_FOR_EVENT WaitForEvent
Definition: UefiSpec.h:1956
void efi_wrap_image(EFI_HANDLE handle)
Wrap calls made by a newly loaded image.
Definition: efi_wrap.c:1566
#define EFI_INVALID_LANGUAGE
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:144
EFI_FREE_POOL FreePool
Definition: UefiSpec.h:1949
#define EFI_WARN_STALE_DATA
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:153
UINT8 Month
Definition: UefiBaseType.h:72
EFI_OPEN_PROTOCOL_INFORMATION OpenProtocolInformation
Definition: UefiSpec.h:2001
#define EFI_WARN_DELETE_FAILURE
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:150
EFI API.
EFI Time Abstraction: Year: 1900 - 9999 Month: 1 - 12 Day: 1 - 31 Hour: 0 - 23 Minute: 0 - 59 Second:...
Definition: UefiBaseType.h:70
uint8_t status
Status.
Definition: ena.h:16
static EFI_STATUS EFIAPI efi_uninstall_protocol_interface_wrapper(EFI_HANDLE handle, EFI_GUID *protocol, VOID *interface)
Wrap UninstallProtocolInterface()
Definition: efi_wrap.c:610
uint64_t guid
GUID.
Definition: edd.h:30
#define EFI_SECURITY_VIOLATION
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:140
static const char * efi_time(EFI_TIME *time)
Convert EFI time to text.
Definition: efi_wrap.c:207
EFI_ALLOCATE_TYPE
Enumeration of EFI memory allocation types.
Definition: UefiSpec.h:31
struct edd_interface_type interface_type
Interface type.
Definition: edd.h:20
#define EFI_MEDIA_CHANGED
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:127
EFI_GET_MEMORY_MAP GetMemoryMap
Definition: UefiSpec.h:1947
EFI_ALLOCATE_PAGES AllocatePages
Definition: UefiSpec.h:1945
static EFI_STATUS EFIAPI efi_allocate_pool_wrapper(EFI_MEMORY_TYPE pool_type, UINTN size, VOID **buffer)
Wrap AllocatePool()
Definition: efi_wrap.c:418
EFI_SET_WAKEUP_TIME SetWakeupTime
Definition: UefiSpec.h:1891
EFI_RUNTIME_SERVICES * RuntimeServices
A pointer to the EFI Runtime Services Table.
Definition: UefiSpec.h:2094
The data portions of a loaded Runtime Services Driver and the default data allocation type used by a ...
static unsigned int source_size
Definition: bigint.h:248
#define EFI_NOT_FOUND
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:128
UINTN EFI_TPL
Task priority level.
Definition: UefiBaseType.h:43
EFI_PROTOCOLS_PER_HANDLE ProtocolsPerHandle
Definition: UefiSpec.h:2006
#define DBGC2(...)
Definition: compiler.h:522
#define CONST
Datum is read-only.
Definition: Base.h:261
static EFI_STATUS EFIAPI efi_locate_handle_buffer_wrapper(EFI_LOCATE_SEARCH_TYPE search_type, EFI_GUID *protocol, VOID *search_key, UINTN *no_handles, EFI_HANDLE **buffer)
Wrap LocateHandleBuffer()
Definition: efi_wrap.c:1073
#define EFI_INCOMPATIBLE_VERSION
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:139
#define EFI_SUCCESS
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:114
#define EFI_WARN_UNKNOWN_GLYPH
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:149
EFI_TIMER_DELAY
Timer delay types.
Definition: UefiSpec.h:539
static EFI_STATUS EFIAPI efi_open_protocol_wrapper(EFI_HANDLE handle, EFI_GUID *protocol, VOID **interface, EFI_HANDLE agent_handle, EFI_HANDLE controller_handle, UINT32 attributes)
Wrap OpenProtocol()
Definition: efi_wrap.c:973
#define EFI_NO_MAPPING
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:131
EFI_CHECK_EVENT CheckEvent
Definition: UefiSpec.h:1959
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
EFI_GET_NEXT_VARIABLE_NAME GetNextVariableName
Definition: UefiSpec.h:1903
The code portions of a loaded Runtime Services Driver.
static EFI_RUNTIME_SERVICES * efi_rs_orig
Original EFI runtime services table pointer.
Definition: efi_wrap.c:62
static EFI_STATUS EFIAPI efi_close_event_wrapper(EFI_EVENT event)
Wrap CloseEvent()
Definition: efi_wrap.c:535
Allocate any available range of pages that satisfies the request.
Definition: UefiSpec.h:35
static VOID EFIAPI efi_reset_system_wrapper(EFI_RESET_TYPE type, EFI_STATUS status, UINTN len, VOID *data)
Wrap ResetSystem()
Definition: efi_wrap.c:1396
uint8_t data[48]
Additional event data.
Definition: ena.h:22
static EFI_STATUS EFIAPI efi_load_image_wrapper(BOOLEAN boot_policy, EFI_HANDLE parent_image_handle, EFI_DEVICE_PATH_PROTOCOL *device_path, VOID *source_buffer, UINTN source_size, EFI_HANDLE *image_handle)
Wrap LoadImage()
Definition: efi_wrap.c:739
static const char * efi_timer_delay(EFI_TIMER_DELAY type)
Convert EFI timer delay type to text.
Definition: efi_wrap.c:188
const char * efi_open_attributes_name(unsigned int attributes)
Name protocol open attributes.
Definition: efi_debug.c:102
static EFI_STATUS EFIAPI efi_disconnect_controller_wrapper(EFI_HANDLE controller_handle, EFI_HANDLE driver_image_handle, EFI_HANDLE child_handle)
Wrap DisconnectController()
Definition: efi_wrap.c:950
static EFI_STATUS EFIAPI efi_locate_device_path_wrapper(EFI_GUID *protocol, EFI_DEVICE_PATH_PROTOCOL **device_path, EFI_HANDLE *device)
Wrap LocateDevicePath()
Definition: efi_wrap.c:701
#define DBGCP(...)
Definition: compiler.h:539
static EFI_STATUS EFIAPI efi_exit_boot_services_wrapper(EFI_HANDLE image_handle, UINTN map_key)
Wrap ExitBootServices()
Definition: efi_wrap.c:834
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:382
static EFI_STATUS EFIAPI efi_get_variable_wrapper(CHAR16 *name, EFI_GUID *guid, UINT32 *attrs, UINTN *len, VOID *data)
Wrap GetVariable()
Definition: efi_wrap.c:1318
void timeout(int)
EFI_SYSTEM_TABLE * efi_systab
EFI_OPEN_PROTOCOL OpenProtocol
Definition: UefiSpec.h:1999
static EFI_STATUS EFIAPI efi_exit_wrapper(EFI_HANDLE image_handle, EFI_STATUS exit_status, UINTN exit_data_size, CHAR16 *exit_data)
Wrap Exit()
Definition: efi_wrap.c:793
uint16_t protocol
Protocol ID.
Definition: stp.h:18
EFI_LOCATE_SEARCH_TYPE
Enumeration of EFI Locate Search Types.
Definition: UefiSpec.h:1517
#define DBG_EXTRA
Definition: compiler.h:319
Address space reserved for use by the firmware.
EFI_INTERFACE_TYPE
Enumeration of EFI Interface Types.
Definition: UefiSpec.h:1201
static int efi_prescroll(unsigned int lines)
Pre-scroll display to create space for output lines.
Definition: efi_wrap.c:244
EFI_RESTORE_TPL RestoreTPL
Definition: UefiSpec.h:1940
The data portions of a loaded Boot Serves Driver, and the default data allocation type used by a Boot...
static const char * efi_allocate_type(EFI_ALLOCATE_TYPE type)
Convert EFI allocation type to text.
Definition: efi_wrap.c:138
static EFI_STATUS EFIAPI efi_stall_wrapper(UINTN microseconds)
Wrap Stall()
Definition: efi_wrap.c:881
INT32 CursorRow
The cursor's row.
static EFI_STATUS EFIAPI efi_uninstall_multiple_protocol_interfaces_wrapper(EFI_HANDLE handle,...)
Wrap UninstallMultipleProtocolInterfaces()
Definition: efi_wrap.c:1176
#define EFI_WARN_WRITE_FAILURE
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:151
#define EFI_END_OF_MEDIA
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:142
static EFI_STATUS EFIAPI efi_check_event_wrapper(EFI_EVENT event)
Wrap CheckEvent()
Definition: efi_wrap.c:550
#define EFI_ABORTED
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:135
#define colour
Colour for debug messages.
Definition: efi_wrap.c:41
EFI_FREE_PAGES FreePages
Definition: UefiSpec.h:1946
#define DBG_LOG
Definition: compiler.h:317
void efi_unwrap(void)
Remove boot services table wrapper.
Definition: efi_wrap.c:1542
#define EFI_TFTP_ERROR
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:137
static EFI_SYSTEM_TABLE * efi_systab_pub
Public EFI system table pointer.
Definition: efi_wrap.c:50
static const char * efi_memory_type(EFI_MEMORY_TYPE type)
Convert EFI memory type to text.
Definition: efi_wrap.c:157
uint16_t handle
Handle.
Definition: smbios.h:16
#define EFI_WRAP_PRESCROLL
Number of lines to prescroll when needed.
Definition: efi_wrap.c:47
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
UINT16_t buffer_size
UDP payload buffer size.
Definition: pxe_api.h:62
String functions.
#define MAX_WRAP_MULTI
Maximum number of interfaces for wrapped ...MultipleProtocolInterfaces()
Definition: efi_wrap.c:1119
static EFI_STATUS EFIAPI efi_get_next_variable_name_wrapper(UINTN *len, CHAR16 *name, EFI_GUID *guid)
Wrap GetNextVariableName()
Definition: efi_wrap.c:1350
EFI_HANDLE ParentHandle
Parent image's image handle.
Definition: LoadedImage.h:48
EFI driver interface.
CHAR8 * VA_LIST
Variable used to traverse the list of arguments.
Definition: Base.h:645
Definition: efi.h:61
The data portions of a loaded application and the default data allocation type used by an application...
EFI_LOCATE_HANDLE_BUFFER LocateHandleBuffer
Definition: UefiSpec.h:2007
static const char * efi_reset_type(EFI_RESET_TYPE type)
Convert EFI reset type to text.
Definition: efi_wrap.c:224
EFI_INSTALL_CONFIGURATION_TABLE InstallConfigurationTable
Definition: UefiSpec.h:1972
EFI_LOCATE_DEVICE_PATH LocateDevicePath
Definition: UefiSpec.h:1971
#define EFI_TIMEOUT
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:132
EFI_HANDLE DeviceHandle
The device handle that the EFI Image was loaded from.
Definition: LoadedImage.h:55
const char * efi_tpl_name(EFI_TPL tpl)
Name EFI TPL.
Definition: efi_debug.c:55
Memory in which errors have been detected.
static EFI_STATUS EFIAPI efi_free_pool_wrapper(VOID *buffer)
Wrap FreePool()
Definition: efi_wrap.c:438
EFI_ALLOCATE_POOL AllocatePool
Definition: UefiSpec.h:1948
void * memset(void *dest, int character, size_t len) __nonnull
This provides the capabilities of the real time clock device as exposed through the EFI interfaces.
Definition: UefiSpec.h:805
EFI_DISCONNECT_CONTROLLER DisconnectController
Definition: UefiSpec.h:1994