VirtualBox

Ignore:
Timestamp:
Dec 8, 2008 7:18:32 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
40529
Message:

VBoxDrvTiger.kext (#3202).

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  
    44<dict>
    55    <key>CFBundleDevelopmentRegion</key>        <string>English</string>
    6     <key>CFBundleExecutable</key>               <string>VBoxDrv</string>
     6    <key>CFBundleExecutable</key>               <string>VBoxDrvTiger</string>
    77    <key>CFBundleIdentifier</key>               <string>org.virtualbox.kext.VBoxDrv</string>
    88    <key>CFBundleInfoDictionaryVersion</key>    <string>6.0</string>
    9     <key>CFBundleName</key>                     <string>VBoxDrv</string>
     9    <key>CFBundleName</key>                     <string>VBoxDrvTiger</string>
    1010    <key>CFBundlePackageType</key>              <string>KEXT</string>
    1111    <key>CFBundleSignature</key>                <string>????</string>
  • trunk/src/VBox/HostDrivers/Support/darwin/SUPDrv-darwin.cpp

    r15043 r15130  
    6868#include <IOKit/IOUserclient.h>
    6969#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
    7076
    7177
     
    678684}
    679685
     686/**
     687 * Callback for blah blah blah.
     688 */
    680689IOReturn VBoxDrvDarwinSleepHandler(void * /* pvTarget */, void *pvRefCon, UInt32 uMessageType, IOService * /* pProvider */, void * /* pvMessageArgument */, vm_size_t /* argSize */)
    681690{
    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));
    683692
    684693    if (uMessageType == kIOMessageSystemWillSleep)
     
    692701}
    693702
    694 #if 0 /* doesn't work. */
    695 
    696 /*
    697  * The following is a weak symbol hack to deal with the lack of
    698  * host_vmxon & host_vmxoff in Tiger.
    699  */
    700 __BEGIN_DECLS
    701 #if 1
    702 #pragma weak host_vmxon
    703 int host_vmxon(int exclusive) __attribute__((weak_import));
    704 #pragma weak host_vmxoff
    705 void host_vmxoff(void) __attribute__((weak_import));
    706 #else
    707 int host_vmxon(int exclusive) __attribute__((weak));
    708 void host_vmxoff(void) __attribute__((weak));
    709 #endif
    710 __END_DECLS
    711 PFNRT g_pfn = (PFNRT)&host_vmxon;
    712 
    713 static int g_fWeakHostVmxOnOff = false;
    714 #if 0
    715 /* 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 #endif
    729 
    730703
    731704/**
     
    737710int VBOXCALL supdrvOSEnableVTx(bool fEnable)
    738711{
    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
    745713    int rc;
    746714    if (fEnable)
    747715    {
    748716        rc = host_vmxon(false /* exclusive */);
    749         if (rc == 42)
    750             rc = VERR_NOT_SUPPORTED;
    751         else
    752         {
    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             else
    761                 rc = VERR_UNRESOLVED_ERROR;
    762         }
    763     }
    764     else
    765     {
    766         host_vmxoff();
    767         AssertReturn(!g_fWeakHostVmxOnOff, VERR_NOT_SUPPORTED);
    768         rc = VINF_SUCCESS;
    769     }
    770     return rc;
    771 #else
    772     return VERR_NOT_SUPPORTED;
    773 #endif
    774 }
    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_DECLS
    783 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_DECLS
    789 
    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     union
    807     {
    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_SEGMENT
    823             &&  !strcmp(Cmd.pSeg->segname, "__LINKEDIT")
    824             &&  !pLinkEditSeg)
    825             pLinkEditSeg = Cmd.pSeg;
    826         else if (   Cmd.pGen->cmd == LC_SYMTAB
    827                  && 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 found
    838      * and that the former contains the latter. Then calculate the
    839      * 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 > 0
    868             &&  (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_X86
    872             if (    pszName[0] == '_'  /* cdecl symbols are prefixed */
    873                 &&  !strcmp(pszName + 1, pszSymbol))
    874 #else
    875             if (!strcmp(pszName, pszSymbol))
    876 #endif
    877             {
    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 */);
    932717        if (rc == 0 /* all ok */)
    933718            rc = VINF_SUCCESS;
     
    936721        else if (rc == 2 /* exclusive user */)
    937722            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));
    939726            rc = VERR_UNRESOLVED_ERROR;
     727        }
    940728    }
    941729    else
    942730    {
    943         g_pfnHostVmxOff();
     731        host_vmxoff();
    944732        rc = VINF_SUCCESS;
    945733    }
    946734    return rc;
    947 }
    948 
    949 #endif /* doesn't work*/
     735#else
     736    return VERR_NOT_SUPPORTED;
     737#endif
     738}
    950739
    951740
  • trunk/src/VBox/HostDrivers/Support/darwin/load.sh

    r14745 r15130  
    2929#
    3030
    31 DRVNAME="VBoxDrv.kext"
     31XNU_VERSION=`LC_ALL=C uname -r | LC_ALL=C cut -d . -f 1`
     32if [ "$XNU_VERSION" -ge "9" ]; then
     33  DRVNAME="VBoxDrv.kext"
     34else
     35  DRVNAME="VBoxDrvTiger.kext"
     36fi
    3237BUNDLE="org.virtualbox.kext.VBoxDrv"
    3338
Note: See TracChangeset for help on using the changeset viewer.

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