]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - EDK2/edk2_mod/edk2-edk2-stable201911/MdeModulePkg/Application/Ventoy/VentoyDebug.c
1.0.14 release
[Ventoy.git] / EDK2 / edk2_mod / edk2-edk2-stable201911 / MdeModulePkg / Application / Ventoy / VentoyDebug.c
1 /******************************************************************************
2 * Ventoy.c
3 *
4 * Copyright (c) 2020, longpanda <admin@ventoy.net>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 3 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21 #include <Uefi.h>
22 #include <Library/DebugLib.h>
23 #include <Library/PrintLib.h>
24 #include <Library/UefiLib.h>
25 #include <Library/BaseMemoryLib.h>
26 #include <Library/DevicePathLib.h>
27 #include <Library/MemoryAllocationLib.h>
28 #include <Library/UefiBootServicesTableLib.h>
29 #include <Library/UefiRuntimeServicesTableLib.h>
30 #include <Library/UefiApplicationEntryPoint.h>
31 #include <Protocol/LoadedImage.h>
32 #include <Guid/FileInfo.h>
33 #include <Guid/FileSystemInfo.h>
34 #include <Protocol/BlockIo.h>
35 #include <Protocol/RamDisk.h>
36 #include <Protocol/SimpleFileSystem.h>
37 #include <Ventoy.h>
38
39 #define PROCOTOL_SLEEP_SECONDS 0
40
41 #define debug_sleep() if (PROCOTOL_SLEEP_SECONDS) sleep(PROCOTOL_SLEEP_SECONDS)
42
43 STATIC ventoy_system_wrapper g_system_wrapper;
44
45 static struct well_known_guid g_efi_well_known_guids[] =
46 {
47 { &gEfiAbsolutePointerProtocolGuid, "AbsolutePointer" },
48 { &gEfiAcpiTableProtocolGuid, "AcpiTable" },
49 { &gEfiBlockIoProtocolGuid, "BlockIo" },
50 { &gEfiBlockIo2ProtocolGuid, "BlockIo2" },
51 { &gEfiBusSpecificDriverOverrideProtocolGuid, "BusSpecificDriverOverride" },
52 { &gEfiComponentNameProtocolGuid, "ComponentName" },
53 { &gEfiComponentName2ProtocolGuid, "ComponentName2" },
54 { &gEfiDevicePathProtocolGuid, "DevicePath" },
55 { &gEfiDriverBindingProtocolGuid, "DriverBinding" },
56 { &gEfiDiskIoProtocolGuid, "DiskIo" },
57 { &gEfiDiskIo2ProtocolGuid, "DiskIo2" },
58 { &gEfiGraphicsOutputProtocolGuid, "GraphicsOutput" },
59 { &gEfiHiiConfigAccessProtocolGuid, "HiiConfigAccess" },
60 { &gEfiHiiFontProtocolGuid, "HiiFont" },
61 { &gEfiLoadFileProtocolGuid, "LoadFile" },
62 { &gEfiLoadFile2ProtocolGuid, "LoadFile2" },
63 { &gEfiLoadedImageProtocolGuid, "LoadedImage" },
64 { &gEfiLoadedImageDevicePathProtocolGuid, "LoadedImageDevicePath"},
65 { &gEfiPciIoProtocolGuid, "PciIo" },
66 { &gEfiSerialIoProtocolGuid, "SerialIo" },
67 { &gEfiSimpleFileSystemProtocolGuid, "SimpleFileSystem" },
68 { &gEfiSimpleTextInProtocolGuid, "SimpleTextInput" },
69 { &gEfiSimpleTextInputExProtocolGuid, "SimpleTextInputEx" },
70 { &gEfiSimpleTextOutProtocolGuid, "SimpleTextOutput" },
71 };
72
73 STATIC CHAR8 gEfiGuidName[128];
74
75 static const char * ventoy_get_guid_name(EFI_GUID *guid)
76 {
77 UINTN i;
78
79 for (i = 0; i < ARRAY_SIZE(g_efi_well_known_guids); i++)
80 {
81 if (CompareGuid(g_efi_well_known_guids[i].guid, guid))
82 {
83 return g_efi_well_known_guids[i].name;
84 }
85 }
86
87 AsciiSPrint(gEfiGuidName, sizeof(gEfiGuidName), "%g", guid);
88 return gEfiGuidName;
89 }
90
91 STATIC EFI_STATUS EFIAPI ventoy_handle_protocol
92 (
93 IN EFI_HANDLE Handle,
94 IN EFI_GUID *Protocol,
95 OUT VOID **Interface
96 )
97 {
98 EFI_STATUS Status = EFI_SUCCESS;
99
100 debug("ventoy_handle_protocol:%a", ventoy_get_guid_name(Protocol)); debug_sleep();
101 Status = g_system_wrapper.OriHandleProtocol(Handle, Protocol, Interface);
102
103 if (CompareGuid(Protocol, &gEfiSimpleFileSystemProtocolGuid))
104 {
105 EFI_FILE_PROTOCOL *FileProtocol = NULL;
106 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *pFile = *((EFI_SIMPLE_FILE_SYSTEM_PROTOCOL **)(Interface));
107
108 pFile->OpenVolume(pFile, &FileProtocol);
109
110 trace("Handle FS Protocol: %p OpenVolume:%p, FileProtocol:%p, Open:%p",
111 pFile, pFile->OpenVolume, FileProtocol, FileProtocol->Open);
112
113 sleep(3);
114 }
115
116 return Status;
117 }
118
119 STATIC EFI_STATUS EFIAPI ventoy_open_protocol
120 (
121 IN EFI_HANDLE Handle,
122 IN EFI_GUID *Protocol,
123 OUT VOID **Interface, OPTIONAL
124 IN EFI_HANDLE AgentHandle,
125 IN EFI_HANDLE ControllerHandle,
126 IN UINT32 Attributes
127 )
128 {
129 debug("ventoy_open_protocol:%a", ventoy_get_guid_name(Protocol)); debug_sleep();
130 return g_system_wrapper.OriOpenProtocol(Handle, Protocol, Interface, AgentHandle, ControllerHandle, Attributes);
131 }
132
133 STATIC EFI_STATUS EFIAPI ventoy_locate_protocol
134 (
135 IN EFI_GUID *Protocol,
136 IN VOID *Registration, OPTIONAL
137 OUT VOID **Interface
138 )
139 {
140 debug("ventoy_locate_protocol:%a", ventoy_get_guid_name(Protocol)); debug_sleep();
141 return g_system_wrapper.OriLocateProtocol(Protocol, Registration, Interface);
142 }
143
144 EFI_STATUS EFIAPI ventoy_wrapper_system(VOID)
145 {
146 ventoy_wrapper(gBS, g_system_wrapper, LocateProtocol, ventoy_locate_protocol);
147 ventoy_wrapper(gBS, g_system_wrapper, HandleProtocol, ventoy_handle_protocol);
148 ventoy_wrapper(gBS, g_system_wrapper, OpenProtocol, ventoy_open_protocol);
149
150 return EFI_SUCCESS;
151 }
152