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