- Timestamp:
- Jan 27, 2007 8:09:16 PM (18 years ago)
- Location:
- trunk/src/VBox/HostDrivers/Support
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/Support/Makefile
r378 r387 56 56 include/iprt/mem.h=$(PATH_ROOT)/include/iprt/mem.h \ 57 57 include/iprt/param.h=$(PATH_ROOT)/include/iprt/param.h \ 58 include/iprt/process.h=$(PATH_ROOT)/include/iprt/process.h \ 58 59 include/iprt/semaphore.h=$(PATH_ROOT)/include/iprt/semaphore.h \ 59 60 include/iprt/spinlock.h=$(PATH_ROOT)/include/iprt/spinlock.h \ -
trunk/src/VBox/HostDrivers/Support/SUPDRV.h
r378 r387 543 543 /** The process (id) of the session. (Set by the OS part.) */ 544 544 RTPROCESS Process; 545 /** Which process this session is associated with. */ 546 RTR0PROCESS R0Process; 545 547 #if defined(__DARWIN__) || defined(__OS2__) 546 548 /** Pointer to the next session with the same has. */ 547 549 PSUPDRVSESSION pNextHash; 548 #endif549 #if defined(__DARWIN__)550 /** Pointer to the org_virtualbox_SupDrvClient client that's associated with the session. */551 void *pvClient;552 550 #endif 553 551 } SUPDRVSESSION; … … 669 667 int VBOXCALL supdrvCreateSession(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION *ppSession); 670 668 void VBOXCALL supdrvCloseSession(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession); 669 void VBOXCALL supdrvCleanupSession(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession); 671 670 int VBOXCALL supdrvGipInit(PSUPDRVDEVEXT pDevExt, PSUPGLOBALINFOPAGE pGip, RTHCPHYS HCPhys, uint64_t u64NanoTS, unsigned uUpdateHz); 672 671 void VBOXCALL supdrvGipTerm(PSUPGLOBALINFOPAGE pGip); -
trunk/src/VBox/HostDrivers/Support/SUPDRVShared.c
r378 r387 327 327 void VBOXCALL supdrvCloseSession(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession) 328 328 { 329 /* 330 * Cleanup the session first. 331 */ 332 supdrvCleanupSession(pDevExt, pSession); 333 334 /* 335 * Free the rest of the session stuff. 336 */ 337 RTSpinlockDestroy(pSession->Spinlock); 338 pSession->Spinlock = NIL_RTSPINLOCK; 339 pSession->pDevExt = NULL; 340 RTMemFree(pSession); 341 dprintf2(("supdrvCloseSession: returns\n")); 342 } 343 344 345 /** 346 * Shared code for cleaning up a session (but not quite freeing it). 347 * 348 * This is primarily intended for MAC OS X where we have to clean up the memory 349 * stuff before the file handle is closed. 350 * 351 * @param pDevExt Device extension. 352 * @param pSession Session data. 353 * This data will be freed by this routine. 354 */ 355 void VBOXCALL supdrvCleanupSession(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession) 356 { 329 357 PSUPDRVBUNDLE pBundle; 330 dprintf(("supdrvCl oseSession: pSession=%p\n", pSession));358 dprintf(("supdrvCleanupSession: pSession=%p\n", pSession)); 331 359 332 360 /* … … 429 457 AssertRC(rc); /** @todo figure out how to handle this. */ 430 458 pBundle->aMem[i].MemObj = NIL_RTR0MEMOBJ; 459 pBundle->aMem[i].eType = MEMREF_TYPE_UNUSED; 431 460 } 432 461 … … 454 483 break; 455 484 } 485 pBundle->aMem[i].eType = MEMREF_TYPE_UNUSED; 456 486 } 457 487 #endif /* !USE_NEW_OS_INTERFACE */ … … 472 502 473 503 /* 474 * Loaded images needs to be dereferenced and possibly freed .504 * Loaded images needs to be dereferenced and possibly freed up. 475 505 */ 476 506 RTSemFastMutexRequest(pDevExt->mtxLdr); … … 513 543 } 514 544 dprintf2(("umapping GIP - done\n")); 515 516 /*517 * Free the rest of the session stuff.518 */519 RTSpinlockDestroy(pSession->Spinlock);520 pSession->Spinlock = NIL_RTSPINLOCK;521 pSession->pDevExt = NULL;522 RTMemFree(pSession);523 dprintf2(("supdrvCloseSession: returns\n"));524 545 } 525 546 -
trunk/src/VBox/HostDrivers/Support/darwin/SUPDrv-darwin.cpp
r378 r387 37 37 #include <iprt/spinlock.h> 38 38 #include <iprt/semaphore.h> 39 #include <iprt/process.h> 39 40 #include <iprt/alloc.h> 40 41 … … 114 115 virtual bool initWithTask(task_t OwningTask, void *pvSecurityId, UInt32 u32Type); 115 116 virtual bool start(IOService *pProvider); 116 virtual void stop(IOService *pProvider);117 117 virtual IOReturn clientClose(void); 118 118 virtual IOReturn clientDied(void); 119 119 virtual bool terminate(IOOptionBits fOptions = 0); 120 120 virtual bool finalize(IOOptionBits fOptions); 121 virtual void stop(IOService *pProvider); 121 122 }; 122 123 … … 313 314 pSession->Gid = pCred->cr_gid; 314 315 } 315 pSession->Process = proc_pid(pProcess); 316 pSession->Process = RTProcSelf(); 317 pSession->R0Process = RTR0ProcHandleSelf(); 316 318 317 319 /* … … 768 770 IOReturn org_virtualbox_SupDrvClient::clientDied(void) 769 771 { 770 dprintf(("org_virtualbox_SupDrvClient::clientDied([%p])\n", this)); 771 772 /* IOUserClient::clientDied() only calls calls close... */ 772 dprintf(("org_virtualbox_SupDrvClient::clientDied([%p]) m_Task=%p R0Process=%p Process=%d\n", 773 this, m_Task, RTR0ProcHandleSelf(), RTProcSelf())); 774 775 /* 776 * Do early session cleanup (if there is a session) so 777 * we avoid hanging in vm_map_remove(). 778 */ 779 const RTR0PROCESS R0Process = (RTR0PROCESS)m_Task; 780 RTSPINLOCKTMP Tmp = RTSPINLOCKTMP_INITIALIZER; 781 RTSpinlockAcquireNoInts(g_Spinlock, &Tmp); 782 for (unsigned i = 0; i < RT_ELEMENTS(g_apSessionHashTab); i++) 783 { 784 for (PSUPDRVSESSION pSession = g_apSessionHashTab[i]; pSession; pSession = pSession->pNextHash) 785 { 786 dprintf2(("pSession=%p R0Process=%p (=? %p)\n", pSession, pSession->R0Process, R0Process)); 787 if (pSession->R0Process == R0Process) 788 { 789 /* 790 * It is safe to leave the spinlock here; the session shouldn't be able 791 * to go away while we're cleaning it up, changes to pNextHash will not 792 * harm us, and new sessions can't possibly be added for this process. 793 */ 794 RTSpinlockReleaseNoInts(g_Spinlock, &Tmp); 795 supdrvCleanupSession(&g_DevExt, pSession); 796 RTSpinlockAcquireNoInts(g_Spinlock, &Tmp); 797 } 798 } 799 } 800 RTSpinlockReleaseNoInts(g_Spinlock, &Tmp); 801 802 /* IOUserClient::clientDied() calls close... */ 773 803 return IOUserClient::clientDied(); 804 } 805 806 807 /** 808 * Terminate the service (initiate the destruction). 809 */ 810 bool org_virtualbox_SupDrvClient::terminate(IOOptionBits fOptions) 811 { 812 dprintf(("org_virtualbox_SupDrvClient::terminate([%p], %#x)\n", this, fOptions)); 813 return IOUserClient::terminate(fOptions); 814 } 815 816 817 /** 818 * The final stage of the client service destruction. 819 */ 820 bool org_virtualbox_SupDrvClient::finalize(IOOptionBits fOptions) 821 { 822 dprintf(("org_virtualbox_SupDrvClient::finalize([%p], %#x)\n", this, fOptions)); 823 return IOUserClient::finalize(fOptions); 774 824 } 775 825 … … 784 834 } 785 835 786 787 /**788 * Terminate the service (initiate the destruction).789 */790 bool org_virtualbox_SupDrvClient::terminate(IOOptionBits fOptions)791 {792 dprintf(("org_virtualbox_SupDrvClient::terminate([%p], %#x)\n", this, fOptions));793 return IOUserClient::terminate(fOptions);794 }795 796 797 /**798 * The final stage of the client service destruction.799 */800 bool org_virtualbox_SupDrvClient::finalize(IOOptionBits fOptions)801 {802 dprintf(("org_virtualbox_SupDrvClient::finalize([%p], %#x)\n", this, fOptions));803 return IOUserClient::finalize(fOptions);804 }805 -
trunk/src/VBox/HostDrivers/Support/darwin/SUPLib-darwin.cpp
r1 r387 25 25 * Header Files * 26 26 *******************************************************************************/ 27 #define LOG_GROUP LOG_GROUP_SUP 27 28 #include <VBox/types.h> 28 29 #include <VBox/sup.h> 29 30 #include <VBox/param.h> 30 31 #include <VBox/err.h> 32 #include <VBox/log.h> 31 33 #include <iprt/path.h> 32 34 #include <iprt/assert.h> … … 41 43 #include <unistd.h> 42 44 #include <stdlib.h> 45 #include <mach/mach_port.h> 46 #include <IOKit/IOKitLib.h> 43 47 44 48 … … 48 52 /** BSD Device name. */ 49 53 #define DEVICE_NAME "/dev/vboxdrv" 54 /** The IOClass key of the service (see SUPDrv-darwin.cpp / Info.plist). */ 55 #define IOCLASS_NAME "org_virtualbox_SupDrv" 50 56 51 57 … … 54 60 *******************************************************************************/ 55 61 /** Handle to the open device. */ 56 static int g_hDevice = -1; 62 static int g_hDevice = -1; 63 /** The IOMasterPort. */ 64 static mach_port_t g_MasterPort = 0; 65 /** The current service connection. */ 66 static io_connect_t g_Connection = NULL; 57 67 58 68 … … 66 76 67 77 /* 68 * Try open the device. 78 * Open the IOKit client first - The first step is finding the service. 79 */ 80 mach_port_t MasterPort; 81 kern_return_t kr = IOMasterPort(MACH_PORT_NULL, &MasterPort); 82 if (kr != kIOReturnSuccess) 83 { 84 LogRel(("IOMasterPort -> %d\n", kr)); 85 return VERR_GENERAL_FAILURE; 86 } 87 88 CFDictionaryRef ClassToMatch = IOServiceMatching(IOCLASS_NAME); 89 if (!ClassToMatch) 90 { 91 LogRel(("IOServiceMatching(\"%s\") failed.\n", IOCLASS_NAME)); 92 return VERR_GENERAL_FAILURE; 93 } 94 95 /* Create an io_iterator_t for all instances of our drivers class that exist in the IORegistry. */ 96 io_iterator_t Iterator; 97 kr = IOServiceGetMatchingServices(g_MasterPort, ClassToMatch, &Iterator); 98 if (kr != kIOReturnSuccess) 99 { 100 LogRel(("IOServiceGetMatchingServices returned %d\n", kr)); 101 return VERR_GENERAL_FAILURE; 102 } 103 104 /* Get the first item in the iterator and release it. */ 105 io_service_t ServiceObject = IOIteratorNext(Iterator); 106 IOObjectRelease(Iterator); 107 if (!ServiceObject) 108 { 109 LogRel(("Couldn't find any matches.\n")); 110 return VERR_GENERAL_FAILURE; 111 } 112 113 /* 114 * Open the service. 115 * This will cause the user client class in SUPDrv-darwin.cpp to be instantiated. 116 */ 117 kr = IOServiceOpen(ServiceObject, mach_task_self(), 0, &g_Connection); 118 IOObjectRelease(ServiceObject); 119 if (kr != kIOReturnSuccess) 120 { 121 LogRel(("IOServiceOpen returned %d\n", kr)); 122 return VERR_GENERAL_FAILURE; 123 } 124 125 /* 126 * Now, try open the BSD device. 69 127 */ 70 128 g_hDevice = open(DEVICE_NAME, O_RDWR, 0); 71 129 if (g_hDevice < 0) 72 130 { 73 /* 74 * Try load the device. 75 */ 76 //todo suplibOsLoadKernelModule(); 77 g_hDevice = open(DEVICE_NAME, O_RDWR, 0); 78 if (g_hDevice < 0) 79 return RTErrConvertFromErrno(errno); 131 int rc = errno; 132 LogRel(("Failed to open \"%s\", errno=%d\n", rc)); 133 kr = IOServiceClose(g_Connection); 134 if (kr != kIOReturnSuccess) 135 LogRel(("Warning: IOServiceClose(%p) returned %d\n", g_Connection, kr)); 136 return RTErrConvertFromErrno(rc); 80 137 } 81 138 … … 98 155 AssertFailed(); 99 156 g_hDevice = -1; 157 } 158 159 /* 160 * Close the connection to the IOService and destroy the connection handle. 161 */ 162 if (g_Connection) 163 { 164 kern_return_t kr = IOServiceClose(g_Connection); 165 if (kr != kIOReturnSuccess) 166 { 167 LogRel(("Warning: IOServiceClose(%p) returned %d\n", g_Connection, kr)); 168 AssertFailed(); 169 } 170 g_Connection = NULL; 100 171 } 101 172 -
trunk/src/VBox/HostDrivers/Support/linux/SUPDrv-linux.c
r331 r387 27 27 #include <iprt/semaphore.h> 28 28 #include <iprt/initterm.h> 29 #include <iprt/process.h> 29 30 #include <iprt/err.h> 30 31 #include <iprt/mem.h> … … 221 222 222 223 #ifdef __AMD64__ 223 /** 224 /** 224 225 * Memory for the executable memory heap (in IPRT). 225 226 */ … … 233 234 ".size g_abExecMemory, 1572864\n\t" 234 235 ".text\n\t"); 235 #endif 236 #endif 236 237 237 238 … … 363 364 nmi_activated: 364 365 # endif 365 printk(KERN_ERR DEVICE_NAME 366 printk(KERN_ERR DEVICE_NAME 366 367 ": NMI watchdog active -- refused to load the kernel module! Please disable\n" 367 DEVICE_NAME 368 DEVICE_NAME 368 369 ": the NMI watchdog by specifying 'nmi_watchdog=0' at kernel command line.\n"); 369 370 return -EINVAL; … … 534 535 pSession->Uid = current->euid; 535 536 pSession->Gid = current->egid; 536 pSession->Process = (RTPROCESS)current->tgid; 537 pSession->Process = RTProcSelf(); 538 pSession->R0Process = RTR0ProcHandleSelf(); 537 539 } 538 540 -
trunk/src/VBox/HostDrivers/Support/win32/SUPDrv-win32.cpp
r1 r387 223 223 pSession->Uid = NIL_RTUID; 224 224 pSession->Gid = NIL_RTGID; 225 pSession->Process = NIL_RTPROCESS; 225 pSession->Process = RTProcSelf(); 226 pSession->R0Process = RTR0ProcHandleSelf(); 226 227 pFileObj->FsContext = pSession; 227 228 }
Note:
See TracChangeset
for help on using the changeset viewer.