VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware/VBoxPkg/VBoxMimicryDxe/VBoxMimicry.c@ 108198

Last change on this file since 108198 was 106061, checked in by vboxsync, 5 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.0 KB
Line 
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*/
41static 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) \
48static EFI_GUID gFake ## name = guid; \
49static 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) \
66FAKE_IMPL(name ## _fake_impl0, gFake ## name) \
67FAKE_IMPL(name ## _fake_impl1, gFake ## name) \
68FAKE_IMPL(name ## _fake_impl2, gFake ## name) \
69FAKE_IMPL(name ## _fake_impl3, gFake ## name) \
70FAKE_IMPL(name ## _fake_impl4, gFake ## name) \
71FAKE_IMPL(name ## _fake_impl5, gFake ## name) \
72FAKE_IMPL(name ## _fake_impl6, gFake ## name) \
73FAKE_IMPL(name ## _fake_impl7, gFake ## name) \
74FAKE_IMPL(name ## _fake_impl8, gFake ## name) \
75FAKE_IMPL(name ## _fake_impl9, gFake ## name)
76#include "mimic_tbl.h"
77#undef MIM_TBL_ENTRY
78
79
80
81EFI_STATUS
82EFIAPI
83VBoxMimicryInit(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
118EFI_STATUS
119EFIAPI
120VBoxMimicryFini(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
134EFI_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}
145EFI_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}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette