OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
UefiRuntimeServices.c
Go to the documentation of this file.
1
15#include "OpenRuntimePrivate.h"
16
17#include <Guid/OcVariable.h>
18#include <Guid/GlobalVariable.h>
19#include <Guid/ImageAuthentication.h>
21
22#include <Library/BaseLib.h>
23#include <Library/BaseMemoryLib.h>
24#include <Library/BaseOverflowLib.h>
25#include <Library/DebugLib.h>
26#include <Library/DevicePathLib.h>
29#include <Library/OcStringLib.h>
30#include <Library/UefiBootServicesTableLib.h>
31#include <Library/UefiRuntimeServicesTableLib.h>
32
36STATIC EFI_GET_TIME mStoredGetTime;
37STATIC EFI_SET_TIME mStoredSetTime;
38STATIC EFI_GET_WAKEUP_TIME mStoredGetWakeupTime;
39STATIC EFI_SET_WAKEUP_TIME mStoredSetWakeupTime;
40STATIC EFI_GET_VARIABLE mStoredGetVariable;
41STATIC EFI_GET_NEXT_VARIABLE_NAME mStoredGetNextVariableName;
42STATIC EFI_SET_VARIABLE mStoredSetVariable;
43STATIC EFI_GET_NEXT_HIGH_MONO_COUNT mStoredGetNextHighMonotonicCount;
44STATIC EFI_RESET_SYSTEM mStoredResetSystem;
45STATIC EFI_SET_VIRTUAL_ADDRESS_MAP mSetVirtualAddressMap;
46
53
57STATIC EFI_EVENT mTranslateEvent;
58STATIC EFI_GET_VARIABLE mCustomGetVariable;
59STATIC EFI_SET_VIRTUAL_ADDRESS_MAP mCustomSetVirtualAddressMap;
61STATIC BOOLEAN mKernelStarted;
62#ifdef OC_DEBUG_VAR_SERVICE
63STATIC BOOLEAN mInsideVarService;
64#endif
65
66STATIC
67VOID
69 OUT BOOLEAN *Ints,
70 OUT BOOLEAN *Wp,
71 OUT BOOLEAN *Ts
72 )
73{
74 IA32_CR0 Cr0;
75
77 *Ints = SaveAndDisableInterrupts ();
78 Cr0.UintN = AsmReadCr0 ();
79
81 if (Cr0.Bits.WP == 1) {
82 *Wp = TRUE;
83 Cr0.Bits.WP = 0;
84 } else {
85 *Wp = FALSE;
86 }
87 }
88
90 if (Cr0.Bits.TS == 1) {
91 *Ts = TRUE;
92 Cr0.Bits.TS = 0;
93 } else {
94 *Ts = FALSE;
95 }
96 }
97
98 if (*Wp || *Ts) {
99 AsmWriteCr0 (Cr0.UintN);
100 }
101 } else {
102 *Ints = FALSE;
103 *Wp = FALSE;
104 *Ts = FALSE;
105 }
106}
107
108STATIC
109VOID
111 IN BOOLEAN Ints,
112 IN BOOLEAN Wp,
113 IN BOOLEAN Ts
114 )
115{
116 IA32_CR0 Cr0;
117
119 if (Wp || Ts) {
120 Cr0.UintN = AsmReadCr0 ();
121 }
122
124 if (Wp) {
125 Cr0.Bits.WP = 1;
126 }
127 }
128
130 if (Ts) {
131 Cr0.Bits.TS = 1;
132 }
133 }
134
135 if (Wp || Ts) {
136 AsmWriteCr0 (Cr0.UintN);
137 }
138
139 if (Ints) {
141 }
142 }
143}
144
145STATIC
146BOOLEAN
148 IN CHAR16 *VariableName,
149 IN EFI_GUID *VendorGuid,
150 OUT CHAR16 *NewVariableName OPTIONAL
151 )
152{
153 UINTN Size;
154
155 if (!CompareGuid (VendorGuid, &gEfiGlobalVariableGuid)) {
156 return FALSE;
157 }
158
159 if (StrnCmp (L"Boot", VariableName, L_STR_LEN (L"Boot")) != 0) {
160 return FALSE;
161 }
162
163 //
164 // Return OC option path if requested.
165 //
166 // Many modern AMI BIOSes (e.g. ASUS ROG STRIX Z370-F GAMING)
167 // have bugs in AMI Post Manager protocol implementation in AMI TSE.
168 //
169 // The handshake function, responsible for obtaining firmware
170 // boot option list, calls gRT->GetNextVariableName and then matches
171 // every Boot#### variable as a potential boot option regardless
172 // of the GUID namespace it is in.
173 //
174 // The correct way is to only check for Boot#### variables under the
175 // gEfiGlobalVariableGuid VendorGuid. Due to these bugs however, the
176 // boot option list on most ASUS firmware, and perhaps other vendors, is
177 // corrupted (e.g. duplicated options) if Boot#### variables are present
178 // outside gEfiGlobalVariableGuid.
179 //
180 // This is the case with OpenCore as we store macOS-specific boot options
181 // in a separate GUID (gOcVendorVariableGuid). To workaround the issue
182 // we store Boot options with a different prefix - OCBt. This way
183 // Boot0001 becomes OCBt0001 and Bootorder becomes OCBtOrder.
184 //
185 // One of the ways to reproduce the issue is to enable Fast Boot
186 // and let an ExitBootServices handler try to update BootOrder.
187 // It can be easily noticed by BootFlow GetVariable with an uninitialised
188 // size argument.
189 //
190 if (NewVariableName != NULL) {
191 Size = StrSize (VariableName);
192 if (Size > OC_VARIABLE_NAME_SIZE * sizeof (CHAR16)) {
193 return FALSE;
194 }
195
197 CopyMem (
198 &NewVariableName[L_STR_LEN (OC_VENDOR_BOOT_VARIABLE_PREFIX)],
201 );
202 }
203
204 return TRUE;
205}
206
207STATIC
208BOOLEAN
210 IN CHAR16 *VariableName,
211 IN EFI_GUID *VendorGuid,
212 OUT CHAR16 *NewVariableName OPTIONAL
213 )
214{
215 UINTN Size;
216
217 if (!CompareGuid (VendorGuid, &gOcVendorVariableGuid)) {
218 return FALSE;
219 }
220
221 if (StrnCmp (OC_VENDOR_BOOT_VARIABLE_PREFIX, VariableName, L_STR_LEN (OC_VENDOR_BOOT_VARIABLE_PREFIX)) != 0) {
222 return FALSE;
223 }
224
225 //
226 // Return boot option if requested.
227 //
228 if (NewVariableName != NULL) {
229 Size = StrSize (VariableName);
230 if (Size > OC_VARIABLE_NAME_SIZE * sizeof (CHAR16)) {
231 return FALSE;
232 }
233
234 CopyMem (NewVariableName, L"Boot", L_STR_SIZE_NT (L"Boot"));
235 CopyMem (
236 &NewVariableName[L_STR_LEN (L"Boot")],
237 &VariableName[L_STR_LEN (L"Boot")],
238 Size - L_STR_SIZE_NT (L"Boot")
239 );
240 }
241
242 return TRUE;
243}
244
245STATIC
246EFI_STATUS
247EFIAPI
249 OUT EFI_TIME *Time,
250 OUT EFI_TIME_CAPABILITIES *Capabilities OPTIONAL
251 )
252{
253 EFI_STATUS Status;
254 BOOLEAN Ints;
255 BOOLEAN Wp;
256 BOOLEAN Ts;
257
258 Cr0QuirkPrologue (&Ints, &Wp, &Ts);
259
260 Status = mStoredGetTime (
261 Time,
262 Capabilities
263 );
264
265 if (!EFI_ERROR (Status)) {
266 //
267 // On old AMI firmware, such as found in the GA-Z87X-UD4H, there is a chance
268 // of getting 2047 (EFI_UNSPECIFIED_TIMEZONE) from GetTime. This is valid,
269 // yet is disliked by some software including but not limited to UEFI Shell.
270 // See the patch: https://lists.01.org/pipermail/edk2-devel/2018-May/024534.html
271 // As a workaround we make sure this does not happen at all.
272 //
273 if (Time->TimeZone == EFI_UNSPECIFIED_TIMEZONE) {
274 Time->TimeZone = 0;
275 }
276 }
277
278 Cr0QuirkEpilogue (Ints, Wp, Ts);
279
280 return Status;
281}
282
283STATIC
284EFI_STATUS
285EFIAPI
287 IN EFI_TIME *Time
288 )
289{
290 EFI_STATUS Status;
291 BOOLEAN Ints;
292 BOOLEAN Wp;
293 BOOLEAN Ts;
294
295 Cr0QuirkPrologue (&Ints, &Wp, &Ts);
296
297 Status = mStoredSetTime (
298 Time
299 );
300
301 Cr0QuirkEpilogue (Ints, Wp, Ts);
302
303 return Status;
304}
305
306STATIC
307EFI_STATUS
308EFIAPI
310 OUT BOOLEAN *Enabled,
311 OUT BOOLEAN *Pending,
312 OUT EFI_TIME *Time
313 )
314{
315 EFI_STATUS Status;
316 BOOLEAN Ints;
317 BOOLEAN Wp;
318 BOOLEAN Ts;
319
320 Cr0QuirkPrologue (&Ints, &Wp, &Ts);
321
322 Status = mStoredGetWakeupTime (
323 Enabled,
324 Pending,
325 Time
326 );
327
328 Cr0QuirkEpilogue (Ints, Wp, Ts);
329
330 return Status;
331}
332
333STATIC
334EFI_STATUS
335EFIAPI
337 IN BOOLEAN Enable,
338 IN EFI_TIME *Time OPTIONAL
339 )
340{
341 EFI_STATUS Status;
342 BOOLEAN Ints;
343 BOOLEAN Wp;
344 BOOLEAN Ts;
345
346 Cr0QuirkPrologue (&Ints, &Wp, &Ts);
347
348 Status = mStoredSetWakeupTime (
349 Enable,
350 Time
351 );
352
353 Cr0QuirkEpilogue (Ints, Wp, Ts);
354
355 return Status;
356}
357
358STATIC
359EFI_STATUS
360EFIAPI
362 IN CHAR16 *VariableName,
363 IN EFI_GUID *VendorGuid,
364 OUT UINT32 *Attributes OPTIONAL,
365 IN OUT UINTN *DataSize,
366 OUT VOID *Data OPTIONAL
367 )
368{
369 EFI_STATUS Status;
370 CHAR16 TempName[OC_VARIABLE_NAME_SIZE];
371 BOOLEAN Ints;
372 BOOLEAN Wp;
373 BOOLEAN Ts;
374
375 //
376 // Perform early checks for speedup.
377 //
378 if ( (VariableName == NULL)
379 || (VendorGuid == NULL)
380 || (DataSize == NULL)
381 || ((Data == NULL) && (*DataSize != 0)))
382 {
383 return EFI_INVALID_PARAMETER;
384 }
385
386 #ifdef OC_DEBUG_VAR_SERVICE
387 if (!mInsideVarService && (StrCmp (VariableName, L"EfiTime") != 0)) {
388 mInsideVarService = TRUE;
389 DEBUG ((DEBUG_INFO, "GETVAR %g:%s (%u)\n", VendorGuid, VariableName, (UINT32)*DataSize));
390 mInsideVarService = FALSE;
391 }
392
393 #endif
394
395 //
396 // Abort access to write-only variables.
397 //
400 && CompareGuid (VendorGuid, &gOcWriteOnlyVariableGuid))
401 {
402 return EFI_SECURITY_VIOLATION;
403 }
404
405 //
406 // Redirect Boot-prefixed variables to our own GUID.
407 //
408 if (gCurrentConfig->BootVariableRedirect && IsEfiBootVar (VariableName, VendorGuid, TempName)) {
409 VariableName = TempName;
410 VendorGuid = &gOcVendorVariableGuid;
411 }
412
413 Cr0QuirkPrologue (&Ints, &Wp, &Ts);
414
416 VariableName,
417 VendorGuid,
418 Attributes,
419 DataSize,
420 Data
421 );
422
423 Cr0QuirkEpilogue (Ints, Wp, Ts);
424
425 return Status;
426}
427
428STATIC
429EFI_STATUS
430EFIAPI
432 IN OUT UINTN *VariableNameSize,
433 IN OUT CHAR16 *VariableName,
434 IN OUT EFI_GUID *VendorGuid
435 )
436{
437 EFI_STATUS Status;
438 UINTN Index;
439 UINTN Size;
440 CHAR16 TempName[OC_VARIABLE_NAME_SIZE];
441 EFI_GUID TempGuid;
442 BOOLEAN StartBootVar;
443 BOOLEAN Ints;
444 BOOLEAN Wp;
445 BOOLEAN Ts;
446
447 #ifdef OC_DEBUG_VAR_SERVICE
448 if (!mInsideVarService) {
449 mInsideVarService = TRUE;
450 DEBUG ((DEBUG_INFO, "NEXVAR %g:%s (%u/%u)\n", VendorGuid, VariableName, (UINT32)*VariableNameSize));
451 mInsideVarService = FALSE;
452 }
453
454 #endif
455
456 //
457 // Perform initial checks as per spec. Last check is part of:
458 // Null-terminator is not found in the first VariableNameSize
459 // bytes of the input VariableName buffer.
460 //
461 if ((VariableNameSize == NULL) || (VariableName == NULL) || (VendorGuid == NULL)) {
462 return EFI_INVALID_PARAMETER;
463 }
464
465 //
466 // Checking that VariableName never exceeds *VariableNameSize and is always null-terminated.
467 //
468 Size = 0;
469 for (Index = 0; Index < *VariableNameSize; ++Index) {
470 if (VariableName[Index] == L'\0') {
471 Size = (Index + 1) * sizeof (CHAR16);
472 break;
473 }
474 }
475
476 //
477 // Also assume that too large variables do not exist, as we cannot work with them anyway.
478 //
479 if ((Size == 0) || (Size > sizeof (TempName))) {
480 return EFI_INVALID_PARAMETER;
481 }
482
483 Cr0QuirkPrologue (&Ints, &Wp, &Ts);
484
485 //
486 // In case we do not redirect, simply do nothing.
487 //
489 Status = mStoredGetNextVariableName (VariableNameSize, VariableName, VendorGuid);
490 Cr0QuirkEpilogue (Ints, Wp, Ts);
491 return Status;
492 }
493
494 //
495 // Copy vendor and variable name to internal buffer.
496 //
497 CopyGuid (&TempGuid, VendorGuid);
498 StrnCpyS (TempName, ARRAY_SIZE (TempName), VariableName, StrLen (VariableName));
499
500 StartBootVar = FALSE;
501
502 //
503 // In case we are not yet iterating EfiBoot variables,
504 // then go through the whole variable list and return
505 // variables except EfiBoot.
506 //
507 if (!IsEfiBootVar (TempName, &TempGuid, TempName)) {
508 while (TRUE) {
509 //
510 // Request for variables.
511 //
512 Size = sizeof (TempName);
513 Status = mStoredGetNextVariableName (&Size, TempName, &TempGuid);
514
515 if (!EFI_ERROR (Status)) {
516 if (!IsEfiBootVar (TempName, &TempGuid, NULL)) {
517 Size = StrSize (TempName);
518
519 if (*VariableNameSize >= Size) {
520 //
521 // Return this variable.
522 //
523 CopyGuid (VendorGuid, &TempGuid);
524 StrnCpyS (
525 VariableName,
526 *VariableNameSize / sizeof (CHAR16),
527 TempName,
528 StrLen (TempName)
529 );
530 *VariableNameSize = Size;
531 Status = EFI_SUCCESS;
532 } else {
533 //
534 // Request more space.
535 //
536 *VariableNameSize = Size;
537 Status = EFI_BUFFER_TOO_SMALL;
538 }
539
540 Cr0QuirkEpilogue (Ints, Wp, Ts);
541 return Status;
542 } else {
543 //
544 // EfiBoot variables are handled outside of this loop.
545 //
546 }
547 } else if (Status == EFI_BUFFER_TOO_SMALL) {
548 //
549 // This means sizeof (TempName) is too small for this system.
550 // At this step we cannot do anything, but let's replace error
551 // with something sensible.
552 //
553 Cr0QuirkEpilogue (Ints, Wp, Ts);
554 return EFI_DEVICE_ERROR;
555 } else if (Status == EFI_NOT_FOUND) {
556 //
557 // End of normal variable list.
558 // This means it is the time for boot variables to be searched
559 // from the beginning.
560 //
561 StartBootVar = TRUE;
562 break;
563 } else {
564 //
565 // We got EFI_UNSUPPORTED, EFI_DEVICE_ERROR or EFI_INVALID_PARAMETER.
566 // Return as is.
567 //
568 Cr0QuirkEpilogue (Ints, Wp, Ts);
569 return Status;
570 }
571 }
572 }
573
574 //
575 // Handle EfiBoot variables now.
576 // When StartBootVar is TRUE we start from the beginning.
577 // Otherwise we have boot variable in TempGuid/TempName.
578 //
579
580 if (StartBootVar) {
581 //
582 // It is not required to zero guid, but let's do it just in case.
583 //
584 TempName[0] = L'\0';
585 ZeroMem (&TempGuid, sizeof (TempGuid));
586 } else {
587 //
588 // Switch to real GUID as stored in variable storage.
589 // TempName is already updated with the new name.
590 //
591 CopyGuid (&TempGuid, &gOcVendorVariableGuid);
592 }
593
594 //
595 // Find next EfiBoot variable.
596 //
597 while (TRUE) {
598 Size = sizeof (TempName);
599 Status = mStoredGetNextVariableName (&Size, TempName, &TempGuid);
600
601 if (!EFI_ERROR (Status)) {
602 if (IsOcBootVar (TempName, &TempGuid, TempName)) {
603 Size = StrSize (TempName);
604
605 if (*VariableNameSize >= Size) {
606 //
607 // Return this variable.
608 //
609 CopyGuid (VendorGuid, &gEfiGlobalVariableGuid);
610 StrnCpyS (
611 VariableName,
612 *VariableNameSize / sizeof (CHAR16),
613 TempName,
614 StrLen (TempName)
615 );
616 *VariableNameSize = Size;
617 Status = EFI_SUCCESS;
618 } else {
619 //
620 // Request more space.
621 //
622 *VariableNameSize = Size;
623 Status = EFI_BUFFER_TOO_SMALL;
624 }
625
626 Cr0QuirkEpilogue (Ints, Wp, Ts);
627 return Status;
628 }
629 } else {
630 //
631 // This is some error, but let us not care which and just exit cleanly.
632 //
633 break;
634 }
635 }
636
637 //
638 // Report this is the end.
639 //
640 Cr0QuirkEpilogue (Ints, Wp, Ts);
641 return EFI_NOT_FOUND;
642}
643
644STATIC
645EFI_STATUS
646EFIAPI
648 IN CHAR16 *VariableName,
649 IN EFI_GUID *VendorGuid,
650 IN UINT32 Attributes,
651 IN UINTN DataSize,
652 IN VOID *Data
653 )
654{
655 EFI_STATUS Status;
656 CHAR16 TempName[OC_VARIABLE_NAME_SIZE];
657 BOOLEAN Ints;
658 BOOLEAN Wp;
659 BOOLEAN Ts;
660
661 #ifdef OC_DEBUG_VAR_SERVICE
662 if (!mInsideVarService) {
663 mInsideVarService = TRUE;
664 DEBUG ((DEBUG_INFO, "SETVAR %g:%s (%u/%u)\n", VendorGuid, VariableName, (UINT32)DataSize, Attributes));
665 mInsideVarService = FALSE;
666 }
667
668 #endif
669
670 //
671 // Abort access when running with read-only NVRAM.
672 //
673 if (gCurrentConfig->WriteProtection && ((Attributes & EFI_VARIABLE_NON_VOLATILE) != 0)) {
674 return EFI_SECURITY_VIOLATION;
675 }
676
677 //
678 // Abort access to read-only variables.
679 //
682 && CompareGuid (VendorGuid, &gOcReadOnlyVariableGuid))
683 {
684 return EFI_SECURITY_VIOLATION;
685 }
686
687 //
688 // Abort access to SecureBoot variables.
689 //
691 if (CompareGuid (VendorGuid, &gEfiGlobalVariableGuid)) {
692 if ( (StrCmp (VariableName, EFI_PLATFORM_KEY_NAME) == 0)
693 || (StrCmp (VariableName, EFI_KEY_EXCHANGE_KEY_NAME) == 0))
694 {
695 return EFI_SECURITY_VIOLATION;
696 }
697 } else if (CompareGuid (VendorGuid, &gEfiImageSecurityDatabaseGuid)) {
698 if ( (StrCmp (VariableName, EFI_IMAGE_SECURITY_DATABASE) == 0)
699 || (StrCmp (VariableName, EFI_IMAGE_SECURITY_DATABASE1) == 0)
700 || (StrCmp (VariableName, EFI_IMAGE_SECURITY_DATABASE2) == 0)
701 || (StrCmp (VariableName, L"dbr" /* EFI_IMAGE_SECURITY_DATABASE3 */) == 0))
702 {
703 return EFI_SECURITY_VIOLATION;
704 }
705 } else if (CompareGuid (VendorGuid, &gMicrosoftVariableGuid)) {
706 //
707 // CurrentActivePolicy, CurrentPolicy, RevocationList, WindowsBootChainSvn, whatever.
708 //
709 return EFI_SECURITY_VIOLATION;
710 }
711 }
712
713 //
714 // Redirect Boot-prefixed variables to our own GUID.
715 //
717 && IsEfiBootVar (VariableName, VendorGuid, TempName))
718 {
719 VariableName = TempName;
720 VendorGuid = &gOcVendorVariableGuid;
721 }
722
723 Cr0QuirkPrologue (&Ints, &Wp, &Ts);
724
725 Status = mStoredSetVariable (
726 VariableName,
727 VendorGuid,
728 Attributes,
729 DataSize,
730 Data
731 );
732
733 Cr0QuirkEpilogue (Ints, Wp, Ts);
734
735 return Status;
736}
737
738STATIC
739EFI_STATUS
740EFIAPI
742 OUT UINT32 *Count
743 )
744{
745 EFI_STATUS Status;
746 BOOLEAN Ints;
747 BOOLEAN Wp;
748 BOOLEAN Ts;
749
750 Cr0QuirkPrologue (&Ints, &Wp, &Ts);
751
753 Count
754 );
755
756 Cr0QuirkEpilogue (Ints, Wp, Ts);
757
758 return Status;
759}
760
761STATIC
762VOID
763EFIAPI
765 IN EFI_RESET_TYPE ResetType,
766 IN EFI_STATUS ResetStatus,
767 IN UINTN DataSize,
768 IN VOID *ResetData OPTIONAL
769 )
770{
771 BOOLEAN Ints;
772 BOOLEAN Wp;
773 BOOLEAN Ts;
774
775 Cr0QuirkPrologue (&Ints, &Wp, &Ts);
776
778 ResetType,
779 ResetStatus,
780 DataSize,
781 ResetData
782 );
783
784 Cr0QuirkEpilogue (Ints, Wp, Ts);
785}
786
787STATIC
788EFI_STATUS
789EFIAPI
791 IN UINTN MemoryMapSize,
792 IN UINTN DescriptorSize,
793 IN UINT32 DescriptorVersion,
794 IN EFI_MEMORY_DESCRIPTOR *MemoryMap
795 )
796{
797 EFI_STATUS Status;
798
799 //
800 // This is the time for us to remove our hacks.
801 // Make SetVirtualAddressMap useable once again.
802 // We do not need to recover BS, since they already are invalid.
803 //
804 gRT->SetVirtualAddressMap = mSetVirtualAddressMap;
805 gRT->Hdr.CRC32 = 0;
806 gRT->Hdr.CRC32 = CalculateCrc32 (gRT, gRT->Hdr.HeaderSize);
807
809 Status = gRT->SetVirtualAddressMap (
810 MemoryMapSize,
811 DescriptorSize,
812 DescriptorVersion,
813 MemoryMap
814 );
815 } else {
817 MemoryMapSize,
818 DescriptorSize,
819 DescriptorVersion,
820 MemoryMap
821 );
822 }
823
824 return Status;
825}
826
827EFI_STATUS
828EFIAPI
830 IN EFI_GET_VARIABLE GetVariable,
831 OUT EFI_GET_VARIABLE *OrgGetVariable OPTIONAL
832 )
833{
834 if (mCustomGetVariable != NULL) {
835 return EFI_ALREADY_STARTED;
836 }
837
838 mCustomGetVariable = GetVariable;
839
840 if (OrgGetVariable != NULL) {
841 *OrgGetVariable = mStoredGetVariable;
842 }
843
844 return EFI_SUCCESS;
845}
846
847EFI_STATUS
848EFIAPI
850 IN EFI_SET_VIRTUAL_ADDRESS_MAP SetAddressMap OPTIONAL,
851 IN BOOLEAN Enabled
852 )
853{
854 if (SetAddressMap != NULL) {
855 if (mCustomSetVirtualAddressMap != NULL) {
856 return EFI_ALREADY_STARTED;
857 }
858
859 mCustomSetVirtualAddressMap = SetAddressMap;
860 } else if (mCustomSetVirtualAddressMap == NULL) {
861 return EFI_NOT_FOUND;
862 }
863
865 return EFI_SUCCESS;
866}
867
868STATIC
869VOID
870EFIAPI
872 IN EFI_EVENT Event,
873 IN VOID *Context
874 )
875{
876 gRT->ConvertPointer (0, (VOID **)&mStoredGetTime);
877 gRT->ConvertPointer (0, (VOID **)&mStoredSetTime);
878 gRT->ConvertPointer (0, (VOID **)&mStoredGetWakeupTime);
879 gRT->ConvertPointer (0, (VOID **)&mStoredSetWakeupTime);
880 gRT->ConvertPointer (0, (VOID **)&mStoredGetVariable);
881 gRT->ConvertPointer (0, (VOID **)&mStoredGetNextVariableName);
882 gRT->ConvertPointer (0, (VOID **)&mStoredSetVariable);
883 gRT->ConvertPointer (0, (VOID **)&mStoredGetNextHighMonotonicCount);
884 gRT->ConvertPointer (0, (VOID **)&mStoredResetSystem);
885
886 gRT->ConvertPointer (0, (VOID **)&gCurrentConfig);
887 mCustomGetVariable = NULL;
888
889 //
890 // Ideally we do that from ExitBootServices, but VirtualAddressChange is fine as well.
891 //
892 mKernelStarted = TRUE;
893}
894
895VOID
897 VOID
898 )
899{
900 EFI_STATUS Status;
901
902 mStoredGetTime = gRT->GetTime;
903 mStoredSetTime = gRT->SetTime;
904 mStoredGetWakeupTime = gRT->GetWakeupTime;
905 mStoredSetWakeupTime = gRT->SetWakeupTime;
906 mStoredGetVariable = gRT->GetVariable;
907 mStoredGetNextVariableName = gRT->GetNextVariableName;
908 mStoredSetVariable = gRT->SetVariable;
909 mStoredGetNextHighMonotonicCount = gRT->GetNextHighMonotonicCount;
910 mStoredResetSystem = gRT->ResetSystem;
911 mSetVirtualAddressMap = gRT->SetVirtualAddressMap;
912
913 gRT->GetTime = WrapGetTime;
914 gRT->SetTime = WrapSetTime;
915 gRT->GetWakeupTime = WrapGetWakeupTime;
916 gRT->SetWakeupTime = WrapSetWakeupTime;
917 gRT->GetVariable = WrapGetVariable;
918 gRT->GetNextVariableName = WrapGetNextVariableName;
919 gRT->SetVariable = WrapSetVariable;
920 gRT->GetNextHighMonotonicCount = WrapGetNextHighMonotonicCount;
921 gRT->ResetSystem = WrapResetSystem;
922 gRT->SetVirtualAddressMap = WrapSetVirtualAddressMap;
923
924 gRT->Hdr.CRC32 = 0;
925 gBS->CalculateCrc32 (gRT, gRT->Hdr.HeaderSize, &gRT->Hdr.CRC32);
926
927 Status = gBS->CreateEvent (
928 EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE,
929 TPL_CALLBACK,
931 NULL,
933 );
934
935 ASSERT_EFI_ERROR (Status);
936}
#define ARRAY_SIZE(Array)
Definition AppleMacEfi.h:34
EFI_GUID gMicrosoftVariableGuid
DMG_SIZE_DEVICE_PATH Size
EFI_BOOT_SERVICES * gBS
#define L_STR_LEN(String)
Definition OcStringLib.h:26
#define L_STR_SIZE_NT(String)
Definition OcStringLib.h:44
EFI_GUID gOcWriteOnlyVariableGuid
EFI_GUID gOcReadOnlyVariableGuid
EFI_GUID gOcVendorVariableGuid
#define OC_VENDOR_BOOT_VARIABLE_PREFIX
Definition OcVariable.h:85
#define OC_VARIABLE_NAME_SIZE
STATIC EFI_RESET_SYSTEM mStoredResetSystem
VOID RedirectRuntimeServices(VOID)
STATIC BOOLEAN mCustomSetVirtualAddressMapEnabled
STATIC EFI_GET_NEXT_HIGH_MONO_COUNT mStoredGetNextHighMonotonicCount
STATIC EFI_SET_VARIABLE mStoredSetVariable
STATIC EFI_GET_TIME mStoredGetTime
STATIC VOID EFIAPI TranslateAddressesHandler(IN EFI_EVENT Event, IN VOID *Context)
STATIC EFI_SET_WAKEUP_TIME mStoredSetWakeupTime
STATIC EFI_SET_VIRTUAL_ADDRESS_MAP mSetVirtualAddressMap
STATIC EFI_STATUS EFIAPI WrapGetVariable(IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, OUT UINT32 *Attributes OPTIONAL, IN OUT UINTN *DataSize, OUT VOID *Data OPTIONAL)
STATIC EFI_EVENT mTranslateEvent
OC_FWRT_CONFIG gMainConfig
STATIC EFI_STATUS EFIAPI WrapGetNextVariableName(IN OUT UINTN *VariableNameSize, IN OUT CHAR16 *VariableName, IN OUT EFI_GUID *VendorGuid)
STATIC EFI_STATUS EFIAPI WrapGetTime(OUT EFI_TIME *Time, OUT EFI_TIME_CAPABILITIES *Capabilities OPTIONAL)
OC_FWRT_CONFIG * gCurrentConfig
EFI_STATUS EFIAPI FwOnGetVariable(IN EFI_GET_VARIABLE GetVariable, OUT EFI_GET_VARIABLE *OrgGetVariable OPTIONAL)
STATIC EFI_STATUS EFIAPI WrapSetVariable(IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN UINT32 Attributes, IN UINTN DataSize, IN VOID *Data)
STATIC EFI_GET_NEXT_VARIABLE_NAME mStoredGetNextVariableName
STATIC VOID Cr0QuirkPrologue(OUT BOOLEAN *Ints, OUT BOOLEAN *Wp, OUT BOOLEAN *Ts)
STATIC EFI_STATUS EFIAPI WrapSetVirtualAddressMap(IN UINTN MemoryMapSize, IN UINTN DescriptorSize, IN UINT32 DescriptorVersion, IN EFI_MEMORY_DESCRIPTOR *MemoryMap)
STATIC EFI_SET_VIRTUAL_ADDRESS_MAP mCustomSetVirtualAddressMap
STATIC BOOLEAN IsEfiBootVar(IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, OUT CHAR16 *NewVariableName OPTIONAL)
STATIC EFI_GET_VARIABLE mStoredGetVariable
STATIC EFI_GET_VARIABLE mCustomGetVariable
STATIC VOID Cr0QuirkEpilogue(IN BOOLEAN Ints, IN BOOLEAN Wp, IN BOOLEAN Ts)
EFI_STATUS EFIAPI FwOnSetAddressMap(IN EFI_SET_VIRTUAL_ADDRESS_MAP SetAddressMap OPTIONAL, IN BOOLEAN Enabled)
STATIC EFI_STATUS EFIAPI WrapGetNextHighMonotonicCount(OUT UINT32 *Count)
STATIC EFI_STATUS EFIAPI WrapSetWakeupTime(IN BOOLEAN Enable, IN EFI_TIME *Time OPTIONAL)
STATIC BOOLEAN IsOcBootVar(IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, OUT CHAR16 *NewVariableName OPTIONAL)
STATIC EFI_SET_TIME mStoredSetTime
STATIC EFI_STATUS EFIAPI WrapSetTime(IN EFI_TIME *Time)
STATIC VOID EFIAPI WrapResetSystem(IN EFI_RESET_TYPE ResetType, IN EFI_STATUS ResetStatus, IN UINTN DataSize, IN VOID *ResetData OPTIONAL)
STATIC EFI_GET_WAKEUP_TIME mStoredGetWakeupTime
OC_FWRT_CONFIG gOverrideConfig
STATIC EFI_STATUS EFIAPI WrapGetWakeupTime(OUT BOOLEAN *Enabled, OUT BOOLEAN *Pending, OUT EFI_TIME *Time)
STATIC BOOLEAN mKernelStarted
For file logging disable TPL checking in OcLogAddEntry.
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
GUID *EFIAPI CopyGuid(OUT GUID *DestinationGuid, IN CONST GUID *SourceGuid)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
EFI_RUNTIME_SERVICES * gRT
EFI_GUID gEfiGlobalVariableGuid
VOID EFIAPI EnableInterrupts(VOID)
Definition UserMisc.c:38