VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/Support/darwin/SUPDrv-darwin.cpp@ 57252

Last change on this file since 57252 was 57252, checked in by vboxsync, 9 years ago

SUPDrv,VBoxNetFlt,VBoxNetAdp: Include the-darwin-kernel.h to avoid duplicating workarounds and EFLAGS.AC macros.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 55.7 KB
Line 
1/* $Id: SUPDrv-darwin.cpp 57252 2015-08-08 23:21:45Z vboxsync $ */
2/** @file
3 * VirtualBox Support Driver - Darwin Specific Code.
4 */
5
6/*
7 * Copyright (C) 2006-2015 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 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27/*******************************************************************************
28* Header Files *
29*******************************************************************************/
30#define LOG_GROUP LOG_GROUP_SUP_DRV
31#include "../../../Runtime/r0drv/darwin/the-darwin-kernel.h"
32
33#include "../SUPDrvInternal.h"
34#include <VBox/version.h>
35#include <iprt/asm.h>
36#include <iprt/asm-amd64-x86.h>
37#include <iprt/initterm.h>
38#include <iprt/assert.h>
39#include <iprt/spinlock.h>
40#include <iprt/semaphore.h>
41#include <iprt/process.h>
42#include <iprt/alloc.h>
43#include <iprt/power.h>
44#include <iprt/dbg.h>
45#include <iprt/x86.h>
46#include <VBox/err.h>
47#include <VBox/log.h>
48
49#include <mach/kmod.h>
50#include <miscfs/devfs/devfs.h>
51#include <sys/conf.h>
52#include <sys/errno.h>
53#include <sys/ioccom.h>
54#include <sys/malloc.h>
55#include <sys/proc.h>
56#include <sys/kauth.h>
57#include <IOKit/IOService.h>
58#include <IOKit/IOUserClient.h>
59#include <IOKit/pwr_mgt/RootDomain.h>
60#include <IOKit/IODeviceTreeSupport.h>
61#include <IOKit/usb/IOUSBHIDDriver.h>
62#include <IOKit/bluetooth/IOBluetoothHIDDriver.h>
63#include <IOKit/bluetooth/IOBluetoothHIDDriverTypes.h>
64
65#ifdef VBOX_WITH_HOST_VMX
66# include <libkern/version.h>
67RT_C_DECLS_BEGIN
68# include <i386/vmx.h>
69RT_C_DECLS_END
70#endif
71
72/* Temporary debugging - very temporary... */
73#define VBOX_PROC_SELFNAME_LEN (20)
74#define VBOX_RETRIEVE_CUR_PROC_NAME(_name) char _name[VBOX_PROC_SELFNAME_LEN]; \
75 proc_selfname(pszProcName, VBOX_PROC_SELFNAME_LEN)
76
77
78/*******************************************************************************
79* Defined Constants And Macros *
80*******************************************************************************/
81
82/** The system device node name. */
83#define DEVICE_NAME_SYS "vboxdrv"
84/** The user device node name. */
85#define DEVICE_NAME_USR "vboxdrvu"
86
87
88
89/*******************************************************************************
90* Internal Functions *
91*******************************************************************************/
92RT_C_DECLS_BEGIN
93static kern_return_t VBoxDrvDarwinStart(struct kmod_info *pKModInfo, void *pvData);
94static kern_return_t VBoxDrvDarwinStop(struct kmod_info *pKModInfo, void *pvData);
95
96static int VBoxDrvDarwinOpen(dev_t Dev, int fFlags, int fDevType, struct proc *pProcess);
97static int VBoxDrvDarwinClose(dev_t Dev, int fFlags, int fDevType, struct proc *pProcess);
98static int VBoxDrvDarwinIOCtl(dev_t Dev, u_long iCmd, caddr_t pData, int fFlags, struct proc *pProcess);
99static int VBoxDrvDarwinIOCtlSMAP(dev_t Dev, u_long iCmd, caddr_t pData, int fFlags, struct proc *pProcess);
100static int VBoxDrvDarwinIOCtlSlow(PSUPDRVSESSION pSession, u_long iCmd, caddr_t pData, struct proc *pProcess);
101
102static int VBoxDrvDarwinErr2DarwinErr(int rc);
103
104static IOReturn VBoxDrvDarwinSleepHandler(void *pvTarget, void *pvRefCon, UInt32 uMessageType, IOService *pProvider, void *pvMessageArgument, vm_size_t argSize);
105RT_C_DECLS_END
106
107static int vboxdrvDarwinResolveSymbols(void);
108static bool vboxdrvDarwinCpuHasSMAP(void);
109
110
111/*******************************************************************************
112* Structures and Typedefs *
113*******************************************************************************/
114/**
115 * The service class.
116 * This is just a formality really.
117 */
118class org_virtualbox_SupDrv : public IOService
119{
120 OSDeclareDefaultStructors(org_virtualbox_SupDrv);
121
122public:
123 virtual bool init(OSDictionary *pDictionary = 0);
124 virtual void free(void);
125 virtual bool start(IOService *pProvider);
126 virtual void stop(IOService *pProvider);
127 virtual IOService *probe(IOService *pProvider, SInt32 *pi32Score);
128 virtual bool terminate(IOOptionBits fOptions);
129};
130
131OSDefineMetaClassAndStructors(org_virtualbox_SupDrv, IOService);
132
133
134/**
135 * An attempt at getting that clientDied() notification.
136 * I don't think it'll work as I cannot figure out where/what creates the correct
137 * port right.
138 */
139class org_virtualbox_SupDrvClient : public IOUserClient
140{
141 OSDeclareDefaultStructors(org_virtualbox_SupDrvClient);
142
143private:
144 PSUPDRVSESSION m_pSession; /**< The session. */
145 task_t m_Task; /**< The client task. */
146 org_virtualbox_SupDrv *m_pProvider; /**< The service provider. */
147
148public:
149 virtual bool initWithTask(task_t OwningTask, void *pvSecurityId, UInt32 u32Type);
150 virtual bool start(IOService *pProvider);
151 static void sessionClose(RTPROCESS Process);
152 virtual IOReturn clientClose(void);
153 virtual IOReturn clientDied(void);
154 virtual bool terminate(IOOptionBits fOptions = 0);
155 virtual bool finalize(IOOptionBits fOptions);
156 virtual void stop(IOService *pProvider);
157};
158
159OSDefineMetaClassAndStructors(org_virtualbox_SupDrvClient, IOUserClient);
160
161
162
163/*******************************************************************************
164* Global Variables *
165*******************************************************************************/
166/**
167 * Declare the module stuff.
168 */
169RT_C_DECLS_BEGIN
170extern kern_return_t _start(struct kmod_info *pKModInfo, void *pvData);
171extern kern_return_t _stop(struct kmod_info *pKModInfo, void *pvData);
172
173KMOD_EXPLICIT_DECL(VBoxDrv, VBOX_VERSION_STRING, _start, _stop)
174DECLHIDDEN(kmod_start_func_t *) _realmain = VBoxDrvDarwinStart;
175DECLHIDDEN(kmod_stop_func_t *) _antimain = VBoxDrvDarwinStop;
176DECLHIDDEN(int) _kext_apple_cc = __APPLE_CC__;
177RT_C_DECLS_END
178
179
180/**
181 * Device extention & session data association structure.
182 */
183static SUPDRVDEVEXT g_DevExt;
184
185/**
186 * The character device switch table for the driver.
187 */
188static struct cdevsw g_DevCW =
189{
190 /** @todo g++ doesn't like this syntax - it worked with gcc before renaming to .cpp. */
191 /*.d_open = */VBoxDrvDarwinOpen,
192 /*.d_close = */VBoxDrvDarwinClose,
193 /*.d_read = */eno_rdwrt,
194 /*.d_write = */eno_rdwrt,
195 /*.d_ioctl = */VBoxDrvDarwinIOCtl,
196 /*.d_stop = */eno_stop,
197 /*.d_reset = */eno_reset,
198 /*.d_ttys = */NULL,
199 /*.d_select= */eno_select,
200 /*.d_mmap = */eno_mmap,
201 /*.d_strategy = */eno_strat,
202 /*.d_getc = */eno_getc,
203 /*.d_putc = */eno_putc,
204 /*.d_type = */0
205};
206
207/** Major device number. */
208static int g_iMajorDeviceNo = -1;
209/** Registered devfs device handle for the system device. */
210static void *g_hDevFsDeviceSys = NULL;
211/** Registered devfs device handle for the user device. */
212static void *g_hDevFsDeviceUsr = NULL;
213
214/** Spinlock protecting g_apSessionHashTab. */
215static RTSPINLOCK g_Spinlock = NIL_RTSPINLOCK;
216/** Hash table */
217static PSUPDRVSESSION g_apSessionHashTab[19];
218/** Calculates the index into g_apSessionHashTab.*/
219#define SESSION_HASH(pid) ((pid) % RT_ELEMENTS(g_apSessionHashTab))
220/** The number of open sessions. */
221static int32_t volatile g_cSessions = 0;
222/** The notifier handle for the sleep callback handler. */
223static IONotifier *g_pSleepNotifier = NULL;
224
225/** Pointer to vmx_suspend(). */
226static PFNRT g_pfnVmxSuspend = NULL;
227/** Pointer to vmx_resume(). */
228static PFNRT g_pfnVmxResume = NULL;
229/** Pointer to vmx_use_count. */
230static int volatile *g_pVmxUseCount = NULL;
231
232#ifdef SUPDRV_WITH_MSR_PROBER
233/** Pointer to rdmsr_carefully if found. Returns 0 on success. */
234static int (*g_pfnRdMsrCarefully)(uint32_t uMsr, uint32_t *puLow, uint32_t *puHigh) = NULL;
235/** Pointer to rdmsr64_carefully if found. Returns 0 on success. */
236static int (*g_pfnRdMsr64Carefully)(uint32_t uMsr, uint64_t *uValue) = NULL;
237/** Pointer to wrmsr[64]_carefully if found. Returns 0 on success. */
238static int (*g_pfnWrMsr64Carefully)(uint32_t uMsr, uint64_t uValue) = NULL;
239#endif
240
241
242/**
243 * Start the kernel module.
244 */
245static kern_return_t VBoxDrvDarwinStart(struct kmod_info *pKModInfo, void *pvData)
246{
247 int rc;
248#ifdef DEBUG
249 printf("VBoxDrvDarwinStart\n");
250#endif
251
252 /*
253 * Initialize IPRT.
254 */
255 rc = RTR0Init(0);
256 if (RT_SUCCESS(rc))
257 {
258 /*
259 * Initialize the device extension.
260 */
261 rc = supdrvInitDevExt(&g_DevExt, sizeof(SUPDRVSESSION));
262 if (RT_SUCCESS(rc))
263 {
264 /*
265 * Initialize the session hash table.
266 */
267 memset(g_apSessionHashTab, 0, sizeof(g_apSessionHashTab)); /* paranoia */
268 rc = RTSpinlockCreate(&g_Spinlock, RTSPINLOCK_FLAGS_INTERRUPT_SAFE, "VBoxDrvDarwin");
269 if (RT_SUCCESS(rc))
270 {
271 if (vboxdrvDarwinCpuHasSMAP())
272 {
273 LogRel(("disabling SMAP for VBoxDrvDarwinIOCtl\n"));
274 g_DevCW.d_ioctl = VBoxDrvDarwinIOCtlSMAP;
275 }
276
277 /*
278 * Resolve some extra kernel symbols.
279 */
280 rc = vboxdrvDarwinResolveSymbols();
281 if (RT_SUCCESS(rc))
282 {
283
284 /*
285 * Registering ourselves as a character device.
286 */
287 g_iMajorDeviceNo = cdevsw_add(-1, &g_DevCW);
288 if (g_iMajorDeviceNo >= 0)
289 {
290#ifdef VBOX_WITH_HARDENING
291 g_hDevFsDeviceSys = devfs_make_node(makedev(g_iMajorDeviceNo, 0), DEVFS_CHAR,
292 UID_ROOT, GID_WHEEL, 0600, DEVICE_NAME_SYS);
293#else
294 g_hDevFsDeviceSys = devfs_make_node(makedev(g_iMajorDeviceNo, 0), DEVFS_CHAR,
295 UID_ROOT, GID_WHEEL, 0666, DEVICE_NAME_SYS);
296#endif
297 if (g_hDevFsDeviceSys)
298 {
299 g_hDevFsDeviceUsr = devfs_make_node(makedev(g_iMajorDeviceNo, 1), DEVFS_CHAR,
300 UID_ROOT, GID_WHEEL, 0666, DEVICE_NAME_USR);
301 if (g_hDevFsDeviceUsr)
302 {
303 LogRel(("VBoxDrv: version " VBOX_VERSION_STRING " r%d; IOCtl version %#x; IDC version %#x; dev major=%d\n",
304 VBOX_SVN_REV, SUPDRV_IOC_VERSION, SUPDRV_IDC_VERSION, g_iMajorDeviceNo));
305
306 /* Register a sleep/wakeup notification callback */
307 g_pSleepNotifier = registerPrioritySleepWakeInterest(&VBoxDrvDarwinSleepHandler, &g_DevExt, NULL);
308 if (g_pSleepNotifier == NULL)
309 LogRel(("VBoxDrv: register for sleep/wakeup events failed\n"));
310
311 return KMOD_RETURN_SUCCESS;
312 }
313
314 LogRel(("VBoxDrv: devfs_make_node(makedev(%d,1),,,,%s) failed\n", g_iMajorDeviceNo, DEVICE_NAME_USR));
315 devfs_remove(g_hDevFsDeviceSys);
316 g_hDevFsDeviceSys = NULL;
317 }
318 else
319 LogRel(("VBoxDrv: devfs_make_node(makedev(%d,0),,,,%s) failed\n", g_iMajorDeviceNo, DEVICE_NAME_SYS));
320
321 cdevsw_remove(g_iMajorDeviceNo, &g_DevCW);
322 g_iMajorDeviceNo = -1;
323 }
324 else
325 LogRel(("VBoxDrv: cdevsw_add failed (%d)\n", g_iMajorDeviceNo));
326 }
327 RTSpinlockDestroy(g_Spinlock);
328 g_Spinlock = NIL_RTSPINLOCK;
329 }
330 else
331 LogRel(("VBoxDrv: RTSpinlockCreate failed (rc=%d)\n", rc));
332 supdrvDeleteDevExt(&g_DevExt);
333 }
334 else
335 printf("VBoxDrv: failed to initialize device extension (rc=%d)\n", rc);
336 RTR0TermForced();
337 }
338 else
339 printf("VBoxDrv: failed to initialize IPRT (rc=%d)\n", rc);
340
341 memset(&g_DevExt, 0, sizeof(g_DevExt));
342 return KMOD_RETURN_FAILURE;
343}
344
345
346/**
347 * Resolves kernel symbols we need and some we just would like to have.
348 */
349static int vboxdrvDarwinResolveSymbols(void)
350{
351 RTDBGKRNLINFO hKrnlInfo;
352 int rc = RTR0DbgKrnlInfoOpen(&hKrnlInfo, 0);
353 if (RT_SUCCESS(rc))
354 {
355 /*
356 * The VMX stuff - required with raw-mode (in theory for 64-bit on
357 * 32-bit too, but we never did that on darwin).
358 */
359 int rc1 = RTR0DbgKrnlInfoQuerySymbol(hKrnlInfo, NULL, "vmx_resume", (void **)&g_pfnVmxResume);
360 int rc2 = RTR0DbgKrnlInfoQuerySymbol(hKrnlInfo, NULL, "vmx_suspend", (void **)&g_pfnVmxSuspend);
361 int rc3 = RTR0DbgKrnlInfoQuerySymbol(hKrnlInfo, NULL, "vmx_use_count", (void **)&g_pVmxUseCount);
362 if (RT_SUCCESS(rc1) && RT_SUCCESS(rc2) && RT_SUCCESS(rc3))
363 {
364 LogRel(("VBoxDrv: vmx_resume=%p vmx_suspend=%p vmx_use_count=%p (%d) cr4=%#x\n",
365 g_pfnVmxResume, g_pfnVmxSuspend, g_pVmxUseCount, *g_pVmxUseCount, ASMGetCR4() ));
366 }
367 else
368 {
369 LogRel(("VBoxDrv: failed to resolve vmx stuff: vmx_resume=%Rrc vmx_suspend=%Rrc vmx_use_count=%Rrc", rc1, rc2, rc3));
370 g_pfnVmxResume = NULL;
371 g_pfnVmxSuspend = NULL;
372 g_pVmxUseCount = NULL;
373#ifdef VBOX_WITH_RAW_MODE
374 rc = VERR_SYMBOL_NOT_FOUND;
375#endif
376 }
377
378 if (RT_SUCCESS(rc))
379 {
380#ifdef SUPDRV_WITH_MSR_PROBER
381 /*
382 * MSR prober stuff - optional!
383 */
384 int rc2 = RTR0DbgKrnlInfoQuerySymbol(hKrnlInfo, NULL, "rdmsr_carefully", (void **)&g_pfnRdMsrCarefully);
385 if (RT_FAILURE(rc2))
386 g_pfnRdMsrCarefully = NULL;
387 rc2 = RTR0DbgKrnlInfoQuerySymbol(hKrnlInfo, NULL, "rdmsr64_carefully", (void **)&g_pfnRdMsr64Carefully);
388 if (RT_FAILURE(rc2))
389 g_pfnRdMsr64Carefully = NULL;
390# ifdef RT_ARCH_AMD64 /* Missing 64 in name, so if implemented on 32-bit it could have different signature. */
391 rc2 = RTR0DbgKrnlInfoQuerySymbol(hKrnlInfo, NULL, "wrmsr_carefully", (void **)&g_pfnWrMsr64Carefully);
392 if (RT_FAILURE(rc2))
393# endif
394 g_pfnWrMsr64Carefully = NULL;
395
396 LogRel(("VBoxDrv: g_pfnRdMsrCarefully=%p g_pfnRdMsr64Carefully=%p g_pfnWrMsr64Carefully=%p\n",
397 g_pfnRdMsrCarefully, g_pfnRdMsr64Carefully, g_pfnWrMsr64Carefully));
398
399#endif /* SUPDRV_WITH_MSR_PROBER */
400 }
401
402 RTR0DbgKrnlInfoRelease(hKrnlInfo);
403 }
404 else
405 LogRel(("VBoxDrv: Failed to open kernel symbols, rc=%Rrc\n", rc));
406 return rc;
407}
408
409
410/**
411 * Stop the kernel module.
412 */
413static kern_return_t VBoxDrvDarwinStop(struct kmod_info *pKModInfo, void *pvData)
414{
415 int rc;
416 LogFlow(("VBoxDrvDarwinStop\n"));
417
418 /** @todo I've got a nagging feeling that we'll have to keep track of users and refuse
419 * unloading if we're busy. Investigate and implement this! */
420
421 /*
422 * Undo the work done during start (in reverse order).
423 */
424 if (g_pSleepNotifier)
425 {
426 g_pSleepNotifier->remove();
427 g_pSleepNotifier = NULL;
428 }
429
430 devfs_remove(g_hDevFsDeviceUsr);
431 g_hDevFsDeviceUsr = NULL;
432
433 devfs_remove(g_hDevFsDeviceSys);
434 g_hDevFsDeviceSys = NULL;
435
436 rc = cdevsw_remove(g_iMajorDeviceNo, &g_DevCW);
437 Assert(rc == g_iMajorDeviceNo);
438 g_iMajorDeviceNo = -1;
439
440 supdrvDeleteDevExt(&g_DevExt);
441
442 rc = RTSpinlockDestroy(g_Spinlock);
443 AssertRC(rc);
444 g_Spinlock = NIL_RTSPINLOCK;
445
446 RTR0TermForced();
447
448 memset(&g_DevExt, 0, sizeof(g_DevExt));
449#ifdef DEBUG
450 printf("VBoxDrvDarwinStop - done\n");
451#endif
452 return KMOD_RETURN_SUCCESS;
453}
454
455
456/**
457 * Device open. Called on open /dev/vboxdrv
458 *
459 * @param Dev The device number.
460 * @param fFlags ???.
461 * @param fDevType ???.
462 * @param pProcess The process issuing this request.
463 */
464static int VBoxDrvDarwinOpen(dev_t Dev, int fFlags, int fDevType, struct proc *pProcess)
465{
466#ifdef DEBUG_DARWIN_GIP
467 char szName[128];
468 szName[0] = '\0';
469 proc_name(proc_pid(pProcess), szName, sizeof(szName));
470 Log(("VBoxDrvDarwinOpen: pid=%d '%s'\n", proc_pid(pProcess), szName));
471#endif
472
473 /*
474 * Only two minor devices numbers are allowed.
475 */
476 if (minor(Dev) != 0 && minor(Dev) != 1)
477 return EACCES;
478
479 /*
480 * The process issuing the request must be the current process.
481 */
482 RTPROCESS Process = RTProcSelf();
483 if ((int)Process != proc_pid(pProcess))
484 return EIO;
485
486 /*
487 * Find the session created by org_virtualbox_SupDrvClient, fail
488 * if no such session, and mark it as opened. We set the uid & gid
489 * here too, since that is more straight forward at this point.
490 */
491 const bool fUnrestricted = minor(Dev) == 0;
492 int rc = VINF_SUCCESS;
493 PSUPDRVSESSION pSession = NULL;
494 kauth_cred_t pCred = kauth_cred_proc_ref(pProcess);
495 if (pCred)
496 {
497#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
498 RTUID Uid = kauth_cred_getruid(pCred);
499 RTGID Gid = kauth_cred_getrgid(pCred);
500#else
501 RTUID Uid = pCred->cr_ruid;
502 RTGID Gid = pCred->cr_rgid;
503#endif
504 unsigned iHash = SESSION_HASH(Process);
505 RTSpinlockAcquire(g_Spinlock);
506
507 pSession = g_apSessionHashTab[iHash];
508 while (pSession && pSession->Process != Process)
509 pSession = pSession->pNextHash;
510 if (pSession)
511 {
512 if (!pSession->fOpened)
513 {
514 pSession->fOpened = true;
515 pSession->fUnrestricted = fUnrestricted;
516 pSession->Uid = Uid;
517 pSession->Gid = Gid;
518 }
519 else
520 rc = VERR_ALREADY_LOADED;
521 }
522 else
523 rc = VERR_GENERAL_FAILURE;
524
525 RTSpinlockRelease(g_Spinlock);
526#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
527 kauth_cred_unref(&pCred);
528#else /* 10.4 */
529 /* The 10.4u SDK headers and 10.4.11 kernel source have inconsistent definitions
530 of kauth_cred_unref(), so use the other (now deprecated) API for releasing it. */
531 kauth_cred_rele(pCred);
532#endif /* 10.4 */
533 }
534 else
535 rc = VERR_INVALID_PARAMETER;
536
537#ifdef DEBUG_DARWIN_GIP
538 OSDBGPRINT(("VBoxDrvDarwinOpen: pid=%d '%s' pSession=%p rc=%d\n", proc_pid(pProcess), szName, pSession, rc));
539#else
540 Log(("VBoxDrvDarwinOpen: g_DevExt=%p pSession=%p rc=%d pid=%d\n", &g_DevExt, pSession, rc, proc_pid(pProcess)));
541#endif
542 return VBoxDrvDarwinErr2DarwinErr(rc);
543}
544
545
546/**
547 * Close device.
548 */
549static int VBoxDrvDarwinClose(dev_t Dev, int fFlags, int fDevType, struct proc *pProcess)
550{
551 Log(("VBoxDrvDarwinClose: pid=%d\n", (int)RTProcSelf()));
552 Assert(proc_pid(pProcess) == (int)RTProcSelf());
553
554 /*
555 * Hand the session closing to org_virtualbox_SupDrvClient.
556 */
557 org_virtualbox_SupDrvClient::sessionClose(RTProcSelf());
558 return 0;
559}
560
561
562/**
563 * Device I/O Control entry point.
564 *
565 * @returns Darwin for slow IOCtls and VBox status code for the fast ones.
566 * @param Dev The device number (major+minor).
567 * @param iCmd The IOCtl command.
568 * @param pData Pointer to the data (if any it's a SUPDRVIOCTLDATA (kernel copy)).
569 * @param fFlags Flag saying we're a character device (like we didn't know already).
570 * @param pProcess The process issuing this request.
571 */
572static int VBoxDrvDarwinIOCtl(dev_t Dev, u_long iCmd, caddr_t pData, int fFlags, struct proc *pProcess)
573{
574 const bool fUnrestricted = minor(Dev) == 0;
575 const RTPROCESS Process = proc_pid(pProcess);
576 const unsigned iHash = SESSION_HASH(Process);
577 PSUPDRVSESSION pSession;
578
579#ifdef VBOX_WITH_EFLAGS_AC_SET_IN_VBOXDRV
580 /*
581 * Refuse all I/O control calls if we've ever detected EFLAGS.AC being cleared.
582 *
583 * This isn't a problem, as there is absolutely nothing in the kernel context that
584 * depend on user context triggering cleanups. That would be pretty wild, right?
585 */
586 if (RT_UNLIKELY(g_DevExt.cBadContextCalls > 0))
587 {
588 SUPR0Printf("VBoxDrvDarwinIOCtl: EFLAGS.AC=0 detected %u times, refusing all I/O controls!\n", g_DevExt.cBadContextCalls);
589 return EDEVERR;
590 }
591#endif
592
593 /*
594 * Find the session.
595 */
596 RTSpinlockAcquire(g_Spinlock);
597
598 pSession = g_apSessionHashTab[iHash];
599 while (pSession && (pSession->Process != Process || pSession->fUnrestricted != fUnrestricted || !pSession->fOpened))
600 pSession = pSession->pNextHash;
601
602 if (RT_LIKELY(pSession))
603 supdrvSessionRetain(pSession);
604
605 RTSpinlockRelease(g_Spinlock);
606 if (RT_UNLIKELY(!pSession))
607 {
608 OSDBGPRINT(("VBoxDrvDarwinIOCtl: WHAT?!? pSession == NULL! This must be a mistake... pid=%d iCmd=%#lx\n",
609 (int)Process, iCmd));
610 return EINVAL;
611 }
612
613 /*
614 * Deal with the two high-speed IOCtl that takes it's arguments from
615 * the session and iCmd, and only returns a VBox status code.
616 */
617 int rc;
618 if ( ( iCmd == SUP_IOCTL_FAST_DO_RAW_RUN
619 || iCmd == SUP_IOCTL_FAST_DO_HM_RUN
620 || iCmd == SUP_IOCTL_FAST_DO_NOP)
621 && fUnrestricted)
622 rc = supdrvIOCtlFast(iCmd, *(uint32_t *)pData, &g_DevExt, pSession);
623 else
624 rc = VBoxDrvDarwinIOCtlSlow(pSession, iCmd, pData, pProcess);
625
626 supdrvSessionRelease(pSession);
627 return rc;
628}
629
630
631/**
632 * Alternative Device I/O Control entry point on hosts with SMAP support.
633 *
634 * @returns Darwin for slow IOCtls and VBox status code for the fast ones.
635 * @param Dev The device number (major+minor).
636 * @param iCmd The IOCtl command.
637 * @param pData Pointer to the data (if any it's a SUPDRVIOCTLDATA (kernel copy)).
638 * @param fFlags Flag saying we're a character device (like we didn't know already).
639 * @param pProcess The process issuing this request.
640 */
641static int VBoxDrvDarwinIOCtlSMAP(dev_t Dev, u_long iCmd, caddr_t pData, int fFlags, struct proc *pProcess)
642{
643 /*
644 * Allow VBox R0 code to touch R3 memory. Setting the AC bit disables the
645 * SMAP check.
646 */
647#ifdef VBOX_WITH_EFLAGS_AC_SET_IN_VBOXDRV
648 RTCCUINTREG fSavedEfl = ASMAddFlags(X86_EFL_AC);
649#else
650 RTCCUINTREG fSavedEfl = ASMGetFlags();
651 ASMSetAC();
652#endif
653
654 int rc = VBoxDrvDarwinIOCtl(Dev, iCmd, pData, fFlags, pProcess);
655
656#if defined(VBOX_STRICT) || defined(VBOX_WITH_EFLAGS_AC_SET_IN_VBOXDRV)
657 if (RT_UNLIKELY(!(ASMGetFlags() & X86_EFL_AC)))
658 {
659 char szTmp[32];
660 RTStrPrintf(szTmp, sizeof(szTmp), "iCmd=%#x!", iCmd);
661 supdrvBadContext(&g_DevExt, "SUPDrv-darwin.cpp", __LINE__, szTmp);
662 }
663#endif
664 ASMSetFlags(fSavedEfl);
665 return rc;
666}
667
668
669/**
670 * Worker for VBoxDrvDarwinIOCtl that takes the slow IOCtl functions.
671 *
672 * @returns Darwin errno.
673 *
674 * @param pSession The session.
675 * @param iCmd The IOCtl command.
676 * @param pData Pointer to the kernel copy of the SUPDRVIOCTLDATA buffer.
677 * @param pProcess The calling process.
678 */
679static int VBoxDrvDarwinIOCtlSlow(PSUPDRVSESSION pSession, u_long iCmd, caddr_t pData, struct proc *pProcess)
680{
681 LogFlow(("VBoxDrvDarwinIOCtlSlow: pSession=%p iCmd=%p pData=%p pProcess=%p\n", pSession, iCmd, pData, pProcess));
682
683
684 /*
685 * Buffered or unbuffered?
686 */
687 PSUPREQHDR pHdr;
688 user_addr_t pUser = 0;
689 void *pvPageBuf = NULL;
690 uint32_t cbReq = IOCPARM_LEN(iCmd);
691 if ((IOC_DIRMASK & iCmd) == IOC_INOUT)
692 {
693 pHdr = (PSUPREQHDR)pData;
694 if (RT_UNLIKELY(cbReq < sizeof(*pHdr)))
695 {
696 OSDBGPRINT(("VBoxDrvDarwinIOCtlSlow: cbReq=%#x < %#x; iCmd=%#lx\n", cbReq, (int)sizeof(*pHdr), iCmd));
697 return EINVAL;
698 }
699 if (RT_UNLIKELY((pHdr->fFlags & SUPREQHDR_FLAGS_MAGIC_MASK) != SUPREQHDR_FLAGS_MAGIC))
700 {
701 OSDBGPRINT(("VBoxDrvDarwinIOCtlSlow: bad magic fFlags=%#x; iCmd=%#lx\n", pHdr->fFlags, iCmd));
702 return EINVAL;
703 }
704 if (RT_UNLIKELY( RT_MAX(pHdr->cbIn, pHdr->cbOut) != cbReq
705 || pHdr->cbIn < sizeof(*pHdr)
706 || pHdr->cbOut < sizeof(*pHdr)))
707 {
708 OSDBGPRINT(("VBoxDrvDarwinIOCtlSlow: max(%#x,%#x) != %#x; iCmd=%#lx\n", pHdr->cbIn, pHdr->cbOut, cbReq, iCmd));
709 return EINVAL;
710 }
711 }
712 else if ((IOC_DIRMASK & iCmd) == IOC_VOID && !cbReq)
713 {
714 /*
715 * Get the header and figure out how much we're gonna have to read.
716 */
717 SUPREQHDR Hdr;
718 pUser = (user_addr_t)*(void **)pData;
719 int rc = copyin(pUser, &Hdr, sizeof(Hdr));
720 if (RT_UNLIKELY(rc))
721 {
722 OSDBGPRINT(("VBoxDrvDarwinIOCtlSlow: copyin(%llx,Hdr,) -> %#x; iCmd=%#lx\n", (unsigned long long)pUser, rc, iCmd));
723 return rc;
724 }
725 if (RT_UNLIKELY((Hdr.fFlags & SUPREQHDR_FLAGS_MAGIC_MASK) != SUPREQHDR_FLAGS_MAGIC))
726 {
727 OSDBGPRINT(("VBoxDrvDarwinIOCtlSlow: bad magic fFlags=%#x; iCmd=%#lx\n", Hdr.fFlags, iCmd));
728 return EINVAL;
729 }
730 cbReq = RT_MAX(Hdr.cbIn, Hdr.cbOut);
731 if (RT_UNLIKELY( Hdr.cbIn < sizeof(Hdr)
732 || Hdr.cbOut < sizeof(Hdr)
733 || cbReq > _1M*16))
734 {
735 OSDBGPRINT(("VBoxDrvDarwinIOCtlSlow: max(%#x,%#x); iCmd=%#lx\n", Hdr.cbIn, Hdr.cbOut, iCmd));
736 return EINVAL;
737 }
738
739 /*
740 * Allocate buffer and copy in the data.
741 */
742 pHdr = (PSUPREQHDR)RTMemTmpAlloc(cbReq);
743 if (!pHdr)
744 pvPageBuf = pHdr = (PSUPREQHDR)IOMallocAligned(RT_ALIGN_Z(cbReq, PAGE_SIZE), 8);
745 if (RT_UNLIKELY(!pHdr))
746 {
747 OSDBGPRINT(("VBoxDrvDarwinIOCtlSlow: failed to allocate buffer of %d bytes; iCmd=%#lx\n", cbReq, iCmd));
748 return ENOMEM;
749 }
750 rc = copyin(pUser, pHdr, Hdr.cbIn);
751 if (RT_UNLIKELY(rc))
752 {
753 OSDBGPRINT(("VBoxDrvDarwinIOCtlSlow: copyin(%llx,%p,%#x) -> %#x; iCmd=%#lx\n",
754 (unsigned long long)pUser, pHdr, Hdr.cbIn, rc, iCmd));
755 if (pvPageBuf)
756 IOFreeAligned(pvPageBuf, RT_ALIGN_Z(cbReq, PAGE_SIZE));
757 else
758 RTMemTmpFree(pHdr);
759 return rc;
760 }
761 if (Hdr.cbIn < cbReq)
762 RT_BZERO((uint8_t *)pHdr + Hdr.cbIn, cbReq - Hdr.cbIn);
763 }
764 else
765 {
766 Log(("VBoxDrvDarwinIOCtlSlow: huh? cbReq=%#x iCmd=%#lx\n", cbReq, iCmd));
767 return EINVAL;
768 }
769
770 /*
771 * Process the IOCtl.
772 */
773 int rc = supdrvIOCtl(iCmd, &g_DevExt, pSession, pHdr, cbReq);
774 if (RT_LIKELY(!rc))
775 {
776 /*
777 * If not buffered, copy back the buffer before returning.
778 */
779 if (pUser)
780 {
781 uint32_t cbOut = pHdr->cbOut;
782 if (cbOut > cbReq)
783 {
784 OSDBGPRINT(("VBoxDrvDarwinIOCtlSlow: too much output! %#x > %#x; uCmd=%#lx!\n", cbOut, cbReq, iCmd));
785 cbOut = cbReq;
786 }
787 rc = copyout(pHdr, pUser, cbOut);
788 if (RT_UNLIKELY(rc))
789 OSDBGPRINT(("VBoxDrvDarwinIOCtlSlow: copyout(%p,%llx,%#x) -> %d; uCmd=%#lx!\n",
790 pHdr, (unsigned long long)pUser, cbOut, rc, iCmd));
791
792 /* cleanup */
793 if (pvPageBuf)
794 IOFreeAligned(pvPageBuf, RT_ALIGN_Z(cbReq, PAGE_SIZE));
795 else
796 RTMemTmpFree(pHdr);
797 }
798 }
799 else
800 {
801 /*
802 * The request failed, just clean up.
803 */
804 if (pUser)
805 {
806 if (pvPageBuf)
807 IOFreeAligned(pvPageBuf, RT_ALIGN_Z(cbReq, PAGE_SIZE));
808 else
809 RTMemTmpFree(pHdr);
810 }
811
812 Log(("VBoxDrvDarwinIOCtlSlow: pid=%d iCmd=%lx pData=%p failed, rc=%d\n", proc_pid(pProcess), iCmd, (void *)pData, rc));
813 rc = EINVAL;
814 }
815
816 Log2(("VBoxDrvDarwinIOCtlSlow: returns %d\n", rc));
817 return rc;
818}
819
820
821/**
822 * The SUPDRV IDC entry point.
823 *
824 * @returns VBox status code, see supdrvIDC.
825 * @param iReq The request code.
826 * @param pReq The request.
827 */
828DECLEXPORT(int) VBOXCALL SUPDrvDarwinIDC(uint32_t uReq, PSUPDRVIDCREQHDR pReq)
829{
830 PSUPDRVSESSION pSession;
831
832 /*
833 * Some quick validations.
834 */
835 if (RT_UNLIKELY(!VALID_PTR(pReq)))
836 return VERR_INVALID_POINTER;
837
838 pSession = pReq->pSession;
839 if (pSession)
840 {
841 if (RT_UNLIKELY(!VALID_PTR(pSession)))
842 return VERR_INVALID_PARAMETER;
843 if (RT_UNLIKELY(pSession->pDevExt != &g_DevExt))
844 return VERR_INVALID_PARAMETER;
845 }
846 else if (RT_UNLIKELY(uReq != SUPDRV_IDC_REQ_CONNECT))
847 return VERR_INVALID_PARAMETER;
848
849 /*
850 * Do the job.
851 */
852 return supdrvIDC(uReq, &g_DevExt, pSession, pReq);
853}
854
855
856void VBOXCALL supdrvOSCleanupSession(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession)
857{
858 NOREF(pDevExt);
859 NOREF(pSession);
860}
861
862
863void VBOXCALL supdrvOSSessionHashTabInserted(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, void *pvUser)
864{
865 NOREF(pDevExt); NOREF(pSession); NOREF(pvUser);
866}
867
868
869void VBOXCALL supdrvOSSessionHashTabRemoved(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, void *pvUser)
870{
871 NOREF(pDevExt); NOREF(pSession); NOREF(pvUser);
872}
873
874
875/**
876 * Initializes any OS specific object creator fields.
877 */
878void VBOXCALL supdrvOSObjInitCreator(PSUPDRVOBJ pObj, PSUPDRVSESSION pSession)
879{
880 NOREF(pObj);
881 NOREF(pSession);
882}
883
884
885/**
886 * Checks if the session can access the object.
887 *
888 * @returns true if a decision has been made.
889 * @returns false if the default access policy should be applied.
890 *
891 * @param pObj The object in question.
892 * @param pSession The session wanting to access the object.
893 * @param pszObjName The object name, can be NULL.
894 * @param prc Where to store the result when returning true.
895 */
896bool VBOXCALL supdrvOSObjCanAccess(PSUPDRVOBJ pObj, PSUPDRVSESSION pSession, const char *pszObjName, int *prc)
897{
898 NOREF(pObj);
899 NOREF(pSession);
900 NOREF(pszObjName);
901 NOREF(prc);
902 return false;
903}
904
905/**
906 * Callback for blah blah blah.
907 */
908IOReturn VBoxDrvDarwinSleepHandler(void * /* pvTarget */, void *pvRefCon, UInt32 uMessageType, IOService * /* pProvider */, void * /* pvMessageArgument */, vm_size_t /* argSize */)
909{
910 LogFlow(("VBoxDrv: Got sleep/wake notice. Message type was %X\n", (uint)uMessageType));
911
912 if (uMessageType == kIOMessageSystemWillSleep)
913 RTPowerSignalEvent(RTPOWEREVENT_SUSPEND);
914 else if (uMessageType == kIOMessageSystemHasPoweredOn)
915 RTPowerSignalEvent(RTPOWEREVENT_RESUME);
916
917 acknowledgeSleepWakeNotification(pvRefCon);
918
919 return 0;
920}
921
922
923#ifdef VBOX_WITH_HOST_VMX
924/**
925 * For cleaning up the mess we left behind on Yosemite with 4.3.28 and earlier.
926 *
927 * We ASSUME VT-x is supported by the CPU.
928 *
929 * @param idCpu Unused.
930 * @param pvUser1 Unused.
931 * @param pvUser2 Unused.
932 */
933static DECLCALLBACK(void) vboxdrvDarwinVmxEnableFix(RTCPUID idCpu, void *pvUser1, void *pvUser2)
934{
935 RTCCUINTREG uCr4 = ASMGetCR4();
936 if (!(uCr4 & X86_CR4_VMXE))
937 {
938 uCr4 |= X86_CR4_VMXE;
939 ASMSetCR4(uCr4);
940 }
941}
942#endif
943
944
945/**
946 * @copydoc SUPR0EnableVTx
947 */
948int VBOXCALL supdrvOSEnableVTx(bool fEnable)
949{
950#ifdef VBOX_WITH_HOST_VMX
951 int rc;
952 if ( version_major >= 10 /* 10 = 10.6.x = Snow Leopard */
953# ifdef VBOX_WITH_RAW_MODE
954 && g_pfnVmxSuspend
955 && g_pfnVmxResume
956 && g_pVmxUseCount
957# endif
958 )
959 {
960 if (fEnable)
961 {
962 /*
963 * We screwed up on Yosemite and didn't notice that we weren't
964 * calling host_vmxon. CR4.VMXE may therefore have been disabled
965 * by us. So, first time around we make sure it's set so we won't
966 * crash in the pre-4.3.28/5.0RC1 upgrade scenario.
967 * See @bugref{7907}.
968 */
969 static bool volatile g_fDoneCleanup = false;
970 if (!g_fDoneCleanup)
971 {
972 if (version_major == 14 /* 14 = 10.10 = yosemite */)
973 {
974 uint32_t fCaps;
975 int rc = supdrvQueryVTCapsInternal(&fCaps);
976 if (RT_SUCCESS(rc))
977 {
978 if (fCaps & SUPVTCAPS_VT_X)
979 rc = RTMpOnAll(vboxdrvDarwinVmxEnableFix, NULL, NULL);
980 else
981 rc = VERR_VMX_NO_VMX;
982 }
983 if (RT_FAILURE(rc))
984 return rc;
985 }
986 g_fDoneCleanup = true;
987 }
988
989 /*
990 * Call the kernel.
991 */
992 AssertLogRelMsg(!g_pVmxUseCount || *g_pVmxUseCount >= 0,
993 ("vmx_use_count=%d (@ %p, expected it to be a positive number\n",
994 *g_pVmxUseCount, g_pVmxUseCount));
995
996 rc = host_vmxon(false /* exclusive */);
997 if (rc == VMX_OK)
998 rc = VINF_SUCCESS;
999 else if (rc == VMX_UNSUPPORTED)
1000 rc = VERR_VMX_NO_VMX;
1001 else if (rc == VMX_INUSE)
1002 rc = VERR_VMX_IN_VMX_ROOT_MODE;
1003 else /* shouldn't happen, but just in case. */
1004 {
1005 LogRel(("host_vmxon returned %d\n", rc));
1006 rc = VERR_UNRESOLVED_ERROR;
1007 }
1008 LogRel(("VBoxDrv: host_vmxon -> vmx_use_count=%d rc=%Rrc\n", *g_pVmxUseCount, rc));
1009 }
1010 else
1011 {
1012 AssertLogRelMsgReturn(!g_pVmxUseCount || *g_pVmxUseCount >= 1,
1013 ("vmx_use_count=%d (@ %p, expected it to be a non-zero positive number\n",
1014 *g_pVmxUseCount, g_pVmxUseCount),
1015 VERR_WRONG_ORDER);
1016 host_vmxoff();
1017 rc = VINF_SUCCESS;
1018 LogRel(("VBoxDrv: host_vmxoff -> vmx_use_count=%d\n", *g_pVmxUseCount));
1019 }
1020 }
1021 else
1022 {
1023 /* In 10.5.x the host_vmxon is severely broken! Don't use it, it will
1024 frequnetly panic the host. */
1025 rc = VERR_NOT_SUPPORTED;
1026 }
1027 return rc;
1028#else
1029 return VERR_NOT_SUPPORTED;
1030#endif
1031}
1032
1033
1034/**
1035 * @copydoc SUPR0SuspendVTxOnCpu
1036 */
1037bool VBOXCALL supdrvOSSuspendVTxOnCpu(void)
1038{
1039#ifdef VBOX_WITH_HOST_VMX
1040 /*
1041 * Consult the VMX usage counter, don't try suspend if not enabled.
1042 *
1043 * Note! The host_vmxon/off code is still race prone since, but this is
1044 * currently the best we can do without always enable VMX when
1045 * loading the driver.
1046 */
1047 if ( g_pVmxUseCount
1048 && *g_pVmxUseCount > 0)
1049 {
1050 g_pfnVmxSuspend();
1051 return true;
1052 }
1053 return false;
1054#else
1055 return false;
1056#endif
1057}
1058
1059
1060/**
1061 * @copydoc SUPR0ResumeVTxOnCpu
1062 */
1063void VBOXCALL supdrvOSResumeVTxOnCpu(bool fSuspended)
1064{
1065#ifdef VBOX_WITH_HOST_VMX
1066 /*
1067 * Don't consult the counter here, the state knows better.
1068 * We're executing with interrupts disabled and anyone racing us with
1069 * disabling VT-x will be waiting in the rendezvous code.
1070 */
1071 if ( fSuspended
1072 && g_pfnVmxResume)
1073 g_pfnVmxResume();
1074 else
1075 Assert(!fSuspended);
1076#else
1077 Assert(!fSuspended);
1078#endif
1079}
1080
1081
1082bool VBOXCALL supdrvOSGetForcedAsyncTscMode(PSUPDRVDEVEXT pDevExt)
1083{
1084 NOREF(pDevExt);
1085 return false;
1086}
1087
1088
1089bool VBOXCALL supdrvOSAreCpusOfflinedOnSuspend(void)
1090{
1091 /** @todo verify this. */
1092 return false;
1093}
1094
1095
1096bool VBOXCALL supdrvOSAreTscDeltasInSync(void)
1097{
1098 return false;
1099}
1100
1101void VBOXCALL supdrvOSLdrNotifyOpened(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage)
1102{
1103#if 1
1104 NOREF(pDevExt); NOREF(pImage);
1105#else
1106 /*
1107 * Try store the image load address in NVRAM so we can retrived it on panic.
1108 * Note! This only works if you're root! - Acutally, it doesn't work at all at the moment. FIXME!
1109 */
1110 IORegistryEntry *pEntry = IORegistryEntry::fromPath("/options", gIODTPlane);
1111 if (pEntry)
1112 {
1113 char szVar[80];
1114 RTStrPrintf(szVar, sizeof(szVar), "vboximage"/*-%s*/, pImage->szName);
1115 char szValue[48];
1116 RTStrPrintf(szValue, sizeof(szValue), "%#llx,%#llx", (uint64_t)(uintptr_t)pImage->pvImage,
1117 (uint64_t)(uintptr_t)pImage->pvImage + pImage->cbImageBits - 1);
1118 bool fRc = pEntry->setProperty(szVar, szValue); NOREF(fRc);
1119 pEntry->release();
1120 SUPR0Printf("fRc=%d '%s'='%s'\n", fRc, szVar, szValue);
1121 }
1122 /*else
1123 SUPR0Printf("failed to find /options in gIODTPlane\n");*/
1124#endif
1125}
1126
1127
1128int VBOXCALL supdrvOSLdrOpen(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, const char *pszFilename)
1129{
1130 NOREF(pDevExt); NOREF(pImage); NOREF(pszFilename);
1131 return VERR_NOT_SUPPORTED;
1132}
1133
1134
1135int VBOXCALL supdrvOSLdrValidatePointer(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, void *pv, const uint8_t *pbImageBits)
1136{
1137 NOREF(pDevExt); NOREF(pImage); NOREF(pv); NOREF(pbImageBits);
1138 return VERR_NOT_SUPPORTED;
1139}
1140
1141
1142int VBOXCALL supdrvOSLdrLoad(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, const uint8_t *pbImageBits, PSUPLDRLOAD pReq)
1143{
1144 NOREF(pDevExt); NOREF(pImage); NOREF(pbImageBits); NOREF(pReq);
1145 return VERR_NOT_SUPPORTED;
1146}
1147
1148
1149void VBOXCALL supdrvOSLdrUnload(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage)
1150{
1151 NOREF(pDevExt); NOREF(pImage);
1152}
1153
1154
1155#ifdef SUPDRV_WITH_MSR_PROBER
1156
1157typedef struct SUPDRVDARWINMSRARGS
1158{
1159 RTUINT64U uValue;
1160 uint32_t uMsr;
1161 int rc;
1162} SUPDRVDARWINMSRARGS, *PSUPDRVDARWINMSRARGS;
1163
1164/**
1165 * On CPU worker for supdrvOSMsrProberRead.
1166 *
1167 * @param idCpu Ignored.
1168 * @param pvUser1 Pointer to a SUPDRVDARWINMSRARGS.
1169 * @param pvUser2 Ignored.
1170 */
1171static DECLCALLBACK(void) supdrvDarwinMsrProberReadOnCpu(RTCPUID idCpu, void *pvUser1, void *pvUser2)
1172{
1173 PSUPDRVDARWINMSRARGS pArgs = (PSUPDRVDARWINMSRARGS)pvUser1;
1174 if (g_pfnRdMsr64Carefully)
1175 pArgs->rc = g_pfnRdMsr64Carefully(pArgs->uMsr, &pArgs->uValue.u);
1176 else if (g_pfnRdMsrCarefully)
1177 pArgs->rc = g_pfnRdMsrCarefully(pArgs->uMsr, &pArgs->uValue.s.Lo, &pArgs->uValue.s.Hi);
1178 else
1179 pArgs->rc = 2;
1180 NOREF(idCpu); NOREF(pvUser2);
1181}
1182
1183
1184int VBOXCALL supdrvOSMsrProberRead(uint32_t uMsr, RTCPUID idCpu, uint64_t *puValue)
1185{
1186 if (!g_pfnRdMsr64Carefully && !g_pfnRdMsrCarefully)
1187 return VERR_NOT_SUPPORTED;
1188
1189 SUPDRVDARWINMSRARGS Args;
1190 Args.uMsr = uMsr;
1191 Args.uValue.u = 0;
1192 Args.rc = -1;
1193
1194 if (idCpu == NIL_RTCPUID)
1195 supdrvDarwinMsrProberReadOnCpu(idCpu, &Args, NULL);
1196 else
1197 {
1198 int rc = RTMpOnSpecific(idCpu, supdrvDarwinMsrProberReadOnCpu, &Args, NULL);
1199 if (RT_FAILURE(rc))
1200 return rc;
1201 }
1202
1203 if (Args.rc)
1204 return VERR_ACCESS_DENIED;
1205 *puValue = Args.uValue.u;
1206 return VINF_SUCCESS;
1207}
1208
1209
1210/**
1211 * On CPU worker for supdrvOSMsrProberWrite.
1212 *
1213 * @param idCpu Ignored.
1214 * @param pvUser1 Pointer to a SUPDRVDARWINMSRARGS.
1215 * @param pvUser2 Ignored.
1216 */
1217static DECLCALLBACK(void) supdrvDarwinMsrProberWriteOnCpu(RTCPUID idCpu, void *pvUser1, void *pvUser2)
1218{
1219 PSUPDRVDARWINMSRARGS pArgs = (PSUPDRVDARWINMSRARGS)pvUser1;
1220 if (g_pfnWrMsr64Carefully)
1221 pArgs->rc = g_pfnWrMsr64Carefully(pArgs->uMsr, pArgs->uValue.u);
1222 else
1223 pArgs->rc = 2;
1224 NOREF(idCpu); NOREF(pvUser2);
1225}
1226
1227
1228int VBOXCALL supdrvOSMsrProberWrite(uint32_t uMsr, RTCPUID idCpu, uint64_t uValue)
1229{
1230 if (!g_pfnWrMsr64Carefully)
1231 return VERR_NOT_SUPPORTED;
1232
1233 SUPDRVDARWINMSRARGS Args;
1234 Args.uMsr = uMsr;
1235 Args.uValue.u = uValue;
1236 Args.rc = -1;
1237
1238 if (idCpu == NIL_RTCPUID)
1239 supdrvDarwinMsrProberWriteOnCpu(idCpu, &Args, NULL);
1240 else
1241 {
1242 int rc = RTMpOnSpecific(idCpu, supdrvDarwinMsrProberWriteOnCpu, &Args, NULL);
1243 if (RT_FAILURE(rc))
1244 return rc;
1245 }
1246
1247 if (Args.rc)
1248 return VERR_ACCESS_DENIED;
1249 return VINF_SUCCESS;
1250}
1251
1252
1253/**
1254 * Worker for supdrvOSMsrProberModify.
1255 */
1256static DECLCALLBACK(void) supdrvDarwinMsrProberModifyOnCpu(RTCPUID idCpu, void *pvUser1, void *pvUser2)
1257{
1258 PSUPMSRPROBER pReq = (PSUPMSRPROBER)pvUser1;
1259 register uint32_t uMsr = pReq->u.In.uMsr;
1260 bool const fFaster = pReq->u.In.enmOp == SUPMSRPROBEROP_MODIFY_FASTER;
1261 uint64_t uBefore;
1262 uint64_t uWritten;
1263 uint64_t uAfter;
1264 int rcBefore, rcWrite, rcAfter, rcRestore;
1265 RTCCUINTREG fOldFlags;
1266
1267 /* Initialize result variables. */
1268 uBefore = uWritten = uAfter = 0;
1269 rcWrite = rcAfter = rcRestore = -1;
1270
1271 /*
1272 * Do the job.
1273 */
1274 fOldFlags = ASMIntDisableFlags();
1275 ASMCompilerBarrier(); /* paranoia */
1276 if (!fFaster)
1277 ASMWriteBackAndInvalidateCaches();
1278
1279 rcBefore = g_pfnRdMsr64Carefully(uMsr, &uBefore);
1280 if (rcBefore >= 0)
1281 {
1282 register uint64_t uRestore = uBefore;
1283 uWritten = uRestore;
1284 uWritten &= pReq->u.In.uArgs.Modify.fAndMask;
1285 uWritten |= pReq->u.In.uArgs.Modify.fOrMask;
1286
1287 rcWrite = g_pfnWrMsr64Carefully(uMsr, uWritten);
1288 rcAfter = g_pfnRdMsr64Carefully(uMsr, &uAfter);
1289 rcRestore = g_pfnWrMsr64Carefully(uMsr, uRestore);
1290
1291 if (!fFaster)
1292 {
1293 ASMWriteBackAndInvalidateCaches();
1294 ASMReloadCR3();
1295 ASMNopPause();
1296 }
1297 }
1298
1299 ASMCompilerBarrier(); /* paranoia */
1300 ASMSetFlags(fOldFlags);
1301
1302 /*
1303 * Write out the results.
1304 */
1305 pReq->u.Out.uResults.Modify.uBefore = uBefore;
1306 pReq->u.Out.uResults.Modify.uWritten = uWritten;
1307 pReq->u.Out.uResults.Modify.uAfter = uAfter;
1308 pReq->u.Out.uResults.Modify.fBeforeGp = rcBefore != 0;
1309 pReq->u.Out.uResults.Modify.fModifyGp = rcWrite != 0;
1310 pReq->u.Out.uResults.Modify.fAfterGp = rcAfter != 0;
1311 pReq->u.Out.uResults.Modify.fRestoreGp = rcRestore != 0;
1312 RT_ZERO(pReq->u.Out.uResults.Modify.afReserved);
1313}
1314
1315
1316int VBOXCALL supdrvOSMsrProberModify(RTCPUID idCpu, PSUPMSRPROBER pReq)
1317{
1318 if (!g_pfnWrMsr64Carefully || !g_pfnRdMsr64Carefully)
1319 return VERR_NOT_SUPPORTED;
1320 if (idCpu == NIL_RTCPUID)
1321 {
1322 supdrvDarwinMsrProberModifyOnCpu(idCpu, pReq, NULL);
1323 return VINF_SUCCESS;
1324 }
1325 return RTMpOnSpecific(idCpu, supdrvDarwinMsrProberModifyOnCpu, pReq, NULL);
1326}
1327
1328#endif /* SUPDRV_WITH_MSR_PROBER */
1329
1330/**
1331 * Resume Bluetooth keyboard.
1332 * If there is no Bluetooth keyboard device connected to the system we just ignore this.
1333 */
1334static void supdrvDarwinResumeBluetoothKbd(void)
1335{
1336 OSDictionary *pDictionary = IOService::serviceMatching("AppleBluetoothHIDKeyboard");
1337 if (pDictionary)
1338 {
1339 OSIterator *pIter;
1340 IOBluetoothHIDDriver *pDriver;
1341
1342 pIter = IOService::getMatchingServices(pDictionary);
1343 if (pIter)
1344 {
1345 while ((pDriver = (IOBluetoothHIDDriver *)pIter->getNextObject()))
1346 if (pDriver->isKeyboard())
1347 (void)pDriver->hidControl(IOBTHID_CONTROL_EXIT_SUSPEND);
1348
1349 pIter->release();
1350 }
1351 pDictionary->release();
1352 }
1353}
1354
1355/**
1356 * Resume built-in keyboard on MacBook Air and Pro hosts.
1357 * If there is no built-in keyboard device attached to the system we just ignore this.
1358 */
1359static void supdrvDarwinResumeBuiltinKbd(void)
1360{
1361 /*
1362 * AppleUSBTCKeyboard KEXT is responsible for built-in keyboard management.
1363 * We resume keyboard by accessing to its IOService. */
1364 OSDictionary *pDictionary = IOService::serviceMatching("AppleUSBTCKeyboard");
1365 if (pDictionary)
1366 {
1367 OSIterator *pIter;
1368 IOUSBHIDDriver *pDriver;
1369
1370 pIter = IOService::getMatchingServices(pDictionary);
1371 if (pIter)
1372 {
1373 while ((pDriver = (IOUSBHIDDriver *)pIter->getNextObject()))
1374 if (pDriver->IsPortSuspended())
1375 pDriver->SuspendPort(false, 0);
1376
1377 pIter->release();
1378 }
1379 pDictionary->release();
1380 }
1381}
1382
1383
1384/**
1385 * Resume suspended keyboard devices (if any).
1386 */
1387int VBOXCALL supdrvDarwinResumeSuspendedKbds(void)
1388{
1389 supdrvDarwinResumeBuiltinKbd();
1390 supdrvDarwinResumeBluetoothKbd();
1391
1392 return 0;
1393}
1394
1395
1396/**
1397 * Converts an IPRT error code to a darwin error code.
1398 *
1399 * @returns corresponding darwin error code.
1400 * @param rc IPRT status code.
1401 */
1402static int VBoxDrvDarwinErr2DarwinErr(int rc)
1403{
1404 switch (rc)
1405 {
1406 case VINF_SUCCESS: return 0;
1407 case VERR_GENERAL_FAILURE: return EACCES;
1408 case VERR_INVALID_PARAMETER: return EINVAL;
1409 case VERR_INVALID_MAGIC: return EILSEQ;
1410 case VERR_INVALID_HANDLE: return ENXIO;
1411 case VERR_INVALID_POINTER: return EFAULT;
1412 case VERR_LOCK_FAILED: return ENOLCK;
1413 case VERR_ALREADY_LOADED: return EEXIST;
1414 case VERR_PERMISSION_DENIED: return EPERM;
1415 case VERR_VERSION_MISMATCH: return ENOSYS;
1416 }
1417
1418 return EPERM;
1419}
1420
1421
1422/**
1423 * Check if the CPU has SMAP support.
1424 */
1425static bool vboxdrvDarwinCpuHasSMAP(void)
1426{
1427 uint32_t uMaxId, uEAX, uEBX, uECX, uEDX;
1428 ASMCpuId(0, &uMaxId, &uEBX, &uECX, &uEDX);
1429 if ( ASMIsValidStdRange(uMaxId)
1430 && uMaxId >= 0x00000007)
1431 {
1432 ASMCpuId_Idx_ECX(0x00000007, 0, &uEAX, &uEBX, &uECX, &uEDX);
1433 if (uEBX & X86_CPUID_STEXT_FEATURE_EBX_SMAP)
1434 return true;
1435 }
1436#ifdef VBOX_WITH_EFLAGS_AC_SET_IN_VBOXDRV
1437 return true;
1438#else
1439 return false;
1440#endif
1441}
1442
1443
1444RTDECL(int) SUPR0Printf(const char *pszFormat, ...)
1445{
1446 IPRT_DARWIN_SAVE_EFL_AC();
1447 va_list va;
1448 char szMsg[512];
1449
1450 va_start(va, pszFormat);
1451 RTStrPrintfV(szMsg, sizeof(szMsg) - 1, pszFormat, va);
1452 va_end(va);
1453 szMsg[sizeof(szMsg) - 1] = '\0';
1454
1455 printf("%s", szMsg);
1456
1457 IPRT_DARWIN_RESTORE_EFL_AC();
1458 return 0;
1459}
1460
1461
1462SUPR0DECL(uint32_t) SUPR0GetKernelFeatures(void)
1463{
1464 uint32_t fFlags = 0;
1465 if (g_DevCW.d_ioctl == VBoxDrvDarwinIOCtlSMAP)
1466 fFlags |= SUPKERNELFEATURES_SMAP;
1467 else
1468 Assert(!(ASMGetCR4() & X86_CR4_SMAP));
1469 return fFlags;
1470}
1471
1472
1473/*
1474 *
1475 * org_virtualbox_SupDrv
1476 *
1477 */
1478
1479
1480/**
1481 * Initialize the object.
1482 */
1483bool org_virtualbox_SupDrv::init(OSDictionary *pDictionary)
1484{
1485 LogFlow(("org_virtualbox_SupDrv::init([%p], %p)\n", this, pDictionary));
1486 if (IOService::init(pDictionary))
1487 {
1488 /* init members. */
1489 return true;
1490 }
1491 return false;
1492}
1493
1494
1495/**
1496 * Free the object.
1497 */
1498void org_virtualbox_SupDrv::free(void)
1499{
1500 LogFlow(("IOService::free([%p])\n", this));
1501 IOService::free();
1502}
1503
1504
1505/**
1506 * Check if it's ok to start this service.
1507 * It's always ok by us, so it's up to IOService to decide really.
1508 */
1509IOService *org_virtualbox_SupDrv::probe(IOService *pProvider, SInt32 *pi32Score)
1510{
1511 LogFlow(("org_virtualbox_SupDrv::probe([%p])\n", this));
1512 return IOService::probe(pProvider, pi32Score);
1513}
1514
1515
1516/**
1517 * Start this service.
1518 */
1519bool org_virtualbox_SupDrv::start(IOService *pProvider)
1520{
1521 LogFlow(("org_virtualbox_SupDrv::start([%p])\n", this));
1522
1523 if (IOService::start(pProvider))
1524 {
1525 /* register the service. */
1526 registerService();
1527 return true;
1528 }
1529 return false;
1530}
1531
1532
1533/**
1534 * Stop this service.
1535 */
1536void org_virtualbox_SupDrv::stop(IOService *pProvider)
1537{
1538 LogFlow(("org_virtualbox_SupDrv::stop([%p], %p)\n", this, pProvider));
1539 IOService::stop(pProvider);
1540}
1541
1542
1543/**
1544 * Termination request.
1545 *
1546 * @return true if we're ok with shutting down now, false if we're not.
1547 * @param fOptions Flags.
1548 */
1549bool org_virtualbox_SupDrv::terminate(IOOptionBits fOptions)
1550{
1551 bool fRc;
1552 LogFlow(("org_virtualbox_SupDrv::terminate: reference_count=%d g_cSessions=%d (fOptions=%#x)\n",
1553 KMOD_INFO_NAME.reference_count, ASMAtomicUoReadS32(&g_cSessions), fOptions));
1554 if ( KMOD_INFO_NAME.reference_count != 0
1555 || ASMAtomicUoReadS32(&g_cSessions))
1556 fRc = false;
1557 else
1558 fRc = IOService::terminate(fOptions);
1559 LogFlow(("org_virtualbox_SupDrv::terminate: returns %d\n", fRc));
1560 return fRc;
1561}
1562
1563
1564/*
1565 *
1566 * org_virtualbox_SupDrvClient
1567 *
1568 */
1569
1570
1571/**
1572 * Initializer called when the client opens the service.
1573 */
1574bool org_virtualbox_SupDrvClient::initWithTask(task_t OwningTask, void *pvSecurityId, UInt32 u32Type)
1575{
1576 LogFlow(("org_virtualbox_SupDrvClient::initWithTask([%p], %#x, %p, %#x) (cur pid=%d proc=%p)\n",
1577 this, OwningTask, pvSecurityId, u32Type, RTProcSelf(), RTR0ProcHandleSelf()));
1578 AssertMsg((RTR0PROCESS)OwningTask == RTR0ProcHandleSelf(), ("%p %p\n", OwningTask, RTR0ProcHandleSelf()));
1579
1580 if (!OwningTask)
1581 return false;
1582
1583 VBOX_RETRIEVE_CUR_PROC_NAME(pszProcName);
1584
1585 if (u32Type != SUP_DARWIN_IOSERVICE_COOKIE)
1586 {
1587 LogRel(("org_virtualbox_SupDrvClient::initWithTask: Bad cookie %#x (%s)\n", u32Type, pszProcName));
1588 return false;
1589 }
1590 else
1591 LogRel(("org_virtualbox_SupDrvClient::initWithTask: Expected cookie %#x (%s)\n", u32Type, pszProcName));
1592
1593 if (IOUserClient::initWithTask(OwningTask, pvSecurityId , u32Type))
1594 {
1595 m_Task = OwningTask;
1596 m_pSession = NULL;
1597 m_pProvider = NULL;
1598 return true;
1599 }
1600 return false;
1601}
1602
1603
1604/**
1605 * Start the client service.
1606 */
1607bool org_virtualbox_SupDrvClient::start(IOService *pProvider)
1608{
1609 LogFlow(("org_virtualbox_SupDrvClient::start([%p], %p) (cur pid=%d proc=%p)\n",
1610 this, pProvider, RTProcSelf(), RTR0ProcHandleSelf() ));
1611 AssertMsgReturn((RTR0PROCESS)m_Task == RTR0ProcHandleSelf(),
1612 ("%p %p\n", m_Task, RTR0ProcHandleSelf()),
1613 false);
1614
1615 if (IOUserClient::start(pProvider))
1616 {
1617 m_pProvider = OSDynamicCast(org_virtualbox_SupDrv, pProvider);
1618 if (m_pProvider)
1619 {
1620 Assert(!m_pSession);
1621
1622 /*
1623 * Create a new session.
1624 */
1625 int rc = supdrvCreateSession(&g_DevExt, true /* fUser */, false /*fUnrestricted*/, &m_pSession);
1626 if (RT_SUCCESS(rc))
1627 {
1628 m_pSession->fOpened = false;
1629 /* The Uid, Gid and fUnrestricted fields are set on open. */
1630
1631 /*
1632 * Insert it into the hash table, checking that there isn't
1633 * already one for this process first. (One session per proc!)
1634 */
1635 unsigned iHash = SESSION_HASH(m_pSession->Process);
1636 RTSpinlockAcquire(g_Spinlock);
1637
1638 PSUPDRVSESSION pCur = g_apSessionHashTab[iHash];
1639 while (pCur && pCur->Process != m_pSession->Process)
1640 pCur = pCur->pNextHash;
1641 if (!pCur)
1642 {
1643 m_pSession->pNextHash = g_apSessionHashTab[iHash];
1644 g_apSessionHashTab[iHash] = m_pSession;
1645 m_pSession->pvSupDrvClient = this;
1646 ASMAtomicIncS32(&g_cSessions);
1647 rc = VINF_SUCCESS;
1648 }
1649 else
1650 rc = VERR_ALREADY_LOADED;
1651
1652 RTSpinlockRelease(g_Spinlock);
1653 if (RT_SUCCESS(rc))
1654 {
1655 Log(("org_virtualbox_SupDrvClient::start: created session %p for pid %d\n", m_pSession, (int)RTProcSelf()));
1656 return true;
1657 }
1658
1659 LogFlow(("org_virtualbox_SupDrvClient::start: already got a session for this process (%p)\n", pCur));
1660 supdrvSessionRelease(m_pSession);
1661 }
1662
1663 m_pSession = NULL;
1664 LogFlow(("org_virtualbox_SupDrvClient::start: rc=%Rrc from supdrvCreateSession\n", rc));
1665 }
1666 else
1667 LogFlow(("org_virtualbox_SupDrvClient::start: %p isn't org_virtualbox_SupDrv\n", pProvider));
1668 }
1669 return false;
1670}
1671
1672
1673/**
1674 * Common worker for clientClose and VBoxDrvDarwinClose.
1675 */
1676/* static */ void org_virtualbox_SupDrvClient::sessionClose(RTPROCESS Process)
1677{
1678 /*
1679 * Find the session and remove it from the hash table.
1680 *
1681 * Note! Only one session per process. (Both start() and
1682 * VBoxDrvDarwinOpen makes sure this is so.)
1683 */
1684 const unsigned iHash = SESSION_HASH(Process);
1685 RTSpinlockAcquire(g_Spinlock);
1686 PSUPDRVSESSION pSession = g_apSessionHashTab[iHash];
1687 if (pSession)
1688 {
1689 if (pSession->Process == Process)
1690 {
1691 g_apSessionHashTab[iHash] = pSession->pNextHash;
1692 pSession->pNextHash = NULL;
1693 ASMAtomicDecS32(&g_cSessions);
1694 }
1695 else
1696 {
1697 PSUPDRVSESSION pPrev = pSession;
1698 pSession = pSession->pNextHash;
1699 while (pSession)
1700 {
1701 if (pSession->Process == Process)
1702 {
1703 pPrev->pNextHash = pSession->pNextHash;
1704 pSession->pNextHash = NULL;
1705 ASMAtomicDecS32(&g_cSessions);
1706 break;
1707 }
1708
1709 /* next */
1710 pPrev = pSession;
1711 pSession = pSession->pNextHash;
1712 }
1713 }
1714 }
1715 RTSpinlockRelease(g_Spinlock);
1716 if (!pSession)
1717 {
1718 Log(("SupDrvClient::sessionClose: pSession == NULL, pid=%d; freed already?\n", (int)Process));
1719 return;
1720 }
1721
1722 /*
1723 * Remove it from the client object.
1724 */
1725 org_virtualbox_SupDrvClient *pThis = (org_virtualbox_SupDrvClient *)pSession->pvSupDrvClient;
1726 pSession->pvSupDrvClient = NULL;
1727 if (pThis)
1728 {
1729 Assert(pThis->m_pSession == pSession);
1730 pThis->m_pSession = NULL;
1731 }
1732
1733 /*
1734 * Close the session.
1735 */
1736 supdrvSessionRelease(pSession);
1737}
1738
1739
1740/**
1741 * Client exits normally.
1742 */
1743IOReturn org_virtualbox_SupDrvClient::clientClose(void)
1744{
1745 LogFlow(("org_virtualbox_SupDrvClient::clientClose([%p]) (cur pid=%d proc=%p)\n", this, RTProcSelf(), RTR0ProcHandleSelf()));
1746 AssertMsg((RTR0PROCESS)m_Task == RTR0ProcHandleSelf(), ("%p %p\n", m_Task, RTR0ProcHandleSelf()));
1747
1748 /*
1749 * Clean up the session if it's still around.
1750 *
1751 * We cannot rely 100% on close, and in the case of a dead client
1752 * we'll end up hanging inside vm_map_remove() if we postpone it.
1753 */
1754 if (m_pSession)
1755 {
1756 sessionClose(RTProcSelf());
1757 Assert(!m_pSession);
1758 }
1759
1760 m_pProvider = NULL;
1761 terminate();
1762
1763 return kIOReturnSuccess;
1764}
1765
1766
1767/**
1768 * The client exits abnormally / forgets to do cleanups. (logging)
1769 */
1770IOReturn org_virtualbox_SupDrvClient::clientDied(void)
1771{
1772 LogFlow(("org_virtualbox_SupDrvClient::clientDied([%p]) m_Task=%p R0Process=%p Process=%d\n",
1773 this, m_Task, RTR0ProcHandleSelf(), RTProcSelf()));
1774
1775 /* IOUserClient::clientDied() calls clientClose, so we'll just do the work there. */
1776 return IOUserClient::clientDied();
1777}
1778
1779
1780/**
1781 * Terminate the service (initiate the destruction). (logging)
1782 */
1783bool org_virtualbox_SupDrvClient::terminate(IOOptionBits fOptions)
1784{
1785 LogFlow(("org_virtualbox_SupDrvClient::terminate([%p], %#x)\n", this, fOptions));
1786 return IOUserClient::terminate(fOptions);
1787}
1788
1789
1790/**
1791 * The final stage of the client service destruction. (logging)
1792 */
1793bool org_virtualbox_SupDrvClient::finalize(IOOptionBits fOptions)
1794{
1795 LogFlow(("org_virtualbox_SupDrvClient::finalize([%p], %#x)\n", this, fOptions));
1796 return IOUserClient::finalize(fOptions);
1797}
1798
1799
1800/**
1801 * Stop the client service. (logging)
1802 */
1803void org_virtualbox_SupDrvClient::stop(IOService *pProvider)
1804{
1805 LogFlow(("org_virtualbox_SupDrvClient::stop([%p])\n", this));
1806 IOUserClient::stop(pProvider);
1807}
1808
Note: See TracBrowser for help on using the repository browser.

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