VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/Support/SUPLib.cpp@ 108724

Last change on this file since 108724 was 108724, checked in by vboxsync, 3 weeks ago

HostDrivers/Support: Make SUPR3 work on hosts where the page size is not known during compile time, bugref:10391

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 85.7 KB
Line 
1/* $Id: SUPLib.cpp 108724 2025-03-24 18:53:21Z vboxsync $ */
2/** @file
3 * VirtualBox Support Library - Common code.
4 */
5
6/*
7 * Copyright (C) 2006-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/** @page pg_sup SUP - The Support Library
38 *
39 * The support library is responsible for providing facilities to load
40 * VMM Host Ring-0 code, to call Host VMM Ring-0 code from Ring-3 Host
41 * code, to pin down physical memory, and more.
42 *
43 * The VMM Host Ring-0 code can be combined in the support driver if
44 * permitted by kernel module license policies. If it is not combined
45 * it will be externalized in a .r0 module that will be loaded using
46 * the IPRT loader.
47 *
48 * The Ring-0 calling is done thru a generic SUP interface which will
49 * transfer an argument set and call a predefined entry point in the Host
50 * VMM Ring-0 code.
51 *
52 * See @ref grp_sup "SUP - Support APIs" for API details.
53 */
54
55
56/*********************************************************************************************************************************
57* Header Files *
58*********************************************************************************************************************************/
59#define LOG_GROUP LOG_GROUP_SUP
60#include <VBox/sup.h>
61#include <VBox/err.h>
62#include <VBox/param.h>
63#include <VBox/log.h>
64#include <VBox/VBoxTpG.h>
65
66#include <iprt/assert.h>
67#include <iprt/alloc.h>
68#include <iprt/alloca.h>
69#include <iprt/ldr.h>
70#include <iprt/asm.h>
71#include <iprt/mp.h>
72#include <iprt/cpuset.h>
73#include <iprt/thread.h>
74#include <iprt/process.h>
75#include <iprt/path.h>
76#include <iprt/string.h>
77#include <iprt/system.h>
78#include <iprt/env.h>
79#include <iprt/rand.h>
80#include <iprt/x86.h>
81
82#include "SUPDrvIOC.h"
83#include "SUPLibInternal.h"
84
85
86/*********************************************************************************************************************************
87* Defined Constants And Macros *
88*********************************************************************************************************************************/
89/** R0 VMM module name. */
90#define VMMR0_NAME "VMMR0"
91
92
93/*********************************************************************************************************************************
94* Structures and Typedefs *
95*********************************************************************************************************************************/
96typedef DECLCALLBACKTYPE(int, FNCALLVMMR0,(PVMR0 pVMR0, unsigned uOperation, void *pvArg));
97typedef FNCALLVMMR0 *PFNCALLVMMR0;
98
99
100/*********************************************************************************************************************************
101* Global Variables *
102*********************************************************************************************************************************/
103/** Init counter. */
104static uint32_t g_cInits = 0;
105/** Whether we've been preinitied. */
106static bool g_fPreInited = false;
107/** The SUPLib instance data.
108 * Well, at least parts of it, specifically the parts that are being handed over
109 * via the pre-init mechanism from the hardened executable stub. */
110DECL_HIDDEN_DATA(SUPLIBDATA) g_supLibData =
111{
112 /*.hDevice = */ SUP_HDEVICE_NIL,
113 /*.fUnrestricted = */ true,
114 /*.fDriverless = */ false
115#if defined(RT_OS_DARWIN)
116 ,/* .uConnection = */ 0
117#elif defined(RT_OS_LINUX)
118 ,/* .fSysMadviseWorks = */ false
119#endif
120};
121
122/** Pointer to the Global Information Page.
123 *
124 * This pointer is valid as long as SUPLib has a open session. Anyone using
125 * the page must treat this pointer as highly volatile and not trust it beyond
126 * one transaction.
127 *
128 * @todo This will probably deserve it's own session or some other good solution...
129 */
130DECLEXPORT(PSUPGLOBALINFOPAGE) g_pSUPGlobalInfoPage;
131/** Address of the ring-0 mapping of the GIP. */
132PSUPGLOBALINFOPAGE g_pSUPGlobalInfoPageR0;
133/** The physical address of the GIP. */
134static RTHCPHYS g_HCPhysSUPGlobalInfoPage = NIL_RTHCPHYS;
135
136/** The negotiated cookie. */
137DECL_HIDDEN_DATA(uint32_t) g_u32Cookie = 0;
138/** The negotiated session cookie. */
139DECL_HIDDEN_DATA(uint32_t) g_u32SessionCookie;
140/** The session version. */
141DECL_HIDDEN_DATA(uint32_t) g_uSupSessionVersion = 0;
142/** Session handle. */
143DECL_HIDDEN_DATA(PSUPDRVSESSION) g_pSession;
144/** R0 SUP Functions used for resolving referenced to the SUPR0 module. */
145DECL_HIDDEN_DATA(PSUPQUERYFUNCS) g_pSupFunctions;
146
147/** PAGE_ALLOC_EX sans kernel mapping support indicator. */
148static bool g_fSupportsPageAllocNoKernel = true;
149/** Fake mode indicator. (~0 at first, 0 or 1 after first test) */
150DECL_HIDDEN_DATA(uint32_t) g_uSupFakeMode = UINT32_MAX;
151
152
153/*********************************************************************************************************************************
154* Internal Functions *
155*********************************************************************************************************************************/
156static int supInitFake(PSUPDRVSESSION *ppSession);
157
158
159#ifdef RT_OS_DARWIN
160/** Touch a range of pages. */
161DECLINLINE(void) supR3TouchPages(void *pv, size_t cPages)
162{
163 uint32_t volatile *pu32 = (uint32_t volatile *)pv;
164 while (cPages-- > 0)
165 {
166 ASMAtomicCmpXchgU32(pu32, 0, 0);
167 pu32 += PAGE_SIZE / sizeof(uint32_t);
168 }
169}
170#endif
171
172
173SUPR3DECL(int) SUPR3Install(void)
174{
175 return suplibOsInstall();
176}
177
178
179SUPR3DECL(int) SUPR3Uninstall(void)
180{
181 return suplibOsUninstall();
182}
183
184
185DECL_NOTHROW(DECLEXPORT(int)) supR3PreInit(PSUPPREINITDATA pPreInitData, uint32_t fFlags)
186{
187 /*
188 * The caller is kind of trustworthy, just perform some basic checks.
189 *
190 * Note! Do not do any fancy stuff here because IPRT has NOT been
191 * initialized at this point.
192 */
193 if (!RT_VALID_PTR(pPreInitData))
194 return VERR_INVALID_POINTER;
195 if (g_fPreInited || g_cInits > 0)
196 return VERR_WRONG_ORDER;
197
198 if ( pPreInitData->u32Magic != SUPPREINITDATA_MAGIC
199 || pPreInitData->u32EndMagic != SUPPREINITDATA_MAGIC)
200 return VERR_INVALID_MAGIC;
201 if ( !(fFlags & SUPSECMAIN_FLAGS_DONT_OPEN_DEV)
202 && pPreInitData->Data.hDevice == SUP_HDEVICE_NIL
203 && !pPreInitData->Data.fDriverless)
204 return VERR_INVALID_HANDLE;
205 if ( ( (fFlags & SUPSECMAIN_FLAGS_DONT_OPEN_DEV)
206 || pPreInitData->Data.fDriverless)
207 && pPreInitData->Data.hDevice != SUP_HDEVICE_NIL)
208 return VERR_INVALID_PARAMETER;
209
210 /*
211 * Hand out the data.
212 */
213 int rc = supR3HardenedRecvPreInitData(pPreInitData);
214 if (RT_FAILURE(rc))
215 return rc;
216
217 /** @todo This may need some small restructuring later, it doesn't quite work with a root service flag... */
218 if (!(fFlags & SUPSECMAIN_FLAGS_DONT_OPEN_DEV))
219 {
220 g_supLibData = pPreInitData->Data;
221 g_fPreInited = true;
222 }
223
224 return VINF_SUCCESS;
225}
226
227
228SUPR3DECL(int) SUPR3InitEx(uint32_t fFlags, PSUPDRVSESSION *ppSession)
229{
230 /*
231 * Perform some sanity checks.
232 * (Got some trouble with compile time member alignment assertions.)
233 */
234 Assert(!(RT_UOFFSETOF(SUPGLOBALINFOPAGE, u64NanoTSLastUpdateHz) & 0x7));
235 Assert(!(RT_UOFFSETOF(SUPGLOBALINFOPAGE, aCPUs) & 0x1f));
236 Assert(!(RT_UOFFSETOF(SUPGLOBALINFOPAGE, aCPUs[1]) & 0x1f));
237 Assert(!(RT_UOFFSETOF(SUPGLOBALINFOPAGE, aCPUs[0].u64NanoTS) & 0x7));
238 Assert(!(RT_UOFFSETOF(SUPGLOBALINFOPAGE, aCPUs[0].u64TSC) & 0x7));
239 Assert(!(RT_UOFFSETOF(SUPGLOBALINFOPAGE, aCPUs[0].u64CpuHz) & 0x7));
240
241#ifdef VBOX_WITH_DRIVERLESS_FORCED
242 fFlags |= SUPR3INIT_F_DRIVERLESS;
243 fFlags &= ~SUPR3INIT_F_UNRESTRICTED;
244#endif
245
246 /*
247 * Check if already initialized.
248 */
249 if (ppSession)
250 *ppSession = g_pSession;
251 if (g_cInits++ > 0)
252 {
253 if ( (fFlags & SUPR3INIT_F_UNRESTRICTED)
254 && !g_supLibData.fUnrestricted
255 && !g_supLibData.fDriverless)
256 {
257 g_cInits--;
258 if (ppSession)
259 *ppSession = NIL_RTR0PTR;
260 return VERR_VM_DRIVER_NOT_ACCESSIBLE; /** @todo different status code? */
261 }
262 return VINF_SUCCESS;
263 }
264
265 /*
266 * Check for fake mode.
267 *
268 * Fake mode is used when we're doing smoke testing and debugging.
269 * It's also useful on platforms where we haven't root access or which
270 * we haven't ported the support driver to.
271 */
272 if (g_uSupFakeMode == ~0U)
273 {
274 const char *psz = RTEnvGet("VBOX_SUPLIB_FAKE");
275 if (psz && !strcmp(psz, "fake"))
276 ASMAtomicCmpXchgU32(&g_uSupFakeMode, 1, ~0U);
277 else
278 ASMAtomicCmpXchgU32(&g_uSupFakeMode, 0, ~0U);
279 }
280 if (RT_UNLIKELY(g_uSupFakeMode))
281 return supInitFake(ppSession);
282
283 /*
284 * Open the support driver.
285 */
286 SUPINITOP enmWhat = kSupInitOp_Driver;
287 int rc = suplibOsInit(&g_supLibData, g_fPreInited, fFlags, &enmWhat, NULL);
288 if (RT_SUCCESS(rc) && !g_supLibData.fDriverless)
289 {
290 /*
291 * Negotiate the cookie.
292 */
293 SUPCOOKIE CookieReq;
294 memset(&CookieReq, 0xff, sizeof(CookieReq));
295 CookieReq.Hdr.u32Cookie = SUPCOOKIE_INITIAL_COOKIE;
296 CookieReq.Hdr.u32SessionCookie = RTRandU32();
297 CookieReq.Hdr.cbIn = SUP_IOCTL_COOKIE_SIZE_IN;
298 CookieReq.Hdr.cbOut = SUP_IOCTL_COOKIE_SIZE_OUT;
299 CookieReq.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT;
300 CookieReq.Hdr.rc = VERR_INTERNAL_ERROR;
301 strcpy(CookieReq.u.In.szMagic, SUPCOOKIE_MAGIC);
302 CookieReq.u.In.u32ReqVersion = SUPDRV_IOC_VERSION;
303 const uint32_t uMinVersion = (SUPDRV_IOC_VERSION & 0xffff0000) == 0x00340000
304 ? 0x00340001
305 : SUPDRV_IOC_VERSION & 0xffff0000;
306 CookieReq.u.In.u32MinVersion = uMinVersion;
307 rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_COOKIE, &CookieReq, SUP_IOCTL_COOKIE_SIZE);
308 if ( RT_SUCCESS(rc)
309 && RT_SUCCESS(CookieReq.Hdr.rc))
310 {
311 g_uSupSessionVersion = CookieReq.u.Out.u32SessionVersion;
312 if ( (CookieReq.u.Out.u32SessionVersion & 0xffff0000) == (SUPDRV_IOC_VERSION & 0xffff0000)
313 && CookieReq.u.Out.u32SessionVersion >= uMinVersion)
314 {
315 /*
316 * Query the functions.
317 */
318 PSUPQUERYFUNCS pFuncsReq = NULL;
319 if (g_supLibData.fUnrestricted)
320 {
321 pFuncsReq = (PSUPQUERYFUNCS)RTMemAllocZ(SUP_IOCTL_QUERY_FUNCS_SIZE(CookieReq.u.Out.cFunctions));
322 if (pFuncsReq)
323 {
324 pFuncsReq->Hdr.u32Cookie = CookieReq.u.Out.u32Cookie;
325 pFuncsReq->Hdr.u32SessionCookie = CookieReq.u.Out.u32SessionCookie;
326 pFuncsReq->Hdr.cbIn = SUP_IOCTL_QUERY_FUNCS_SIZE_IN;
327 pFuncsReq->Hdr.cbOut = SUP_IOCTL_QUERY_FUNCS_SIZE_OUT(CookieReq.u.Out.cFunctions);
328 pFuncsReq->Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT;
329 pFuncsReq->Hdr.rc = VERR_INTERNAL_ERROR;
330 rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_QUERY_FUNCS(CookieReq.u.Out.cFunctions), pFuncsReq,
331 SUP_IOCTL_QUERY_FUNCS_SIZE(CookieReq.u.Out.cFunctions));
332 if (RT_SUCCESS(rc))
333 rc = pFuncsReq->Hdr.rc;
334 if (RT_SUCCESS(rc))
335 {
336 /*
337 * Map the GIP into userspace.
338 */
339 Assert(!g_pSUPGlobalInfoPage);
340 SUPGIPMAP GipMapReq;
341 GipMapReq.Hdr.u32Cookie = CookieReq.u.Out.u32Cookie;
342 GipMapReq.Hdr.u32SessionCookie = CookieReq.u.Out.u32SessionCookie;
343 GipMapReq.Hdr.cbIn = SUP_IOCTL_GIP_MAP_SIZE_IN;
344 GipMapReq.Hdr.cbOut = SUP_IOCTL_GIP_MAP_SIZE_OUT;
345 GipMapReq.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT;
346 GipMapReq.Hdr.rc = VERR_INTERNAL_ERROR;
347 GipMapReq.u.Out.HCPhysGip = NIL_RTHCPHYS;
348 GipMapReq.u.Out.pGipR0 = NIL_RTR0PTR;
349 GipMapReq.u.Out.pGipR3 = NULL;
350 rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_GIP_MAP, &GipMapReq, SUP_IOCTL_GIP_MAP_SIZE);
351 if (RT_SUCCESS(rc))
352 rc = GipMapReq.Hdr.rc;
353 if (RT_SUCCESS(rc))
354 {
355 /*
356 * Set the GIP globals.
357 */
358 AssertRelease(GipMapReq.u.Out.pGipR3->u32Magic == SUPGLOBALINFOPAGE_MAGIC);
359 AssertRelease(GipMapReq.u.Out.pGipR3->u32Version >= SUPGLOBALINFOPAGE_VERSION);
360
361 ASMAtomicXchgSize(&g_HCPhysSUPGlobalInfoPage, GipMapReq.u.Out.HCPhysGip);
362 ASMAtomicCmpXchgPtr((void * volatile *)&g_pSUPGlobalInfoPage, GipMapReq.u.Out.pGipR3, NULL);
363 ASMAtomicCmpXchgPtr((void * volatile *)&g_pSUPGlobalInfoPageR0, (void *)GipMapReq.u.Out.pGipR0, NULL);
364 }
365 }
366 }
367 else
368 rc = VERR_NO_MEMORY;
369 }
370
371 if (RT_SUCCESS(rc))
372 {
373 /*
374 * Set the globals and return success.
375 */
376 g_u32Cookie = CookieReq.u.Out.u32Cookie;
377 g_u32SessionCookie = CookieReq.u.Out.u32SessionCookie;
378 g_pSession = CookieReq.u.Out.pSession;
379 g_pSupFunctions = pFuncsReq;
380 if (ppSession)
381 *ppSession = CookieReq.u.Out.pSession;
382 return VINF_SUCCESS;
383 }
384
385 /* bailout */
386 RTMemFree(pFuncsReq);
387 }
388 else
389 {
390 LogRel(("Support driver version mismatch: SessionVersion=%#x DriverVersion=%#x ClientVersion=%#x MinVersion=%#x\n",
391 CookieReq.u.Out.u32SessionVersion, CookieReq.u.Out.u32DriverVersion, SUPDRV_IOC_VERSION, uMinVersion));
392 rc = VERR_VM_DRIVER_VERSION_MISMATCH;
393 }
394 }
395 else
396 {
397 if (RT_SUCCESS(rc))
398 {
399 rc = CookieReq.Hdr.rc;
400 LogRel(("Support driver version mismatch: DriverVersion=%#x ClientVersion=%#x rc=%Rrc\n",
401 CookieReq.u.Out.u32DriverVersion, SUPDRV_IOC_VERSION, rc));
402 if (rc != VERR_VM_DRIVER_VERSION_MISMATCH)
403 rc = VERR_VM_DRIVER_VERSION_MISMATCH;
404 }
405 else
406 {
407 /* for pre 0x00060000 drivers */
408 LogRel(("Support driver version mismatch: DriverVersion=too-old ClientVersion=%#x\n", SUPDRV_IOC_VERSION));
409 rc = VERR_VM_DRIVER_VERSION_MISMATCH;
410 }
411 }
412
413 suplibOsTerm(&g_supLibData);
414 }
415 else if (RT_SUCCESS(rc))
416 {
417 /*
418 * Driverless initialization.
419 */
420 Assert(fFlags & SUPR3INIT_F_DRIVERLESS_MASK);
421 LogRel(("SUP: In driverless mode.\n"));
422 return VINF_SUCCESS;
423 }
424
425 g_cInits--;
426
427 return rc;
428}
429
430
431SUPR3DECL(int) SUPR3Init(PSUPDRVSESSION *ppSession)
432{
433#ifndef VBOX_WITH_DRIVERLESS_FORCED
434 return SUPR3InitEx(SUPR3INIT_F_UNRESTRICTED, ppSession);
435#else
436 return SUPR3InitEx(SUPR3INIT_F_DRIVERLESS, ppSession);
437#endif
438}
439
440/**
441 * Fake mode init.
442 */
443static int supInitFake(PSUPDRVSESSION *ppSession)
444{
445 Log(("SUP: Fake mode!\n"));
446 static const SUPFUNC s_aFakeFunctions[] =
447 {
448 /* name 0, function */
449 { "SUPR0AbsIs64bit", 0, 0 },
450 { "SUPR0Abs64bitKernelCS", 0, 0 },
451 { "SUPR0Abs64bitKernelSS", 0, 0 },
452 { "SUPR0Abs64bitKernelDS", 0, 0 },
453 { "SUPR0AbsKernelCS", 0, 8 },
454 { "SUPR0AbsKernelSS", 0, 16 },
455 { "SUPR0AbsKernelDS", 0, 16 },
456 { "SUPR0AbsKernelES", 0, 16 },
457 { "SUPR0AbsKernelFS", 0, 24 },
458 { "SUPR0AbsKernelGS", 0, 32 },
459 { "SUPR0ComponentRegisterFactory", 0, 0xefeefffd },
460 { "SUPR0ComponentDeregisterFactory", 0, 0xefeefffe },
461 { "SUPR0ComponentQueryFactory", 0, 0xefeeffff },
462 { "SUPR0ObjRegister", 0, 0xefef0000 },
463 { "SUPR0ObjAddRef", 0, 0xefef0001 },
464 { "SUPR0ObjAddRefEx", 0, 0xefef0001 },
465 { "SUPR0ObjRelease", 0, 0xefef0002 },
466 { "SUPR0ObjVerifyAccess", 0, 0xefef0003 },
467 { "SUPR0LockMem", 0, 0xefef0004 },
468 { "SUPR0UnlockMem", 0, 0xefef0005 },
469 { "SUPR0ContAlloc", 0, 0xefef0006 },
470 { "SUPR0ContFree", 0, 0xefef0007 },
471 { "SUPR0MemAlloc", 0, 0xefef0008 },
472 { "SUPR0MemGetPhys", 0, 0xefef0009 },
473 { "SUPR0MemFree", 0, 0xefef000a },
474 { "SUPR0Printf", 0, 0xefef000b },
475 { "SUPR0GetPagingMode", 0, 0xefef000c },
476 { "SUPR0EnableVTx", 0, 0xefef000e },
477 { "RTMemAlloc", 0, 0xefef000f },
478 { "RTMemAllocZ", 0, 0xefef0010 },
479 { "RTMemFree", 0, 0xefef0011 },
480 { "RTR0MemObjAddress", 0, 0xefef0012 },
481 { "RTR0MemObjAddressR3", 0, 0xefef0013 },
482 { "RTR0MemObjAllocPage", 0, 0xefef0014 },
483 { "RTR0MemObjAllocPhysNC", 0, 0xefef0015 },
484 { "RTR0MemObjAllocLow", 0, 0xefef0016 },
485 { "RTR0MemObjEnterPhys", 0, 0xefef0017 },
486 { "RTR0MemObjFree", 0, 0xefef0018 },
487 { "RTR0MemObjGetPagePhysAddr", 0, 0xefef0019 },
488 { "RTR0MemObjMapUser", 0, 0xefef001a },
489 { "RTR0MemObjMapKernel", 0, 0xefef001b },
490 { "RTR0MemObjMapKernelEx", 0, 0xefef001c },
491 { "RTMpGetArraySize", 0, 0xefef001c },
492 { "RTProcSelf", 0, 0xefef001d },
493 { "RTR0ProcHandleSelf", 0, 0xefef001e },
494 { "RTSemEventCreate", 0, 0xefef001f },
495 { "RTSemEventSignal", 0, 0xefef0020 },
496 { "RTSemEventWait", 0, 0xefef0021 },
497 { "RTSemEventWaitNoResume", 0, 0xefef0022 },
498 { "RTSemEventDestroy", 0, 0xefef0023 },
499 { "RTSemEventMultiCreate", 0, 0xefef0024 },
500 { "RTSemEventMultiSignal", 0, 0xefef0025 },
501 { "RTSemEventMultiReset", 0, 0xefef0026 },
502 { "RTSemEventMultiWait", 0, 0xefef0027 },
503 { "RTSemEventMultiWaitNoResume", 0, 0xefef0028 },
504 { "RTSemEventMultiDestroy", 0, 0xefef0029 },
505 { "RTSemFastMutexCreate", 0, 0xefef002a },
506 { "RTSemFastMutexDestroy", 0, 0xefef002b },
507 { "RTSemFastMutexRequest", 0, 0xefef002c },
508 { "RTSemFastMutexRelease", 0, 0xefef002d },
509 { "RTSpinlockCreate", 0, 0xefef002e },
510 { "RTSpinlockDestroy", 0, 0xefef002f },
511 { "RTSpinlockAcquire", 0, 0xefef0030 },
512 { "RTSpinlockRelease", 0, 0xefef0031 },
513 { "RTSpinlockAcquireNoInts", 0, 0xefef0032 },
514 { "RTTimeNanoTS", 0, 0xefef0034 },
515 { "RTTimeMillieTS", 0, 0xefef0035 },
516 { "RTTimeSystemNanoTS", 0, 0xefef0036 },
517 { "RTTimeSystemMillieTS", 0, 0xefef0037 },
518 { "RTThreadNativeSelf", 0, 0xefef0038 },
519 { "RTThreadSleep", 0, 0xefef0039 },
520 { "RTThreadYield", 0, 0xefef003a },
521 { "RTTimerCreate", 0, 0xefef003a },
522 { "RTTimerCreateEx", 0, 0xefef003a },
523 { "RTTimerDestroy", 0, 0xefef003a },
524 { "RTTimerStart", 0, 0xefef003a },
525 { "RTTimerStop", 0, 0xefef003a },
526 { "RTTimerChangeInterval", 0, 0xefef003a },
527 { "RTTimerGetSystemGranularity", 0, 0xefef003a },
528 { "RTTimerRequestSystemGranularity", 0, 0xefef003a },
529 { "RTTimerReleaseSystemGranularity", 0, 0xefef003a },
530 { "RTTimerCanDoHighResolution", 0, 0xefef003a },
531 { "RTLogDefaultInstance", 0, 0xefef003b },
532 { "RTLogRelGetDefaultInstance", 0, 0xefef003c },
533 { "RTLogSetDefaultInstanceThread", 0, 0xefef003d },
534 { "RTLogLogger", 0, 0xefef003e },
535 { "RTLogLoggerEx", 0, 0xefef003f },
536 { "RTLogLoggerExV", 0, 0xefef0040 },
537 { "RTAssertMsg1", 0, 0xefef0041 },
538 { "RTAssertMsg2", 0, 0xefef0042 },
539 { "RTAssertMsg2V", 0, 0xefef0043 },
540 { "SUPR0QueryVTCaps", 0, 0xefef0044 },
541 };
542
543 /* fake r0 functions. */
544 g_pSupFunctions = (PSUPQUERYFUNCS)RTMemAllocZ(SUP_IOCTL_QUERY_FUNCS_SIZE(RT_ELEMENTS(s_aFakeFunctions)));
545 if (g_pSupFunctions)
546 {
547 g_pSupFunctions->u.Out.cFunctions = RT_ELEMENTS(s_aFakeFunctions);
548 memcpy(&g_pSupFunctions->u.Out.aFunctions[0], &s_aFakeFunctions[0], sizeof(s_aFakeFunctions));
549 g_pSession = (PSUPDRVSESSION)(void *)g_pSupFunctions;
550 if (ppSession)
551 *ppSession = g_pSession;
552
553 /* fake the GIP. */
554 g_pSUPGlobalInfoPage = (PSUPGLOBALINFOPAGE)RTMemPageAllocZ(SUP_PAGE_SIZE);
555 if (g_pSUPGlobalInfoPage)
556 {
557 g_pSUPGlobalInfoPageR0 = g_pSUPGlobalInfoPage;
558 g_HCPhysSUPGlobalInfoPage = NIL_RTHCPHYS & ~(RTHCPHYS)SUP_PAGE_OFFSET_MASK;
559 /* the page is supposed to be invalid, so don't set the magic. */
560 return VINF_SUCCESS;
561 }
562
563 RTMemFree(g_pSupFunctions);
564 g_pSupFunctions = NULL;
565 }
566 return VERR_NO_MEMORY;
567}
568
569
570SUPR3DECL(int) SUPR3Term(bool fForced)
571{
572 /*
573 * Verify state.
574 */
575 AssertMsg(g_cInits > 0, ("SUPR3Term() is called before SUPR3Init()!\n"));
576 if (g_cInits == 0)
577 return VERR_WRONG_ORDER;
578 if (g_cInits == 1 || fForced)
579 {
580 /*
581 * NULL the GIP pointer.
582 */
583 if (g_pSUPGlobalInfoPage)
584 {
585 ASMAtomicWriteNullPtr((void * volatile *)&g_pSUPGlobalInfoPage);
586 ASMAtomicWriteNullPtr((void * volatile *)&g_pSUPGlobalInfoPageR0);
587 ASMAtomicWriteU64(&g_HCPhysSUPGlobalInfoPage, NIL_RTHCPHYS);
588 /* just a little safe guard against threads using the page. */
589 RTThreadSleep(50);
590 }
591
592 /*
593 * Close the support driver.
594 */
595 int rc = suplibOsTerm(&g_supLibData);
596 if (rc)
597 return rc;
598
599 g_supLibData.hDevice = SUP_HDEVICE_NIL;
600 g_supLibData.fUnrestricted = true;
601 g_supLibData.fDriverless = false;
602 g_u32Cookie = 0;
603 g_u32SessionCookie = 0;
604 g_cInits = 0;
605 }
606 else
607 g_cInits--;
608
609 return 0;
610}
611
612
613SUPR3DECL(bool) SUPR3IsDriverless(void)
614{
615 /* Assert(g_cInits > 0); - tstSSM does not initialize SUP, but SSM calls to
616 check status, so return driverless if not initialized. */
617 return g_supLibData.fDriverless || g_cInits == 0;
618}
619
620
621SUPR3DECL(SUPPAGINGMODE) SUPR3GetPagingMode(void)
622{
623 /*
624 * Deal with driverless first.
625 */
626 if (g_supLibData.fDriverless)
627#if defined(RT_ARCH_AMD64)
628 return SUPPAGINGMODE_AMD64_GLOBAL_NX;
629#elif defined(RT_ARCH_X86)
630 return SUPPAGINGMODE_32_BIT_GLOBAL;
631#else
632 return SUPPAGINGMODE_INVALID;
633#endif
634
635 /*
636 * Issue IOCtl to the SUPDRV kernel module.
637 */
638 SUPGETPAGINGMODE Req;
639 Req.Hdr.u32Cookie = g_u32Cookie;
640 Req.Hdr.u32SessionCookie = g_u32SessionCookie;
641 Req.Hdr.cbIn = SUP_IOCTL_GET_PAGING_MODE_SIZE_IN;
642 Req.Hdr.cbOut = SUP_IOCTL_GET_PAGING_MODE_SIZE_OUT;
643 Req.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT;
644 Req.Hdr.rc = VERR_INTERNAL_ERROR;
645 int rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_GET_PAGING_MODE, &Req, SUP_IOCTL_GET_PAGING_MODE_SIZE);
646 if ( RT_FAILURE(rc)
647 || RT_FAILURE(Req.Hdr.rc))
648 {
649 LogRel(("SUPR3GetPagingMode: %Rrc %Rrc\n", rc, Req.Hdr.rc));
650 Req.u.Out.enmMode = SUPPAGINGMODE_INVALID;
651 }
652
653 return Req.u.Out.enmMode;
654}
655
656
657/**
658 * For later.
659 */
660static int supCallVMMR0ExFake(PVMR0 pVMR0, unsigned uOperation, uint64_t u64Arg, PSUPVMMR0REQHDR pReqHdr)
661{
662 AssertMsgFailed(("%d\n", uOperation)); NOREF(pVMR0); NOREF(uOperation); NOREF(u64Arg); NOREF(pReqHdr);
663 return VERR_NOT_SUPPORTED;
664}
665
666
667SUPR3DECL(int) SUPR3CallVMMR0Fast(PVMR0 pVMR0, unsigned uOperation, VMCPUID idCpu)
668{
669 NOREF(pVMR0);
670 static const uintptr_t s_auFunctions[3] =
671 {
672 SUP_IOCTL_FAST_DO_HM_RUN,
673 SUP_IOCTL_FAST_DO_NEM_RUN,
674 SUP_IOCTL_FAST_DO_NOP,
675 };
676 AssertCompile(SUP_VMMR0_DO_HM_RUN == 0);
677 AssertCompile(SUP_VMMR0_DO_NEM_RUN == 1);
678 AssertCompile(SUP_VMMR0_DO_NOP == 2);
679 AssertMsgReturn(uOperation < RT_ELEMENTS(s_auFunctions), ("%#x\n", uOperation), VERR_INTERNAL_ERROR);
680 return suplibOsIOCtlFast(&g_supLibData, s_auFunctions[uOperation], idCpu);
681}
682
683
684SUPR3DECL(int) SUPR3CallVMMR0Ex(PVMR0 pVMR0, VMCPUID idCpu, unsigned uOperation, uint64_t u64Arg, PSUPVMMR0REQHDR pReqHdr)
685{
686 /*
687 * The following operations don't belong here.
688 */
689 AssertMsgReturn( uOperation != SUP_VMMR0_DO_HM_RUN
690 && uOperation != SUP_VMMR0_DO_NEM_RUN
691 && uOperation != SUP_VMMR0_DO_NOP,
692 ("%#x\n", uOperation),
693 VERR_INTERNAL_ERROR);
694
695 /* fake */
696 if (RT_UNLIKELY(g_uSupFakeMode))
697 return supCallVMMR0ExFake(pVMR0, uOperation, u64Arg, pReqHdr);
698
699 int rc;
700 if (!pReqHdr)
701 {
702 /* no data. */
703 SUPCALLVMMR0 Req;
704 Req.Hdr.u32Cookie = g_u32Cookie;
705 Req.Hdr.u32SessionCookie = g_u32SessionCookie;
706 Req.Hdr.cbIn = SUP_IOCTL_CALL_VMMR0_SIZE_IN(0);
707 Req.Hdr.cbOut = SUP_IOCTL_CALL_VMMR0_SIZE_OUT(0);
708 Req.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT;
709 Req.Hdr.rc = VERR_INTERNAL_ERROR;
710 Req.u.In.pVMR0 = pVMR0;
711 Req.u.In.idCpu = idCpu;
712 Req.u.In.uOperation = uOperation;
713 Req.u.In.u64Arg = u64Arg;
714 rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_CALL_VMMR0(0), &Req, SUP_IOCTL_CALL_VMMR0_SIZE(0));
715 if (RT_SUCCESS(rc))
716 rc = Req.Hdr.rc;
717 }
718 else if (SUP_IOCTL_CALL_VMMR0_SIZE(pReqHdr->cbReq) < _4K) /* FreeBSD won't copy more than 4K. */
719 {
720 AssertPtrReturn(pReqHdr, VERR_INVALID_POINTER);
721 AssertReturn(pReqHdr->u32Magic == SUPVMMR0REQHDR_MAGIC, VERR_INVALID_MAGIC);
722 const size_t cbReq = pReqHdr->cbReq;
723
724 PSUPCALLVMMR0 pReq = (PSUPCALLVMMR0)alloca(SUP_IOCTL_CALL_VMMR0_SIZE(cbReq));
725 pReq->Hdr.u32Cookie = g_u32Cookie;
726 pReq->Hdr.u32SessionCookie = g_u32SessionCookie;
727 pReq->Hdr.cbIn = SUP_IOCTL_CALL_VMMR0_SIZE_IN(cbReq);
728 pReq->Hdr.cbOut = SUP_IOCTL_CALL_VMMR0_SIZE_OUT(cbReq);
729 pReq->Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT;
730 pReq->Hdr.rc = VERR_INTERNAL_ERROR;
731 pReq->u.In.pVMR0 = pVMR0;
732 pReq->u.In.idCpu = idCpu;
733 pReq->u.In.uOperation = uOperation;
734 pReq->u.In.u64Arg = u64Arg;
735 memcpy(&pReq->abReqPkt[0], pReqHdr, cbReq);
736 rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_CALL_VMMR0(cbReq), pReq, SUP_IOCTL_CALL_VMMR0_SIZE(cbReq));
737 if (RT_SUCCESS(rc))
738 rc = pReq->Hdr.rc;
739 memcpy(pReqHdr, &pReq->abReqPkt[0], cbReq);
740 }
741 else if (pReqHdr->cbReq <= _512K)
742 {
743 AssertPtrReturn(pReqHdr, VERR_INVALID_POINTER);
744 AssertReturn(pReqHdr->u32Magic == SUPVMMR0REQHDR_MAGIC, VERR_INVALID_MAGIC);
745 const size_t cbReq = pReqHdr->cbReq;
746
747 PSUPCALLVMMR0 pReq = (PSUPCALLVMMR0)RTMemTmpAlloc(SUP_IOCTL_CALL_VMMR0_BIG_SIZE(cbReq));
748 pReq->Hdr.u32Cookie = g_u32Cookie;
749 pReq->Hdr.u32SessionCookie = g_u32SessionCookie;
750 pReq->Hdr.cbIn = SUP_IOCTL_CALL_VMMR0_BIG_SIZE_IN(cbReq);
751 pReq->Hdr.cbOut = SUP_IOCTL_CALL_VMMR0_BIG_SIZE_OUT(cbReq);
752 pReq->Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT;
753 pReq->Hdr.rc = VERR_INTERNAL_ERROR;
754 pReq->u.In.pVMR0 = pVMR0;
755 pReq->u.In.idCpu = idCpu;
756 pReq->u.In.uOperation = uOperation;
757 pReq->u.In.u64Arg = u64Arg;
758 memcpy(&pReq->abReqPkt[0], pReqHdr, cbReq);
759 rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_CALL_VMMR0_BIG, pReq, SUP_IOCTL_CALL_VMMR0_BIG_SIZE(cbReq));
760 if (RT_SUCCESS(rc))
761 rc = pReq->Hdr.rc;
762 memcpy(pReqHdr, &pReq->abReqPkt[0], cbReq);
763 RTMemTmpFree(pReq);
764 }
765 else
766 AssertMsgFailedReturn(("cbReq=%#x\n", pReqHdr->cbReq), VERR_OUT_OF_RANGE);
767 return rc;
768}
769
770
771SUPR3DECL(int) SUPR3CallVMMR0(PVMR0 pVMR0, VMCPUID idCpu, unsigned uOperation, void *pvArg)
772{
773 /*
774 * The following operations don't belong here.
775 */
776 AssertMsgReturn( uOperation != SUP_VMMR0_DO_HM_RUN
777 && uOperation != SUP_VMMR0_DO_NEM_RUN
778 && uOperation != SUP_VMMR0_DO_NOP,
779 ("%#x\n", uOperation),
780 VERR_INTERNAL_ERROR);
781 return SUPR3CallVMMR0Ex(pVMR0, idCpu, uOperation, (uintptr_t)pvArg, NULL);
782}
783
784
785SUPR3DECL(int) SUPR3SetVMForFastIOCtl(PVMR0 pVMR0)
786{
787 if (RT_UNLIKELY(g_uSupFakeMode))
788 return VINF_SUCCESS;
789
790 SUPSETVMFORFAST Req;
791 Req.Hdr.u32Cookie = g_u32Cookie;
792 Req.Hdr.u32SessionCookie = g_u32SessionCookie;
793 Req.Hdr.cbIn = SUP_IOCTL_SET_VM_FOR_FAST_SIZE_IN;
794 Req.Hdr.cbOut = SUP_IOCTL_SET_VM_FOR_FAST_SIZE_OUT;
795 Req.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT;
796 Req.Hdr.rc = VERR_INTERNAL_ERROR;
797 Req.u.In.pVMR0 = pVMR0;
798 int rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_SET_VM_FOR_FAST, &Req, SUP_IOCTL_SET_VM_FOR_FAST_SIZE);
799 if (RT_SUCCESS(rc))
800 rc = Req.Hdr.rc;
801 return rc;
802}
803
804
805SUPR3DECL(int) SUPR3CallR0Service(const char *pszService, size_t cchService, uint32_t uOperation, uint64_t u64Arg, PSUPR0SERVICEREQHDR pReqHdr)
806{
807 AssertReturn(cchService < RT_SIZEOFMEMB(SUPCALLSERVICE, u.In.szName), VERR_INVALID_PARAMETER);
808 Assert(strlen(pszService) == cchService);
809
810 /* fake */
811 if (RT_UNLIKELY(g_uSupFakeMode))
812 return VERR_NOT_SUPPORTED;
813
814 int rc;
815 if (!pReqHdr)
816 {
817 /* no data. */
818 SUPCALLSERVICE Req;
819 Req.Hdr.u32Cookie = g_u32Cookie;
820 Req.Hdr.u32SessionCookie = g_u32SessionCookie;
821 Req.Hdr.cbIn = SUP_IOCTL_CALL_SERVICE_SIZE_IN(0);
822 Req.Hdr.cbOut = SUP_IOCTL_CALL_SERVICE_SIZE_OUT(0);
823 Req.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT;
824 Req.Hdr.rc = VERR_INTERNAL_ERROR;
825 memcpy(Req.u.In.szName, pszService, cchService);
826 Req.u.In.szName[cchService] = '\0';
827 Req.u.In.uOperation = uOperation;
828 Req.u.In.u64Arg = u64Arg;
829 rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_CALL_SERVICE(0), &Req, SUP_IOCTL_CALL_SERVICE_SIZE(0));
830 if (RT_SUCCESS(rc))
831 rc = Req.Hdr.rc;
832 }
833 else if (SUP_IOCTL_CALL_SERVICE_SIZE(pReqHdr->cbReq) < _4K) /* FreeBSD won't copy more than 4K. */
834 {
835 AssertPtrReturn(pReqHdr, VERR_INVALID_POINTER);
836 AssertReturn(pReqHdr->u32Magic == SUPR0SERVICEREQHDR_MAGIC, VERR_INVALID_MAGIC);
837 const size_t cbReq = pReqHdr->cbReq;
838
839 PSUPCALLSERVICE pReq = (PSUPCALLSERVICE)alloca(SUP_IOCTL_CALL_SERVICE_SIZE(cbReq));
840 pReq->Hdr.u32Cookie = g_u32Cookie;
841 pReq->Hdr.u32SessionCookie = g_u32SessionCookie;
842 pReq->Hdr.cbIn = SUP_IOCTL_CALL_SERVICE_SIZE_IN(cbReq);
843 pReq->Hdr.cbOut = SUP_IOCTL_CALL_SERVICE_SIZE_OUT(cbReq);
844 pReq->Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT;
845 pReq->Hdr.rc = VERR_INTERNAL_ERROR;
846 memcpy(pReq->u.In.szName, pszService, cchService);
847 pReq->u.In.szName[cchService] = '\0';
848 pReq->u.In.uOperation = uOperation;
849 pReq->u.In.u64Arg = u64Arg;
850 memcpy(&pReq->abReqPkt[0], pReqHdr, cbReq);
851 rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_CALL_SERVICE(cbReq), pReq, SUP_IOCTL_CALL_SERVICE_SIZE(cbReq));
852 if (RT_SUCCESS(rc))
853 rc = pReq->Hdr.rc;
854 memcpy(pReqHdr, &pReq->abReqPkt[0], cbReq);
855 }
856 else /** @todo may have to remove the size limits one this request... */
857 AssertMsgFailedReturn(("cbReq=%#x\n", pReqHdr->cbReq), VERR_INTERNAL_ERROR);
858 return rc;
859}
860
861
862/**
863 * Worker for the SUPR3Logger* APIs.
864 *
865 * @returns VBox status code.
866 * @param enmWhich Which logger.
867 * @param fWhat What to do with the logger.
868 * @param pszFlags The flags settings.
869 * @param pszGroups The groups settings.
870 * @param pszDest The destination specificier.
871 */
872static int supR3LoggerSettings(SUPLOGGER enmWhich, uint32_t fWhat, const char *pszFlags, const char *pszGroups, const char *pszDest)
873{
874 uint32_t const cchFlags = pszFlags ? (uint32_t)strlen(pszFlags) : 0;
875 uint32_t const cchGroups = pszGroups ? (uint32_t)strlen(pszGroups) : 0;
876 uint32_t const cchDest = pszDest ? (uint32_t)strlen(pszDest) : 0;
877 uint32_t const cbStrTab = cchFlags + !!cchFlags
878 + cchGroups + !!cchGroups
879 + cchDest + !!cchDest
880 + (!cchFlags && !cchGroups && !cchDest);
881
882 PSUPLOGGERSETTINGS pReq = (PSUPLOGGERSETTINGS)alloca(SUP_IOCTL_LOGGER_SETTINGS_SIZE(cbStrTab));
883 pReq->Hdr.u32Cookie = g_u32Cookie;
884 pReq->Hdr.u32SessionCookie = g_u32SessionCookie;
885 pReq->Hdr.cbIn = SUP_IOCTL_LOGGER_SETTINGS_SIZE_IN(cbStrTab);
886 pReq->Hdr.cbOut = SUP_IOCTL_LOGGER_SETTINGS_SIZE_OUT;
887 pReq->Hdr.fFlags= SUPREQHDR_FLAGS_DEFAULT;
888 pReq->Hdr.rc = VERR_INTERNAL_ERROR;
889 switch (enmWhich)
890 {
891 case SUPLOGGER_DEBUG: pReq->u.In.fWhich = SUPLOGGERSETTINGS_WHICH_DEBUG; break;
892 case SUPLOGGER_RELEASE: pReq->u.In.fWhich = SUPLOGGERSETTINGS_WHICH_RELEASE; break;
893 default:
894 return VERR_INVALID_PARAMETER;
895 }
896 pReq->u.In.fWhat = fWhat;
897
898 uint32_t off = 0;
899 if (cchFlags)
900 {
901 pReq->u.In.offFlags = off;
902 memcpy(&pReq->u.In.szStrings[off], pszFlags, cchFlags + 1);
903 off += cchFlags + 1;
904 }
905 else
906 pReq->u.In.offFlags = cbStrTab - 1;
907
908 if (cchGroups)
909 {
910 pReq->u.In.offGroups = off;
911 memcpy(&pReq->u.In.szStrings[off], pszGroups, cchGroups + 1);
912 off += cchGroups + 1;
913 }
914 else
915 pReq->u.In.offGroups = cbStrTab - 1;
916
917 if (cchDest)
918 {
919 pReq->u.In.offDestination = off;
920 memcpy(&pReq->u.In.szStrings[off], pszDest, cchDest + 1);
921 off += cchDest + 1;
922 }
923 else
924 pReq->u.In.offDestination = cbStrTab - 1;
925
926 if (!off)
927 {
928 pReq->u.In.szStrings[0] = '\0';
929 off++;
930 }
931 Assert(off == cbStrTab);
932 Assert(pReq->u.In.szStrings[cbStrTab - 1] == '\0');
933
934
935 int rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_LOGGER_SETTINGS(cbStrTab), pReq, SUP_IOCTL_LOGGER_SETTINGS_SIZE(cbStrTab));
936 if (RT_SUCCESS(rc))
937 rc = pReq->Hdr.rc;
938 return rc;
939}
940
941
942SUPR3DECL(int) SUPR3LoggerSettings(SUPLOGGER enmWhich, const char *pszFlags, const char *pszGroups, const char *pszDest)
943{
944 return supR3LoggerSettings(enmWhich, SUPLOGGERSETTINGS_WHAT_SETTINGS, pszFlags, pszGroups, pszDest);
945}
946
947
948SUPR3DECL(int) SUPR3LoggerCreate(SUPLOGGER enmWhich, const char *pszFlags, const char *pszGroups, const char *pszDest)
949{
950 return supR3LoggerSettings(enmWhich, SUPLOGGERSETTINGS_WHAT_CREATE, pszFlags, pszGroups, pszDest);
951}
952
953
954SUPR3DECL(int) SUPR3LoggerDestroy(SUPLOGGER enmWhich)
955{
956 return supR3LoggerSettings(enmWhich, SUPLOGGERSETTINGS_WHAT_DESTROY, NULL, NULL, NULL);
957}
958
959
960SUPR3DECL(int) SUPR3PageAlloc(size_t cPages, uint32_t fFlags, void **ppvPages)
961{
962 /*
963 * Validate.
964 */
965 AssertPtrReturn(ppvPages, VERR_INVALID_POINTER);
966 *ppvPages = NULL;
967 AssertReturn(cPages > 0, VERR_PAGE_COUNT_OUT_OF_RANGE);
968 AssertReturn(!(fFlags & ~SUP_PAGE_ALLOC_F_VALID_MASK), VERR_INVALID_FLAGS);
969
970 /*
971 * Call OS specific worker.
972 */
973 return suplibOsPageAlloc(&g_supLibData, cPages, fFlags, ppvPages);
974}
975
976
977SUPR3DECL(int) SUPR3PageFree(void *pvPages, size_t cPages)
978{
979 /*
980 * Validate.
981 */
982 AssertPtrReturn(pvPages, VERR_INVALID_POINTER);
983 AssertReturn(cPages > 0, VERR_PAGE_COUNT_OUT_OF_RANGE);
984
985 /*
986 * Call OS specific worker.
987 */
988 return suplibOsPageFree(&g_supLibData, pvPages, cPages);
989}
990
991
992/**
993 * Locks down the physical memory backing a virtual memory
994 * range in the current process.
995 *
996 * @returns VBox status code.
997 * @param pvStart Start of virtual memory range.
998 * Must be page aligned.
999 * @param cPages Number of pages.
1000 * @param paPages Where to store the physical page addresses returned.
1001 * On entry this will point to an array of with cbMemory >> PAGE_SHIFT entries.
1002 */
1003SUPR3DECL(int) supR3PageLock(void *pvStart, size_t cPages, PSUPPAGE paPages)
1004{
1005 uint32_t const cbPage = SUP_PAGE_SIZE;
1006
1007 /*
1008 * Validate.
1009 */
1010 AssertPtr(pvStart);
1011 AssertMsg(RT_ALIGN_P(pvStart, cbPage) == pvStart, ("pvStart (%p) must be page aligned\n", pvStart));
1012 AssertPtr(paPages);
1013
1014 /* fake */
1015 if (RT_UNLIKELY(g_uSupFakeMode))
1016 {
1017 RTHCPHYS Phys = (uintptr_t)pvStart + cbPage * 1024;
1018 size_t iPage = cPages;
1019 while (iPage-- > 0)
1020 paPages[iPage].Phys = Phys + (iPage << SUP_PAGE_SHIFT);
1021 return VINF_SUCCESS;
1022 }
1023
1024 /*
1025 * Issue IOCtl to the SUPDRV kernel module.
1026 */
1027 int rc;
1028 PSUPPAGELOCK pReq = (PSUPPAGELOCK)RTMemTmpAllocZ(SUP_IOCTL_PAGE_LOCK_SIZE(cPages));
1029 if (RT_LIKELY(pReq))
1030 {
1031 pReq->Hdr.u32Cookie = g_u32Cookie;
1032 pReq->Hdr.u32SessionCookie = g_u32SessionCookie;
1033 pReq->Hdr.cbIn = SUP_IOCTL_PAGE_LOCK_SIZE_IN;
1034 pReq->Hdr.cbOut = SUP_IOCTL_PAGE_LOCK_SIZE_OUT(cPages);
1035 pReq->Hdr.fFlags = SUPREQHDR_FLAGS_MAGIC | SUPREQHDR_FLAGS_EXTRA_OUT;
1036 pReq->Hdr.rc = VERR_INTERNAL_ERROR;
1037 pReq->u.In.pvR3 = pvStart;
1038 pReq->u.In.cPages = (uint32_t)cPages; AssertRelease(pReq->u.In.cPages == cPages);
1039 rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_PAGE_LOCK, pReq, SUP_IOCTL_PAGE_LOCK_SIZE(cPages));
1040 if (RT_SUCCESS(rc))
1041 rc = pReq->Hdr.rc;
1042 if (RT_SUCCESS(rc))
1043 {
1044 for (uint32_t iPage = 0; iPage < cPages; iPage++)
1045 {
1046 paPages[iPage].uReserved = 0;
1047 paPages[iPage].Phys = pReq->u.Out.aPages[iPage];
1048 Assert(!(paPages[iPage].Phys & ~X86_PTE_PAE_PG_MASK));
1049 }
1050 }
1051 RTMemTmpFree(pReq);
1052 }
1053 else
1054 rc = VERR_NO_TMP_MEMORY;
1055
1056 return rc;
1057}
1058
1059
1060/**
1061 * Releases locked down pages.
1062 *
1063 * @returns VBox status code.
1064 * @param pvStart Start of virtual memory range previously locked
1065 * down by SUPPageLock().
1066 */
1067SUPR3DECL(int) supR3PageUnlock(void *pvStart)
1068{
1069 /*
1070 * Validate.
1071 */
1072 AssertPtr(pvStart);
1073 AssertMsg(RT_ALIGN_P(pvStart, SUP_PAGE_SIZE) == pvStart, ("pvStart (%p) must be page aligned\n", pvStart));
1074
1075 /* fake */
1076 if (RT_UNLIKELY(g_uSupFakeMode))
1077 return VINF_SUCCESS;
1078
1079 /*
1080 * Issue IOCtl to the SUPDRV kernel module.
1081 */
1082 SUPPAGEUNLOCK Req;
1083 Req.Hdr.u32Cookie = g_u32Cookie;
1084 Req.Hdr.u32SessionCookie = g_u32SessionCookie;
1085 Req.Hdr.cbIn = SUP_IOCTL_PAGE_UNLOCK_SIZE_IN;
1086 Req.Hdr.cbOut = SUP_IOCTL_PAGE_UNLOCK_SIZE_OUT;
1087 Req.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT;
1088 Req.Hdr.rc = VERR_INTERNAL_ERROR;
1089 Req.u.In.pvR3 = pvStart;
1090 int rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_PAGE_UNLOCK, &Req, SUP_IOCTL_PAGE_UNLOCK_SIZE);
1091 if (RT_SUCCESS(rc))
1092 rc = Req.Hdr.rc;
1093 return rc;
1094}
1095
1096
1097SUPR3DECL(int) SUPR3LockDownLoader(PRTERRINFO pErrInfo)
1098{
1099 /* fake */
1100 if (RT_UNLIKELY(g_uSupFakeMode))
1101 return VINF_SUCCESS;
1102
1103 /*
1104 * Lock down the module loader interface.
1105 */
1106 SUPREQHDR ReqHdr;
1107 ReqHdr.u32Cookie = g_u32Cookie;
1108 ReqHdr.u32SessionCookie = g_u32SessionCookie;
1109 ReqHdr.cbIn = SUP_IOCTL_LDR_LOCK_DOWN_SIZE_IN;
1110 ReqHdr.cbOut = SUP_IOCTL_LDR_LOCK_DOWN_SIZE_OUT;
1111 ReqHdr.fFlags = SUPREQHDR_FLAGS_DEFAULT;
1112 ReqHdr.rc = VERR_INTERNAL_ERROR;
1113 int rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_LDR_LOCK_DOWN, &ReqHdr, SUP_IOCTL_LDR_LOCK_DOWN_SIZE);
1114 if (RT_FAILURE(rc))
1115 return RTErrInfoSetF(pErrInfo, rc,
1116 "SUPR3LockDownLoader: SUP_IOCTL_LDR_LOCK_DOWN ioctl returned %Rrc", rc);
1117
1118 return ReqHdr.rc;
1119}
1120
1121
1122#ifdef VBOX_WITH_R0_MODULES
1123/**
1124 * Fallback for SUPR3PageAllocEx on systems where RTR0MemObjPhysAllocNC isn't
1125 * supported.
1126 */
1127static int supPagePageAllocNoKernelFallback(size_t cPages, void **ppvPages, PSUPPAGE paPages)
1128{
1129 int rc = suplibOsPageAlloc(&g_supLibData, cPages, 0, ppvPages);
1130 if (RT_SUCCESS(rc))
1131 {
1132 Assert(ASMMemIsZero(*ppvPages, cPages << PAGE_SHIFT));
1133 if (!paPages)
1134 paPages = (PSUPPAGE)alloca(sizeof(paPages[0]) * cPages);
1135 rc = supR3PageLock(*ppvPages, cPages, paPages);
1136 if (RT_FAILURE(rc))
1137 suplibOsPageFree(&g_supLibData, *ppvPages, cPages);
1138 }
1139 return rc;
1140}
1141#endif /* VBOX_WITH_R0_MODULES */
1142
1143
1144SUPR3DECL(int) SUPR3PageAllocEx(size_t cPages, uint32_t fFlags, void **ppvPages, PRTR0PTR pR0Ptr, PSUPPAGE paPages)
1145{
1146 /*
1147 * Validate.
1148 */
1149 AssertPtrReturn(ppvPages, VERR_INVALID_POINTER);
1150 *ppvPages = NULL;
1151 AssertPtrNullReturn(pR0Ptr, VERR_INVALID_POINTER);
1152 if (pR0Ptr)
1153 *pR0Ptr = NIL_RTR0PTR;
1154 AssertPtrNullReturn(paPages, VERR_INVALID_POINTER);
1155 AssertMsgReturn(cPages > 0 && cPages <= VBOX_MAX_ALLOC_SIZE / SUP_PAGE_SIZE, ("cPages=%zu\n", cPages), VERR_PAGE_COUNT_OUT_OF_RANGE);
1156 AssertReturn(!fFlags, VERR_INVALID_FLAGS);
1157
1158 /*
1159 * Deal with driverless mode first.
1160 */
1161 if (g_supLibData.fDriverless)
1162 {
1163 int rc = SUPR3PageAlloc(cPages, 0 /*fFlags*/, ppvPages);
1164 Assert(RT_FAILURE(rc) || ASMMemIsZero(*ppvPages, cPages << SUP_PAGE_SHIFT));
1165 if (pR0Ptr)
1166 *pR0Ptr = NIL_RTR0PTR;
1167 if (paPages)
1168 for (size_t iPage = 0; iPage < cPages; iPage++)
1169 {
1170 paPages[iPage].uReserved = 0;
1171 paPages[iPage].Phys = NIL_RTHCPHYS;
1172 }
1173 return rc;
1174 }
1175
1176 /* Check that we've got a kernel connection so rtMemSaferSupR3AllocPages
1177 can do fallback without first having to hit assertions. */
1178 if (g_supLibData.hDevice != SUP_HDEVICE_NIL)
1179 { /* likely */ }
1180 else
1181 return VERR_WRONG_ORDER;
1182
1183#ifdef VBOX_WITH_R0_MODULES
1184 /*
1185 * Use fallback for non-R0 mapping?
1186 */
1187 if ( !pR0Ptr
1188 && !g_fSupportsPageAllocNoKernel)
1189 return supPagePageAllocNoKernelFallback(cPages, ppvPages, paPages);
1190
1191 /*
1192 * Issue IOCtl to the SUPDRV kernel module.
1193 */
1194 int rc;
1195 PSUPPAGEALLOCEX pReq = (PSUPPAGEALLOCEX)RTMemTmpAllocZ(SUP_IOCTL_PAGE_ALLOC_EX_SIZE(cPages));
1196 if (pReq)
1197 {
1198 pReq->Hdr.u32Cookie = g_u32Cookie;
1199 pReq->Hdr.u32SessionCookie = g_u32SessionCookie;
1200 pReq->Hdr.cbIn = SUP_IOCTL_PAGE_ALLOC_EX_SIZE_IN;
1201 pReq->Hdr.cbOut = SUP_IOCTL_PAGE_ALLOC_EX_SIZE_OUT(cPages);
1202 pReq->Hdr.fFlags = SUPREQHDR_FLAGS_MAGIC | SUPREQHDR_FLAGS_EXTRA_OUT;
1203 pReq->Hdr.rc = VERR_INTERNAL_ERROR;
1204 pReq->u.In.cPages = (uint32_t)cPages; AssertRelease(pReq->u.In.cPages == cPages);
1205 pReq->u.In.fKernelMapping = pR0Ptr != NULL;
1206 pReq->u.In.fUserMapping = true;
1207 pReq->u.In.fReserved0 = false;
1208 pReq->u.In.fReserved1 = false;
1209 rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_PAGE_ALLOC_EX, pReq, SUP_IOCTL_PAGE_ALLOC_EX_SIZE(cPages));
1210 if (RT_SUCCESS(rc))
1211 {
1212 rc = pReq->Hdr.rc;
1213 if (RT_SUCCESS(rc))
1214 {
1215 *ppvPages = pReq->u.Out.pvR3;
1216 if (pR0Ptr)
1217 {
1218 *pR0Ptr = pReq->u.Out.pvR0;
1219 Assert(ASMMemIsZero(pReq->u.Out.pvR3, cPages << PAGE_SHIFT));
1220#ifdef RT_OS_DARWIN /* HACK ALERT! */
1221 supR3TouchPages(pReq->u.Out.pvR3, cPages);
1222#endif
1223 }
1224 else
1225 RT_BZERO(pReq->u.Out.pvR3, cPages << PAGE_SHIFT);
1226
1227 if (paPages)
1228 for (size_t iPage = 0; iPage < cPages; iPage++)
1229 {
1230 paPages[iPage].uReserved = 0;
1231 paPages[iPage].Phys = pReq->u.Out.aPages[iPage];
1232 Assert(!(paPages[iPage].Phys & ~X86_PTE_PAE_PG_MASK));
1233 }
1234 }
1235 else if ( rc == VERR_NOT_SUPPORTED
1236 && !pR0Ptr)
1237 {
1238 g_fSupportsPageAllocNoKernel = false;
1239 rc = supPagePageAllocNoKernelFallback(cPages, ppvPages, paPages);
1240 }
1241 }
1242
1243 RTMemTmpFree(pReq);
1244 }
1245 else
1246 rc = VERR_NO_TMP_MEMORY;
1247 return rc;
1248#else
1249 AssertFailedReturn(VERR_NOT_SUPPORTED);
1250#endif /* VBOX_WITH_R0_MODULES */
1251}
1252
1253
1254#ifdef VBOX_WITH_R0_MODULES
1255SUPR3DECL(int) SUPR3PageMapKernel(void *pvR3, uint32_t off, uint32_t cb, uint32_t fFlags, PRTR0PTR pR0Ptr)
1256{
1257 /*
1258 * Validate.
1259 */
1260 AssertPtrReturn(pvR3, VERR_INVALID_POINTER);
1261 AssertPtrReturn(pR0Ptr, VERR_INVALID_POINTER);
1262 Assert(!(off & PAGE_OFFSET_MASK));
1263 Assert(!(cb & PAGE_OFFSET_MASK) && cb);
1264 Assert(!fFlags);
1265 *pR0Ptr = NIL_RTR0PTR;
1266
1267 /*
1268 * Not a valid operation in driverless mode.
1269 */
1270 AssertReturn(g_supLibData.fDriverless, VERR_SUP_DRIVERLESS);
1271
1272 /*
1273 * Issue IOCtl to the SUPDRV kernel module.
1274 */
1275 SUPPAGEMAPKERNEL Req;
1276 Req.Hdr.u32Cookie = g_u32Cookie;
1277 Req.Hdr.u32SessionCookie = g_u32SessionCookie;
1278 Req.Hdr.cbIn = SUP_IOCTL_PAGE_MAP_KERNEL_SIZE_IN;
1279 Req.Hdr.cbOut = SUP_IOCTL_PAGE_MAP_KERNEL_SIZE_OUT;
1280 Req.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT;
1281 Req.Hdr.rc = VERR_INTERNAL_ERROR;
1282 Req.u.In.pvR3 = pvR3;
1283 Req.u.In.offSub = off;
1284 Req.u.In.cbSub = cb;
1285 Req.u.In.fFlags = fFlags;
1286 int rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_PAGE_MAP_KERNEL, &Req, SUP_IOCTL_PAGE_MAP_KERNEL_SIZE);
1287 if (RT_SUCCESS(rc))
1288 rc = Req.Hdr.rc;
1289 if (RT_SUCCESS(rc))
1290 *pR0Ptr = Req.u.Out.pvR0;
1291 return rc;
1292}
1293#endif
1294
1295
1296SUPR3DECL(int) SUPR3PageProtect(void *pvR3, RTR0PTR R0Ptr, uint32_t off, uint32_t cb, uint32_t fProt)
1297{
1298 /*
1299 * Validate.
1300 */
1301 AssertPtrReturn(pvR3, VERR_INVALID_POINTER);
1302 Assert(!(off & SUP_PAGE_OFFSET_MASK));
1303 Assert(!(cb & SUP_PAGE_OFFSET_MASK) && cb);
1304 AssertReturn(!(fProt & ~(RTMEM_PROT_NONE | RTMEM_PROT_READ | RTMEM_PROT_WRITE | RTMEM_PROT_EXEC)), VERR_INVALID_PARAMETER);
1305
1306 /*
1307 * Deal with driverless mode first.
1308 */
1309 if (g_supLibData.fDriverless)
1310 return RTMemProtect((uint8_t *)pvR3 + off, cb, fProt);
1311
1312 /*
1313 * Some OSes can do this from ring-3, so try that before we
1314 * issue the IOCtl to the SUPDRV kernel module.
1315 * (Yea, this isn't very nice, but just try get the job done for now.)
1316 */
1317#if !defined(RT_OS_SOLARIS)
1318 RTMemProtect((uint8_t *)pvR3 + off, cb, fProt);
1319#endif
1320
1321 SUPPAGEPROTECT Req;
1322 Req.Hdr.u32Cookie = g_u32Cookie;
1323 Req.Hdr.u32SessionCookie = g_u32SessionCookie;
1324 Req.Hdr.cbIn = SUP_IOCTL_PAGE_PROTECT_SIZE_IN;
1325 Req.Hdr.cbOut = SUP_IOCTL_PAGE_PROTECT_SIZE_OUT;
1326 Req.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT;
1327 Req.Hdr.rc = VERR_INTERNAL_ERROR;
1328 Req.u.In.pvR3 = pvR3;
1329 Req.u.In.pvR0 = R0Ptr;
1330 Req.u.In.offSub = off;
1331 Req.u.In.cbSub = cb;
1332 Req.u.In.fProt = fProt;
1333 int rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_PAGE_PROTECT, &Req, SUP_IOCTL_PAGE_PROTECT_SIZE);
1334 if (RT_SUCCESS(rc))
1335 rc = Req.Hdr.rc;
1336 return rc;
1337}
1338
1339
1340SUPR3DECL(int) SUPR3PageFreeEx(void *pvPages, size_t cPages)
1341{
1342 /*
1343 * Validate.
1344 */
1345 AssertPtrReturn(pvPages, VERR_INVALID_POINTER);
1346 AssertReturn(cPages > 0, VERR_PAGE_COUNT_OUT_OF_RANGE);
1347
1348 /*
1349 * Deal with driverless mode first.
1350 */
1351 if (g_supLibData.fDriverless)
1352 {
1353 SUPR3PageFree(pvPages, cPages);
1354 return VINF_SUCCESS;
1355 }
1356
1357 /*
1358 * Try normal free first, then if it fails check if we're using the fallback
1359 * for the allocations without kernel mappings and attempt unlocking it.
1360 */
1361 NOREF(cPages);
1362 SUPPAGEFREE Req;
1363 Req.Hdr.u32Cookie = g_u32Cookie;
1364 Req.Hdr.u32SessionCookie = g_u32SessionCookie;
1365 Req.Hdr.cbIn = SUP_IOCTL_PAGE_FREE_SIZE_IN;
1366 Req.Hdr.cbOut = SUP_IOCTL_PAGE_FREE_SIZE_OUT;
1367 Req.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT;
1368 Req.Hdr.rc = VERR_INTERNAL_ERROR;
1369 Req.u.In.pvR3 = pvPages;
1370 int rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_PAGE_FREE, &Req, SUP_IOCTL_PAGE_FREE_SIZE);
1371 if (RT_SUCCESS(rc))
1372 {
1373 rc = Req.Hdr.rc;
1374 if ( rc == VERR_INVALID_PARAMETER
1375 && !g_fSupportsPageAllocNoKernel)
1376 {
1377 int rc2 = supR3PageUnlock(pvPages);
1378 if (RT_SUCCESS(rc2))
1379 rc = suplibOsPageFree(&g_supLibData, pvPages, cPages);
1380 }
1381 }
1382 return rc;
1383}
1384
1385
1386SUPR3DECL(void *) SUPR3ContAlloc(size_t cPages, PRTR0PTR pR0Ptr, PRTHCPHYS pHCPhys)
1387{
1388 /*
1389 * Validate.
1390 */
1391 AssertPtrReturn(pHCPhys, NULL);
1392 *pHCPhys = NIL_RTHCPHYS;
1393 AssertPtrNullReturn(pR0Ptr, NULL);
1394 if (pR0Ptr)
1395 *pR0Ptr = NIL_RTR0PTR;
1396 AssertPtrNullReturn(pHCPhys, NULL);
1397 AssertMsgReturn(cPages > 0 && cPages < 256, ("cPages=%d must be > 0 and < 256\n", cPages), NULL);
1398
1399 /*
1400 * Deal with driverless mode first.
1401 */
1402 if (g_supLibData.fDriverless)
1403 {
1404 void *pvPages = NULL;
1405 int rc = SUPR3PageAlloc(cPages, 0 /*fFlags*/, &pvPages);
1406 if (pR0Ptr)
1407 *pR0Ptr = NIL_RTR0PTR;
1408 if (pHCPhys)
1409 *pHCPhys = NIL_RTHCPHYS;
1410 return RT_SUCCESS(rc) ? pvPages : NULL;
1411 }
1412
1413 /*
1414 * Issue IOCtl to the SUPDRV kernel module.
1415 */
1416 SUPCONTALLOC Req;
1417 Req.Hdr.u32Cookie = g_u32Cookie;
1418 Req.Hdr.u32SessionCookie = g_u32SessionCookie;
1419 Req.Hdr.cbIn = SUP_IOCTL_CONT_ALLOC_SIZE_IN;
1420 Req.Hdr.cbOut = SUP_IOCTL_CONT_ALLOC_SIZE_OUT;
1421 Req.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT;
1422 Req.Hdr.rc = VERR_INTERNAL_ERROR;
1423 Req.u.In.cPages = (uint32_t)cPages;
1424 int rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_CONT_ALLOC, &Req, SUP_IOCTL_CONT_ALLOC_SIZE);
1425 if ( RT_SUCCESS(rc)
1426 && RT_SUCCESS(Req.Hdr.rc))
1427 {
1428 *pHCPhys = Req.u.Out.HCPhys;
1429 if (pR0Ptr)
1430 *pR0Ptr = Req.u.Out.pvR0;
1431#ifdef RT_OS_DARWIN /* HACK ALERT! */
1432 supR3TouchPages(Req.u.Out.pvR3, cPages);
1433#endif
1434 return Req.u.Out.pvR3;
1435 }
1436
1437 return NULL;
1438}
1439
1440
1441SUPR3DECL(int) SUPR3ContFree(void *pv, size_t cPages)
1442{
1443 /*
1444 * Validate.
1445 */
1446 if (!pv)
1447 return VINF_SUCCESS;
1448 AssertPtrReturn(pv, VERR_INVALID_POINTER);
1449 AssertReturn(cPages > 0, VERR_PAGE_COUNT_OUT_OF_RANGE);
1450
1451 /*
1452 * Deal with driverless mode first.
1453 */
1454 if (g_supLibData.fDriverless)
1455 return SUPR3PageFree(pv, cPages);
1456
1457 /*
1458 * Issue IOCtl to the SUPDRV kernel module.
1459 */
1460 SUPCONTFREE Req;
1461 Req.Hdr.u32Cookie = g_u32Cookie;
1462 Req.Hdr.u32SessionCookie = g_u32SessionCookie;
1463 Req.Hdr.cbIn = SUP_IOCTL_CONT_FREE_SIZE_IN;
1464 Req.Hdr.cbOut = SUP_IOCTL_CONT_FREE_SIZE_OUT;
1465 Req.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT;
1466 Req.Hdr.rc = VERR_INTERNAL_ERROR;
1467 Req.u.In.pvR3 = pv;
1468 int rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_CONT_FREE, &Req, SUP_IOCTL_CONT_FREE_SIZE);
1469 if (RT_SUCCESS(rc))
1470 rc = Req.Hdr.rc;
1471 return rc;
1472}
1473
1474
1475SUPR3DECL(int) SUPR3LowAlloc(size_t cPages, void **ppvPages, PRTR0PTR ppvPagesR0, PSUPPAGE paPages)
1476{
1477 /*
1478 * Validate.
1479 */
1480 AssertPtrReturn(ppvPages, VERR_INVALID_POINTER);
1481 *ppvPages = NULL;
1482 AssertPtrReturn(paPages, VERR_INVALID_POINTER);
1483 AssertMsgReturn(cPages > 0 && cPages < 256, ("cPages=%d must be > 0 and < 256\n", cPages), VERR_PAGE_COUNT_OUT_OF_RANGE);
1484
1485 /* fake */
1486 if (RT_UNLIKELY(g_uSupFakeMode))
1487 {
1488 *ppvPages = RTMemPageAllocZ((size_t)cPages * SUP_PAGE_SIZE);
1489 if (!*ppvPages)
1490 return VERR_NO_LOW_MEMORY;
1491
1492 /* fake physical addresses. */
1493 RTHCPHYS Phys = (uintptr_t)*ppvPages + SUP_PAGE_SIZE * 1024;
1494 size_t iPage = cPages;
1495 while (iPage-- > 0)
1496 paPages[iPage].Phys = Phys + (iPage << SUP_PAGE_SHIFT);
1497 return VINF_SUCCESS;
1498 }
1499
1500 /*
1501 * Issue IOCtl to the SUPDRV kernel module.
1502 */
1503 int rc;
1504 PSUPLOWALLOC pReq = (PSUPLOWALLOC)RTMemTmpAllocZ(SUP_IOCTL_LOW_ALLOC_SIZE(cPages));
1505 if (pReq)
1506 {
1507 pReq->Hdr.u32Cookie = g_u32Cookie;
1508 pReq->Hdr.u32SessionCookie = g_u32SessionCookie;
1509 pReq->Hdr.cbIn = SUP_IOCTL_LOW_ALLOC_SIZE_IN;
1510 pReq->Hdr.cbOut = SUP_IOCTL_LOW_ALLOC_SIZE_OUT(cPages);
1511 pReq->Hdr.fFlags = SUPREQHDR_FLAGS_MAGIC | SUPREQHDR_FLAGS_EXTRA_OUT;
1512 pReq->Hdr.rc = VERR_INTERNAL_ERROR;
1513 pReq->u.In.cPages = (uint32_t)cPages; AssertRelease(pReq->u.In.cPages == cPages);
1514 rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_LOW_ALLOC, pReq, SUP_IOCTL_LOW_ALLOC_SIZE(cPages));
1515 if (RT_SUCCESS(rc))
1516 rc = pReq->Hdr.rc;
1517 if (RT_SUCCESS(rc))
1518 {
1519 *ppvPages = pReq->u.Out.pvR3;
1520 if (ppvPagesR0)
1521 *ppvPagesR0 = pReq->u.Out.pvR0;
1522 if (paPages)
1523 for (size_t iPage = 0; iPage < cPages; iPage++)
1524 {
1525 paPages[iPage].uReserved = 0;
1526 paPages[iPage].Phys = pReq->u.Out.aPages[iPage];
1527 Assert(!(paPages[iPage].Phys & ~X86_PTE_PAE_PG_MASK));
1528 Assert(paPages[iPage].Phys <= UINT32_C(0xfffff000));
1529 }
1530#ifdef RT_OS_DARWIN /* HACK ALERT! */
1531 supR3TouchPages(pReq->u.Out.pvR3, cPages);
1532#endif
1533 }
1534 RTMemTmpFree(pReq);
1535 }
1536 else
1537 rc = VERR_NO_TMP_MEMORY;
1538
1539 return rc;
1540}
1541
1542
1543SUPR3DECL(int) SUPR3LowFree(void *pv, size_t cPages)
1544{
1545 /*
1546 * Validate.
1547 */
1548 if (!pv)
1549 return VINF_SUCCESS;
1550 AssertPtrReturn(pv, VERR_INVALID_POINTER);
1551 AssertReturn(cPages > 0, VERR_PAGE_COUNT_OUT_OF_RANGE);
1552
1553 /* fake */
1554 if (RT_UNLIKELY(g_uSupFakeMode))
1555 {
1556 RTMemPageFree(pv, cPages * SUP_PAGE_SIZE);
1557 return VINF_SUCCESS;
1558 }
1559
1560 /*
1561 * Issue IOCtl to the SUPDRV kernel module.
1562 */
1563 SUPCONTFREE Req;
1564 Req.Hdr.u32Cookie = g_u32Cookie;
1565 Req.Hdr.u32SessionCookie = g_u32SessionCookie;
1566 Req.Hdr.cbIn = SUP_IOCTL_LOW_FREE_SIZE_IN;
1567 Req.Hdr.cbOut = SUP_IOCTL_LOW_FREE_SIZE_OUT;
1568 Req.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT;
1569 Req.Hdr.rc = VERR_INTERNAL_ERROR;
1570 Req.u.In.pvR3 = pv;
1571 int rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_LOW_FREE, &Req, SUP_IOCTL_LOW_FREE_SIZE);
1572 if (RT_SUCCESS(rc))
1573 rc = Req.Hdr.rc;
1574 return rc;
1575}
1576
1577
1578SUPR3DECL(int) SUPR3HardenedVerifyInit(void)
1579{
1580#ifdef RT_OS_WINDOWS
1581 if (g_cInits == 0)
1582 return suplibOsHardenedVerifyInit();
1583#endif
1584 return VINF_SUCCESS;
1585}
1586
1587
1588SUPR3DECL(int) SUPR3HardenedVerifyTerm(void)
1589{
1590#ifdef RT_OS_WINDOWS
1591 if (g_cInits == 0)
1592 return suplibOsHardenedVerifyTerm();
1593#endif
1594 return VINF_SUCCESS;
1595}
1596
1597
1598SUPR3DECL(int) SUPR3HardenedVerifyFile(const char *pszFilename, const char *pszMsg, PRTFILE phFile)
1599{
1600 /*
1601 * Quick input validation.
1602 */
1603 AssertPtr(pszFilename);
1604 AssertPtr(pszMsg);
1605 AssertReturn(!phFile, VERR_NOT_IMPLEMENTED); /** @todo Implement this. The deal is that we make sure the
1606 file is the same we verified after opening it. */
1607 RT_NOREF2(pszFilename, pszMsg);
1608
1609 /*
1610 * Only do the actual check in hardened builds.
1611 */
1612#ifdef VBOX_WITH_HARDENING
1613 int rc = supR3HardenedVerifyFixedFile(pszFilename, false /* fFatal */);
1614 if (RT_FAILURE(rc))
1615 LogRel(("SUPR3HardenedVerifyFile: %s: Verification of \"%s\" failed, rc=%Rrc\n", pszMsg, pszFilename, rc));
1616 return rc;
1617#else
1618 return VINF_SUCCESS;
1619#endif
1620}
1621
1622
1623SUPR3DECL(int) SUPR3HardenedVerifySelf(const char *pszArgv0, bool fInternal, PRTERRINFO pErrInfo)
1624{
1625 /*
1626 * Quick input validation.
1627 */
1628 AssertPtr(pszArgv0);
1629 RTErrInfoClear(pErrInfo);
1630
1631 /*
1632 * Get the executable image path as we need it for all the tests here.
1633 */
1634 char szExecPath[RTPATH_MAX];
1635 if (!RTProcGetExecutablePath(szExecPath, sizeof(szExecPath)))
1636 return RTErrInfoSet(pErrInfo, VERR_INTERNAL_ERROR_2, "RTProcGetExecutablePath failed");
1637
1638 int rc;
1639 if (fInternal)
1640 {
1641 /*
1642 * Internal applications must be launched directly without any PATH
1643 * searching involved.
1644 */
1645 if (RTPathCompare(pszArgv0, szExecPath) != 0)
1646 return RTErrInfoSetF(pErrInfo, VERR_SUPLIB_INVALID_ARGV0_INTERNAL,
1647 "argv[0] does not match the executable image path: '%s' != '%s'", pszArgv0, szExecPath);
1648
1649 /*
1650 * Internal applications must reside in or under the
1651 * RTPathAppPrivateArch directory.
1652 */
1653 char szAppPrivateArch[RTPATH_MAX];
1654 rc = RTPathAppPrivateArch(szAppPrivateArch, sizeof(szAppPrivateArch));
1655 if (RT_FAILURE(rc))
1656 return RTErrInfoSetF(pErrInfo, VERR_SUPLIB_INVALID_ARGV0_INTERNAL,
1657 "RTPathAppPrivateArch failed with rc=%Rrc", rc);
1658 size_t cchAppPrivateArch = strlen(szAppPrivateArch);
1659 if ( cchAppPrivateArch >= strlen(szExecPath)
1660 || !RTPATH_IS_SLASH(szExecPath[cchAppPrivateArch]))
1661 return RTErrInfoSet(pErrInfo, VERR_SUPLIB_INVALID_INTERNAL_APP_DIR,
1662 "Internal executable does reside under RTPathAppPrivateArch");
1663 szExecPath[cchAppPrivateArch] = '\0';
1664 if (RTPathCompare(szExecPath, szAppPrivateArch) != 0)
1665 return RTErrInfoSet(pErrInfo, VERR_SUPLIB_INVALID_INTERNAL_APP_DIR,
1666 "Internal executable does reside under RTPathAppPrivateArch");
1667 szExecPath[cchAppPrivateArch] = RTPATH_SLASH;
1668 }
1669
1670#ifdef VBOX_WITH_HARDENING
1671 /*
1672 * Verify that the image file and parent directories are sane.
1673 */
1674 rc = supR3HardenedVerifyFile(szExecPath, RTHCUINTPTR_MAX, false /*fMaybe3rdParty*/, pErrInfo);
1675 if (RT_FAILURE(rc))
1676 return rc;
1677#endif
1678
1679 return VINF_SUCCESS;
1680}
1681
1682
1683SUPR3DECL(int) SUPR3HardenedVerifyDir(const char *pszDirPath, bool fRecursive, bool fCheckFiles, PRTERRINFO pErrInfo)
1684{
1685 /*
1686 * Quick input validation
1687 */
1688 AssertPtr(pszDirPath);
1689 RTErrInfoClear(pErrInfo);
1690
1691 /*
1692 * Only do the actual check in hardened builds.
1693 */
1694#ifdef VBOX_WITH_HARDENING
1695 int rc = supR3HardenedVerifyDir(pszDirPath, fRecursive, fCheckFiles, pErrInfo);
1696 if (RT_FAILURE(rc) && !RTErrInfoIsSet(pErrInfo))
1697 LogRel(("supR3HardenedVerifyDir: Verification of \"%s\" failed, rc=%Rrc\n", pszDirPath, rc));
1698 return rc;
1699#else
1700 NOREF(pszDirPath); NOREF(fRecursive); NOREF(fCheckFiles);
1701 return VINF_SUCCESS;
1702#endif
1703}
1704
1705
1706SUPR3DECL(int) SUPR3HardenedVerifyPlugIn(const char *pszFilename, PRTERRINFO pErrInfo)
1707{
1708 /*
1709 * Quick input validation
1710 */
1711 AssertPtr(pszFilename);
1712 RTErrInfoClear(pErrInfo);
1713
1714 /*
1715 * Only do the actual check in hardened builds.
1716 */
1717#ifdef VBOX_WITH_HARDENING
1718 int rc = supR3HardenedVerifyFile(pszFilename, RTHCUINTPTR_MAX, true /*fMaybe3rdParty*/, pErrInfo);
1719 if (RT_FAILURE(rc) && !RTErrInfoIsSet(pErrInfo))
1720 LogRel(("supR3HardenedVerifyFile: Verification of \"%s\" failed, rc=%Rrc\n", pszFilename, rc));
1721 return rc;
1722#else
1723 RT_NOREF1(pszFilename);
1724 return VINF_SUCCESS;
1725#endif
1726}
1727
1728
1729SUPR3DECL(int) SUPR3GipGetPhys(PRTHCPHYS pHCPhys)
1730{
1731 if (g_pSUPGlobalInfoPage)
1732 {
1733 *pHCPhys = g_HCPhysSUPGlobalInfoPage;
1734 return VINF_SUCCESS;
1735 }
1736 *pHCPhys = NIL_RTHCPHYS;
1737 return VERR_WRONG_ORDER;
1738}
1739
1740
1741SUPR3DECL(int) SUPR3QueryVTxSupported(const char **ppszWhy)
1742{
1743 *ppszWhy = NULL;
1744#ifdef RT_OS_LINUX
1745 return suplibOsQueryVTxSupported(ppszWhy);
1746#else
1747 return VINF_SUCCESS;
1748#endif
1749}
1750
1751
1752SUPR3DECL(int) SUPR3QueryVTCaps(uint32_t *pfCaps)
1753{
1754 AssertPtrReturn(pfCaps, VERR_INVALID_POINTER);
1755
1756 *pfCaps = 0;
1757
1758 int rc;
1759 if (!g_supLibData.fDriverless)
1760 {
1761 /*
1762 * Issue IOCtl to the SUPDRV kernel module.
1763 */
1764 SUPVTCAPS Req;
1765 Req.Hdr.u32Cookie = g_u32Cookie;
1766 Req.Hdr.u32SessionCookie = g_u32SessionCookie;
1767 Req.Hdr.cbIn = SUP_IOCTL_VT_CAPS_SIZE_IN;
1768 Req.Hdr.cbOut = SUP_IOCTL_VT_CAPS_SIZE_OUT;
1769 Req.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT;
1770 Req.Hdr.rc = VERR_INTERNAL_ERROR;
1771 Req.u.Out.fCaps = 0;
1772 rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_VT_CAPS, &Req, SUP_IOCTL_VT_CAPS_SIZE);
1773 if (RT_SUCCESS(rc))
1774 {
1775 rc = Req.Hdr.rc;
1776 if (RT_SUCCESS(rc))
1777 *pfCaps = Req.u.Out.fCaps;
1778 }
1779 }
1780 /*
1781 * Fail this call in driverless mode.
1782 */
1783 else
1784 rc = VERR_SUP_DRIVERLESS;
1785 return rc;
1786}
1787
1788
1789SUPR3DECL(bool) SUPR3IsNemSupportedWhenNoVtxOrAmdV(void)
1790{
1791#if defined(RT_OS_WINDOWS) || defined(RT_OS_DARWIN)
1792 return suplibOsIsNemSupportedWhenNoVtxOrAmdV();
1793#else
1794 return false;
1795#endif
1796}
1797
1798
1799SUPR3DECL(int) SUPR3QueryMicrocodeRev(uint32_t *puMicrocodeRev)
1800{
1801 AssertPtrReturn(puMicrocodeRev, VERR_INVALID_POINTER);
1802
1803 *puMicrocodeRev = 0;
1804
1805 int rc;
1806 if (!g_supLibData.fDriverless)
1807 {
1808 /*
1809 * Issue IOCtl to the SUPDRV kernel module.
1810 */
1811 SUPUCODEREV Req;
1812 Req.Hdr.u32Cookie = g_u32Cookie;
1813 Req.Hdr.u32SessionCookie = g_u32SessionCookie;
1814 Req.Hdr.cbIn = SUP_IOCTL_UCODE_REV_SIZE_IN;
1815 Req.Hdr.cbOut = SUP_IOCTL_UCODE_REV_SIZE_OUT;
1816 Req.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT;
1817 Req.Hdr.rc = VERR_INTERNAL_ERROR;
1818 Req.u.Out.MicrocodeRev = 0;
1819 rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_UCODE_REV, &Req, SUP_IOCTL_UCODE_REV_SIZE);
1820 if (RT_SUCCESS(rc))
1821 {
1822 rc = Req.Hdr.rc;
1823 if (RT_SUCCESS(rc))
1824 *puMicrocodeRev = Req.u.Out.MicrocodeRev;
1825 }
1826 }
1827 /*
1828 * Just fail the call in driverless mode if there is a host specific way of
1829 * getting the information.
1830 */
1831 else
1832#if defined(RT_OS_DARWIN) && defined(RT_ARCH_AMD64)
1833 rc = suplibOsQueryMicrocodeRev(puMicrocodeRev);
1834#else
1835 rc = VERR_SUP_DRIVERLESS;
1836#endif
1837 return rc;
1838}
1839
1840
1841SUPR3DECL(int) SUPR3TracerOpen(uint32_t uCookie, uintptr_t uArg)
1842{
1843 /* fake */
1844 if (RT_UNLIKELY(g_uSupFakeMode))
1845 return VINF_SUCCESS;
1846
1847 /*
1848 * Issue IOCtl to the SUPDRV kernel module.
1849 */
1850 SUPTRACEROPEN Req;
1851 Req.Hdr.u32Cookie = g_u32Cookie;
1852 Req.Hdr.u32SessionCookie= g_u32SessionCookie;
1853 Req.Hdr.cbIn = SUP_IOCTL_TRACER_OPEN_SIZE_IN;
1854 Req.Hdr.cbOut = SUP_IOCTL_TRACER_OPEN_SIZE_OUT;
1855 Req.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT;
1856 Req.Hdr.rc = VERR_INTERNAL_ERROR;
1857 Req.u.In.uCookie = uCookie;
1858 Req.u.In.uArg = uArg;
1859 int rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_TRACER_OPEN, &Req, SUP_IOCTL_TRACER_OPEN_SIZE);
1860 if (RT_SUCCESS(rc))
1861 rc = Req.Hdr.rc;
1862 return rc;
1863}
1864
1865
1866SUPR3DECL(int) SUPR3TracerClose(void)
1867{
1868 /* fake */
1869 if (RT_UNLIKELY(g_uSupFakeMode))
1870 return VINF_SUCCESS;
1871
1872 /*
1873 * Issue IOCtl to the SUPDRV kernel module.
1874 */
1875 SUPREQHDR Req;
1876 Req.u32Cookie = g_u32Cookie;
1877 Req.u32SessionCookie= g_u32SessionCookie;
1878 Req.cbIn = SUP_IOCTL_TRACER_OPEN_SIZE_IN;
1879 Req.cbOut = SUP_IOCTL_TRACER_OPEN_SIZE_OUT;
1880 Req.fFlags = SUPREQHDR_FLAGS_DEFAULT;
1881 Req.rc = VERR_INTERNAL_ERROR;
1882 int rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_TRACER_CLOSE, &Req, SUP_IOCTL_TRACER_CLOSE_SIZE);
1883 if (RT_SUCCESS(rc))
1884 rc = Req.rc;
1885 return rc;
1886}
1887
1888
1889SUPR3DECL(int) SUPR3TracerIoCtl(uintptr_t uCmd, uintptr_t uArg, int32_t *piRetVal)
1890{
1891 /* fake */
1892 if (RT_UNLIKELY(g_uSupFakeMode))
1893 {
1894 *piRetVal = -1;
1895 return VERR_NOT_SUPPORTED;
1896 }
1897
1898 /*
1899 * Issue IOCtl to the SUPDRV kernel module.
1900 */
1901 SUPTRACERIOCTL Req;
1902 Req.Hdr.u32Cookie = g_u32Cookie;
1903 Req.Hdr.u32SessionCookie= g_u32SessionCookie;
1904 Req.Hdr.cbIn = SUP_IOCTL_TRACER_IOCTL_SIZE_IN;
1905 Req.Hdr.cbOut = SUP_IOCTL_TRACER_IOCTL_SIZE_OUT;
1906 Req.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT;
1907 Req.Hdr.rc = VERR_INTERNAL_ERROR;
1908 Req.u.In.uCmd = uCmd;
1909 Req.u.In.uArg = uArg;
1910 int rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_TRACER_IOCTL, &Req, SUP_IOCTL_TRACER_IOCTL_SIZE);
1911 if (RT_SUCCESS(rc))
1912 {
1913 rc = Req.Hdr.rc;
1914 *piRetVal = Req.u.Out.iRetVal;
1915 }
1916 return rc;
1917}
1918
1919
1920
1921typedef struct SUPDRVTRACERSTRTAB
1922{
1923 /** Pointer to the string table. */
1924 char *pchStrTab;
1925 /** The actual string table size. */
1926 uint32_t cbStrTab;
1927 /** The original string pointers. */
1928 RTUINTPTR apszOrgFunctions[1];
1929} SUPDRVTRACERSTRTAB, *PSUPDRVTRACERSTRTAB;
1930
1931
1932/**
1933 * Destroys a string table, restoring the original pszFunction member valus.
1934 *
1935 * @param pThis The string table structure.
1936 * @param paProbeLocs32 The probe location array, 32-bit type variant.
1937 * @param paProbeLocs64 The probe location array, 64-bit type variant.
1938 * @param cProbeLocs The number of elements in the array.
1939 * @param f32Bit Set if @a paProbeLocs32 should be used, when
1940 * clear use @a paProbeLocs64.
1941 */
1942static void supr3TracerDestroyStrTab(PSUPDRVTRACERSTRTAB pThis, PVTGPROBELOC32 paProbeLocs32, PVTGPROBELOC64 paProbeLocs64,
1943 uint32_t cProbeLocs, bool f32Bit)
1944{
1945 /* Restore. */
1946 size_t i = cProbeLocs;
1947 if (f32Bit)
1948 while (i--)
1949 paProbeLocs32[i].pszFunction = (uint32_t)pThis->apszOrgFunctions[i];
1950 else
1951 while (i--)
1952 paProbeLocs64[i].pszFunction = pThis->apszOrgFunctions[i];
1953
1954 /* Free. */
1955 RTMemFree(pThis->pchStrTab);
1956 RTMemFree(pThis);
1957}
1958
1959
1960/**
1961 * Creates a string table for the pszFunction members in the probe location
1962 * array.
1963 *
1964 * This will save and replace the pszFunction members with offsets.
1965 *
1966 * @returns Pointer to a string table structure. NULL on failure.
1967 * @param paProbeLocs32 The probe location array, 32-bit type variant.
1968 * @param paProbeLocs64 The probe location array, 64-bit type variant.
1969 * @param cProbeLocs The number of elements in the array.
1970 * @param offDelta Relocation offset for the string pointers.
1971 * @param f32Bit Set if @a paProbeLocs32 should be used, when
1972 * clear use @a paProbeLocs64.
1973 */
1974static PSUPDRVTRACERSTRTAB supr3TracerCreateStrTab(PVTGPROBELOC32 paProbeLocs32,
1975 PVTGPROBELOC64 paProbeLocs64,
1976 uint32_t cProbeLocs,
1977 RTUINTPTR offDelta,
1978 bool f32Bit)
1979{
1980 if (cProbeLocs > _128K)
1981 return NULL;
1982
1983 /*
1984 * Allocate the string table structures.
1985 */
1986 size_t cbThis = RT_UOFFSETOF_DYN(SUPDRVTRACERSTRTAB, apszOrgFunctions[cProbeLocs]);
1987 PSUPDRVTRACERSTRTAB pThis = (PSUPDRVTRACERSTRTAB)RTMemAlloc(cbThis);
1988 if (!pThis)
1989 return NULL;
1990
1991 uint32_t const cHashBits = cProbeLocs * 2 - 1;
1992 uint32_t *pbmHash = (uint32_t *)RTMemAllocZ(RT_ALIGN_32(cHashBits, 64) / 8 );
1993 if (!pbmHash)
1994 {
1995 RTMemFree(pThis);
1996 return NULL;
1997 }
1998
1999 /*
2000 * Calc the max string table size and save the orignal pointers so we can
2001 * replace them later.
2002 */
2003 size_t cbMax = 1;
2004 for (uint32_t i = 0; i < cProbeLocs; i++)
2005 {
2006 pThis->apszOrgFunctions[i] = f32Bit ? paProbeLocs32[i].pszFunction : paProbeLocs64[i].pszFunction;
2007 const char *pszFunction = (const char *)(uintptr_t)(pThis->apszOrgFunctions[i] + offDelta);
2008 size_t cch = strlen(pszFunction);
2009 if (cch > _1K)
2010 {
2011 cbMax = 0;
2012 break;
2013 }
2014 cbMax += cch + 1;
2015 }
2016
2017 /* Alloc space for it. */
2018 if (cbMax > 0)
2019 pThis->pchStrTab = (char *)RTMemAlloc(cbMax);
2020 else
2021 pThis->pchStrTab = NULL;
2022 if (!pThis->pchStrTab)
2023 {
2024 RTMemFree(pbmHash);
2025 RTMemFree(pThis);
2026 return NULL;
2027 }
2028
2029 /*
2030 * Create the string table.
2031 */
2032 uint32_t off = 0;
2033 uint32_t offPrev = 0;
2034
2035 for (uint32_t i = 0; i < cProbeLocs; i++)
2036 {
2037 const char * const psz = (const char *)(uintptr_t)(pThis->apszOrgFunctions[i] + offDelta);
2038 size_t const cch = strlen(psz);
2039 uint32_t const iHashBit = RTStrHash1(psz) % cHashBits;
2040 if (ASMBitTestAndSet(pbmHash, iHashBit))
2041 {
2042 /* Often it's the most recent string. */
2043 if ( off - offPrev < cch + 1
2044 || memcmp(&pThis->pchStrTab[offPrev], psz, cch + 1))
2045 {
2046 /* It wasn't, search the entire string table. (lazy bird) */
2047 offPrev = 0;
2048 while (offPrev < off)
2049 {
2050 size_t cchCur = strlen(&pThis->pchStrTab[offPrev]);
2051 if ( cchCur == cch
2052 && !memcmp(&pThis->pchStrTab[offPrev], psz, cch + 1))
2053 break;
2054 offPrev += (uint32_t)cchCur + 1;
2055 }
2056 }
2057 }
2058 else
2059 offPrev = off;
2060
2061 /* Add the string to the table. */
2062 if (offPrev >= off)
2063 {
2064 memcpy(&pThis->pchStrTab[off], psz, cch + 1);
2065 offPrev = off;
2066 off += (uint32_t)cch + 1;
2067 }
2068
2069 /* Update the entry */
2070 if (f32Bit)
2071 paProbeLocs32[i].pszFunction = offPrev;
2072 else
2073 paProbeLocs64[i].pszFunction = offPrev;
2074 }
2075
2076 pThis->cbStrTab = off;
2077 RTMemFree(pbmHash);
2078 return pThis;
2079}
2080
2081
2082
2083SUPR3DECL(int) SUPR3TracerRegisterModule(uintptr_t hModNative, const char *pszModule, struct VTGOBJHDR *pVtgHdr,
2084 RTUINTPTR uVtgHdrAddr, uint32_t fFlags)
2085{
2086 /* Validate input. */
2087 NOREF(hModNative);
2088 AssertPtrReturn(pVtgHdr, VERR_INVALID_POINTER);
2089 AssertReturn(!memcmp(pVtgHdr->szMagic, VTGOBJHDR_MAGIC, sizeof(pVtgHdr->szMagic)), VERR_SUPDRV_VTG_MAGIC);
2090 AssertPtrReturn(pszModule, VERR_INVALID_POINTER);
2091 size_t cchModule = strlen(pszModule);
2092 AssertReturn(cchModule < RT_SIZEOFMEMB(SUPTRACERUMODREG, u.In.szName), VERR_FILENAME_TOO_LONG);
2093 AssertReturn(!RTPathHavePath(pszModule), VERR_INVALID_PARAMETER);
2094 AssertReturn(fFlags == SUP_TRACER_UMOD_FLAGS_EXE || fFlags == SUP_TRACER_UMOD_FLAGS_SHARED, VERR_INVALID_PARAMETER);
2095
2096 /*
2097 * Set the probe location array offset and size members. If the size is
2098 * zero, don't bother ring-0 with it.
2099 */
2100 if (!pVtgHdr->offProbeLocs)
2101 {
2102 uint64_t u64Tmp = pVtgHdr->uProbeLocsEnd.u64 - pVtgHdr->uProbeLocs.u64;
2103 if (u64Tmp >= UINT32_MAX)
2104 return VERR_SUPDRV_VTG_BAD_HDR_TOO_MUCH;
2105 pVtgHdr->cbProbeLocs = (uint32_t)u64Tmp;
2106
2107 u64Tmp = pVtgHdr->uProbeLocs.u64 - uVtgHdrAddr;
2108 if ((int64_t)u64Tmp != (int32_t)u64Tmp)
2109 {
2110 LogRel(("SUPR3TracerRegisterModule: VERR_SUPDRV_VTG_BAD_HDR_PTR - u64Tmp=%#llx uProbeLocs=%#llx uVtgHdrAddr=%RTptr\n",
2111 u64Tmp, pVtgHdr->uProbeLocs.u64, uVtgHdrAddr));
2112 return VERR_SUPDRV_VTG_BAD_HDR_PTR;
2113 }
2114 pVtgHdr->offProbeLocs = (int32_t)u64Tmp;
2115 }
2116
2117 if ( !pVtgHdr->cbProbeLocs
2118 || !pVtgHdr->cbProbes)
2119 return VINF_SUCCESS;
2120
2121 /*
2122 * Fake out.
2123 */
2124 if (RT_UNLIKELY(g_uSupFakeMode))
2125 return VINF_SUCCESS;
2126
2127 /*
2128 * Create a string table for the function names in the location array.
2129 * It's somewhat easier to do that here than from ring-0.
2130 */
2131 uint32_t const cProbeLocs = pVtgHdr->cbProbeLocs
2132 / (pVtgHdr->cBits == 32 ? sizeof(VTGPROBELOC32) : sizeof(VTGPROBELOC64));
2133 PVTGPROBELOC paProbeLocs = (PVTGPROBELOC)((uintptr_t)pVtgHdr + pVtgHdr->offProbeLocs);
2134 PSUPDRVTRACERSTRTAB pStrTab = supr3TracerCreateStrTab((PVTGPROBELOC32)paProbeLocs,
2135 (PVTGPROBELOC64)paProbeLocs,
2136 cProbeLocs, (uintptr_t)pVtgHdr - uVtgHdrAddr,
2137 pVtgHdr->cBits == 32);
2138 if (!pStrTab)
2139 return VERR_NO_MEMORY;
2140
2141
2142 /*
2143 * Issue IOCtl to the SUPDRV kernel module.
2144 */
2145 SUPTRACERUMODREG Req;
2146 Req.Hdr.u32Cookie = g_u32Cookie;
2147 Req.Hdr.u32SessionCookie= g_u32SessionCookie;
2148 Req.Hdr.cbIn = SUP_IOCTL_TRACER_UMOD_REG_SIZE_IN;
2149 Req.Hdr.cbOut = SUP_IOCTL_TRACER_UMOD_REG_SIZE_OUT;
2150 Req.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT;
2151 Req.Hdr.rc = VERR_INTERNAL_ERROR;
2152 Req.u.In.uVtgHdrAddr = uVtgHdrAddr;
2153 Req.u.In.R3PtrVtgHdr = pVtgHdr;
2154 Req.u.In.R3PtrStrTab = pStrTab->pchStrTab;
2155 Req.u.In.cbStrTab = pStrTab->cbStrTab;
2156 Req.u.In.fFlags = fFlags;
2157
2158 memcpy(Req.u.In.szName, pszModule, cchModule + 1);
2159 if (!RTPathHasSuffix(Req.u.In.szName))
2160 {
2161 /* Add the default suffix if none is given. */
2162 switch (fFlags & SUP_TRACER_UMOD_FLAGS_TYPE_MASK)
2163 {
2164#if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
2165 case SUP_TRACER_UMOD_FLAGS_EXE:
2166 if (cchModule + sizeof(".exe") <= sizeof(Req.u.In.szName))
2167 strcpy(&Req.u.In.szName[cchModule], ".exe");
2168 break;
2169#endif
2170
2171 case SUP_TRACER_UMOD_FLAGS_SHARED:
2172 {
2173 const char *pszSuff = RTLdrGetSuff();
2174 size_t cchSuff = strlen(pszSuff);
2175 if (cchModule + cchSuff < sizeof(Req.u.In.szName))
2176 memcpy(&Req.u.In.szName[cchModule], pszSuff, cchSuff + 1);
2177 break;
2178 }
2179 }
2180 }
2181
2182 int rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_TRACER_UMOD_REG, &Req, SUP_IOCTL_TRACER_UMOD_REG_SIZE);
2183 if (RT_SUCCESS(rc))
2184 rc = Req.Hdr.rc;
2185
2186 supr3TracerDestroyStrTab(pStrTab, (PVTGPROBELOC32)paProbeLocs, (PVTGPROBELOC64)paProbeLocs,
2187 cProbeLocs, pVtgHdr->cBits == 32);
2188 return rc;
2189}
2190
2191
2192SUPR3DECL(int) SUPR3TracerDeregisterModule(struct VTGOBJHDR *pVtgHdr)
2193{
2194 /* Validate input. */
2195 AssertPtrReturn(pVtgHdr, VERR_INVALID_POINTER);
2196 AssertReturn(!memcmp(pVtgHdr->szMagic, VTGOBJHDR_MAGIC, sizeof(pVtgHdr->szMagic)), VERR_SUPDRV_VTG_MAGIC);
2197
2198 /*
2199 * Don't bother if the object is empty.
2200 */
2201 if ( !pVtgHdr->cbProbeLocs
2202 || !pVtgHdr->cbProbes)
2203 return VINF_SUCCESS;
2204
2205 /*
2206 * Fake out.
2207 */
2208 if (RT_UNLIKELY(g_uSupFakeMode))
2209 return VINF_SUCCESS;
2210
2211 /*
2212 * Issue IOCtl to the SUPDRV kernel module.
2213 */
2214 SUPTRACERUMODDEREG Req;
2215 Req.Hdr.u32Cookie = g_u32Cookie;
2216 Req.Hdr.u32SessionCookie= g_u32SessionCookie;
2217 Req.Hdr.cbIn = SUP_IOCTL_TRACER_UMOD_REG_SIZE_IN;
2218 Req.Hdr.cbOut = SUP_IOCTL_TRACER_UMOD_REG_SIZE_OUT;
2219 Req.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT;
2220 Req.Hdr.rc = VERR_INTERNAL_ERROR;
2221 Req.u.In.pVtgHdr = pVtgHdr;
2222
2223 int rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_TRACER_UMOD_DEREG, &Req, SUP_IOCTL_TRACER_UMOD_DEREG_SIZE);
2224 if (RT_SUCCESS(rc))
2225 rc = Req.Hdr.rc;
2226 return rc;
2227}
2228
2229
2230DECLASM(void) suplibTracerFireProbe(PVTGPROBELOC pProbeLoc, PSUPTRACERUMODFIREPROBE pReq)
2231{
2232 RT_NOREF1(pProbeLoc);
2233
2234 pReq->Hdr.u32Cookie = g_u32Cookie;
2235 pReq->Hdr.u32SessionCookie = g_u32SessionCookie;
2236 Assert(pReq->Hdr.cbIn == SUP_IOCTL_TRACER_UMOD_FIRE_PROBE_SIZE_IN);
2237 Assert(pReq->Hdr.cbOut == SUP_IOCTL_TRACER_UMOD_FIRE_PROBE_SIZE_OUT);
2238 pReq->Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT;
2239 pReq->Hdr.rc = VINF_SUCCESS;
2240
2241 suplibOsIOCtl(&g_supLibData, SUP_IOCTL_TRACER_UMOD_FIRE_PROBE, pReq, SUP_IOCTL_TRACER_UMOD_FIRE_PROBE_SIZE);
2242}
2243
2244
2245SUPR3DECL(int) SUPR3MsrProberRead(uint32_t uMsr, RTCPUID idCpu, uint64_t *puValue, bool *pfGp)
2246{
2247 SUPMSRPROBER Req;
2248 Req.Hdr.u32Cookie = g_u32Cookie;
2249 Req.Hdr.u32SessionCookie = g_u32SessionCookie;
2250 Req.Hdr.cbIn = SUP_IOCTL_MSR_PROBER_SIZE_IN;
2251 Req.Hdr.cbOut = SUP_IOCTL_MSR_PROBER_SIZE_OUT;
2252 Req.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT;
2253 Req.Hdr.rc = VERR_INTERNAL_ERROR;
2254
2255 Req.u.In.enmOp = SUPMSRPROBEROP_READ;
2256 Req.u.In.uMsr = uMsr;
2257 Req.u.In.idCpu = idCpu == NIL_RTCPUID ? UINT32_MAX : idCpu;
2258
2259 int rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_MSR_PROBER, &Req, SUP_IOCTL_MSR_PROBER_SIZE);
2260 if (RT_SUCCESS(rc))
2261 rc = Req.Hdr.rc;
2262 if (RT_SUCCESS(rc))
2263 {
2264 if (puValue)
2265 *puValue = Req.u.Out.uResults.Read.uValue;
2266 if (pfGp)
2267 *pfGp = Req.u.Out.uResults.Read.fGp;
2268 }
2269
2270 return rc;
2271}
2272
2273
2274SUPR3DECL(int) SUPR3MsrProberWrite(uint32_t uMsr, RTCPUID idCpu, uint64_t uValue, bool *pfGp)
2275{
2276 SUPMSRPROBER Req;
2277 Req.Hdr.u32Cookie = g_u32Cookie;
2278 Req.Hdr.u32SessionCookie = g_u32SessionCookie;
2279 Req.Hdr.cbIn = SUP_IOCTL_MSR_PROBER_SIZE_IN;
2280 Req.Hdr.cbOut = SUP_IOCTL_MSR_PROBER_SIZE_OUT;
2281 Req.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT;
2282 Req.Hdr.rc = VERR_INTERNAL_ERROR;
2283
2284 Req.u.In.enmOp = SUPMSRPROBEROP_WRITE;
2285 Req.u.In.uMsr = uMsr;
2286 Req.u.In.idCpu = idCpu == NIL_RTCPUID ? UINT32_MAX : idCpu;
2287 Req.u.In.uArgs.Write.uToWrite = uValue;
2288
2289 int rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_MSR_PROBER, &Req, SUP_IOCTL_MSR_PROBER_SIZE);
2290 if (RT_SUCCESS(rc))
2291 rc = Req.Hdr.rc;
2292 if (RT_SUCCESS(rc) && pfGp)
2293 *pfGp = Req.u.Out.uResults.Write.fGp;
2294
2295 return rc;
2296}
2297
2298
2299SUPR3DECL(int) SUPR3MsrProberModify(uint32_t uMsr, RTCPUID idCpu, uint64_t fAndMask, uint64_t fOrMask,
2300 PSUPMSRPROBERMODIFYRESULT pResult)
2301{
2302 return SUPR3MsrProberModifyEx(uMsr, idCpu, fAndMask, fOrMask, false /*fFaster*/, pResult);
2303}
2304
2305
2306SUPR3DECL(int) SUPR3MsrProberModifyEx(uint32_t uMsr, RTCPUID idCpu, uint64_t fAndMask, uint64_t fOrMask, bool fFaster,
2307 PSUPMSRPROBERMODIFYRESULT pResult)
2308{
2309 SUPMSRPROBER Req;
2310 Req.Hdr.u32Cookie = g_u32Cookie;
2311 Req.Hdr.u32SessionCookie = g_u32SessionCookie;
2312 Req.Hdr.cbIn = SUP_IOCTL_MSR_PROBER_SIZE_IN;
2313 Req.Hdr.cbOut = SUP_IOCTL_MSR_PROBER_SIZE_OUT;
2314 Req.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT;
2315 Req.Hdr.rc = VERR_INTERNAL_ERROR;
2316
2317 Req.u.In.enmOp = fFaster ? SUPMSRPROBEROP_MODIFY_FASTER : SUPMSRPROBEROP_MODIFY;
2318 Req.u.In.uMsr = uMsr;
2319 Req.u.In.idCpu = idCpu == NIL_RTCPUID ? UINT32_MAX : idCpu;
2320 Req.u.In.uArgs.Modify.fAndMask = fAndMask;
2321 Req.u.In.uArgs.Modify.fOrMask = fOrMask;
2322
2323 int rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_MSR_PROBER, &Req, SUP_IOCTL_MSR_PROBER_SIZE);
2324 if (RT_SUCCESS(rc))
2325 rc = Req.Hdr.rc;
2326 if (RT_SUCCESS(rc))
2327 *pResult = Req.u.Out.uResults.Modify;
2328
2329 return rc;
2330}
2331
2332
2333SUPR3DECL(int) SUPR3ResumeSuspendedKeyboards(void)
2334{
2335#ifdef RT_OS_DARWIN
2336 /*
2337 * Issue IOCtl to the SUPDRV kernel module.
2338 */
2339 SUPREQHDR Req;
2340 Req.u32Cookie = g_u32Cookie;
2341 Req.u32SessionCookie= g_u32SessionCookie;
2342 Req.cbIn = SUP_IOCTL_RESUME_SUSPENDED_KBDS_SIZE_IN;
2343 Req.cbOut = SUP_IOCTL_RESUME_SUSPENDED_KBDS_SIZE_OUT;
2344 Req.fFlags = SUPREQHDR_FLAGS_DEFAULT;
2345 Req.rc = VERR_INTERNAL_ERROR;
2346 int rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_RESUME_SUSPENDED_KBDS, &Req, SUP_IOCTL_RESUME_SUSPENDED_KBDS_SIZE);
2347 if (RT_SUCCESS(rc))
2348 rc = Req.rc;
2349 return rc;
2350#else /* !RT_OS_DARWIN */
2351 return VERR_NOT_SUPPORTED;
2352#endif
2353}
2354
2355
2356SUPR3DECL(int) SUPR3TscDeltaMeasure(RTCPUID idCpu, bool fAsync, bool fForce, uint8_t cRetries, uint8_t cMsWaitRetry)
2357{
2358 SUPTSCDELTAMEASURE Req;
2359 Req.Hdr.u32Cookie = g_u32Cookie;
2360 Req.Hdr.u32SessionCookie = g_u32SessionCookie;
2361 Req.Hdr.cbIn = SUP_IOCTL_TSC_DELTA_MEASURE_SIZE_IN;
2362 Req.Hdr.cbOut = SUP_IOCTL_TSC_DELTA_MEASURE_SIZE_OUT;
2363 Req.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT;
2364 Req.Hdr.rc = VERR_INTERNAL_ERROR;
2365
2366 Req.u.In.cRetries = cRetries;
2367 Req.u.In.fAsync = fAsync;
2368 Req.u.In.fForce = fForce;
2369 Req.u.In.idCpu = idCpu;
2370 Req.u.In.cMsWaitRetry = cMsWaitRetry;
2371
2372 int rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_TSC_DELTA_MEASURE, &Req, SUP_IOCTL_TSC_DELTA_MEASURE_SIZE);
2373 if (RT_SUCCESS(rc))
2374 rc = Req.Hdr.rc;
2375 return rc;
2376}
2377
2378
2379SUPR3DECL(int) SUPR3ReadTsc(uint64_t *puTsc, uint16_t *pidApic)
2380{
2381 AssertReturn(puTsc, VERR_INVALID_PARAMETER);
2382
2383 SUPTSCREAD Req;
2384 Req.Hdr.u32Cookie = g_u32Cookie;
2385 Req.Hdr.u32SessionCookie = g_u32SessionCookie;
2386 Req.Hdr.cbIn = SUP_IOCTL_TSC_READ_SIZE_IN;
2387 Req.Hdr.cbOut = SUP_IOCTL_TSC_READ_SIZE_OUT;
2388 Req.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT;
2389 Req.Hdr.rc = VERR_INTERNAL_ERROR;
2390
2391 int rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_TSC_READ, &Req, SUP_IOCTL_TSC_READ_SIZE);
2392 if (RT_SUCCESS(rc))
2393 {
2394 rc = Req.Hdr.rc;
2395 *puTsc = Req.u.Out.u64AdjustedTsc;
2396 if (pidApic)
2397 *pidApic = Req.u.Out.idApic;
2398 }
2399 return rc;
2400}
2401
2402
2403SUPR3DECL(int) SUPR3GipSetFlags(uint32_t fOrMask, uint32_t fAndMask)
2404{
2405 AssertMsgReturn(!(fOrMask & ~SUPGIP_FLAGS_VALID_MASK),
2406 ("fOrMask=%#x ValidMask=%#x\n", fOrMask, SUPGIP_FLAGS_VALID_MASK), VERR_INVALID_PARAMETER);
2407 AssertMsgReturn((fAndMask & ~SUPGIP_FLAGS_VALID_MASK) == ~SUPGIP_FLAGS_VALID_MASK,
2408 ("fAndMask=%#x ValidMask=%#x\n", fAndMask, SUPGIP_FLAGS_VALID_MASK), VERR_INVALID_PARAMETER);
2409
2410 SUPGIPSETFLAGS Req;
2411 Req.Hdr.u32Cookie = g_u32Cookie;
2412 Req.Hdr.u32SessionCookie = g_u32SessionCookie;
2413 Req.Hdr.cbIn = SUP_IOCTL_GIP_SET_FLAGS_SIZE_IN;
2414 Req.Hdr.cbOut = SUP_IOCTL_GIP_SET_FLAGS_SIZE_OUT;
2415 Req.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT;
2416 Req.Hdr.rc = VERR_INTERNAL_ERROR;
2417
2418 Req.u.In.fAndMask = fAndMask;
2419 Req.u.In.fOrMask = fOrMask;
2420
2421 int rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_GIP_SET_FLAGS, &Req, SUP_IOCTL_GIP_SET_FLAGS_SIZE);
2422 if (RT_SUCCESS(rc))
2423 rc = Req.Hdr.rc;
2424 return rc;
2425}
2426
2427
2428SUPR3DECL(int) SUPR3GetHwvirtMsrs(PSUPHWVIRTMSRS pHwvirtMsrs, bool fForceRequery)
2429{
2430 AssertReturn(pHwvirtMsrs, VERR_INVALID_PARAMETER);
2431
2432 SUPGETHWVIRTMSRS Req;
2433 Req.Hdr.u32Cookie = g_u32Cookie;
2434 Req.Hdr.u32SessionCookie = g_u32SessionCookie;
2435 Req.Hdr.cbIn = SUP_IOCTL_GET_HWVIRT_MSRS_SIZE_IN;
2436 Req.Hdr.cbOut = SUP_IOCTL_GET_HWVIRT_MSRS_SIZE_OUT;
2437 Req.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT;
2438 Req.Hdr.rc = VERR_INTERNAL_ERROR;
2439
2440 Req.u.In.fForce = fForceRequery;
2441 Req.u.In.fReserved0 = false;
2442 Req.u.In.fReserved1 = false;
2443 Req.u.In.fReserved2 = false;
2444
2445 int rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_GET_HWVIRT_MSRS, &Req, SUP_IOCTL_GET_HWVIRT_MSRS_SIZE);
2446 if (RT_SUCCESS(rc))
2447 {
2448 rc = Req.Hdr.rc;
2449 *pHwvirtMsrs = Req.u.Out.HwvirtMsrs;
2450 }
2451 else
2452 RT_ZERO(*pHwvirtMsrs);
2453 return rc;
2454}
2455
Note: See TracBrowser for help on using the repository browser.

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