Changeset 15130 in vbox for trunk/src/VBox/HostDrivers/Support/darwin
- Timestamp:
- Dec 8, 2008 7:18:32 PM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 40529
- Location:
- trunk/src/VBox/HostDrivers/Support/darwin
- Files:
-
- 2 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/Support/darwin/Info-Tiger.plist
r15112 r15130 4 4 <dict> 5 5 <key>CFBundleDevelopmentRegion</key> <string>English</string> 6 <key>CFBundleExecutable</key> <string>VBoxDrv </string>6 <key>CFBundleExecutable</key> <string>VBoxDrvTiger</string> 7 7 <key>CFBundleIdentifier</key> <string>org.virtualbox.kext.VBoxDrv</string> 8 8 <key>CFBundleInfoDictionaryVersion</key> <string>6.0</string> 9 <key>CFBundleName</key> <string>VBoxDrv </string>9 <key>CFBundleName</key> <string>VBoxDrvTiger</string> 10 10 <key>CFBundlePackageType</key> <string>KEXT</string> 11 11 <key>CFBundleSignature</key> <string>????</string> -
trunk/src/VBox/HostDrivers/Support/darwin/SUPDrv-darwin.cpp
r15043 r15130 68 68 #include <IOKit/IOUserclient.h> 69 69 #include <IOKit/pwr_mgt/RootDomain.h> 70 71 #ifdef VBOX_WITH_HOST_VMX 72 __BEGIN_DECLS 73 # include <i386/vmx.h> 74 __END_DECLS 75 #endif 70 76 71 77 … … 678 684 } 679 685 686 /** 687 * Callback for blah blah blah. 688 */ 680 689 IOReturn VBoxDrvDarwinSleepHandler(void * /* pvTarget */, void *pvRefCon, UInt32 uMessageType, IOService * /* pProvider */, void * /* pvMessageArgument */, vm_size_t /* argSize */) 681 690 { 682 /* IOLog("VBoxDrv: Got sleep/wake notice. Message type was %X\n", (uint)uMessageType); */691 LogFlow(("VBoxDrv: Got sleep/wake notice. Message type was %X\n", (uint)uMessageType)); 683 692 684 693 if (uMessageType == kIOMessageSystemWillSleep) … … 692 701 } 693 702 694 #if 0 /* doesn't work. */695 696 /*697 * The following is a weak symbol hack to deal with the lack of698 * host_vmxon & host_vmxoff in Tiger.699 */700 __BEGIN_DECLS701 #if 1702 #pragma weak host_vmxon703 int host_vmxon(int exclusive) __attribute__((weak_import));704 #pragma weak host_vmxoff705 void host_vmxoff(void) __attribute__((weak_import));706 #else707 int host_vmxon(int exclusive) __attribute__((weak));708 void host_vmxoff(void) __attribute__((weak));709 #endif710 __END_DECLS711 PFNRT g_pfn = (PFNRT)&host_vmxon;712 713 static int g_fWeakHostVmxOnOff = false;714 #if 0715 /* weak version for Tiger. */716 int host_vmxon(int exclusive)717 {718 NOREF(exclusive);719 g_fWeakHostVmxOnOff = true;720 return 42;721 }722 723 /* weak version for Tiger. */724 void host_vmxoff(void)725 {726 g_fWeakHostVmxOnOff = true;727 }728 #endif729 730 703 731 704 /** … … 737 710 int VBOXCALL supdrvOSEnableVTx(bool fEnable) 738 711 { 739 #if 0 740 if (host_vmxon == NULL || host_vmxoff == NULL) 741 g_fWeakHostVmxOnOff = true; 742 if (g_fWeakHostVmxOnOff) 743 return VERR_NOT_SUPPORTED; 744 712 #ifdef VBOX_WITH_HOST_VMX 745 713 int rc; 746 714 if (fEnable) 747 715 { 748 716 rc = host_vmxon(false /* exclusive */); 749 if (rc == 42)750 rc = VERR_NOT_SUPPORTED;751 else752 {753 AssertReturn(!g_fWeakHostVmxOnOff, VERR_NOT_SUPPORTED);754 if (rc == 0 /* all ok */)755 rc = VINF_SUCCESS;756 else if (rc == 1 /* unsupported */)757 rc = VERR_VMX_NO_VMX;758 else if (rc == 2 /* exclusive user */)759 rc = VERR_VMX_IN_VMX_ROOT_MODE;760 else761 rc = VERR_UNRESOLVED_ERROR;762 }763 }764 else765 {766 host_vmxoff();767 AssertReturn(!g_fWeakHostVmxOnOff, VERR_NOT_SUPPORTED);768 rc = VINF_SUCCESS;769 }770 return rc;771 #else772 return VERR_NOT_SUPPORTED;773 #endif774 }775 776 777 #else /* more non-working code: */778 779 #include <mach-o/loader.h>780 #include </usr/include/mach-o/nlist.h> /* ugly! but it's missing from the Kernel.framework */781 782 __BEGIN_DECLS783 extern struct mach_header _mh_execute_header;784 //extern kmod_info_t *kmod;785 typedef struct pmap *pmap_t;786 extern pmap_t kernel_pmap;787 extern ppnum_t pmap_find_phys(pmap_t, addr64_t);788 __END_DECLS789 790 RTDECL(int) RTLdrGetKernelSymbol(const char *pszSymbol, void **ppvValue)791 {792 struct mach_header const *pMHdr = &_mh_execute_header;793 794 /*795 * Validate basic restrictions.796 */797 AssertPtrReturn(pMHdr, VERR_INVALID_POINTER);798 AssertMsgReturn(pMHdr->magic == MH_MAGIC, ("%#x\n", pMHdr->magic), VERR_INVALID_EXE_SIGNATURE);799 AssertMsgReturn(pMHdr->filetype == MH_EXECUTE, ("%#x\n", pMHdr->filetype), VERR_BAD_EXE_FORMAT);800 801 /*802 * Search for the __LINKEDIT segment and LC_SYMTAB.803 */804 struct symtab_command const *pSymTabCmd = NULL;805 struct segment_command const *pLinkEditSeg = NULL;806 union807 {808 void const *pv;809 uint8_t const *pb;810 struct load_command const *pGen;811 struct segment_command const *pSeg;812 struct symtab_command const *pSymTab;813 } Cmd;814 815 Cmd.pv = pMHdr + 1;816 uint32_t iCmd = pMHdr->ncmds;817 uint32_t cbCmdLeft = pMHdr->sizeofcmds;818 while (iCmd-- > 0)819 {820 AssertReturn(Cmd.pGen->cmdsize <= cbCmdLeft, VERR_BAD_EXE_FORMAT);821 822 if ( Cmd.pGen->cmd == LC_SEGMENT823 && !strcmp(Cmd.pSeg->segname, "__LINKEDIT")824 && !pLinkEditSeg)825 pLinkEditSeg = Cmd.pSeg;826 else if ( Cmd.pGen->cmd == LC_SYMTAB827 && Cmd.pGen->cmdsize == sizeof(struct symtab_command)828 && !pSymTabCmd)829 pSymTabCmd = Cmd.pSymTab;830 831 /* advance */832 cbCmdLeft -= Cmd.pGen->cmdsize;833 Cmd.pb += Cmd.pGen->cmdsize;834 }835 836 /*837 * Check that the link edit segment and symbol table was found838 * and that the former contains the latter. Then calculate the839 * addresses of the symbol and string tables.840 */841 AssertReturn(pLinkEditSeg, VERR_BAD_EXE_FORMAT);842 AssertReturn(pSymTabCmd, VERR_BAD_EXE_FORMAT);843 AssertReturn(pSymTabCmd->symoff - pLinkEditSeg->fileoff < pLinkEditSeg->filesize, VERR_BAD_EXE_FORMAT);844 AssertReturn(pSymTabCmd->symoff + pSymTabCmd->nsyms * sizeof(struct nlist) - pLinkEditSeg->fileoff <= pLinkEditSeg->filesize, VERR_BAD_EXE_FORMAT);845 AssertReturn(pSymTabCmd->stroff - pLinkEditSeg->fileoff < pLinkEditSeg->filesize, VERR_BAD_EXE_FORMAT);846 AssertReturn(pSymTabCmd->stroff + pSymTabCmd->strsize - pLinkEditSeg->fileoff <= pLinkEditSeg->filesize, VERR_BAD_EXE_FORMAT);847 AssertReturn(pLinkEditSeg->filesize <= pLinkEditSeg->vmsize, VERR_BAD_EXE_FORMAT);848 const struct nlist *paSyms = (const struct nlist *)(pLinkEditSeg->vmaddr + pSymTabCmd->symoff - pLinkEditSeg->fileoff);849 const char *pchStrTab = (const char *)(pLinkEditSeg->vmaddr + pSymTabCmd->stroff - pLinkEditSeg->fileoff);850 851 /*852 * Check that the link edit segment wasn't freed yet.853 */854 ppnum_t PgNo = pmap_find_phys(kernel_pmap, pLinkEditSeg->vmaddr);855 if (!PgNo)856 return VERR_MODULE_NOT_FOUND;857 858 /*859 * Search the symbol table for the desired symbol.860 */861 uint32_t const cbStrTab = pSymTabCmd->strsize;862 uint32_t const cSyms = pSymTabCmd->nsyms;863 for (uint32_t iSym = 0; iSym < cSyms; iSym++)864 {865 unsigned int uSymType = paSyms[iSym].n_type & N_TYPE;866 if ( (uSymType == N_SECT || uSymType == N_ABS)867 && paSyms[iSym].n_un.n_strx > 0868 && (unsigned long)paSyms[iSym].n_un.n_strx < cbStrTab)869 {870 const char *pszName = pchStrTab + paSyms[iSym].n_un.n_strx;871 #ifdef RT_ARCH_X86872 if ( pszName[0] == '_' /* cdecl symbols are prefixed */873 && !strcmp(pszName + 1, pszSymbol))874 #else875 if (!strcmp(pszName, pszSymbol))876 #endif877 {878 *ppvValue = (uint8_t *)paSyms[iSym].n_value;879 return VINF_SUCCESS;880 }881 }882 }883 return VERR_SYMBOL_NOT_FOUND;884 }885 886 static bool volatile g_fHostVmxResolved = false;887 static int (*g_pfnHostVmxOn)(boolean_t exclusive) = NULL;888 static void (*g_pfnHostVmxOff)(void) = NULL;889 890 891 /**892 * Enables or disables VT-x using kernel functions.893 *894 * @returns VBox status code. VERR_NOT_SUPPORTED has a special meaning.895 * @param fEnable Whether to enable or disable.896 */897 int VBOXCALL supdrvOSEnableVTx(bool fEnable)898 {899 /*900 * Lazy initialization.901 */902 if (!g_fHostVmxResolved)903 {904 void *pvOn;905 int rc = RTLdrGetKernelSymbol("host_vmxon", &pvOn);906 if (RT_SUCCESS(rc))907 {908 void *pvOff;909 rc = RTLdrGetKernelSymbol("host_vmxoff", &pvOff);910 if (RT_SUCCESS(rc))911 {912 ASMAtomicUoWritePtr((void * volatile *)&g_pfnHostVmxOff, pvOff);913 ASMAtomicUoWritePtr((void * volatile *)&g_pfnHostVmxOn, pvOn);914 }915 }916 ASMAtomicWriteBool(&g_fHostVmxResolved, true);917 }918 919 /*920 * Available?921 */922 if (!g_pfnHostVmxOn || !g_pfnHostVmxOff)923 return VERR_NOT_SUPPORTED;924 925 /*926 * Do the job.927 */928 int rc;929 if (fEnable)930 {931 rc = g_pfnHostVmxOn(false /* exclusive */);932 717 if (rc == 0 /* all ok */) 933 718 rc = VINF_SUCCESS; … … 936 721 else if (rc == 2 /* exclusive user */) 937 722 rc = VERR_VMX_IN_VMX_ROOT_MODE; 938 else 723 else /* shouldn't happen, but just in case. */ 724 { 725 LogRel(("host_vmxon returned %d\n", rc)); 939 726 rc = VERR_UNRESOLVED_ERROR; 727 } 940 728 } 941 729 else 942 730 { 943 g_pfnHostVmxOff();731 host_vmxoff(); 944 732 rc = VINF_SUCCESS; 945 733 } 946 734 return rc; 947 } 948 949 #endif /* doesn't work*/ 735 #else 736 return VERR_NOT_SUPPORTED; 737 #endif 738 } 950 739 951 740 -
trunk/src/VBox/HostDrivers/Support/darwin/load.sh
r14745 r15130 29 29 # 30 30 31 DRVNAME="VBoxDrv.kext" 31 XNU_VERSION=`LC_ALL=C uname -r | LC_ALL=C cut -d . -f 1` 32 if [ "$XNU_VERSION" -ge "9" ]; then 33 DRVNAME="VBoxDrv.kext" 34 else 35 DRVNAME="VBoxDrvTiger.kext" 36 fi 32 37 BUNDLE="org.virtualbox.kext.VBoxDrv" 33 38
Note:
See TracChangeset
for help on using the changeset viewer.