1 | /* $Id: PDMR0Driver.cpp 84071 2020-04-29 07:30:02Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * PDM - Pluggable Device and Driver Manager, R0 Driver parts.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2010-2020 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 |
|
---|
19 | /*********************************************************************************************************************************
|
---|
20 | * Header Files *
|
---|
21 | *********************************************************************************************************************************/
|
---|
22 | #define LOG_GROUP LOG_GROUP_PDM_DRIVER
|
---|
23 | #include "PDMInternal.h"
|
---|
24 | #include <VBox/vmm/pdm.h>
|
---|
25 | #include <VBox/vmm/vmcc.h>
|
---|
26 | #include <VBox/vmm/gvmm.h>
|
---|
27 |
|
---|
28 | #include <VBox/log.h>
|
---|
29 | #include <iprt/errcore.h>
|
---|
30 | #include <iprt/assert.h>
|
---|
31 |
|
---|
32 |
|
---|
33 | /*********************************************************************************************************************************
|
---|
34 | * Global Variables *
|
---|
35 | *********************************************************************************************************************************/
|
---|
36 | RT_C_DECLS_BEGIN
|
---|
37 | extern DECLEXPORT(const PDMDRVHLPR0) g_pdmR0DrvHlp;
|
---|
38 | RT_C_DECLS_END
|
---|
39 |
|
---|
40 |
|
---|
41 | /** @name Ring-0 Context Driver Helpers
|
---|
42 | * @{
|
---|
43 | */
|
---|
44 |
|
---|
45 | /** @interface_method_impl{PDMDRVHLPR0,pfnVMSetError} */
|
---|
46 | static DECLCALLBACK(int) pdmR0DrvHlp_VMSetError(PPDMDRVINS pDrvIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, ...)
|
---|
47 | {
|
---|
48 | PDMDRV_ASSERT_DRVINS(pDrvIns);
|
---|
49 | va_list args;
|
---|
50 | va_start(args, pszFormat);
|
---|
51 | int rc2 = VMSetErrorV(pDrvIns->Internal.s.pVMR0, rc, RT_SRC_POS_ARGS, pszFormat, args); Assert(rc2 == rc); NOREF(rc2);
|
---|
52 | va_end(args);
|
---|
53 | return rc;
|
---|
54 | }
|
---|
55 |
|
---|
56 |
|
---|
57 | /** @interface_method_impl{PDMDRVHLPR0,pfnVMSetErrorV} */
|
---|
58 | static DECLCALLBACK(int) pdmR0DrvHlp_VMSetErrorV(PPDMDRVINS pDrvIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va)
|
---|
59 | {
|
---|
60 | PDMDRV_ASSERT_DRVINS(pDrvIns);
|
---|
61 | int rc2 = VMSetErrorV(pDrvIns->Internal.s.pVMR0, rc, RT_SRC_POS_ARGS, pszFormat, va); Assert(rc2 == rc); NOREF(rc2);
|
---|
62 | return rc;
|
---|
63 | }
|
---|
64 |
|
---|
65 |
|
---|
66 | /** @interface_method_impl{PDMDRVHLPR0,pfnVMSetRuntimeError} */
|
---|
67 | static DECLCALLBACK(int) pdmR0DrvHlp_VMSetRuntimeError(PPDMDRVINS pDrvIns, uint32_t fFlags, const char *pszErrorId,
|
---|
68 | const char *pszFormat, ...)
|
---|
69 | {
|
---|
70 | PDMDRV_ASSERT_DRVINS(pDrvIns);
|
---|
71 | va_list va;
|
---|
72 | va_start(va, pszFormat);
|
---|
73 | int rc = VMSetRuntimeErrorV(pDrvIns->Internal.s.pVMR0, fFlags, pszErrorId, pszFormat, va);
|
---|
74 | va_end(va);
|
---|
75 | return rc;
|
---|
76 | }
|
---|
77 |
|
---|
78 |
|
---|
79 | /** @interface_method_impl{PDMDRVHLPR0,pfnVMSetRuntimeErrorV} */
|
---|
80 | static DECLCALLBACK(int) pdmR0DrvHlp_VMSetRuntimeErrorV(PPDMDRVINS pDrvIns, uint32_t fFlags, const char *pszErrorId,
|
---|
81 | const char *pszFormat, va_list va)
|
---|
82 | {
|
---|
83 | PDMDRV_ASSERT_DRVINS(pDrvIns);
|
---|
84 | int rc = VMSetRuntimeErrorV(pDrvIns->Internal.s.pVMR0, fFlags, pszErrorId, pszFormat, va);
|
---|
85 | return rc;
|
---|
86 | }
|
---|
87 |
|
---|
88 |
|
---|
89 | /** @interface_method_impl{PDMDRVHLPR0,pfnAssertEMT} */
|
---|
90 | static DECLCALLBACK(bool) pdmR0DrvHlp_AssertEMT(PPDMDRVINS pDrvIns, const char *pszFile, unsigned iLine, const char *pszFunction)
|
---|
91 | {
|
---|
92 | PDMDRV_ASSERT_DRVINS(pDrvIns);
|
---|
93 | if (VM_IS_EMT(pDrvIns->Internal.s.pVMR0))
|
---|
94 | return true;
|
---|
95 |
|
---|
96 | RTAssertMsg1Weak("AssertEMT", iLine, pszFile, pszFunction);
|
---|
97 | RTAssertPanic();
|
---|
98 | return false;
|
---|
99 | }
|
---|
100 |
|
---|
101 |
|
---|
102 | /** @interface_method_impl{PDMDRVHLPR0,pfnAssertOther} */
|
---|
103 | static DECLCALLBACK(bool) pdmR0DrvHlp_AssertOther(PPDMDRVINS pDrvIns, const char *pszFile, unsigned iLine, const char *pszFunction)
|
---|
104 | {
|
---|
105 | PDMDRV_ASSERT_DRVINS(pDrvIns);
|
---|
106 | if (!VM_IS_EMT(pDrvIns->Internal.s.pVMR0))
|
---|
107 | return true;
|
---|
108 |
|
---|
109 | RTAssertMsg1Weak("AssertOther", iLine, pszFile, pszFunction);
|
---|
110 | RTAssertPanic();
|
---|
111 | return false;
|
---|
112 | }
|
---|
113 |
|
---|
114 |
|
---|
115 | /**
|
---|
116 | * The Ring-0 Context Driver Helper Callbacks.
|
---|
117 | */
|
---|
118 | extern DECLEXPORT(const PDMDRVHLPR0) g_pdmR0DrvHlp =
|
---|
119 | {
|
---|
120 | PDM_DRVHLPRC_VERSION,
|
---|
121 | pdmR0DrvHlp_VMSetError,
|
---|
122 | pdmR0DrvHlp_VMSetErrorV,
|
---|
123 | pdmR0DrvHlp_VMSetRuntimeError,
|
---|
124 | pdmR0DrvHlp_VMSetRuntimeErrorV,
|
---|
125 | pdmR0DrvHlp_AssertEMT,
|
---|
126 | pdmR0DrvHlp_AssertOther,
|
---|
127 | PDM_DRVHLPRC_VERSION
|
---|
128 | };
|
---|
129 |
|
---|
130 | /** @} */
|
---|
131 |
|
---|
132 |
|
---|
133 |
|
---|
134 | /**
|
---|
135 | * PDMDrvHlpCallR0 helper.
|
---|
136 | *
|
---|
137 | * @returns See PFNPDMDRVREQHANDLERR0.
|
---|
138 | * @param pGVM The global (ring-0) VM structure. (For validation.)
|
---|
139 | * @param pReq Pointer to the request buffer.
|
---|
140 | */
|
---|
141 | VMMR0_INT_DECL(int) PDMR0DriverCallReqHandler(PGVM pGVM, PPDMDRIVERCALLREQHANDLERREQ pReq)
|
---|
142 | {
|
---|
143 | /*
|
---|
144 | * Validate input and make the call.
|
---|
145 | */
|
---|
146 | int rc = GVMMR0ValidateGVM(pGVM);
|
---|
147 | if (RT_SUCCESS(rc))
|
---|
148 | {
|
---|
149 | AssertPtrReturn(pReq, VERR_INVALID_POINTER);
|
---|
150 | AssertMsgReturn(pReq->Hdr.cbReq == sizeof(*pReq), ("%#x != %#x\n", pReq->Hdr.cbReq, sizeof(*pReq)), VERR_INVALID_PARAMETER);
|
---|
151 |
|
---|
152 | PPDMDRVINS pDrvIns = pReq->pDrvInsR0;
|
---|
153 | AssertPtrReturn(pDrvIns, VERR_INVALID_POINTER);
|
---|
154 | AssertReturn(pDrvIns->Internal.s.pVMR0 == pGVM, VERR_INVALID_PARAMETER);
|
---|
155 |
|
---|
156 | PFNPDMDRVREQHANDLERR0 pfnReqHandlerR0 = pDrvIns->Internal.s.pfnReqHandlerR0;
|
---|
157 | AssertPtrReturn(pfnReqHandlerR0, VERR_INVALID_POINTER);
|
---|
158 |
|
---|
159 | rc = pfnReqHandlerR0(pDrvIns, pReq->uOperation, pReq->u64Arg);
|
---|
160 | }
|
---|
161 | return rc;
|
---|
162 | }
|
---|
163 |
|
---|