1 | /* $Id: SUPDrv-freebsd.c 53396 2014-11-25 15:01:59Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxDrv - The VirtualBox Support Driver - FreeBSD specifics.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (c) 2007 knut st. osmundsen <[email protected]>
|
---|
8 | *
|
---|
9 | * Permission is hereby granted, free of charge, to any person
|
---|
10 | * obtaining a copy of this software and associated documentation
|
---|
11 | * files (the "Software"), to deal in the Software without
|
---|
12 | * restriction, including without limitation the rights to use,
|
---|
13 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
|
---|
14 | * copies of the Software, and to permit persons to whom the
|
---|
15 | * Software is furnished to do so, subject to the following
|
---|
16 | * conditions:
|
---|
17 | *
|
---|
18 | * The above copyright notice and this permission notice shall be
|
---|
19 | * included in all copies or substantial portions of the Software.
|
---|
20 | *
|
---|
21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
---|
22 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
---|
23 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
---|
24 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
---|
25 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
---|
26 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
---|
27 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
---|
28 | * OTHER DEALINGS IN THE SOFTWARE.
|
---|
29 | */
|
---|
30 |
|
---|
31 | /*******************************************************************************
|
---|
32 | * Header Files *
|
---|
33 | *******************************************************************************/
|
---|
34 | #define LOG_GROUP LOG_GROUP_SUP_DRV
|
---|
35 | /* Deal with conflicts first. */
|
---|
36 | #include <sys/param.h>
|
---|
37 | #undef PVM
|
---|
38 | #include <sys/types.h>
|
---|
39 | #include <sys/module.h>
|
---|
40 | #include <sys/systm.h>
|
---|
41 | #include <sys/errno.h>
|
---|
42 | #include <sys/kernel.h>
|
---|
43 | #include <sys/fcntl.h>
|
---|
44 | #include <sys/conf.h>
|
---|
45 | #include <sys/uio.h>
|
---|
46 |
|
---|
47 | #include "../SUPDrvInternal.h"
|
---|
48 | #include <VBox/version.h>
|
---|
49 | #include <iprt/initterm.h>
|
---|
50 | #include <iprt/string.h>
|
---|
51 | #include <iprt/spinlock.h>
|
---|
52 | #include <iprt/process.h>
|
---|
53 | #include <iprt/assert.h>
|
---|
54 | #include <iprt/uuid.h>
|
---|
55 | #include <VBox/log.h>
|
---|
56 | #include <iprt/alloc.h>
|
---|
57 | #include <iprt/err.h>
|
---|
58 | #include <iprt/asm.h>
|
---|
59 |
|
---|
60 | #ifdef VBOX_WITH_HARDENING
|
---|
61 | # define VBOXDRV_PERM 0600
|
---|
62 | #else
|
---|
63 | # define VBOXDRV_PERM 0666
|
---|
64 | #endif
|
---|
65 |
|
---|
66 | /*******************************************************************************
|
---|
67 | * Internal Functions *
|
---|
68 | *******************************************************************************/
|
---|
69 | static int VBoxDrvFreeBSDModuleEvent(struct module *pMod, int enmEventType, void *pvArg);
|
---|
70 | static int VBoxDrvFreeBSDLoad(void);
|
---|
71 | static int VBoxDrvFreeBSDUnload(void);
|
---|
72 |
|
---|
73 | static d_open_t VBoxDrvFreeBSDOpenUsr;
|
---|
74 | static d_open_t VBoxDrvFreeBSDOpenSys;
|
---|
75 | static void VBoxDrvFreeBSDDtr(void *pData);
|
---|
76 | static d_ioctl_t VBoxDrvFreeBSDIOCtl;
|
---|
77 | static int VBoxDrvFreeBSDIOCtlSlow(PSUPDRVSESSION pSession, u_long ulCmd, caddr_t pvData, struct thread *pTd);
|
---|
78 |
|
---|
79 |
|
---|
80 | /*******************************************************************************
|
---|
81 | * Global Variables *
|
---|
82 | *******************************************************************************/
|
---|
83 | /**
|
---|
84 | * Module info structure used by the kernel.
|
---|
85 | */
|
---|
86 | static moduledata_t g_VBoxDrvFreeBSDModule =
|
---|
87 | {
|
---|
88 | "vboxdrv",
|
---|
89 | VBoxDrvFreeBSDModuleEvent,
|
---|
90 | NULL
|
---|
91 | };
|
---|
92 |
|
---|
93 | /** Declare the module as a pseudo device. */
|
---|
94 | DECLARE_MODULE(vboxdrv, g_VBoxDrvFreeBSDModule, SI_SUB_PSEUDO, SI_ORDER_ANY);
|
---|
95 | MODULE_VERSION(vboxdrv, 1);
|
---|
96 |
|
---|
97 | /**
|
---|
98 | * The /dev/vboxdrv character device entry points.
|
---|
99 | */
|
---|
100 | static struct cdevsw g_VBoxDrvFreeBSDChrDevSwSys =
|
---|
101 | {
|
---|
102 | .d_version = D_VERSION,
|
---|
103 | .d_open = VBoxDrvFreeBSDOpenSys,
|
---|
104 | .d_ioctl = VBoxDrvFreeBSDIOCtl,
|
---|
105 | .d_name = "vboxdrv"
|
---|
106 | };
|
---|
107 | /** The /dev/vboxdrv character device. */
|
---|
108 | static struct cdev *g_pVBoxDrvFreeBSDChrDevSys;
|
---|
109 |
|
---|
110 | /**
|
---|
111 | * The /dev/vboxdrvu character device entry points.
|
---|
112 | */
|
---|
113 | static struct cdevsw g_VBoxDrvFreeBSDChrDevSwUsr =
|
---|
114 | {
|
---|
115 | .d_version = D_VERSION,
|
---|
116 | .d_open = VBoxDrvFreeBSDOpenUsr,
|
---|
117 | .d_ioctl = VBoxDrvFreeBSDIOCtl,
|
---|
118 | .d_name = "vboxdrvu"
|
---|
119 | };
|
---|
120 | /** The /dev/vboxdrvu character device. */
|
---|
121 | static struct cdev *g_pVBoxDrvFreeBSDChrDevUsr;
|
---|
122 |
|
---|
123 | /** Reference counter. */
|
---|
124 | static volatile uint32_t g_cUsers;
|
---|
125 |
|
---|
126 | /** The device extention. */
|
---|
127 | static SUPDRVDEVEXT g_VBoxDrvFreeBSDDevExt;
|
---|
128 |
|
---|
129 | /**
|
---|
130 | * Module event handler.
|
---|
131 | *
|
---|
132 | * @param pMod The module structure.
|
---|
133 | * @param enmEventType The event type (modeventtype_t).
|
---|
134 | * @param pvArg Module argument. NULL.
|
---|
135 | *
|
---|
136 | * @return 0 on success, errno.h status code on failure.
|
---|
137 | */
|
---|
138 | static int VBoxDrvFreeBSDModuleEvent(struct module *pMod, int enmEventType, void *pvArg)
|
---|
139 | {
|
---|
140 | int rc;
|
---|
141 | switch (enmEventType)
|
---|
142 | {
|
---|
143 | case MOD_LOAD:
|
---|
144 | rc = VBoxDrvFreeBSDLoad();
|
---|
145 | break;
|
---|
146 |
|
---|
147 | case MOD_UNLOAD:
|
---|
148 | mtx_unlock(&Giant);
|
---|
149 | rc = VBoxDrvFreeBSDUnload();
|
---|
150 | mtx_lock(&Giant);
|
---|
151 | break;
|
---|
152 |
|
---|
153 | case MOD_SHUTDOWN:
|
---|
154 | case MOD_QUIESCE:
|
---|
155 | default:
|
---|
156 | return EOPNOTSUPP;
|
---|
157 | }
|
---|
158 |
|
---|
159 | if (RT_SUCCESS(rc))
|
---|
160 | return 0;
|
---|
161 | return RTErrConvertToErrno(rc);
|
---|
162 | }
|
---|
163 |
|
---|
164 |
|
---|
165 | static int VBoxDrvFreeBSDLoad(void)
|
---|
166 | {
|
---|
167 | g_cUsers = 0;
|
---|
168 |
|
---|
169 | /*
|
---|
170 | * Initialize the runtime.
|
---|
171 | */
|
---|
172 | int rc = RTR0Init(0);
|
---|
173 | if (RT_SUCCESS(rc))
|
---|
174 | {
|
---|
175 | Log(("VBoxDrvFreeBSDLoad:\n"));
|
---|
176 |
|
---|
177 | /*
|
---|
178 | * Initialize the device extension.
|
---|
179 | */
|
---|
180 | rc = supdrvInitDevExt(&g_VBoxDrvFreeBSDDevExt, sizeof(SUPDRVSESSION));
|
---|
181 | if (RT_SUCCESS(rc))
|
---|
182 | {
|
---|
183 | /*
|
---|
184 | * Configure character devices. Add symbolic links for compatibility.
|
---|
185 | */
|
---|
186 | g_pVBoxDrvFreeBSDChrDevSys = make_dev(&g_VBoxDrvFreeBSDChrDevSwSys, 0, UID_ROOT, GID_WHEEL, VBOXDRV_PERM, "vboxdrv");
|
---|
187 | g_pVBoxDrvFreeBSDChrDevUsr = make_dev(&g_VBoxDrvFreeBSDChrDevSwUsr, 1, UID_ROOT, GID_WHEEL, 0666, "vboxdrvu");
|
---|
188 | return VINF_SUCCESS;
|
---|
189 | }
|
---|
190 |
|
---|
191 | printf("vboxdrv: supdrvInitDevExt failed, rc=%d\n", rc);
|
---|
192 | RTR0Term();
|
---|
193 | }
|
---|
194 | else
|
---|
195 | printf("vboxdrv: RTR0Init failed, rc=%d\n", rc);
|
---|
196 | return rc;
|
---|
197 | }
|
---|
198 |
|
---|
199 | static int VBoxDrvFreeBSDUnload(void)
|
---|
200 | {
|
---|
201 | Log(("VBoxDrvFreeBSDUnload:\n"));
|
---|
202 |
|
---|
203 | if (g_cUsers > 0)
|
---|
204 | return VERR_RESOURCE_BUSY;
|
---|
205 |
|
---|
206 | /*
|
---|
207 | * Reserve what we did in VBoxDrvFreeBSDInit.
|
---|
208 | */
|
---|
209 | destroy_dev(g_pVBoxDrvFreeBSDChrDevUsr);
|
---|
210 | destroy_dev(g_pVBoxDrvFreeBSDChrDevSys);
|
---|
211 |
|
---|
212 | supdrvDeleteDevExt(&g_VBoxDrvFreeBSDDevExt);
|
---|
213 |
|
---|
214 | RTR0TermForced();
|
---|
215 |
|
---|
216 | memset(&g_VBoxDrvFreeBSDDevExt, 0, sizeof(g_VBoxDrvFreeBSDDevExt));
|
---|
217 | return VINF_SUCCESS;
|
---|
218 | }
|
---|
219 |
|
---|
220 |
|
---|
221 | /**
|
---|
222 | *
|
---|
223 | * @returns 0 on success, errno on failure.
|
---|
224 | * EBUSY if the device is used by someone else.
|
---|
225 | * @param pDev The device node.
|
---|
226 | * @param fOpen The open flags.
|
---|
227 | * @param pTd The thread.
|
---|
228 | * @param iDevType ???
|
---|
229 | */
|
---|
230 | static int vboxdrvFreeBSDOpenCommon(struct cdev *pDev, int fOpen, int iDevtype, struct thread *pTd, bool fUnrestricted)
|
---|
231 | {
|
---|
232 | PSUPDRVSESSION pSession;
|
---|
233 | int rc;
|
---|
234 |
|
---|
235 | /*
|
---|
236 | * Let's be a bit picky about the flags...
|
---|
237 | */
|
---|
238 | if (fOpen != (FREAD | FWRITE /*=O_RDWR*/))
|
---|
239 | {
|
---|
240 | Log(("VBoxDrvFreeBSDOpen: fOpen=%#x expected %#x\n", fOpen, O_RDWR));
|
---|
241 | return EINVAL;
|
---|
242 | }
|
---|
243 |
|
---|
244 | /*
|
---|
245 | * Create a new session.
|
---|
246 | */
|
---|
247 | rc = supdrvCreateSession(&g_VBoxDrvFreeBSDDevExt, true /* fUser */, fUnrestricted, &pSession);
|
---|
248 | if (RT_SUCCESS(rc))
|
---|
249 | {
|
---|
250 | /** @todo get (r)uid and (r)gid.
|
---|
251 | pSession->Uid = stuff;
|
---|
252 | pSession->Gid = stuff; */
|
---|
253 | devfs_set_cdevpriv(pSession, VBoxDrvFreeBSDDtr);
|
---|
254 | Log(("VBoxDrvFreeBSDOpen: pSession=%p\n", pSession));
|
---|
255 | ASMAtomicIncU32(&g_cUsers);
|
---|
256 | return 0;
|
---|
257 | }
|
---|
258 |
|
---|
259 | return RTErrConvertToErrno(rc);
|
---|
260 | }
|
---|
261 |
|
---|
262 |
|
---|
263 | /** For vboxdrv. */
|
---|
264 | static int VBoxDrvFreeBSDOpenSys(struct cdev *pDev, int fOpen, int iDevtype, struct thread *pTd)
|
---|
265 | {
|
---|
266 | return vboxdrvFreeBSDOpenCommon(pDev, fOpen, iDevtype, pTd, true);
|
---|
267 | }
|
---|
268 |
|
---|
269 |
|
---|
270 | /** For vboxdrvu. */
|
---|
271 | static int VBoxDrvFreeBSDOpenUsr(struct cdev *pDev, int fOpen, int iDevtype, struct thread *pTd)
|
---|
272 | {
|
---|
273 | return vboxdrvFreeBSDOpenCommon(pDev, fOpen, iDevtype, pTd, false);
|
---|
274 | }
|
---|
275 |
|
---|
276 |
|
---|
277 | /**
|
---|
278 | * Close a file device previously opened by VBoxDrvFreeBSDOpen
|
---|
279 | *
|
---|
280 | * @returns 0 on success.
|
---|
281 | * @param pDev The device.
|
---|
282 | * @param fFile The file descriptor flags.
|
---|
283 | * @param DevType The device type (CHR.
|
---|
284 | * @param pTd The calling thread.
|
---|
285 | */
|
---|
286 | static void VBoxDrvFreeBSDDtr(void *pData)
|
---|
287 | {
|
---|
288 | PSUPDRVSESSION pSession = pData;
|
---|
289 | Log(("VBoxDrvFreeBSDDtr: pSession=%p\n", pSession));
|
---|
290 |
|
---|
291 | /*
|
---|
292 | * Close the session.
|
---|
293 | */
|
---|
294 | supdrvSessionRelease(pSession);
|
---|
295 | ASMAtomicDecU32(&g_cUsers);
|
---|
296 | }
|
---|
297 |
|
---|
298 |
|
---|
299 | /**
|
---|
300 | * I/O control request.
|
---|
301 | *
|
---|
302 | * @returns depends...
|
---|
303 | * @param pDev The device.
|
---|
304 | * @param ulCmd The command.
|
---|
305 | * @param pvData Pointer to the data.
|
---|
306 | * @param fFile The file descriptor flags.
|
---|
307 | * @param pTd The calling thread.
|
---|
308 | */
|
---|
309 | static int VBoxDrvFreeBSDIOCtl(struct cdev *pDev, u_long ulCmd, caddr_t pvData, int fFile, struct thread *pTd)
|
---|
310 | {
|
---|
311 | PSUPDRVSESSION pSession;
|
---|
312 | devfs_get_cdevpriv((void **)&pSession);
|
---|
313 |
|
---|
314 | /*
|
---|
315 | * Deal with the fast ioctl path first.
|
---|
316 | */
|
---|
317 | if ( ( ulCmd == SUP_IOCTL_FAST_DO_RAW_RUN
|
---|
318 | || ulCmd == SUP_IOCTL_FAST_DO_HM_RUN
|
---|
319 | || ulCmd == SUP_IOCTL_FAST_DO_NOP)
|
---|
320 | && pSession->fUnrestricted == true)
|
---|
321 | return supdrvIOCtlFast(ulCmd, *(uint32_t *)pvData, &g_VBoxDrvFreeBSDDevExt, pSession);
|
---|
322 |
|
---|
323 | return VBoxDrvFreeBSDIOCtlSlow(pSession, ulCmd, pvData, pTd);
|
---|
324 | }
|
---|
325 |
|
---|
326 |
|
---|
327 | /**
|
---|
328 | * Deal with the 'slow' I/O control requests.
|
---|
329 | *
|
---|
330 | * @returns 0 on success, appropriate errno on failure.
|
---|
331 | * @param pSession The session.
|
---|
332 | * @param ulCmd The command.
|
---|
333 | * @param pvData The request data.
|
---|
334 | * @param pTd The calling thread.
|
---|
335 | */
|
---|
336 | static int VBoxDrvFreeBSDIOCtlSlow(PSUPDRVSESSION pSession, u_long ulCmd, caddr_t pvData, struct thread *pTd)
|
---|
337 | {
|
---|
338 | PSUPREQHDR pHdr;
|
---|
339 | uint32_t cbReq = IOCPARM_LEN(ulCmd);
|
---|
340 | void *pvUser = NULL;
|
---|
341 |
|
---|
342 | /*
|
---|
343 | * Buffered request?
|
---|
344 | */
|
---|
345 | if ((IOC_DIRMASK & ulCmd) == IOC_INOUT)
|
---|
346 | {
|
---|
347 | pHdr = (PSUPREQHDR)pvData;
|
---|
348 | if (RT_UNLIKELY(cbReq < sizeof(*pHdr)))
|
---|
349 | {
|
---|
350 | OSDBGPRINT(("VBoxDrvFreeBSDIOCtlSlow: cbReq=%#x < %#x; ulCmd=%#lx\n", cbReq, (int)sizeof(*pHdr), ulCmd));
|
---|
351 | return EINVAL;
|
---|
352 | }
|
---|
353 | if (RT_UNLIKELY((pHdr->fFlags & SUPREQHDR_FLAGS_MAGIC_MASK) != SUPREQHDR_FLAGS_MAGIC))
|
---|
354 | {
|
---|
355 | OSDBGPRINT(("VBoxDrvFreeBSDIOCtlSlow: bad magic fFlags=%#x; ulCmd=%#lx\n", pHdr->fFlags, ulCmd));
|
---|
356 | return EINVAL;
|
---|
357 | }
|
---|
358 | if (RT_UNLIKELY( RT_MAX(pHdr->cbIn, pHdr->cbOut) != cbReq
|
---|
359 | || pHdr->cbIn < sizeof(*pHdr)
|
---|
360 | || pHdr->cbOut < sizeof(*pHdr)))
|
---|
361 | {
|
---|
362 | OSDBGPRINT(("VBoxDrvFreeBSDIOCtlSlow: max(%#x,%#x) != %#x; ulCmd=%#lx\n", pHdr->cbIn, pHdr->cbOut, cbReq, ulCmd));
|
---|
363 | return EINVAL;
|
---|
364 | }
|
---|
365 | }
|
---|
366 | /*
|
---|
367 | * Big unbuffered request?
|
---|
368 | */
|
---|
369 | else if ((IOC_DIRMASK & ulCmd) == IOC_VOID && !cbReq)
|
---|
370 | {
|
---|
371 | /*
|
---|
372 | * Read the header, validate it and figure out how much that needs to be buffered.
|
---|
373 | */
|
---|
374 | SUPREQHDR Hdr;
|
---|
375 | pvUser = *(void **)pvData;
|
---|
376 | int rc = copyin(pvUser, &Hdr, sizeof(Hdr));
|
---|
377 | if (RT_UNLIKELY(rc))
|
---|
378 | {
|
---|
379 | OSDBGPRINT(("VBoxDrvFreeBSDIOCtlSlow: copyin(%p,Hdr,) -> %#x; ulCmd=%#lx\n", pvUser, rc, ulCmd));
|
---|
380 | return rc;
|
---|
381 | }
|
---|
382 | if (RT_UNLIKELY((Hdr.fFlags & SUPREQHDR_FLAGS_MAGIC_MASK) != SUPREQHDR_FLAGS_MAGIC))
|
---|
383 | {
|
---|
384 | OSDBGPRINT(("VBoxDrvFreeBSDIOCtlSlow: bad magic fFlags=%#x; ulCmd=%#lx\n", Hdr.fFlags, ulCmd));
|
---|
385 | return EINVAL;
|
---|
386 | }
|
---|
387 | cbReq = RT_MAX(Hdr.cbIn, Hdr.cbOut);
|
---|
388 | if (RT_UNLIKELY( Hdr.cbIn < sizeof(Hdr)
|
---|
389 | || Hdr.cbOut < sizeof(Hdr)
|
---|
390 | || cbReq > _1M*16))
|
---|
391 | {
|
---|
392 | OSDBGPRINT(("VBoxDrvFreeBSDIOCtlSlow: max(%#x,%#x); ulCmd=%#lx\n", Hdr.cbIn, Hdr.cbOut, ulCmd));
|
---|
393 | return EINVAL;
|
---|
394 | }
|
---|
395 |
|
---|
396 | /*
|
---|
397 | * Allocate buffer and copy in the data.
|
---|
398 | */
|
---|
399 | pHdr = (PSUPREQHDR)RTMemTmpAlloc(cbReq);
|
---|
400 | if (RT_UNLIKELY(!pHdr))
|
---|
401 | {
|
---|
402 | OSDBGPRINT(("VBoxDrvFreeBSDIOCtlSlow: failed to allocate buffer of %d bytes; ulCmd=%#lx\n", cbReq, ulCmd));
|
---|
403 | return ENOMEM;
|
---|
404 | }
|
---|
405 | rc = copyin(pvUser, pHdr, Hdr.cbIn);
|
---|
406 | if (RT_UNLIKELY(rc))
|
---|
407 | {
|
---|
408 | OSDBGPRINT(("VBoxDrvFreeBSDIOCtlSlow: copyin(%p,%p,%#x) -> %#x; ulCmd=%#lx\n",
|
---|
409 | pvUser, pHdr, Hdr.cbIn, rc, ulCmd));
|
---|
410 | RTMemTmpFree(pHdr);
|
---|
411 | return rc;
|
---|
412 | }
|
---|
413 | if (Hdr.cbIn < cbReq)
|
---|
414 | RT_BZERO((uint8_t *)pHdr + Hdr.cbIn, cbReq - Hdr.cbIn);
|
---|
415 | }
|
---|
416 | else
|
---|
417 | {
|
---|
418 | Log(("VBoxDrvFreeBSDIOCtlSlow: huh? cbReq=%#x ulCmd=%#lx\n", cbReq, ulCmd));
|
---|
419 | return EINVAL;
|
---|
420 | }
|
---|
421 |
|
---|
422 | /*
|
---|
423 | * Process the IOCtl.
|
---|
424 | */
|
---|
425 | int rc = supdrvIOCtl(ulCmd, &g_VBoxDrvFreeBSDDevExt, pSession, pHdr, cbReq);
|
---|
426 | if (RT_LIKELY(!rc))
|
---|
427 | {
|
---|
428 | /*
|
---|
429 | * If unbuffered, copy back the result before returning.
|
---|
430 | */
|
---|
431 | if (pvUser)
|
---|
432 | {
|
---|
433 | uint32_t cbOut = pHdr->cbOut;
|
---|
434 | if (cbOut > cbReq)
|
---|
435 | {
|
---|
436 | OSDBGPRINT(("VBoxDrvFreeBSDIOCtlSlow: too much output! %#x > %#x; uCmd=%#lx!\n", cbOut, cbReq, ulCmd));
|
---|
437 | cbOut = cbReq;
|
---|
438 | }
|
---|
439 | rc = copyout(pHdr, pvUser, cbOut);
|
---|
440 | if (RT_UNLIKELY(rc))
|
---|
441 | OSDBGPRINT(("VBoxDrvFreeBSDIOCtlSlow: copyout(%p,%p,%#x) -> %d; uCmd=%#lx!\n", pHdr, pvUser, cbOut, rc, ulCmd));
|
---|
442 |
|
---|
443 | Log(("VBoxDrvFreeBSDIOCtlSlow: returns %d / %d ulCmd=%lx\n", 0, pHdr->rc, ulCmd));
|
---|
444 |
|
---|
445 | /* cleanup */
|
---|
446 | RTMemTmpFree(pHdr);
|
---|
447 | }
|
---|
448 | }
|
---|
449 | else
|
---|
450 | {
|
---|
451 | /*
|
---|
452 | * The request failed, just clean up.
|
---|
453 | */
|
---|
454 | if (pvUser)
|
---|
455 | RTMemTmpFree(pHdr);
|
---|
456 |
|
---|
457 | Log(("VBoxDrvFreeBSDIOCtlSlow: ulCmd=%lx pData=%p failed, rc=%d\n", ulCmd, pvData, rc));
|
---|
458 | rc = EINVAL;
|
---|
459 | }
|
---|
460 |
|
---|
461 | return rc;
|
---|
462 | }
|
---|
463 |
|
---|
464 |
|
---|
465 | /**
|
---|
466 | * The SUPDRV IDC entry point.
|
---|
467 | *
|
---|
468 | * @returns VBox status code, see supdrvIDC.
|
---|
469 | * @param iReq The request code.
|
---|
470 | * @param pReq The request.
|
---|
471 | */
|
---|
472 | int VBOXCALL SUPDrvFreeBSDIDC(uint32_t uReq, PSUPDRVIDCREQHDR pReq)
|
---|
473 | {
|
---|
474 | PSUPDRVSESSION pSession;
|
---|
475 |
|
---|
476 | /*
|
---|
477 | * Some quick validations.
|
---|
478 | */
|
---|
479 | if (RT_UNLIKELY(!VALID_PTR(pReq)))
|
---|
480 | return VERR_INVALID_POINTER;
|
---|
481 |
|
---|
482 | pSession = pReq->pSession;
|
---|
483 | if (pSession)
|
---|
484 | {
|
---|
485 | if (RT_UNLIKELY(!VALID_PTR(pReq->pSession)))
|
---|
486 | return VERR_INVALID_PARAMETER;
|
---|
487 | if (RT_UNLIKELY(pSession->pDevExt != &g_VBoxDrvFreeBSDDevExt))
|
---|
488 | return VERR_INVALID_PARAMETER;
|
---|
489 | }
|
---|
490 | else if (RT_UNLIKELY(uReq != SUPDRV_IDC_REQ_CONNECT))
|
---|
491 | return VERR_INVALID_PARAMETER;
|
---|
492 |
|
---|
493 | /*
|
---|
494 | * Do the job.
|
---|
495 | */
|
---|
496 | return supdrvIDC(uReq, &g_VBoxDrvFreeBSDDevExt, pSession, pReq);
|
---|
497 | }
|
---|
498 |
|
---|
499 |
|
---|
500 | void VBOXCALL supdrvOSCleanupSession(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession)
|
---|
501 | {
|
---|
502 | NOREF(pDevExt);
|
---|
503 | NOREF(pSession);
|
---|
504 | }
|
---|
505 |
|
---|
506 |
|
---|
507 | void VBOXCALL supdrvOSSessionHashTabInserted(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, void *pvUser)
|
---|
508 | {
|
---|
509 | NOREF(pDevExt); NOREF(pSession); NOREF(pvUser);
|
---|
510 | }
|
---|
511 |
|
---|
512 |
|
---|
513 | void VBOXCALL supdrvOSSessionHashTabRemoved(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, void *pvUser)
|
---|
514 | {
|
---|
515 | NOREF(pDevExt); NOREF(pSession); NOREF(pvUser);
|
---|
516 | }
|
---|
517 |
|
---|
518 |
|
---|
519 | void VBOXCALL supdrvOSObjInitCreator(PSUPDRVOBJ pObj, PSUPDRVSESSION pSession)
|
---|
520 | {
|
---|
521 | NOREF(pObj);
|
---|
522 | NOREF(pSession);
|
---|
523 | }
|
---|
524 |
|
---|
525 |
|
---|
526 | bool VBOXCALL supdrvOSObjCanAccess(PSUPDRVOBJ pObj, PSUPDRVSESSION pSession, const char *pszObjName, int *prc)
|
---|
527 | {
|
---|
528 | NOREF(pObj);
|
---|
529 | NOREF(pSession);
|
---|
530 | NOREF(pszObjName);
|
---|
531 | NOREF(prc);
|
---|
532 | return false;
|
---|
533 | }
|
---|
534 |
|
---|
535 |
|
---|
536 | bool VBOXCALL supdrvOSGetForcedAsyncTscMode(PSUPDRVDEVEXT pDevExt)
|
---|
537 | {
|
---|
538 | return false;
|
---|
539 | }
|
---|
540 |
|
---|
541 |
|
---|
542 | bool VBOXCALL supdrvOSAreTscDeltasInSync(void)
|
---|
543 | {
|
---|
544 | return false;
|
---|
545 | }
|
---|
546 |
|
---|
547 |
|
---|
548 | int VBOXCALL supdrvOSLdrOpen(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, const char *pszFilename)
|
---|
549 | {
|
---|
550 | NOREF(pDevExt); NOREF(pImage); NOREF(pszFilename);
|
---|
551 | return VERR_NOT_SUPPORTED;
|
---|
552 | }
|
---|
553 |
|
---|
554 |
|
---|
555 | void VBOXCALL supdrvOSLdrNotifyOpened(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage)
|
---|
556 | {
|
---|
557 | NOREF(pDevExt); NOREF(pImage);
|
---|
558 | }
|
---|
559 |
|
---|
560 |
|
---|
561 | int VBOXCALL supdrvOSLdrValidatePointer(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, void *pv, const uint8_t *pbImageBits)
|
---|
562 | {
|
---|
563 | NOREF(pDevExt); NOREF(pImage); NOREF(pv); NOREF(pbImageBits);
|
---|
564 | return VERR_NOT_SUPPORTED;
|
---|
565 | }
|
---|
566 |
|
---|
567 |
|
---|
568 | int VBOXCALL supdrvOSLdrLoad(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, const uint8_t *pbImageBits, PSUPLDRLOAD pReq)
|
---|
569 | {
|
---|
570 | NOREF(pDevExt); NOREF(pImage); NOREF(pbImageBits); NOREF(pReq);
|
---|
571 | return VERR_NOT_SUPPORTED;
|
---|
572 | }
|
---|
573 |
|
---|
574 |
|
---|
575 | void VBOXCALL supdrvOSLdrUnload(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage)
|
---|
576 | {
|
---|
577 | NOREF(pDevExt); NOREF(pImage);
|
---|
578 | }
|
---|
579 |
|
---|
580 |
|
---|
581 | #ifdef SUPDRV_WITH_MSR_PROBER
|
---|
582 |
|
---|
583 | int VBOXCALL supdrvOSMsrProberRead(uint32_t uMsr, RTCPUID idCpu, uint64_t *puValue)
|
---|
584 | {
|
---|
585 | NOREF(uMsr); NOREF(idCpu); NOREF(puValue);
|
---|
586 | return VERR_NOT_SUPPORTED;
|
---|
587 | }
|
---|
588 |
|
---|
589 |
|
---|
590 | int VBOXCALL supdrvOSMsrProberWrite(uint32_t uMsr, RTCPUID idCpu, uint64_t uValue)
|
---|
591 | {
|
---|
592 | NOREF(uMsr); NOREF(idCpu); NOREF(uValue);
|
---|
593 | return VERR_NOT_SUPPORTED;
|
---|
594 | }
|
---|
595 |
|
---|
596 |
|
---|
597 | int VBOXCALL supdrvOSMsrProberModify(RTCPUID idCpu, PSUPMSRPROBER pReq)
|
---|
598 | {
|
---|
599 | NOREF(idCpu); NOREF(pReq);
|
---|
600 | return VERR_NOT_SUPPORTED;
|
---|
601 | }
|
---|
602 |
|
---|
603 | #endif /* SUPDRV_WITH_MSR_PROBER */
|
---|
604 |
|
---|
605 |
|
---|
606 | SUPR0DECL(int) SUPR0Printf(const char *pszFormat, ...)
|
---|
607 | {
|
---|
608 | va_list va;
|
---|
609 | char szMsg[256];
|
---|
610 | int cch;
|
---|
611 |
|
---|
612 | va_start(va, pszFormat);
|
---|
613 | cch = RTStrPrintfV(szMsg, sizeof(szMsg), pszFormat, va);
|
---|
614 | va_end(va);
|
---|
615 |
|
---|
616 | printf("%s", szMsg);
|
---|
617 |
|
---|
618 | return cch;
|
---|
619 | }
|
---|
620 |
|
---|
621 |
|
---|
622 | /**
|
---|
623 | * Returns configuration flags of the host kernel.
|
---|
624 | */
|
---|
625 | SUPR0DECL(uint32_t) SUPR0GetKernelFeatures(void)
|
---|
626 | {
|
---|
627 | return 0;
|
---|
628 | }
|
---|
629 |
|
---|