VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware/VBoxPkg/VBoxInterceptorDxe/VBoxInterceptor.c

Last change on this file was 98103, checked in by vboxsync, 17 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: 3.8 KB
Line 
1/* $Id: VBoxInterceptor.c 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * VBoxIntercepter.c - Entry point.
4 */
5
6/*
7 * Copyright (C) 2009-2023 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#include "VBoxInterceptor.h"
37
38#define VBOX_INTERCEPTOR_VAR L"VBOX_INTERCEPTOR"
39/*8e7505ec-d103-11de-8dbb-678848bdcb46*/
40static EFI_GUID gVBoxInterceptorVarGuid = { 0x817505ec, 0xd103, 0x11de, {0x8d, 0xbb, 0x67, 0x88, 0x48, 0xbd, 0xcb, 0x46}};
41
42static int g_indent = 0;
43
44static char* getIndent(int count, int enter)
45{
46 static char buf[64];
47 int i;
48 char ch = enter ? '>' : '<';
49
50 for (i=0; i<count+1; i++)
51 buf[i] = ch;
52
53 buf[i++] = ' ';
54 buf[i] = 0;
55
56 return buf;
57}
58
59char* indentRight()
60{
61 return getIndent(g_indent++, 1);
62}
63
64char* indentLeft()
65{
66 return getIndent(--g_indent, 0);
67}
68
69
70EFI_STATUS
71EFIAPI
72VBoxInterceptorInit(EFI_HANDLE hImage, EFI_SYSTEM_TABLE *pSysTable)
73{
74 /* Set'n'check intercept variable */
75 EFI_STATUS r;
76 UINT32 val;
77 UINTN size = sizeof(UINT32);
78 r = gRT->GetVariable(VBOX_INTERCEPTOR_VAR, &gVBoxInterceptorVarGuid, NULL, &size, &val);
79 if ( EFI_ERROR(r)
80 && r == EFI_NOT_FOUND)
81 {
82 size = sizeof(UINT32);
83 val = 1;
84 r = gRT->SetVariable(VBOX_INTERCEPTOR_VAR, &gVBoxInterceptorVarGuid, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, size, &val);
85 if (EFI_ERROR(r))
86 {
87 DEBUG((DEBUG_INFO, "%a:%d - %r\n", __FILE__, __LINE__, r));
88 return r;
89 }
90 /* intercept installation */
91 gThis = AllocateZeroPool(sizeof(VBOXINTERCEPTOR));
92 r = install_bs_interceptors();
93 if(EFI_ERROR(r))
94 {
95 DEBUG((DEBUG_INFO, "%a:%d - %r\n", __FILE__, __LINE__, r));
96 return r;
97 }
98
99 r = install_rt_interceptors();
100 if(EFI_ERROR(r))
101 {
102 DEBUG((DEBUG_INFO, "%a:%d - %r\n", __FILE__, __LINE__, r));
103 return r;
104 }
105 return r;
106 }
107 if (!EFI_ERROR(r))
108 {
109 return EFI_ALREADY_STARTED;
110 }
111 return r;
112}
113
114EFI_STATUS
115EFIAPI
116VBoxInterceptorFini(EFI_HANDLE hImage)
117{
118 EFI_STATUS r;
119 uninstall_rt_interceptors();
120 uninstall_bs_interceptors();
121 FreePool(gThis);
122 r = gRT->SetVariable(VBOX_INTERCEPTOR_VAR, &gVBoxInterceptorVarGuid, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, 0, NULL);
123 if (EFI_ERROR(r))
124 {
125 DEBUG((DEBUG_INFO, "%a:%d - %r\n", __FILE__, __LINE__, r));
126 return r;
127 }
128 return EFI_SUCCESS;
129}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use