VirtualBox

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

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

SUPDrv: Enabled AC=1 I/O control checks on Linux and extended the checks to include the interrupt flag, I/O privilege level and the direction flag.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 55.9 KB
Line 
1/* $Id: SUPDrv-darwin.cpp 57254 2015-08-09 14:26:51Z 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 RTCCUINTREG fSavedEfl = ASMAddFlags(X86_EFL_AC);
648
649 int rc = VBoxDrvDarwinIOCtl(Dev, iCmd, pData, fFlags, pProcess);
650
651#if defined(VBOX_STRICT) || defined(VBOX_WITH_EFLAGS_AC_SET_IN_VBOXDRV)
652 /*
653 * Before we restore AC and the rest of EFLAGS, check if the IOCtl handler code
654 * accidentially modified it or some other important flag.
655 */
656 if (RT_UNLIKELY( (ASMGetFlags() & (X86_EFL_AC | X86_EFL_IF | X86_EFL_DF | X86_EFL_IOPL))
657 != ((fSavedEfl & (X86_EFL_AC | X86_EFL_IF | X86_EFL_DF | X86_EFL_IOPL)) | X86_EFL_AC) ))
658 {
659 char szTmp[48];
660 RTStrPrintf(szTmp, sizeof(szTmp), "iCmd=%#x: %#x->%#x!", iCmd, (uint32_t)fSavedEfl, (uint32_t)ASMGetFlags());
661 supdrvBadContext(&g_DevExt, "SUPDrv-darwin.cpp", __LINE__, szTmp);
662 }
663#endif
664
665 ASMSetFlags(fSavedEfl);
666 return rc;
667}
668
669
670/**
671 * Worker for VBoxDrvDarwinIOCtl that takes the slow IOCtl functions.
672 *
673 * @returns Darwin errno.
674 *
675 * @param pSession The session.
676 * @param iCmd The IOCtl command.
677 * @param pData Pointer to the kernel copy of the SUPDRVIOCTLDATA buffer.
678 * @param pProcess The calling process.
679 */
680static int VBoxDrvDarwinIOCtlSlow(PSUPDRVSESSION pSession, u_long iCmd, caddr_t pData, struct proc *pProcess)
681{
682 LogFlow(("VBoxDrvDarwinIOCtlSlow: pSession=%p iCmd=%p pData=%p pProcess=%p\n", pSession, iCmd, pData, pProcess));
683
684
685 /*
686 * Buffered or unbuffered?
687 */
688 PSUPREQHDR pHdr;
689 user_addr_t pUser = 0;
690 void *pvPageBuf = NULL;
691 uint32_t cbReq = IOCPARM_LEN(iCmd);
692 if ((IOC_DIRMASK & iCmd) == IOC_INOUT)
693 {
694 pHdr = (PSUPREQHDR)pData;
695 if (RT_UNLIKELY(cbReq < sizeof(*pHdr)))
696 {
697 OSDBGPRINT(("VBoxDrvDarwinIOCtlSlow: cbReq=%#x < %#x; iCmd=%#lx\n", cbReq, (int)sizeof(*pHdr), iCmd));
698 return EINVAL;
699 }
700 if (RT_UNLIKELY((pHdr->fFlags & SUPREQHDR_FLAGS_MAGIC_MASK) != SUPREQHDR_FLAGS_MAGIC))
701 {
702 OSDBGPRINT(("VBoxDrvDarwinIOCtlSlow: bad magic fFlags=%#x; iCmd=%#lx\n", pHdr->fFlags, iCmd));
703 return EINVAL;
704 }
705 if (RT_UNLIKELY( RT_MAX(pHdr->cbIn, pHdr->cbOut) != cbReq
706 || pHdr->cbIn < sizeof(*pHdr)
707 || pHdr->cbOut < sizeof(*pHdr)))
708 {
709 OSDBGPRINT(("VBoxDrvDarwinIOCtlSlow: max(%#x,%#x) != %#x; iCmd=%#lx\n", pHdr->cbIn, pHdr->cbOut, cbReq, iCmd));
710 return EINVAL;
711 }
712 }
713 else if ((IOC_DIRMASK & iCmd) == IOC_VOID && !cbReq)
714 {
715 /*
716 * Get the header and figure out how much we're gonna have to read.
717 */
718 SUPREQHDR Hdr;
719 pUser = (user_addr_t)*(void **)pData;
720 int rc = copyin(pUser, &Hdr, sizeof(Hdr));
721 if (RT_UNLIKELY(rc))
722 {
723 OSDBGPRINT(("VBoxDrvDarwinIOCtlSlow: copyin(%llx,Hdr,) -> %#x; iCmd=%#lx\n", (unsigned long long)pUser, rc, iCmd));
724 return rc;
725 }
726 if (RT_UNLIKELY((Hdr.fFlags & SUPREQHDR_FLAGS_MAGIC_MASK) != SUPREQHDR_FLAGS_MAGIC))
727 {
728 OSDBGPRINT(("VBoxDrvDarwinIOCtlSlow: bad magic fFlags=%#x; iCmd=%#lx\n", Hdr.fFlags, iCmd));
729 return EINVAL;
730 }
731 cbReq = RT_MAX(Hdr.cbIn, Hdr.cbOut);
732 if (RT_UNLIKELY( Hdr.cbIn < sizeof(Hdr)
733 || Hdr.cbOut < sizeof(Hdr)
734 || cbReq > _1M*16))
735 {
736 OSDBGPRINT(("VBoxDrvDarwinIOCtlSlow: max(%#x,%#x); iCmd=%#lx\n", Hdr.cbIn, Hdr.cbOut, iCmd));
737 return EINVAL;
738 }
739
740 /*
741 * Allocate buffer and copy in the data.
742 */
743 pHdr = (PSUPREQHDR)RTMemTmpAlloc(cbReq);
744 if (!pHdr)
745 pvPageBuf = pHdr = (PSUPREQHDR)IOMallocAligned(RT_ALIGN_Z(cbReq, PAGE_SIZE), 8);
746 if (RT_UNLIKELY(!pHdr))
747 {
748 OSDBGPRINT(("VBoxDrvDarwinIOCtlSlow: failed to allocate buffer of %d bytes; iCmd=%#lx\n", cbReq, iCmd));
749 return ENOMEM;
750 }
751 rc = copyin(pUser, pHdr, Hdr.cbIn);
752 if (RT_UNLIKELY(rc))
753 {
754 OSDBGPRINT(("VBoxDrvDarwinIOCtlSlow: copyin(%llx,%p,%#x) -> %#x; iCmd=%#lx\n",
755 (unsigned long long)pUser, pHdr, Hdr.cbIn, rc, iCmd));
756 if (pvPageBuf)
757 IOFreeAligned(pvPageBuf, RT_ALIGN_Z(cbReq, PAGE_SIZE));
758 else
759 RTMemTmpFree(pHdr);
760 return rc;
761 }
762 if (Hdr.cbIn < cbReq)
763 RT_BZERO((uint8_t *)pHdr + Hdr.cbIn, cbReq - Hdr.cbIn);
764 }
765 else
766 {
767 Log(("VBoxDrvDarwinIOCtlSlow: huh? cbReq=%#x iCmd=%#lx\n", cbReq, iCmd));
768 return EINVAL;
769 }
770
771 /*
772 * Process the IOCtl.
773 */
774 int rc = supdrvIOCtl(iCmd, &g_DevExt, pSession, pHdr, cbReq);
775 if (RT_LIKELY(!rc))
776 {
777 /*
778 * If not buffered, copy back the buffer before returning.
779 */
780 if (pUser)
781 {
782 uint32_t cbOut = pHdr->cbOut;
783 if (cbOut > cbReq)
784 {
785 OSDBGPRINT(("VBoxDrvDarwinIOCtlSlow: too much output! %#x > %#x; uCmd=%#lx!\n", cbOut, cbReq, iCmd));
786 cbOut = cbReq;
787 }
788 rc = copyout(pHdr, pUser, cbOut);
789 if (RT_UNLIKELY(rc))
790 OSDBGPRINT(("VBoxDrvDarwinIOCtlSlow: copyout(%p,%llx,%#x) -> %d; uCmd=%#lx!\n",
791 pHdr, (unsigned long long)pUser, cbOut, rc, iCmd));
792
793 /* cleanup */
794 if (pvPageBuf)
795 IOFreeAligned(pvPageBuf, RT_ALIGN_Z(cbReq, PAGE_SIZE));
796 else
797 RTMemTmpFree(pHdr);
798 }
799 }
800 else
801 {
802 /*
803 * The request failed, just clean up.
804 */
805 if (pUser)
806 {
807 if (pvPageBuf)
808 IOFreeAligned(pvPageBuf, RT_ALIGN_Z(cbReq, PAGE_SIZE));
809 else
810 RTMemTmpFree(pHdr);
811 }
812
813 Log(("VBoxDrvDarwinIOCtlSlow: pid=%d iCmd=%lx pData=%p failed, rc=%d\n", proc_pid(pProcess), iCmd, (void *)pData, rc));
814 rc = EINVAL;
815 }
816
817 Log2(("VBoxDrvDarwinIOCtlSlow: returns %d\n", rc));
818 return rc;
819}
820
821
822/**
823 * The SUPDRV IDC entry point.
824 *
825 * @returns VBox status code, see supdrvIDC.
826 * @param iReq The request code.
827 * @param pReq The request.
828 */
829DECLEXPORT(int) VBOXCALL SUPDrvDarwinIDC(uint32_t uReq, PSUPDRVIDCREQHDR pReq)
830{
831 PSUPDRVSESSION pSession;
832
833 /*
834 * Some quick validations.
835 */
836 if (RT_UNLIKELY(!VALID_PTR(pReq)))
837 return VERR_INVALID_POINTER;
838
839 pSession = pReq->pSession;
840 if (pSession)
841 {
842 if (RT_UNLIKELY(!VALID_PTR(pSession)))
843 return VERR_INVALID_PARAMETER;
844 if (RT_UNLIKELY(pSession->pDevExt != &g_DevExt))
845 return VERR_INVALID_PARAMETER;
846 }
847 else if (RT_UNLIKELY(uReq != SUPDRV_IDC_REQ_CONNECT))
848 return VERR_INVALID_PARAMETER;
849
850 /*
851 * Do the job.
852 */
853 return supdrvIDC(uReq, &g_DevExt, pSession, pReq);
854}
855
856
857void VBOXCALL supdrvOSCleanupSession(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession)
858{
859 NOREF(pDevExt);
860 NOREF(pSession);
861}
862
863
864void VBOXCALL supdrvOSSessionHashTabInserted(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, void *pvUser)
865{
866 NOREF(pDevExt); NOREF(pSession); NOREF(pvUser);
867}
868
869
870void VBOXCALL supdrvOSSessionHashTabRemoved(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, void *pvUser)
871{
872 NOREF(pDevExt); NOREF(pSession); NOREF(pvUser);
873}
874
875
876/**
877 * Initializes any OS specific object creator fields.
878 */
879void VBOXCALL supdrvOSObjInitCreator(PSUPDRVOBJ pObj, PSUPDRVSESSION pSession)
880{
881 NOREF(pObj);
882 NOREF(pSession);
883}
884
885
886/**
887 * Checks if the session can access the object.
888 *
889 * @returns true if a decision has been made.
890 * @returns false if the default access policy should be applied.
891 *
892 * @param pObj The object in question.
893 * @param pSession The session wanting to access the object.
894 * @param pszObjName The object name, can be NULL.
895 * @param prc Where to store the result when returning true.
896 */
897bool VBOXCALL supdrvOSObjCanAccess(PSUPDRVOBJ pObj, PSUPDRVSESSION pSession, const char *pszObjName, int *prc)
898{
899 NOREF(pObj);
900 NOREF(pSession);
901 NOREF(pszObjName);
902 NOREF(prc);
903 return false;
904}
905
906/**
907 * Callback for blah blah blah.
908 */
909IOReturn VBoxDrvDarwinSleepHandler(void * /* pvTarget */, void *pvRefCon, UInt32 uMessageType, IOService * /* pProvider */, void * /* pvMessageArgument */, vm_size_t /* argSize */)
910{
911 LogFlow(("VBoxDrv: Got sleep/wake notice. Message type was %X\n", (uint)uMessageType));
912
913 if (uMessageType == kIOMessageSystemWillSleep)
914 RTPowerSignalEvent(RTPOWEREVENT_SUSPEND);
915 else if (uMessageType == kIOMessageSystemHasPoweredOn)
916 RTPowerSignalEvent(RTPOWEREVENT_RESUME);
917
918 acknowledgeSleepWakeNotification(pvRefCon);
919
920 return 0;
921}
922
923
924#ifdef VBOX_WITH_HOST_VMX
925/**
926 * For cleaning up the mess we left behind on Yosemite with 4.3.28 and earlier.
927 *
928 * We ASSUME VT-x is supported by the CPU.
929 *
930 * @param idCpu Unused.
931 * @param pvUser1 Unused.
932 * @param pvUser2 Unused.
933 */
934static DECLCALLBACK(void) vboxdrvDarwinVmxEnableFix(RTCPUID idCpu, void *pvUser1, void *pvUser2)
935{
936 RTCCUINTREG uCr4 = ASMGetCR4();
937 if (!(uCr4 & X86_CR4_VMXE))
938 {
939 uCr4 |= X86_CR4_VMXE;
940 ASMSetCR4(uCr4);
941 }
942}
943#endif
944
945
946/**
947 * @copydoc SUPR0EnableVTx
948 */
949int VBOXCALL supdrvOSEnableVTx(bool fEnable)
950{
951#ifdef VBOX_WITH_HOST_VMX
952 int rc;
953 if ( version_major >= 10 /* 10 = 10.6.x = Snow Leopard */
954# ifdef VBOX_WITH_RAW_MODE
955 && g_pfnVmxSuspend
956 && g_pfnVmxResume
957 && g_pVmxUseCount
958# endif
959 )
960 {
961 if (fEnable)
962 {
963 /*
964 * We screwed up on Yosemite and didn't notice that we weren't
965 * calling host_vmxon. CR4.VMXE may therefore have been disabled
966 * by us. So, first time around we make sure it's set so we won't
967 * crash in the pre-4.3.28/5.0RC1 upgrade scenario.
968 * See @bugref{7907}.
969 */
970 static bool volatile g_fDoneCleanup = false;
971 if (!g_fDoneCleanup)
972 {
973 if (version_major == 14 /* 14 = 10.10 = yosemite */)
974 {
975 uint32_t fCaps;
976 int rc = supdrvQueryVTCapsInternal(&fCaps);
977 if (RT_SUCCESS(rc))
978 {
979 if (fCaps & SUPVTCAPS_VT_X)
980 rc = RTMpOnAll(vboxdrvDarwinVmxEnableFix, NULL, NULL);
981 else
982 rc = VERR_VMX_NO_VMX;
983 }
984 if (RT_FAILURE(rc))
985 return rc;
986 }
987 g_fDoneCleanup = true;
988 }
989
990 /*
991 * Call the kernel.
992 */
993 AssertLogRelMsg(!g_pVmxUseCount || *g_pVmxUseCount >= 0,
994 ("vmx_use_count=%d (@ %p, expected it to be a positive number\n",
995 *g_pVmxUseCount, g_pVmxUseCount));
996
997 rc = host_vmxon(false /* exclusive */);
998 if (rc == VMX_OK)
999 rc = VINF_SUCCESS;
1000 else if (rc == VMX_UNSUPPORTED)
1001 rc = VERR_VMX_NO_VMX;
1002 else if (rc == VMX_INUSE)
1003 rc = VERR_VMX_IN_VMX_ROOT_MODE;
1004 else /* shouldn't happen, but just in case. */
1005 {
1006 LogRel(("host_vmxon returned %d\n", rc));
1007 rc = VERR_UNRESOLVED_ERROR;
1008 }
1009 LogRel(("VBoxDrv: host_vmxon -> vmx_use_count=%d rc=%Rrc\n", *g_pVmxUseCount, rc));
1010 }
1011 else
1012 {
1013 AssertLogRelMsgReturn(!g_pVmxUseCount || *g_pVmxUseCount >= 1,
1014 ("vmx_use_count=%d (@ %p, expected it to be a non-zero positive number\n",
1015 *g_pVmxUseCount, g_pVmxUseCount),
1016 VERR_WRONG_ORDER);
1017 host_vmxoff();
1018 rc = VINF_SUCCESS;
1019 LogRel(("VBoxDrv: host_vmxoff -> vmx_use_count=%d\n", *g_pVmxUseCount));
1020 }
1021 }
1022 else
1023 {
1024 /* In 10.5.x the host_vmxon is severely broken! Don't use it, it will
1025 frequnetly panic the host. */
1026 rc = VERR_NOT_SUPPORTED;
1027 }
1028 return rc;
1029#else
1030 return VERR_NOT_SUPPORTED;
1031#endif
1032}
1033
1034
1035/**
1036 * @copydoc SUPR0SuspendVTxOnCpu
1037 */
1038bool VBOXCALL supdrvOSSuspendVTxOnCpu(void)
1039{
1040#ifdef VBOX_WITH_HOST_VMX
1041 /*
1042 * Consult the VMX usage counter, don't try suspend if not enabled.
1043 *
1044 * Note! The host_vmxon/off code is still race prone since, but this is
1045 * currently the best we can do without always enable VMX when
1046 * loading the driver.
1047 */
1048 if ( g_pVmxUseCount
1049 && *g_pVmxUseCount > 0)
1050 {
1051 g_pfnVmxSuspend();
1052 return true;
1053 }
1054 return false;
1055#else
1056 return false;
1057#endif
1058}
1059
1060
1061/**
1062 * @copydoc SUPR0ResumeVTxOnCpu
1063 */
1064void VBOXCALL supdrvOSResumeVTxOnCpu(bool fSuspended)
1065{
1066#ifdef VBOX_WITH_HOST_VMX
1067 /*
1068 * Don't consult the counter here, the state knows better.
1069 * We're executing with interrupts disabled and anyone racing us with
1070 * disabling VT-x will be waiting in the rendezvous code.
1071 */
1072 if ( fSuspended
1073 && g_pfnVmxResume)
1074 g_pfnVmxResume();
1075 else
1076 Assert(!fSuspended);
1077#else
1078 Assert(!fSuspended);
1079#endif
1080}
1081
1082
1083bool VBOXCALL supdrvOSGetForcedAsyncTscMode(PSUPDRVDEVEXT pDevExt)
1084{
1085 NOREF(pDevExt);
1086 return false;
1087}
1088
1089
1090bool VBOXCALL supdrvOSAreCpusOfflinedOnSuspend(void)
1091{
1092 /** @todo verify this. */
1093 return false;
1094}
1095
1096
1097bool VBOXCALL supdrvOSAreTscDeltasInSync(void)
1098{
1099 return false;
1100}
1101
1102void VBOXCALL supdrvOSLdrNotifyOpened(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage)
1103{
1104#if 1
1105 NOREF(pDevExt); NOREF(pImage);
1106#else
1107 /*
1108 * Try store the image load address in NVRAM so we can retrived it on panic.
1109 * Note! This only works if you're root! - Acutally, it doesn't work at all at the moment. FIXME!
1110 */
1111 IORegistryEntry *pEntry = IORegistryEntry::fromPath("/options", gIODTPlane);
1112 if (pEntry)
1113 {
1114 char szVar[80];
1115 RTStrPrintf(szVar, sizeof(szVar), "vboximage"/*-%s*/, pImage->szName);
1116 char szValue[48];
1117 RTStrPrintf(szValue, sizeof(szValue), "%#llx,%#llx", (uint64_t)(uintptr_t)pImage->pvImage,
1118 (uint64_t)(uintptr_t)pImage->pvImage + pImage->cbImageBits - 1);
1119 bool fRc = pEntry->setProperty(szVar, szValue); NOREF(fRc);
1120 pEntry->release();
1121 SUPR0Printf("fRc=%d '%s'='%s'\n", fRc, szVar, szValue);
1122 }
1123 /*else
1124 SUPR0Printf("failed to find /options in gIODTPlane\n");*/
1125#endif
1126}
1127
1128
1129int VBOXCALL supdrvOSLdrOpen(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, const char *pszFilename)
1130{
1131 NOREF(pDevExt); NOREF(pImage); NOREF(pszFilename);
1132 return VERR_NOT_SUPPORTED;
1133}
1134
1135
1136int VBOXCALL supdrvOSLdrValidatePointer(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, void *pv, const uint8_t *pbImageBits)
1137{
1138 NOREF(pDevExt); NOREF(pImage); NOREF(pv); NOREF(pbImageBits);
1139 return VERR_NOT_SUPPORTED;
1140}
1141
1142
1143int VBOXCALL supdrvOSLdrLoad(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, const uint8_t *pbImageBits, PSUPLDRLOAD pReq)
1144{
1145 NOREF(pDevExt); NOREF(pImage); NOREF(pbImageBits); NOREF(pReq);
1146 return VERR_NOT_SUPPORTED;
1147}
1148
1149
1150void VBOXCALL supdrvOSLdrUnload(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage)
1151{
1152 NOREF(pDevExt); NOREF(pImage);
1153}
1154
1155
1156#ifdef SUPDRV_WITH_MSR_PROBER
1157
1158typedef struct SUPDRVDARWINMSRARGS
1159{
1160 RTUINT64U uValue;
1161 uint32_t uMsr;
1162 int rc;
1163} SUPDRVDARWINMSRARGS, *PSUPDRVDARWINMSRARGS;
1164
1165/**
1166 * On CPU worker for supdrvOSMsrProberRead.
1167 *
1168 * @param idCpu Ignored.
1169 * @param pvUser1 Pointer to a SUPDRVDARWINMSRARGS.
1170 * @param pvUser2 Ignored.
1171 */
1172static DECLCALLBACK(void) supdrvDarwinMsrProberReadOnCpu(RTCPUID idCpu, void *pvUser1, void *pvUser2)
1173{
1174 PSUPDRVDARWINMSRARGS pArgs = (PSUPDRVDARWINMSRARGS)pvUser1;
1175 if (g_pfnRdMsr64Carefully)
1176 pArgs->rc = g_pfnRdMsr64Carefully(pArgs->uMsr, &pArgs->uValue.u);
1177 else if (g_pfnRdMsrCarefully)
1178 pArgs->rc = g_pfnRdMsrCarefully(pArgs->uMsr, &pArgs->uValue.s.Lo, &pArgs->uValue.s.Hi);
1179 else
1180 pArgs->rc = 2;
1181 NOREF(idCpu); NOREF(pvUser2);
1182}
1183
1184
1185int VBOXCALL supdrvOSMsrProberRead(uint32_t uMsr, RTCPUID idCpu, uint64_t *puValue)
1186{
1187 if (!g_pfnRdMsr64Carefully && !g_pfnRdMsrCarefully)
1188 return VERR_NOT_SUPPORTED;
1189
1190 SUPDRVDARWINMSRARGS Args;
1191 Args.uMsr = uMsr;
1192 Args.uValue.u = 0;
1193 Args.rc = -1;
1194
1195 if (idCpu == NIL_RTCPUID)
1196 supdrvDarwinMsrProberReadOnCpu(idCpu, &Args, NULL);
1197 else
1198 {
1199 int rc = RTMpOnSpecific(idCpu, supdrvDarwinMsrProberReadOnCpu, &Args, NULL);
1200 if (RT_FAILURE(rc))
1201 return rc;
1202 }
1203
1204 if (Args.rc)
1205 return VERR_ACCESS_DENIED;
1206 *puValue = Args.uValue.u;
1207 return VINF_SUCCESS;
1208}
1209
1210
1211/**
1212 * On CPU worker for supdrvOSMsrProberWrite.
1213 *
1214 * @param idCpu Ignored.
1215 * @param pvUser1 Pointer to a SUPDRVDARWINMSRARGS.
1216 * @param pvUser2 Ignored.
1217 */
1218static DECLCALLBACK(void) supdrvDarwinMsrProberWriteOnCpu(RTCPUID idCpu, void *pvUser1, void *pvUser2)
1219{
1220 PSUPDRVDARWINMSRARGS pArgs = (PSUPDRVDARWINMSRARGS)pvUser1;
1221 if (g_pfnWrMsr64Carefully)
1222 pArgs->rc = g_pfnWrMsr64Carefully(pArgs->uMsr, pArgs->uValue.u);
1223 else
1224 pArgs->rc = 2;
1225 NOREF(idCpu); NOREF(pvUser2);
1226}
1227
1228
1229int VBOXCALL supdrvOSMsrProberWrite(uint32_t uMsr, RTCPUID idCpu, uint64_t uValue)
1230{
1231 if (!g_pfnWrMsr64Carefully)
1232 return VERR_NOT_SUPPORTED;
1233
1234 SUPDRVDARWINMSRARGS Args;
1235 Args.uMsr = uMsr;
1236 Args.uValue.u = uValue;
1237 Args.rc = -1;
1238
1239 if (idCpu == NIL_RTCPUID)
1240 supdrvDarwinMsrProberWriteOnCpu(idCpu, &Args, NULL);
1241 else
1242 {
1243 int rc = RTMpOnSpecific(idCpu, supdrvDarwinMsrProberWriteOnCpu, &Args, NULL);
1244 if (RT_FAILURE(rc))
1245 return rc;
1246 }
1247
1248 if (Args.rc)
1249 return VERR_ACCESS_DENIED;
1250 return VINF_SUCCESS;
1251}
1252
1253
1254/**
1255 * Worker for supdrvOSMsrProberModify.
1256 */
1257static DECLCALLBACK(void) supdrvDarwinMsrProberModifyOnCpu(RTCPUID idCpu, void *pvUser1, void *pvUser2)
1258{
1259 PSUPMSRPROBER pReq = (PSUPMSRPROBER)pvUser1;
1260 register uint32_t uMsr = pReq->u.In.uMsr;
1261 bool const fFaster = pReq->u.In.enmOp == SUPMSRPROBEROP_MODIFY_FASTER;
1262 uint64_t uBefore;
1263 uint64_t uWritten;
1264 uint64_t uAfter;
1265 int rcBefore, rcWrite, rcAfter, rcRestore;
1266 RTCCUINTREG fOldFlags;
1267
1268 /* Initialize result variables. */
1269 uBefore = uWritten = uAfter = 0;
1270 rcWrite = rcAfter = rcRestore = -1;
1271
1272 /*
1273 * Do the job.
1274 */
1275 fOldFlags = ASMIntDisableFlags();
1276 ASMCompilerBarrier(); /* paranoia */
1277 if (!fFaster)
1278 ASMWriteBackAndInvalidateCaches();
1279
1280 rcBefore = g_pfnRdMsr64Carefully(uMsr, &uBefore);
1281 if (rcBefore >= 0)
1282 {
1283 register uint64_t uRestore = uBefore;
1284 uWritten = uRestore;
1285 uWritten &= pReq->u.In.uArgs.Modify.fAndMask;
1286 uWritten |= pReq->u.In.uArgs.Modify.fOrMask;
1287
1288 rcWrite = g_pfnWrMsr64Carefully(uMsr, uWritten);
1289 rcAfter = g_pfnRdMsr64Carefully(uMsr, &uAfter);
1290 rcRestore = g_pfnWrMsr64Carefully(uMsr, uRestore);
1291
1292 if (!fFaster)
1293 {
1294 ASMWriteBackAndInvalidateCaches();
1295 ASMReloadCR3();
1296 ASMNopPause();
1297 }
1298 }
1299
1300 ASMCompilerBarrier(); /* paranoia */
1301 ASMSetFlags(fOldFlags);
1302
1303 /*
1304 * Write out the results.
1305 */
1306 pReq->u.Out.uResults.Modify.uBefore = uBefore;
1307 pReq->u.Out.uResults.Modify.uWritten = uWritten;
1308 pReq->u.Out.uResults.Modify.uAfter = uAfter;
1309 pReq->u.Out.uResults.Modify.fBeforeGp = rcBefore != 0;
1310 pReq->u.Out.uResults.Modify.fModifyGp = rcWrite != 0;
1311 pReq->u.Out.uResults.Modify.fAfterGp = rcAfter != 0;
1312 pReq->u.Out.uResults.Modify.fRestoreGp = rcRestore != 0;
1313 RT_ZERO(pReq->u.Out.uResults.Modify.afReserved);
1314}
1315
1316
1317int VBOXCALL supdrvOSMsrProberModify(RTCPUID idCpu, PSUPMSRPROBER pReq)
1318{
1319 if (!g_pfnWrMsr64Carefully || !g_pfnRdMsr64Carefully)
1320 return VERR_NOT_SUPPORTED;
1321 if (idCpu == NIL_RTCPUID)
1322 {
1323 supdrvDarwinMsrProberModifyOnCpu(idCpu, pReq, NULL);
1324 return VINF_SUCCESS;
1325 }
1326 return RTMpOnSpecific(idCpu, supdrvDarwinMsrProberModifyOnCpu, pReq, NULL);
1327}
1328
1329#endif /* SUPDRV_WITH_MSR_PROBER */
1330
1331/**
1332 * Resume Bluetooth keyboard.
1333 * If there is no Bluetooth keyboard device connected to the system we just ignore this.
1334 */
1335static void supdrvDarwinResumeBluetoothKbd(void)
1336{
1337 OSDictionary *pDictionary = IOService::serviceMatching("AppleBluetoothHIDKeyboard");
1338 if (pDictionary)
1339 {
1340 OSIterator *pIter;
1341 IOBluetoothHIDDriver *pDriver;
1342
1343 pIter = IOService::getMatchingServices(pDictionary);
1344 if (pIter)
1345 {
1346 while ((pDriver = (IOBluetoothHIDDriver *)pIter->getNextObject()))
1347 if (pDriver->isKeyboard())
1348 (void)pDriver->hidControl(IOBTHID_CONTROL_EXIT_SUSPEND);
1349
1350 pIter->release();
1351 }
1352 pDictionary->release();
1353 }
1354}
1355
1356/**
1357 * Resume built-in keyboard on MacBook Air and Pro hosts.
1358 * If there is no built-in keyboard device attached to the system we just ignore this.
1359 */
1360static void supdrvDarwinResumeBuiltinKbd(void)
1361{
1362 /*
1363 * AppleUSBTCKeyboard KEXT is responsible for built-in keyboard management.
1364 * We resume keyboard by accessing to its IOService. */
1365 OSDictionary *pDictionary = IOService::serviceMatching("AppleUSBTCKeyboard");
1366 if (pDictionary)
1367 {
1368 OSIterator *pIter;
1369 IOUSBHIDDriver *pDriver;
1370
1371 pIter = IOService::getMatchingServices(pDictionary);
1372 if (pIter)
1373 {
1374 while ((pDriver = (IOUSBHIDDriver *)pIter->getNextObject()))
1375 if (pDriver->IsPortSuspended())
1376 pDriver->SuspendPort(false, 0);
1377
1378 pIter->release();
1379 }
1380 pDictionary->release();
1381 }
1382}
1383
1384
1385/**
1386 * Resume suspended keyboard devices (if any).
1387 */
1388int VBOXCALL supdrvDarwinResumeSuspendedKbds(void)
1389{
1390 supdrvDarwinResumeBuiltinKbd();
1391 supdrvDarwinResumeBluetoothKbd();
1392
1393 return 0;
1394}
1395
1396
1397/**
1398 * Converts an IPRT error code to a darwin error code.
1399 *
1400 * @returns corresponding darwin error code.
1401 * @param rc IPRT status code.
1402 */
1403static int VBoxDrvDarwinErr2DarwinErr(int rc)
1404{
1405 switch (rc)
1406 {
1407 case VINF_SUCCESS: return 0;
1408 case VERR_GENERAL_FAILURE: return EACCES;
1409 case VERR_INVALID_PARAMETER: return EINVAL;
1410 case VERR_INVALID_MAGIC: return EILSEQ;
1411 case VERR_INVALID_HANDLE: return ENXIO;
1412 case VERR_INVALID_POINTER: return EFAULT;
1413 case VERR_LOCK_FAILED: return ENOLCK;
1414 case VERR_ALREADY_LOADED: return EEXIST;
1415 case VERR_PERMISSION_DENIED: return EPERM;
1416 case VERR_VERSION_MISMATCH: return ENOSYS;
1417 }
1418
1419 return EPERM;
1420}
1421
1422
1423/**
1424 * Check if the CPU has SMAP support.
1425 */
1426static bool vboxdrvDarwinCpuHasSMAP(void)
1427{
1428 uint32_t uMaxId, uEAX, uEBX, uECX, uEDX;
1429 ASMCpuId(0, &uMaxId, &uEBX, &uECX, &uEDX);
1430 if ( ASMIsValidStdRange(uMaxId)
1431 && uMaxId >= 0x00000007)
1432 {
1433 ASMCpuId_Idx_ECX(0x00000007, 0, &uEAX, &uEBX, &uECX, &uEDX);
1434 if (uEBX & X86_CPUID_STEXT_FEATURE_EBX_SMAP)
1435 return true;
1436 }
1437#ifdef VBOX_WITH_EFLAGS_AC_SET_IN_VBOXDRV
1438 return true;
1439#else
1440 return false;
1441#endif
1442}
1443
1444
1445RTDECL(int) SUPR0Printf(const char *pszFormat, ...)
1446{
1447 IPRT_DARWIN_SAVE_EFL_AC();
1448 va_list va;
1449 char szMsg[512];
1450
1451 va_start(va, pszFormat);
1452 RTStrPrintfV(szMsg, sizeof(szMsg) - 1, pszFormat, va);
1453 va_end(va);
1454 szMsg[sizeof(szMsg) - 1] = '\0';
1455
1456 printf("%s", szMsg);
1457
1458 IPRT_DARWIN_RESTORE_EFL_AC();
1459 return 0;
1460}
1461
1462
1463SUPR0DECL(uint32_t) SUPR0GetKernelFeatures(void)
1464{
1465 uint32_t fFlags = 0;
1466 if (g_DevCW.d_ioctl == VBoxDrvDarwinIOCtlSMAP)
1467 fFlags |= SUPKERNELFEATURES_SMAP;
1468 else
1469 Assert(!(ASMGetCR4() & X86_CR4_SMAP));
1470 return fFlags;
1471}
1472
1473
1474/*
1475 *
1476 * org_virtualbox_SupDrv
1477 *
1478 */
1479
1480
1481/**
1482 * Initialize the object.
1483 */
1484bool org_virtualbox_SupDrv::init(OSDictionary *pDictionary)
1485{
1486 LogFlow(("org_virtualbox_SupDrv::init([%p], %p)\n", this, pDictionary));
1487 if (IOService::init(pDictionary))
1488 {
1489 /* init members. */
1490 return true;
1491 }
1492 return false;
1493}
1494
1495
1496/**
1497 * Free the object.
1498 */
1499void org_virtualbox_SupDrv::free(void)
1500{
1501 LogFlow(("IOService::free([%p])\n", this));
1502 IOService::free();
1503}
1504
1505
1506/**
1507 * Check if it's ok to start this service.
1508 * It's always ok by us, so it's up to IOService to decide really.
1509 */
1510IOService *org_virtualbox_SupDrv::probe(IOService *pProvider, SInt32 *pi32Score)
1511{
1512 LogFlow(("org_virtualbox_SupDrv::probe([%p])\n", this));
1513 return IOService::probe(pProvider, pi32Score);
1514}
1515
1516
1517/**
1518 * Start this service.
1519 */
1520bool org_virtualbox_SupDrv::start(IOService *pProvider)
1521{
1522 LogFlow(("org_virtualbox_SupDrv::start([%p])\n", this));
1523
1524 if (IOService::start(pProvider))
1525 {
1526 /* register the service. */
1527 registerService();
1528 return true;
1529 }
1530 return false;
1531}
1532
1533
1534/**
1535 * Stop this service.
1536 */
1537void org_virtualbox_SupDrv::stop(IOService *pProvider)
1538{
1539 LogFlow(("org_virtualbox_SupDrv::stop([%p], %p)\n", this, pProvider));
1540 IOService::stop(pProvider);
1541}
1542
1543
1544/**
1545 * Termination request.
1546 *
1547 * @return true if we're ok with shutting down now, false if we're not.
1548 * @param fOptions Flags.
1549 */
1550bool org_virtualbox_SupDrv::terminate(IOOptionBits fOptions)
1551{
1552 bool fRc;
1553 LogFlow(("org_virtualbox_SupDrv::terminate: reference_count=%d g_cSessions=%d (fOptions=%#x)\n",
1554 KMOD_INFO_NAME.reference_count, ASMAtomicUoReadS32(&g_cSessions), fOptions));
1555 if ( KMOD_INFO_NAME.reference_count != 0
1556 || ASMAtomicUoReadS32(&g_cSessions))
1557 fRc = false;
1558 else
1559 fRc = IOService::terminate(fOptions);
1560 LogFlow(("org_virtualbox_SupDrv::terminate: returns %d\n", fRc));
1561 return fRc;
1562}
1563
1564
1565/*
1566 *
1567 * org_virtualbox_SupDrvClient
1568 *
1569 */
1570
1571
1572/**
1573 * Initializer called when the client opens the service.
1574 */
1575bool org_virtualbox_SupDrvClient::initWithTask(task_t OwningTask, void *pvSecurityId, UInt32 u32Type)
1576{
1577 LogFlow(("org_virtualbox_SupDrvClient::initWithTask([%p], %#x, %p, %#x) (cur pid=%d proc=%p)\n",
1578 this, OwningTask, pvSecurityId, u32Type, RTProcSelf(), RTR0ProcHandleSelf()));
1579 AssertMsg((RTR0PROCESS)OwningTask == RTR0ProcHandleSelf(), ("%p %p\n", OwningTask, RTR0ProcHandleSelf()));
1580
1581 if (!OwningTask)
1582 return false;
1583
1584 VBOX_RETRIEVE_CUR_PROC_NAME(pszProcName);
1585
1586 if (u32Type != SUP_DARWIN_IOSERVICE_COOKIE)
1587 {
1588 LogRel(("org_virtualbox_SupDrvClient::initWithTask: Bad cookie %#x (%s)\n", u32Type, pszProcName));
1589 return false;
1590 }
1591 else
1592 LogRel(("org_virtualbox_SupDrvClient::initWithTask: Expected cookie %#x (%s)\n", u32Type, pszProcName));
1593
1594 if (IOUserClient::initWithTask(OwningTask, pvSecurityId , u32Type))
1595 {
1596 m_Task = OwningTask;
1597 m_pSession = NULL;
1598 m_pProvider = NULL;
1599 return true;
1600 }
1601 return false;
1602}
1603
1604
1605/**
1606 * Start the client service.
1607 */
1608bool org_virtualbox_SupDrvClient::start(IOService *pProvider)
1609{
1610 LogFlow(("org_virtualbox_SupDrvClient::start([%p], %p) (cur pid=%d proc=%p)\n",
1611 this, pProvider, RTProcSelf(), RTR0ProcHandleSelf() ));
1612 AssertMsgReturn((RTR0PROCESS)m_Task == RTR0ProcHandleSelf(),
1613 ("%p %p\n", m_Task, RTR0ProcHandleSelf()),
1614 false);
1615
1616 if (IOUserClient::start(pProvider))
1617 {
1618 m_pProvider = OSDynamicCast(org_virtualbox_SupDrv, pProvider);
1619 if (m_pProvider)
1620 {
1621 Assert(!m_pSession);
1622
1623 /*
1624 * Create a new session.
1625 */
1626 int rc = supdrvCreateSession(&g_DevExt, true /* fUser */, false /*fUnrestricted*/, &m_pSession);
1627 if (RT_SUCCESS(rc))
1628 {
1629 m_pSession->fOpened = false;
1630 /* The Uid, Gid and fUnrestricted fields are set on open. */
1631
1632 /*
1633 * Insert it into the hash table, checking that there isn't
1634 * already one for this process first. (One session per proc!)
1635 */
1636 unsigned iHash = SESSION_HASH(m_pSession->Process);
1637 RTSpinlockAcquire(g_Spinlock);
1638
1639 PSUPDRVSESSION pCur = g_apSessionHashTab[iHash];
1640 while (pCur && pCur->Process != m_pSession->Process)
1641 pCur = pCur->pNextHash;
1642 if (!pCur)
1643 {
1644 m_pSession->pNextHash = g_apSessionHashTab[iHash];
1645 g_apSessionHashTab[iHash] = m_pSession;
1646 m_pSession->pvSupDrvClient = this;
1647 ASMAtomicIncS32(&g_cSessions);
1648 rc = VINF_SUCCESS;
1649 }
1650 else
1651 rc = VERR_ALREADY_LOADED;
1652
1653 RTSpinlockRelease(g_Spinlock);
1654 if (RT_SUCCESS(rc))
1655 {
1656 Log(("org_virtualbox_SupDrvClient::start: created session %p for pid %d\n", m_pSession, (int)RTProcSelf()));
1657 return true;
1658 }
1659
1660 LogFlow(("org_virtualbox_SupDrvClient::start: already got a session for this process (%p)\n", pCur));
1661 supdrvSessionRelease(m_pSession);
1662 }
1663
1664 m_pSession = NULL;
1665 LogFlow(("org_virtualbox_SupDrvClient::start: rc=%Rrc from supdrvCreateSession\n", rc));
1666 }
1667 else
1668 LogFlow(("org_virtualbox_SupDrvClient::start: %p isn't org_virtualbox_SupDrv\n", pProvider));
1669 }
1670 return false;
1671}
1672
1673
1674/**
1675 * Common worker for clientClose and VBoxDrvDarwinClose.
1676 */
1677/* static */ void org_virtualbox_SupDrvClient::sessionClose(RTPROCESS Process)
1678{
1679 /*
1680 * Find the session and remove it from the hash table.
1681 *
1682 * Note! Only one session per process. (Both start() and
1683 * VBoxDrvDarwinOpen makes sure this is so.)
1684 */
1685 const unsigned iHash = SESSION_HASH(Process);
1686 RTSpinlockAcquire(g_Spinlock);
1687 PSUPDRVSESSION pSession = g_apSessionHashTab[iHash];
1688 if (pSession)
1689 {
1690 if (pSession->Process == Process)
1691 {
1692 g_apSessionHashTab[iHash] = pSession->pNextHash;
1693 pSession->pNextHash = NULL;
1694 ASMAtomicDecS32(&g_cSessions);
1695 }
1696 else
1697 {
1698 PSUPDRVSESSION pPrev = pSession;
1699 pSession = pSession->pNextHash;
1700 while (pSession)
1701 {
1702 if (pSession->Process == Process)
1703 {
1704 pPrev->pNextHash = pSession->pNextHash;
1705 pSession->pNextHash = NULL;
1706 ASMAtomicDecS32(&g_cSessions);
1707 break;
1708 }
1709
1710 /* next */
1711 pPrev = pSession;
1712 pSession = pSession->pNextHash;
1713 }
1714 }
1715 }
1716 RTSpinlockRelease(g_Spinlock);
1717 if (!pSession)
1718 {
1719 Log(("SupDrvClient::sessionClose: pSession == NULL, pid=%d; freed already?\n", (int)Process));
1720 return;
1721 }
1722
1723 /*
1724 * Remove it from the client object.
1725 */
1726 org_virtualbox_SupDrvClient *pThis = (org_virtualbox_SupDrvClient *)pSession->pvSupDrvClient;
1727 pSession->pvSupDrvClient = NULL;
1728 if (pThis)
1729 {
1730 Assert(pThis->m_pSession == pSession);
1731 pThis->m_pSession = NULL;
1732 }
1733
1734 /*
1735 * Close the session.
1736 */
1737 supdrvSessionRelease(pSession);
1738}
1739
1740
1741/**
1742 * Client exits normally.
1743 */
1744IOReturn org_virtualbox_SupDrvClient::clientClose(void)
1745{
1746 LogFlow(("org_virtualbox_SupDrvClient::clientClose([%p]) (cur pid=%d proc=%p)\n", this, RTProcSelf(), RTR0ProcHandleSelf()));
1747 AssertMsg((RTR0PROCESS)m_Task == RTR0ProcHandleSelf(), ("%p %p\n", m_Task, RTR0ProcHandleSelf()));
1748
1749 /*
1750 * Clean up the session if it's still around.
1751 *
1752 * We cannot rely 100% on close, and in the case of a dead client
1753 * we'll end up hanging inside vm_map_remove() if we postpone it.
1754 */
1755 if (m_pSession)
1756 {
1757 sessionClose(RTProcSelf());
1758 Assert(!m_pSession);
1759 }
1760
1761 m_pProvider = NULL;
1762 terminate();
1763
1764 return kIOReturnSuccess;
1765}
1766
1767
1768/**
1769 * The client exits abnormally / forgets to do cleanups. (logging)
1770 */
1771IOReturn org_virtualbox_SupDrvClient::clientDied(void)
1772{
1773 LogFlow(("org_virtualbox_SupDrvClient::clientDied([%p]) m_Task=%p R0Process=%p Process=%d\n",
1774 this, m_Task, RTR0ProcHandleSelf(), RTProcSelf()));
1775
1776 /* IOUserClient::clientDied() calls clientClose, so we'll just do the work there. */
1777 return IOUserClient::clientDied();
1778}
1779
1780
1781/**
1782 * Terminate the service (initiate the destruction). (logging)
1783 */
1784bool org_virtualbox_SupDrvClient::terminate(IOOptionBits fOptions)
1785{
1786 LogFlow(("org_virtualbox_SupDrvClient::terminate([%p], %#x)\n", this, fOptions));
1787 return IOUserClient::terminate(fOptions);
1788}
1789
1790
1791/**
1792 * The final stage of the client service destruction. (logging)
1793 */
1794bool org_virtualbox_SupDrvClient::finalize(IOOptionBits fOptions)
1795{
1796 LogFlow(("org_virtualbox_SupDrvClient::finalize([%p], %#x)\n", this, fOptions));
1797 return IOUserClient::finalize(fOptions);
1798}
1799
1800
1801/**
1802 * Stop the client service. (logging)
1803 */
1804void org_virtualbox_SupDrvClient::stop(IOService *pProvider)
1805{
1806 LogFlow(("org_virtualbox_SupDrvClient::stop([%p])\n", this));
1807 IOUserClient::stop(pProvider);
1808}
1809
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