1 | /* $Id: VBoxMimicry.c 106061 2024-09-16 14:03:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxMimicry.c - Mimic table entry.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2009-2024 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * The contents of this file may alternatively be used under the terms
|
---|
26 | * of the Common Development and Distribution License Version 1.0
|
---|
27 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
28 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
29 | * CDDL are applicable instead of those of the GPL.
|
---|
30 | *
|
---|
31 | * You may elect to license modified versions of this file under the
|
---|
32 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
33 | *
|
---|
34 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
35 | */
|
---|
36 |
|
---|
37 | #include "VBoxMimicry.h"
|
---|
38 | #define VBOX_MIMICRY_VAR L"VBOX_MIMICRY"
|
---|
39 |
|
---|
40 | /*610467a0-d8a7-11de-a911-87667af93b7d*/
|
---|
41 | static EFI_GUID gVBoxMimicryVarGuid = { 0x610467a0, 0xd8a7, 0x11de, {0xa9, 0x11, 0x87, 0x66, 0x7a, 0xf9, 0x3b, 0x7d}};
|
---|
42 |
|
---|
43 | #define MIM_TBL_ENTRY(name, guid) DO_9_FAKE_DECL(name)
|
---|
44 | #include "mimic_tbl.h"
|
---|
45 | #undef MIM_TBL_ENTRY
|
---|
46 |
|
---|
47 | #define MIM_TBL_ENTRY(name, guid) \
|
---|
48 | static EFI_GUID gFake ## name = guid; \
|
---|
49 | static void *gFuncArray_ ## name [] = \
|
---|
50 | { \
|
---|
51 | name ## _fake_impl0, \
|
---|
52 | name ## _fake_impl1, \
|
---|
53 | name ## _fake_impl2, \
|
---|
54 | name ## _fake_impl3, \
|
---|
55 | name ## _fake_impl4, \
|
---|
56 | name ## _fake_impl5, \
|
---|
57 | name ## _fake_impl6, \
|
---|
58 | name ## _fake_impl7, \
|
---|
59 | name ## _fake_impl8, \
|
---|
60 | name ## _fake_impl9 \
|
---|
61 | };
|
---|
62 | #include "mimic_tbl.h"
|
---|
63 | #undef MIM_TBL_ENTRY
|
---|
64 |
|
---|
65 | #define MIM_TBL_ENTRY(name, guid) \
|
---|
66 | FAKE_IMPL(name ## _fake_impl0, gFake ## name) \
|
---|
67 | FAKE_IMPL(name ## _fake_impl1, gFake ## name) \
|
---|
68 | FAKE_IMPL(name ## _fake_impl2, gFake ## name) \
|
---|
69 | FAKE_IMPL(name ## _fake_impl3, gFake ## name) \
|
---|
70 | FAKE_IMPL(name ## _fake_impl4, gFake ## name) \
|
---|
71 | FAKE_IMPL(name ## _fake_impl5, gFake ## name) \
|
---|
72 | FAKE_IMPL(name ## _fake_impl6, gFake ## name) \
|
---|
73 | FAKE_IMPL(name ## _fake_impl7, gFake ## name) \
|
---|
74 | FAKE_IMPL(name ## _fake_impl8, gFake ## name) \
|
---|
75 | FAKE_IMPL(name ## _fake_impl9, gFake ## name)
|
---|
76 | #include "mimic_tbl.h"
|
---|
77 | #undef MIM_TBL_ENTRY
|
---|
78 |
|
---|
79 |
|
---|
80 |
|
---|
81 | EFI_STATUS
|
---|
82 | EFIAPI
|
---|
83 | VBoxMimicryInit(EFI_HANDLE hImage, EFI_SYSTEM_TABLE *pSysTable)
|
---|
84 | {
|
---|
85 | /* Set'n'check intercept variable */
|
---|
86 | EFI_STATUS r;
|
---|
87 | UINT32 val;
|
---|
88 | UINTN size = sizeof(UINT32);
|
---|
89 | r = gRT->GetVariable(VBOX_MIMICRY_VAR, &gVBoxMimicryVarGuid, NULL, &size, &val);
|
---|
90 | if ( EFI_ERROR(r)
|
---|
91 | && r == EFI_NOT_FOUND)
|
---|
92 | {
|
---|
93 | size = sizeof(UINT32);
|
---|
94 | val = 1;
|
---|
95 | r = gRT->SetVariable(VBOX_MIMICRY_VAR, &gVBoxMimicryVarGuid, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, size, &val);
|
---|
96 | if (EFI_ERROR(r))
|
---|
97 | {
|
---|
98 | DEBUG((DEBUG_INFO, "%a:%d - %r\n", __FILE__, __LINE__, r));
|
---|
99 | return r;
|
---|
100 | }
|
---|
101 | gThis = AllocateZeroPool(sizeof(VBOXMIMICRY));
|
---|
102 | r = install_mimic_interfaces();
|
---|
103 | if(EFI_ERROR(r))
|
---|
104 | {
|
---|
105 | DEBUG((DEBUG_INFO, "%a:%d - %r\n", __FILE__, __LINE__, r));
|
---|
106 | return r;
|
---|
107 | }
|
---|
108 | gThis->hImage = hImage;
|
---|
109 | return r;
|
---|
110 | }
|
---|
111 | if (!EFI_ERROR(r))
|
---|
112 | {
|
---|
113 | return EFI_ALREADY_STARTED;
|
---|
114 | }
|
---|
115 | return r;
|
---|
116 | }
|
---|
117 |
|
---|
118 | EFI_STATUS
|
---|
119 | EFIAPI
|
---|
120 | VBoxMimicryFini(EFI_HANDLE hImage)
|
---|
121 | {
|
---|
122 | EFI_STATUS r;
|
---|
123 | uninstall_mimic_interfaces();
|
---|
124 | FreePool(gThis);
|
---|
125 | r = gRT->SetVariable(VBOX_MIMICRY_VAR, &gVBoxMimicryVarGuid, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, 0, NULL);
|
---|
126 | if (EFI_ERROR(r))
|
---|
127 | {
|
---|
128 | DEBUG((DEBUG_INFO, "%a:%d - %r\n", __FILE__, __LINE__, r));
|
---|
129 | return r;
|
---|
130 | }
|
---|
131 | return EFI_SUCCESS;
|
---|
132 | }
|
---|
133 |
|
---|
134 | EFI_STATUS install_mimic_interfaces()
|
---|
135 | {
|
---|
136 | EFI_STATUS Status;
|
---|
137 | Status = gBS->InstallMultipleProtocolInterfaces (
|
---|
138 | &gThis->hImage,
|
---|
139 | #define MIM_TBL_ENTRY(name, guid) gFake##name, gFuncArray_##name,
|
---|
140 | #include "mimic_tbl.h"
|
---|
141 | #undef MIM_TBL_ENTRY
|
---|
142 | NULL);
|
---|
143 | return Status;
|
---|
144 | }
|
---|
145 | EFI_STATUS uninstall_mimic_interfaces()
|
---|
146 | {
|
---|
147 | EFI_STATUS Status;
|
---|
148 | Status = gBS->InstallMultipleProtocolInterfaces (
|
---|
149 | &gThis->hImage,
|
---|
150 | #define MIM_TBL_ENTRY(name, guid) gFake##name,
|
---|
151 | #include "mimic_tbl.h"
|
---|
152 | #undef MIM_TBL_ENTRY
|
---|
153 | NULL);
|
---|
154 | return Status;
|
---|
155 | }
|
---|