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