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