- Timestamp:
- Jan 27, 2007 3:54:16 AM (18 years ago)
- Location:
- trunk/src/VBox/HostDrivers/Support
- Files:
-
- 3 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/Support/Makefile
r331 r378 182 182 VBoxDrv_DEFS = IN_RT_R0 IN_SUP_R0 USE_NEW_OS_INTERFACE 183 183 VBoxDrv_INCS = $(VBOX_PATH_SUPPORT) 184 VBoxDrv_LIBS = $(PATH_LIB)/RuntimeR0Drv$(VBOX_SUFF_LIB) $(VBOX_GCC_LIBGCC)184 VBoxDrv_LIBS = $(PATH_LIB)/RuntimeR0Drv$(VBOX_SUFF_LIB) 185 185 VBoxDrv_LDFLAGS = -v -Wl,-whyload -Wl,-v -Wl,-whatsloaded 186 186 VBoxDrv_INST = bin/VBoxDrv.kext/Contents/MacOS/ 187 187 VBoxDrv_SOURCES = \ 188 188 $(VBOX_PATH_SUPPORT)/SUPDRVShared.c \ 189 $(VBOX_PATH_SUPPORT)/$(BUILD_TARGET)/SUPDrv-$(BUILD_TARGET).c 189 $(VBOX_PATH_SUPPORT)/$(BUILD_TARGET)/SUPDrv-$(BUILD_TARGET).cpp 190 190 191 191 INSTALLS += VBoxDrv.kext -
trunk/src/VBox/HostDrivers/Support/SUPDRV.h
r1 r378 171 171 172 172 /* dprintf2 - extended logging. */ 173 #if 0173 #if defined(__DARWIN__) 174 174 # define dprintf2 dprintf 175 175 #else … … 547 547 PSUPDRVSESSION pNextHash; 548 548 #endif 549 #if defined(__DARWIN__) 550 /** Pointer to the org_virtualbox_SupDrvClient client that's associated with the session. */ 551 void *pvClient; 552 #endif 549 553 } SUPDRVSESSION; 550 554 -
trunk/src/VBox/HostDrivers/Support/SUPDRVShared.c
r220 r378 1821 1821 *ppvR0 = RTR0MemObjAddress(Mem.MemObj); 1822 1822 *ppvR3 = RTR0MemObjAddress(Mem.MapObjR3); 1823 *pHCPhys = RTR0MemObjGetPagePhysAddr(Mem.MemObj, 0); 1823 1824 return 0; 1824 1825 } 1826 1825 1827 rc2 = RTR0MemObjFree(Mem.MapObjR3, false); 1826 1828 AssertRC(rc2); … … 1931 1933 return 0; 1932 1934 } 1935 1933 1936 rc2 = RTR0MemObjFree(Mem.MapObjR3, false); 1934 1937 AssertRC(rc2); -
trunk/src/VBox/HostDrivers/Support/darwin/SUPDrv-darwin.cpp
r219 r378 28 28 #include <sys/param.h> 29 29 #undef PVM 30 #include <IOKit/IOLib.h> /* Assert as function */ 30 31 31 32 #include "SUPDRV.h" 33 #include <VBox/version.h> 32 34 #include <iprt/types.h> 33 35 #include <iprt/initterm.h> … … 35 37 #include <iprt/spinlock.h> 36 38 #include <iprt/semaphore.h> 39 #include <iprt/alloc.h> 37 40 38 41 #include <mach/kmod.h> … … 43 46 #include <sys/malloc.h> 44 47 #include <sys/proc.h> 48 #include <IOKit/IOService.h> 49 #include <IOKit/IOUserclient.h> 45 50 46 51 … … 57 62 * Internal Functions * 58 63 *******************************************************************************/ 64 __BEGIN_DECLS 59 65 static kern_return_t VBoxSupDrvStart(struct kmod_info *pKModInfo, void *pvData); 60 66 static kern_return_t VBoxSupDrvStop(struct kmod_info *pKModInfo, void *pvData); … … 66 72 67 73 static int VBoxSupDrvErr2DarwinErr(int rc); 74 __END_DECLS 75 76 77 /******************************************************************************* 78 * Structures and Typedefs * 79 *******************************************************************************/ 80 /** 81 * The service class. 82 * This is just a formality really. 83 */ 84 class org_virtualbox_SupDrv : public IOService 85 { 86 OSDeclareDefaultStructors(org_virtualbox_SupDrv) 87 88 public: 89 virtual bool init(OSDictionary *pDictionary = 0); 90 virtual void free(void); 91 virtual bool start(IOService *pProvider); 92 virtual void stop(IOService *pProvider); 93 virtual IOService *probe(IOService *pProvider, SInt32 *pi32Score); 94 }; 95 96 OSDefineMetaClassAndStructors(org_virtualbox_SupDrv, IOService) 97 98 99 /** 100 * An attempt at getting that clientDied() notification. 101 * I don't think it'll work as I cannot figure out where/what creates the correct 102 * port right. 103 */ 104 class org_virtualbox_SupDrvClient : public IOUserClient 105 { 106 OSDeclareDefaultStructors(org_virtualbox_SupDrvClient) 107 108 private: 109 PSUPDRVSESSION m_pSession; /**< The session. */ 110 task_t m_Task; /**< The client task. */ 111 org_virtualbox_SupDrv *m_pProvider; /**< The service provider. */ 112 113 public: 114 virtual bool initWithTask(task_t OwningTask, void *pvSecurityId, UInt32 u32Type); 115 virtual bool start(IOService *pProvider); 116 virtual void stop(IOService *pProvider); 117 virtual IOReturn clientClose(void); 118 virtual IOReturn clientDied(void); 119 virtual bool terminate(IOOptionBits fOptions = 0); 120 virtual bool finalize(IOOptionBits fOptions); 121 }; 122 123 OSDefineMetaClassAndStructors(org_virtualbox_SupDrvClient, IOUserClient) 124 68 125 69 126 … … 74 131 * Declare the module stuff. 75 132 */ 76 KMOD_EXPLICIT_DECL(vboxdrv, "1.0", VBoxSupDrvStart, VBoxSupDrvStop) 133 __BEGIN_DECLS 134 extern kern_return_t _start(struct kmod_info *pKModInfo, void *pvData); 135 extern kern_return_t _stop(struct kmod_info *pKModInfo, void *pvData); 136 __private_extern__ kmod_start_func_t *_realmain; 137 __private_extern__ kmod_stop_func_t *_antimain; 138 __private_extern__ int _kext_apple_cc; 139 140 KMOD_EXPLICIT_DECL(VBoxDrv, VBOX_VERSION_STRING, _start, _stop) 141 kmod_start_func_t *_realmain = VBoxSupDrvStart; 142 kmod_stop_func_t *_antimain = VBoxSupDrvStop; 143 int _kext_apple_cc = __APPLE_CC__; 144 __END_DECLS 145 77 146 78 147 /** … … 86 155 static struct cdevsw g_DevCW = 87 156 { 88 .d_open = VBoxSupDrvOpen, 89 .d_close = VBoxSupDrvClose, 90 .d_read = eno_rdwrt, 91 .d_write = eno_rdwrt, 92 .d_ioctl = VBoxSupDrvIOCtl, 93 .d_stop = eno_stop, 94 .d_reset = eno_reset, 95 .d_ttys = NULL, 96 .d_select = eno_select, 97 .d_mmap = eno_mmap, 98 .d_strategy = eno_strat, 99 .d_getc = eno_getc, 100 .d_putc = eno_putc, 101 .d_type = 0 157 /** @todo g++ doesn't like this syntax - it worked with gcc before renaming to .cpp. */ 158 /*.d_open = */VBoxSupDrvOpen, 159 /*.d_close = */VBoxSupDrvClose, 160 /*.d_read = */eno_rdwrt, 161 /*.d_write = */eno_rdwrt, 162 /*.d_ioctl = */VBoxSupDrvIOCtl, 163 /*.d_stop = */eno_stop, 164 /*.d_reset = */eno_reset, 165 /*.d_ttys = */NULL, 166 /*.d_select= */eno_select, 167 /*.d_mmap = */eno_mmap, 168 /*.d_strategy = */eno_strat, 169 /*.d_getc = */eno_getc, 170 /*.d_putc = */eno_putc, 171 /*.d_type = */0 102 172 }; 103 173 104 174 /** Major device number. */ 105 static int 175 static int g_iMajorDeviceNo = -1; 106 176 /** Registered devfs device handle. */ 107 177 static void *g_hDevFsDevice = NULL; … … 380 450 void *pvPageBuf = NULL; 381 451 void *pvBuf = NULL; 382 intcbBuf = 0;452 unsigned long cbBuf = 0; 383 453 unsigned cbOut = 0; 384 454 PSUPDRVIOCTLDATA pArgs = (PSUPDRVIOCTLDATA)pData; … … 400 470 { 401 471 cbBuf = max(pArgs->cbIn, pArgs->cbOut); 402 MALLOC(pvBuf, void *, cbBuf, M_TEMP, M_WAITOK);472 pvBuf = RTMemTmpAlloc(cbBuf); 403 473 if (pvBuf == NULL) 404 474 pvPageBuf = pvBuf = IOMallocAligned(cbBuf, 8); … … 415 485 IOFreeAligned(pvPageBuf, cbBuf); 416 486 else 417 FREE(pvBuf, M_TEMP);487 RTMemTmpFree(pvBuf); 418 488 return rc; 419 489 } … … 456 526 IOFreeAligned(pvPageBuf, cbBuf); 457 527 else if (pvBuf) 458 FREE(pvBuf, M_TEMP);528 RTMemTmpFree(pvBuf); 459 529 460 530 dprintf2(("VBoxSupDrvIOCtl: returns %d\n", rc)); … … 524 594 RTDECL(int) SUPR0Printf(const char *pszFormat, ...) 525 595 { 526 va_list 527 char 596 va_list args; 597 char szMsg[512]; 528 598 529 599 va_start(args, pszFormat); … … 551 621 RTDECL(void) AssertMsg2(const char *pszFormat, ...) 552 622 { /* forwarder. */ 553 va_list 554 char 623 va_list ap; 624 char msg[256]; 555 625 556 626 va_start(ap, pszFormat); … … 561 631 } 562 632 633 634 /* 635 * 636 * org_virtualbox_SupDrv 637 * 638 */ 639 640 641 /** 642 * Initialize the object. 643 */ 644 bool org_virtualbox_SupDrv::init(OSDictionary *pDictionary) 645 { 646 dprintf(("org_virtualbox_SupDrv::init([%p], %p)\n", this, pDictionary)); 647 if (IOService::init(pDictionary)) 648 { 649 /* init members. */ 650 return true; 651 } 652 return false; 653 } 654 655 656 /** 657 * Free the object. 658 */ 659 void org_virtualbox_SupDrv::free(void) 660 { 661 dprintf(("IOService::free([%p])\n", this)); 662 IOService::free(); 663 } 664 665 666 /** 667 * Check if it's ok to start this service. 668 * It's always ok by us, so it's up to IOService to decide really. 669 */ 670 IOService *org_virtualbox_SupDrv::probe(IOService *pProvider, SInt32 *pi32Score) 671 { 672 dprintf(("org_virtualbox_SupDrv::probe([%p])\n", this)); 673 return IOService::probe(pProvider, pi32Score); 674 } 675 676 677 /** 678 * Start this service. 679 */ 680 bool org_virtualbox_SupDrv::start(IOService *pProvider) 681 { 682 dprintf(("org_virtualbox_SupDrv::start([%p])\n", this)); 683 684 if (IOService::start(pProvider)) 685 { 686 /* register the service. */ 687 registerService(); 688 return true; 689 } 690 return false; 691 } 692 693 694 /** 695 * Stop this service. 696 */ 697 void org_virtualbox_SupDrv::stop(IOService *pProvider) 698 { 699 dprintf(("org_virtualbox_SupDrv::stop([%p], %p)\n", this, pProvider)); 700 IOService::stop(pProvider); 701 } 702 703 704 /* 705 * 706 * org_virtualbox_SupDrvClient 707 * 708 */ 709 710 711 /** 712 * Initializer called when the client opens the service. 713 */ 714 bool org_virtualbox_SupDrvClient::initWithTask(task_t OwningTask, void *pvSecurityId, UInt32 u32Type) 715 { 716 dprintf(("org_virtualbox_SupDrvClient::initWithTask([%p], %#x, %p, %#x)\n", this, OwningTask, pvSecurityId, u32Type)); 717 718 if (!OwningTask) 719 return false; 720 if (IOUserClient::initWithTask(OwningTask, pvSecurityId , u32Type)) 721 { 722 m_Task = OwningTask; 723 m_pSession = NULL; 724 m_pProvider = NULL; 725 return true; 726 } 727 return false; 728 } 729 730 731 /** 732 * Start the client service. 733 */ 734 bool org_virtualbox_SupDrvClient::start(IOService *pProvider) 735 { 736 dprintf(("org_virtualbox_SupDrvClient::start([%p], %p)\n", this, pProvider)); 737 if (IOUserClient::start(pProvider)) 738 { 739 m_pProvider = OSDynamicCast(org_virtualbox_SupDrv, pProvider); 740 if (m_pProvider) 741 { 742 /* this is where we could create the section. */ 743 return true; 744 } 745 dprintf(("org_virtualbox_SupDrvClient::start: %p isn't org_virtualbox_SupDrv\n", pProvider)); 746 } 747 return false; 748 } 749 750 751 /** 752 * Client exits normally. 753 */ 754 IOReturn org_virtualbox_SupDrvClient::clientClose(void) 755 { 756 dprintf(("org_virtualbox_SupDrvClient::clientClose([%p])\n", this)); 757 758 m_pProvider = NULL; 759 terminate(); 760 761 return kIOReturnSuccess; 762 } 763 764 765 /** 766 * The client exits abnormally / forgets to do cleanups. 767 */ 768 IOReturn org_virtualbox_SupDrvClient::clientDied(void) 769 { 770 dprintf(("org_virtualbox_SupDrvClient::clientDied([%p])\n", this)); 771 772 /* IOUserClient::clientDied() only calls calls close... */ 773 return IOUserClient::clientDied(); 774 } 775 776 777 /** 778 * Stop the client service. 779 */ 780 void org_virtualbox_SupDrvClient::stop(IOService *pProvider) 781 { 782 dprintf(("org_virtualbox_SupDrvClient::stop([%p])\n", this)); 783 IOUserClient::stop(pProvider); 784 } 785 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
Note:
See TracChangeset
for help on using the changeset viewer.