1 | /* $Id: SUPR0IdcClientStubs.c 96407 2022-08-22 17:43:14Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox Support Driver - IDC Client Lib, Stubs for SUPR0 APIs.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2008-2022 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 |
|
---|
38 | /*********************************************************************************************************************************
|
---|
39 | * Header Files *
|
---|
40 | *********************************************************************************************************************************/
|
---|
41 | #include "SUPR0IdcClientInternal.h"
|
---|
42 | #include <iprt/errcore.h>
|
---|
43 | #include <iprt/asm.h>
|
---|
44 |
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * Resolves a symbol.
|
---|
48 | *
|
---|
49 | * @returns Pointer to the symbol on success, NULL on failure.
|
---|
50 | *
|
---|
51 | * @param pHandle The IDC handle.
|
---|
52 | * @param ppfn Where to return the address of the symbol.
|
---|
53 | * @param pszName The name of the symbol.
|
---|
54 | */
|
---|
55 | static void supR0IdcGetSymbol(PSUPDRVIDCHANDLE pHandle, PFNRT *ppfn, const char *pszName)
|
---|
56 | {
|
---|
57 | SUPDRVIDCREQGETSYM Req;
|
---|
58 | int rc;
|
---|
59 |
|
---|
60 | /*
|
---|
61 | * Create and send a get symbol request.
|
---|
62 | */
|
---|
63 | Req.Hdr.cb = sizeof(Req);
|
---|
64 | Req.Hdr.rc = VERR_WRONG_ORDER;
|
---|
65 | Req.Hdr.pSession = pHandle->s.pSession;
|
---|
66 | Req.u.In.pszSymbol = pszName;
|
---|
67 | Req.u.In.pszModule = NULL;
|
---|
68 | rc = supR0IdcNativeCall(pHandle, SUPDRV_IDC_REQ_GET_SYMBOL, &Req.Hdr);
|
---|
69 | if (RT_SUCCESS(rc))
|
---|
70 | ASMAtomicWritePtr((void * volatile *)ppfn, (void *)(uintptr_t)Req.u.Out.pfnSymbol);
|
---|
71 | }
|
---|
72 |
|
---|
73 |
|
---|
74 | /**
|
---|
75 | * Resolves a symbol.
|
---|
76 | *
|
---|
77 | * @returns Pointer to the symbol on success, NULL on failure.
|
---|
78 | *
|
---|
79 | * @param pSession The IDC session.
|
---|
80 | * @param ppfn Where to return the address of the symbol.
|
---|
81 | * @param pszName The name of the symbol.
|
---|
82 | */
|
---|
83 | static void supR0IdcGetSymbolBySession(PSUPDRVSESSION pSession, PFNRT *ppfn, const char *pszName)
|
---|
84 | {
|
---|
85 | PSUPDRVIDCHANDLE pHandle = supR0IdcGetHandleFromSession(pSession);
|
---|
86 | if (pHandle)
|
---|
87 | supR0IdcGetSymbol(pHandle, ppfn, pszName);
|
---|
88 | }
|
---|
89 |
|
---|
90 |
|
---|
91 | SUPR0DECL(void *) SUPR0ObjRegister(PSUPDRVSESSION pSession, SUPDRVOBJTYPE enmType, PFNSUPDRVDESTRUCTOR pfnDestructor, void *pvUser1, void *pvUser2)
|
---|
92 | {
|
---|
93 | static DECLCALLBACKPTR(void *, s_pfn,(PSUPDRVSESSION /* pSession */, SUPDRVOBJTYPE /* enmType */, PFNSUPDRVDESTRUCTOR /* pfnDestructor */, void * /* pvUser1 */, void * /* pvUser2 */));
|
---|
94 | DECLCALLBACKPTR(void *, pfn,(PSUPDRVSESSION /* pSession */, SUPDRVOBJTYPE /* enmType */, PFNSUPDRVDESTRUCTOR /* pfnDestructor */, void * /* pvUser1 */, void * /* pvUser2 */));
|
---|
95 | pfn = s_pfn;
|
---|
96 | if (!pfn)
|
---|
97 | {
|
---|
98 | supR0IdcGetSymbolBySession(pSession, (PFNRT *)&s_pfn, "SUPR0ObjRegister");
|
---|
99 | pfn = s_pfn;
|
---|
100 | if (!pfn)
|
---|
101 | return NULL;
|
---|
102 | }
|
---|
103 |
|
---|
104 | return pfn(pSession, enmType, pfnDestructor, pvUser1, pvUser2);
|
---|
105 | }
|
---|
106 |
|
---|
107 |
|
---|
108 | SUPR0DECL(int) SUPR0ObjAddRef(void *pvObj, PSUPDRVSESSION pSession)
|
---|
109 | {
|
---|
110 | static DECLCALLBACKPTR(int, s_pfn,(void * /* pvObj */, PSUPDRVSESSION /* pSession */));
|
---|
111 | DECLCALLBACKPTR(int, pfn,(void * /* pvObj */, PSUPDRVSESSION /* pSession */));
|
---|
112 | pfn = s_pfn;
|
---|
113 | if (!pfn)
|
---|
114 | {
|
---|
115 | supR0IdcGetSymbolBySession(pSession, (PFNRT *)&s_pfn, "SUPR0ObjAddRef");
|
---|
116 | pfn = s_pfn;
|
---|
117 | if (!pfn)
|
---|
118 | return VERR_NOT_SUPPORTED;
|
---|
119 | }
|
---|
120 |
|
---|
121 | return pfn(pvObj, pSession);
|
---|
122 | }
|
---|
123 |
|
---|
124 |
|
---|
125 | SUPR0DECL(int) SUPR0ObjRelease(void *pvObj, PSUPDRVSESSION pSession)
|
---|
126 | {
|
---|
127 | static DECLCALLBACKPTR(int, s_pfn,(void * /* pvObj */, PSUPDRVSESSION /* pSession */));
|
---|
128 | DECLCALLBACKPTR(int, pfn,(void * /* pvObj */, PSUPDRVSESSION /* pSession */));
|
---|
129 | pfn = s_pfn;
|
---|
130 | if (!pfn)
|
---|
131 | {
|
---|
132 | supR0IdcGetSymbolBySession(pSession, (PFNRT *)&s_pfn, "SUPR0ObjRelease");
|
---|
133 | pfn = s_pfn;
|
---|
134 | if (!pfn)
|
---|
135 | return VERR_NOT_SUPPORTED;
|
---|
136 | }
|
---|
137 |
|
---|
138 | return pfn(pvObj, pSession);
|
---|
139 | }
|
---|
140 |
|
---|
141 |
|
---|
142 | SUPR0DECL(int) SUPR0ObjVerifyAccess(void *pvObj, PSUPDRVSESSION pSession, const char *pszObjName)
|
---|
143 | {
|
---|
144 | static DECLCALLBACKPTR(int, s_pfn,(void * /* pvObj */, PSUPDRVSESSION /* pSession */, const char * /* pszObjName */));
|
---|
145 | DECLCALLBACKPTR(int, pfn,(void * /* pvObj */, PSUPDRVSESSION /* pSession */, const char * /* pszObjName */));
|
---|
146 | pfn = s_pfn;
|
---|
147 | if (!pfn)
|
---|
148 | {
|
---|
149 | supR0IdcGetSymbolBySession(pSession, (PFNRT *)&s_pfn, "SUPR0ObjVerifyAccess");
|
---|
150 | pfn = s_pfn;
|
---|
151 | if (!pfn)
|
---|
152 | return VERR_NOT_SUPPORTED;
|
---|
153 | }
|
---|
154 |
|
---|
155 | return pfn(pvObj, pSession, pszObjName);
|
---|
156 | }
|
---|
157 |
|
---|