1 | /* $Id: SUPDrv-freebsd.c 59217 2015-12-22 21:11:49Z 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 | /*********************************************************************************************************************************
|
---|
33 | * Header Files *
|
---|
34 | *********************************************************************************************************************************/
|
---|
35 | #define LOG_GROUP LOG_GROUP_SUP_DRV
|
---|
36 | /* Deal with conflicts first. */
|
---|
37 | #include <sys/param.h>
|
---|
38 | #undef PVM
|
---|
39 | #include <sys/types.h>
|
---|
40 | #include <sys/module.h>
|
---|
41 | #include <sys/systm.h>
|
---|
42 | #include <sys/errno.h>
|
---|
43 | #include <sys/kernel.h>
|
---|
44 | #include <sys/fcntl.h>
|
---|
45 | #include <sys/conf.h>
|
---|
46 | #include <sys/uio.h>
|
---|
47 |
|
---|
48 | #include "../SUPDrvInternal.h"
|
---|
49 | #include <VBox/version.h>
|
---|
50 | #include <iprt/initterm.h>
|
---|
51 | #include <iprt/string.h>
|
---|
52 | #include <iprt/spinlock.h>
|
---|
53 | #include <iprt/process.h>
|
---|
54 | #include <iprt/assert.h>
|
---|
55 | #include <iprt/uuid.h>
|
---|
56 | #include <VBox/log.h>
|
---|
57 | #include <iprt/alloc.h>
|
---|
58 | #include <iprt/err.h>
|
---|
59 | #include <iprt/asm.h>
|
---|
60 |
|
---|
61 | #ifdef VBOX_WITH_HARDENING
|
---|
62 | # define VBOXDRV_PERM 0600
|
---|
63 | #else
|
---|
64 | # define VBOXDRV_PERM 0666
|
---|
65 | #endif
|
---|
66 |
|
---|
67 |
|
---|
68 | /*********************************************************************************************************************************
|
---|
69 | * Internal Functions *
|
---|
70 | *********************************************************************************************************************************/
|
---|
71 | static int VBoxDrvFreeBSDModuleEvent(struct module *pMod, int enmEventType, void *pvArg);
|
---|
72 | static int VBoxDrvFreeBSDLoad(void);
|
---|
73 | static int VBoxDrvFreeBSDUnload(void);
|
---|
74 |
|
---|
75 | static d_open_t VBoxDrvFreeBSDOpenUsr;
|
---|
76 | static d_open_t VBoxDrvFreeBSDOpenSys;
|
---|
77 | static void vboxdrvFreeBSDDtr(void *pvData);
|
---|
78 | static d_ioctl_t VBoxDrvFreeBSDIOCtl;
|
---|
79 | static int VBoxDrvFreeBSDIOCtlSlow(PSUPDRVSESSION pSession, u_long ulCmd, caddr_t pvData, struct thread *pTd);
|
---|
80 |
|
---|
81 |
|
---|
82 | /*********************************************************************************************************************************
|
---|
83 | * Global Variables *
|
---|
84 | *********************************************************************************************************************************/
|
---|
85 | /**
|
---|
86 | * Module info structure used by the kernel.
|
---|
87 | */
|
---|
88 | static moduledata_t g_VBoxDrvFreeBSDModule =
|
---|
89 | {
|
---|
90 | "vboxdrv",
|
---|
91 | VBoxDrvFreeBSDModuleEvent,
|
---|
92 | NULL
|
---|
93 | };
|
---|
94 |
|
---|
95 | /** Declare the module as a pseudo device. */
|
---|
96 | DECLARE_MODULE(vboxdrv, g_VBoxDrvFreeBSDModule, SI_SUB_PSEUDO, SI_ORDER_ANY);
|
---|
97 | MODULE_VERSION(vboxdrv, 1);
|
---|
98 |
|
---|
99 | /**
|
---|
100 | * The /dev/vboxdrv character device entry points.
|
---|
101 | */
|
---|
102 | static struct cdevsw g_VBoxDrvFreeBSDChrDevSwSys =
|
---|
103 | {
|
---|
104 | .d_version = D_VERSION,
|
---|
105 | .d_open = VBoxDrvFreeBSDOpenSys,
|
---|
106 | .d_ioctl = VBoxDrvFreeBSDIOCtl,
|
---|
107 | .d_name = "vboxdrv"
|
---|
108 | };
|
---|
109 | /** The /dev/vboxdrv character device. */
|
---|
110 | static struct cdev *g_pVBoxDrvFreeBSDChrDevSys;
|
---|
111 |
|
---|
112 | /**
|
---|
113 | * The /dev/vboxdrvu character device entry points.
|
---|
114 | */
|
---|
115 | static struct cdevsw g_VBoxDrvFreeBSDChrDevSwUsr =
|
---|
116 | {
|
---|
117 | .d_version = D_VERSION,
|
---|
118 | .d_open = VBoxDrvFreeBSDOpenUsr,
|
---|
119 | .d_ioctl = VBoxDrvFreeBSDIOCtl,
|
---|
120 | .d_name = "vboxdrvu"
|
---|
121 | };
|
---|
122 | /** The /dev/vboxdrvu character device. */
|
---|
123 | static struct cdev *g_pVBoxDrvFreeBSDChrDevUsr;
|
---|
124 |
|
---|
125 | /** Reference counter. */
|
---|
126 | static volatile uint32_t g_cUsers;
|
---|
127 |
|
---|
128 | /** The device extention. */
|
---|
129 | static SUPDRVDEVEXT g_VBoxDrvFreeBSDDevExt;
|
---|
130 |
|
---|
131 | /**
|
---|
132 | * Module event handler.
|
---|
133 | *
|
---|
134 | * @param pMod The module structure.
|
---|
135 | * @param enmEventType The event type (modeventtype_t).
|
---|
136 | * @param pvArg Module argument. NULL.
|
---|
137 | *
|
---|
138 | * @return 0 on success, errno.h status code on failure.
|
---|
139 | */
|
---|
140 | static int VBoxDrvFreeBSDModuleEvent(struct module *pMod, int enmEventType, void *pvArg)
|
---|
141 | {
|
---|
142 | int rc;
|
---|
143 | switch (enmEventType)
|
---|
144 | {
|
---|
145 | case MOD_LOAD:
|
---|
146 | rc = VBoxDrvFreeBSDLoad();
|
---|
147 | break;
|
---|
148 |
|
---|
149 | case MOD_UNLOAD:
|
---|
150 | mtx_unlock(&Giant);
|
---|
151 | rc = VBoxDrvFreeBSDUnload();
|
---|
152 | mtx_lock(&Giant);
|
---|
153 | break;
|
---|
154 |
|
---|
155 | case MOD_SHUTDOWN:
|
---|
156 | case MOD_QUIESCE:
|
---|
157 | default:
|
---|
158 | return EOPNOTSUPP;
|
---|
159 | }
|
---|
160 |
|
---|
161 | if (RT_SUCCESS(rc))
|
---|
162 | return 0;
|
---|
163 | return RTErrConvertToErrno(rc);
|
---|
164 | }
|
---|
165 |
|
---|
166 |
|
---|
167 | static int VBoxDrvFreeBSDLoad(void)
|
---|
168 | {
|
---|
169 | g_cUsers = 0;
|
---|
170 |
|
---|
171 | /*
|
---|
172 | * Initialize the runtime.
|
---|
173 | */
|
---|
174 | int rc = RTR0Init(0);
|
---|
175 | if (RT_SUCCESS(rc))
|
---|
176 | {
|
---|
177 | Log(("VBoxDrvFreeBSDLoad:\n"));
|
---|
178 |
|
---|
179 | /*
|
---|
180 | * Initialize the device extension.
|
---|
181 | */
|
---|
182 | rc = supdrvInitDevExt(&g_VBoxDrvFreeBSDDevExt, sizeof(SUPDRVSESSION));
|
---|
183 | if (RT_SUCCESS(rc))
|
---|
184 | {
|
---|
185 | /*
|
---|
186 | * Configure character devices. Add symbolic links for compatibility.
|
---|
187 | */
|
---|
188 | g_pVBoxDrvFreeBSDChrDevSys = make_dev(&g_VBoxDrvFreeBSDChrDevSwSys, 0, UID_ROOT, GID_WHEEL, VBOXDRV_PERM, "vboxdrv");
|
---|
189 | g_pVBoxDrvFreeBSDChrDevUsr = make_dev(&g_VBoxDrvFreeBSDChrDevSwUsr, 1, UID_ROOT, GID_WHEEL, 0666, "vboxdrvu");
|
---|
190 | return VINF_SUCCESS;
|
---|
191 | }
|
---|
192 |
|
---|
193 | printf("vboxdrv: supdrvInitDevExt failed, rc=%d\n", rc);
|
---|
194 | RTR0Term();
|
---|
195 | }
|
---|
196 | else
|
---|
197 | printf("vboxdrv: RTR0Init failed, rc=%d\n", rc);
|
---|
198 | return rc;
|
---|
199 | }
|
---|
200 |
|
---|
201 | static int VBoxDrvFreeBSDUnload(void)
|
---|
202 | {
|
---|
203 | Log(("VBoxDrvFreeBSDUnload:\n"));
|
---|
204 |
|
---|
205 | if (g_cUsers > 0)
|
---|
206 | return VERR_RESOURCE_BUSY;
|
---|
207 |
|
---|
208 | /*
|
---|
209 | * Reserve what we did in VBoxDrvFreeBSDInit.
|
---|
210 | */
|
---|
211 | destroy_dev(g_pVBoxDrvFreeBSDChrDevUsr);
|
---|
212 | destroy_dev(g_pVBoxDrvFreeBSDChrDevSys);
|
---|
213 |
|
---|
214 | supdrvDeleteDevExt(&g_VBoxDrvFreeBSDDevExt);
|
---|
215 |
|
---|
216 | RTR0TermForced();
|
---|
217 |
|
---|
218 | memset(&g_VBoxDrvFreeBSDDevExt, 0, sizeof(g_VBoxDrvFreeBSDDevExt));
|
---|
219 | return VINF_SUCCESS;
|
---|
220 | }
|
---|
221 |
|
---|
222 |
|
---|
223 | /**
|
---|
224 | *
|
---|
225 | * @returns 0 on success, errno on failure.
|
---|
226 | * EBUSY if the device is used by someone else.
|
---|
227 | * @param pDev The device node.
|
---|
228 | * @param fOpen The open flags.
|
---|
229 | * @param iDevType Some device type thing we don't use.
|
---|
230 | * @param pTd The thread.
|
---|
231 | * @param fUnrestricted Set if opening /dev/vboxdrv, clear if /dev/vboxdrvu.
|
---|
232 | */
|
---|
233 | static int vboxdrvFreeBSDOpenCommon(struct cdev *pDev, int fOpen, int iDevType, struct thread *pTd, bool fUnrestricted)
|
---|
234 | {
|
---|
235 | PSUPDRVSESSION pSession;
|
---|
236 | int rc;
|
---|
237 |
|
---|
238 | /*
|
---|
239 | * Let's be a bit picky about the flags...
|
---|
240 | */
|
---|
241 | if (fOpen != (FREAD | FWRITE /*=O_RDWR*/))
|
---|
242 | {
|
---|
243 | Log(("VBoxDrvFreeBSDOpen: fOpen=%#x expected %#x\n", fOpen, O_RDWR));
|
---|
244 | return EINVAL;
|
---|
245 | }
|
---|
246 |
|
---|
247 | /*
|
---|
248 | * Create a new session.
|
---|
249 | */
|
---|
250 | rc = supdrvCreateSession(&g_VBoxDrvFreeBSDDevExt, true /* fUser */, fUnrestricted, &pSession);
|
---|
251 | if (RT_SUCCESS(rc))
|
---|
252 | {
|
---|
253 | /** @todo get (r)uid and (r)gid.
|
---|
254 | pSession->Uid = stuff;
|
---|
255 | pSession->Gid = stuff; */
|
---|
256 | rc = devfs_set_cdevpriv(pSession, vboxdrvFreeBSDDtr); Assert(rc == 0);
|
---|
257 | Log(("VBoxDrvFreeBSDOpen: pSession=%p\n", pSession));
|
---|
258 | ASMAtomicIncU32(&g_cUsers);
|
---|
259 | return 0;
|
---|
260 | }
|
---|
261 |
|
---|
262 | return RTErrConvertToErrno(rc);
|
---|
263 | }
|
---|
264 |
|
---|
265 |
|
---|
266 | /** For vboxdrv. */
|
---|
267 | static int VBoxDrvFreeBSDOpenSys(struct cdev *pDev, int fOpen, int iDevType, struct thread *pTd)
|
---|
268 | {
|
---|
269 | return vboxdrvFreeBSDOpenCommon(pDev, fOpen, iDevType, pTd, true);
|
---|
270 | }
|
---|
271 |
|
---|
272 |
|
---|
273 | /** For vboxdrvu. */
|
---|
274 | static int VBoxDrvFreeBSDOpenUsr(struct cdev *pDev, int fOpen, int iDevType, struct thread *pTd)
|
---|
275 | {
|
---|
276 | return vboxdrvFreeBSDOpenCommon(pDev, fOpen, iDevType, pTd, false);
|
---|
277 | }
|
---|
278 |
|
---|
279 |
|
---|
280 | /**
|
---|
281 | * Close a file device previously opened by VBoxDrvFreeBSDOpen.
|
---|
282 | *
|
---|
283 | * @returns 0 on success.
|
---|
284 | * @param pvData The session being closed.
|
---|
285 | */
|
---|
286 | static void vboxdrvFreeBSDDtr(void *pvData)
|
---|
287 | {
|
---|
288 | PSUPDRVSESSION pSession = pvData;
|
---|
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 uReq 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 supdrvOSAreCpusOfflinedOnSuspend(void)
|
---|
543 | {
|
---|
544 | /** @todo verify this. */
|
---|
545 | return false;
|
---|
546 | }
|
---|
547 |
|
---|
548 |
|
---|
549 | bool VBOXCALL supdrvOSAreTscDeltasInSync(void)
|
---|
550 | {
|
---|
551 | return false;
|
---|
552 | }
|
---|
553 |
|
---|
554 |
|
---|
555 | int VBOXCALL supdrvOSLdrOpen(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, const char *pszFilename)
|
---|
556 | {
|
---|
557 | NOREF(pDevExt); NOREF(pImage); NOREF(pszFilename);
|
---|
558 | return VERR_NOT_SUPPORTED;
|
---|
559 | }
|
---|
560 |
|
---|
561 |
|
---|
562 | int VBOXCALL supdrvOSLdrValidatePointer(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, void *pv, const uint8_t *pbImageBits)
|
---|
563 | {
|
---|
564 | NOREF(pDevExt); NOREF(pImage); NOREF(pv); NOREF(pbImageBits);
|
---|
565 | return VERR_NOT_SUPPORTED;
|
---|
566 | }
|
---|
567 |
|
---|
568 |
|
---|
569 | int VBOXCALL supdrvOSLdrLoad(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, const uint8_t *pbImageBits, PSUPLDRLOAD pReq)
|
---|
570 | {
|
---|
571 | NOREF(pDevExt); NOREF(pImage); NOREF(pbImageBits); NOREF(pReq);
|
---|
572 | return VERR_NOT_SUPPORTED;
|
---|
573 | }
|
---|
574 |
|
---|
575 |
|
---|
576 | void VBOXCALL supdrvOSLdrUnload(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage)
|
---|
577 | {
|
---|
578 | NOREF(pDevExt); NOREF(pImage);
|
---|
579 | }
|
---|
580 |
|
---|
581 |
|
---|
582 | void VBOXCALL supdrvOSLdrNotifyOpened(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, const char *pszFilename)
|
---|
583 | {
|
---|
584 | NOREF(pDevExt); NOREF(pImage); NOREF(pszFilename);
|
---|
585 | }
|
---|
586 |
|
---|
587 |
|
---|
588 | void VBOXCALL supdrvOSLdrNotifyUnloaded(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage)
|
---|
589 | {
|
---|
590 | NOREF(pDevExt); NOREF(pImage);
|
---|
591 | }
|
---|
592 |
|
---|
593 |
|
---|
594 | #ifdef SUPDRV_WITH_MSR_PROBER
|
---|
595 |
|
---|
596 | int VBOXCALL supdrvOSMsrProberRead(uint32_t uMsr, RTCPUID idCpu, uint64_t *puValue)
|
---|
597 | {
|
---|
598 | NOREF(uMsr); NOREF(idCpu); NOREF(puValue);
|
---|
599 | return VERR_NOT_SUPPORTED;
|
---|
600 | }
|
---|
601 |
|
---|
602 |
|
---|
603 | int VBOXCALL supdrvOSMsrProberWrite(uint32_t uMsr, RTCPUID idCpu, uint64_t uValue)
|
---|
604 | {
|
---|
605 | NOREF(uMsr); NOREF(idCpu); NOREF(uValue);
|
---|
606 | return VERR_NOT_SUPPORTED;
|
---|
607 | }
|
---|
608 |
|
---|
609 |
|
---|
610 | int VBOXCALL supdrvOSMsrProberModify(RTCPUID idCpu, PSUPMSRPROBER pReq)
|
---|
611 | {
|
---|
612 | NOREF(idCpu); NOREF(pReq);
|
---|
613 | return VERR_NOT_SUPPORTED;
|
---|
614 | }
|
---|
615 |
|
---|
616 | #endif /* SUPDRV_WITH_MSR_PROBER */
|
---|
617 |
|
---|
618 |
|
---|
619 | SUPR0DECL(int) SUPR0Printf(const char *pszFormat, ...)
|
---|
620 | {
|
---|
621 | va_list va;
|
---|
622 | char szMsg[256];
|
---|
623 | int cch;
|
---|
624 |
|
---|
625 | va_start(va, pszFormat);
|
---|
626 | cch = RTStrPrintfV(szMsg, sizeof(szMsg), pszFormat, va);
|
---|
627 | va_end(va);
|
---|
628 |
|
---|
629 | printf("%s", szMsg);
|
---|
630 |
|
---|
631 | return cch;
|
---|
632 | }
|
---|
633 |
|
---|
634 |
|
---|
635 | SUPR0DECL(uint32_t) SUPR0GetKernelFeatures(void)
|
---|
636 | {
|
---|
637 | return 0;
|
---|
638 | }
|
---|
639 |
|
---|