VirtualBox

Changeset 39521 in vbox for trunk/src


Ignore:
Timestamp:
Dec 3, 2011 10:59:46 PM (13 years ago)
Author:
vboxsync
Message:

FreeBSD: Certain fixes to run on CURRENT and clean up the support driver character device handling, thanks to Bernhard Froehlich, Jung-uk Kim and Ed Schouten

Location:
trunk/src/VBox
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/Support/freebsd/SUPDrv-freebsd.c

    r37249 r39521  
    7070static int VBoxDrvFreeBSDLoad(void);
    7171static int VBoxDrvFreeBSDUnload(void);
    72 static void VBoxDrvFreeBSDClone(void *pvArg, struct ucred *pCred, char *pachName, int cchName, struct cdev **ppDev);
    73 
    74 static d_fdopen_t   VBoxDrvFreeBSDOpen;
    75 static d_close_t    VBoxDrvFreeBSDClose;
     72
     73static d_open_t     VBoxDrvFreeBSDOpen;
     74static void         VBoxDrvFreeBSDDtr(void *pData);
    7675static d_ioctl_t    VBoxDrvFreeBSDIOCtl;
    7776static int          VBoxDrvFreeBSDIOCtlSlow(PSUPDRVSESSION pSession, u_long ulCmd, caddr_t pvData, struct thread *pTd);
     
    101100{
    102101    .d_version =        D_VERSION,
    103 #if __FreeBSD_version > 800061
    104     .d_flags =          D_PSEUDO | D_TRACKCLOSE | D_NEEDMINOR,
    105 #else
    106     .d_flags =          D_PSEUDO | D_TRACKCLOSE,
    107 #endif
    108     .d_fdopen =         VBoxDrvFreeBSDOpen,
    109     .d_close =          VBoxDrvFreeBSDClose,
     102    .d_open =           VBoxDrvFreeBSDOpen,
    110103    .d_ioctl =          VBoxDrvFreeBSDIOCtl,
    111104    .d_name =           "vboxdrv"
    112105};
    113106
    114 /** List of cloned device. Managed by the kernel. */
    115 static struct clonedevs    *g_pVBoxDrvFreeBSDClones;
    116 /** The dev_clone event handler tag. */
    117 static eventhandler_tag     g_VBoxDrvFreeBSDEHTag;
     107/** The /dev/vboxdrv character device. */
     108static struct cdev         *g_pVBoxDrvFreeBSDChrDev;
    118109/** Reference counter. */
    119110static volatile uint32_t    g_cUsers;
     
    177168        {
    178169            /*
    179              * Configure device cloning.
     170             * Configure character device. Add symbolic link for compatibility.
    180171             */
    181             clone_setup(&g_pVBoxDrvFreeBSDClones);
    182             g_VBoxDrvFreeBSDEHTag = EVENTHANDLER_REGISTER(dev_clone, VBoxDrvFreeBSDClone, 0, 1000);
    183             if (g_VBoxDrvFreeBSDEHTag)
    184             {
    185                 Log(("VBoxDrvFreeBSDLoad: returns successfully\n"));
    186                 return VINF_SUCCESS;
    187             }
    188 
    189             printf("vboxdrv: EVENTHANDLER_REGISTER(dev_clone,,,) failed\n");
    190             clone_cleanup(&g_pVBoxDrvFreeBSDClones);
    191             rc = VERR_ALREADY_LOADED;
    192             supdrvDeleteDevExt(&g_VBoxDrvFreeBSDDevExt);
     172            g_pVBoxDrvFreeBSDChrDev = make_dev(&g_VBoxDrvFreeBSDChrDevSW, 0, UID_ROOT, GID_WHEEL, VBOXDRV_PERM, "vboxdrv");
     173            return VINF_SUCCESS;
    193174        }
    194175        else
     
    211192     * Reserve what we did in VBoxDrvFreeBSDInit.
    212193     */
    213     EVENTHANDLER_DEREGISTER(dev_clone, g_VBoxDrvFreeBSDEHTag);
    214     clone_cleanup(&g_pVBoxDrvFreeBSDClones);
     194    destroy_dev(g_pVBoxDrvFreeBSDChrDev);
    215195
    216196    supdrvDeleteDevExt(&g_VBoxDrvFreeBSDDevExt);
     
    223203    return VINF_SUCCESS;
    224204}
    225 
    226 
    227 /**
    228  * DEVFS event handler.
    229  */
    230 static void VBoxDrvFreeBSDClone(void *pvArg, struct ucred *pCred, char *pszName, int cchName, struct cdev **ppDev)
    231 {
    232     int iUnit;
    233     int rc;
    234 
    235     Log(("VBoxDrvFreeBSDClone: pszName=%s ppDev=%p\n", pszName, ppDev));
    236 
    237     /*
    238      * One device node per user, si_drv1 points to the session.
    239      * /dev/vboxdrv<N> where N = {0...255}.
    240      */
    241     if (!ppDev)
    242         return;
    243     if (dev_stdclone(pszName, NULL, "vboxdrv", &iUnit) != 1)
    244         return;
    245     if (iUnit >= 256 || iUnit < 0)
    246     {
    247         Log(("VBoxDrvFreeBSDClone: iUnit=%d >= 256 - rejected\n", iUnit));
    248         return;
    249     }
    250 
    251     Log(("VBoxDrvFreeBSDClone: pszName=%s iUnit=%d\n", pszName, iUnit));
    252 
    253     rc = clone_create(&g_pVBoxDrvFreeBSDClones, &g_VBoxDrvFreeBSDChrDevSW, &iUnit, ppDev, 0);
    254     Log(("VBoxDrvFreeBSDClone: clone_create -> %d; iUnit=%d\n", rc, iUnit));
    255     if (rc)
    256     {
    257 #if __FreeBSD_version > 800061
    258         *ppDev = make_dev(&g_VBoxDrvFreeBSDChrDevSW, iUnit, UID_ROOT, GID_WHEEL, VBOXDRV_PERM, "vboxdrv%d", iUnit);
    259 #else
    260         *ppDev = make_dev(&g_VBoxDrvFreeBSDChrDevSW, unit2minor(iUnit), UID_ROOT, GID_WHEEL, VBOXDRV_PERM, "vboxdrv%d", iUnit);
    261 #endif
    262         if (*ppDev)
    263         {
    264             dev_ref(*ppDev);
    265             (*ppDev)->si_flags |= SI_CHEAPCLONE;
    266             Log(("VBoxDrvFreeBSDClone: Created *ppDev=%p iUnit=%d si_drv1=%p si_drv2=%p\n",
    267                  *ppDev, iUnit, (*ppDev)->si_drv1, (*ppDev)->si_drv2));
    268             (*ppDev)->si_drv1 = (*ppDev)->si_drv2 = NULL;
    269         }
    270         else
    271             OSDBGPRINT(("VBoxDrvFreeBSDClone: make_dev iUnit=%d failed\n", iUnit));
    272     }
    273     else
    274         Log(("VBoxDrvFreeBSDClone: Existing *ppDev=%p iUnit=%d si_drv1=%p si_drv2=%p\n",
    275              *ppDev, iUnit, (*ppDev)->si_drv1, (*ppDev)->si_drv2));
    276 }
    277 
    278205
    279206
     
    288215 * @param   iFd     The file descriptor index(?). Pre FreeBSD 7.0.
    289216 */
    290 #if __FreeBSD__ >= 7
    291 static int VBoxDrvFreeBSDOpen(struct cdev *pDev, int fOpen, struct thread *pTd, struct file *pFd)
    292 #else
    293 static int VBoxDrvFreeBSDOpen(struct cdev *pDev, int fOpen, struct thread *pTd, int iFd)
    294 #endif
     217static int VBoxDrvFreeBSDOpen(struct cdev *pDev, int fOpen, int iDevtype, struct thread *pTd)
    295218{
    296219    PSUPDRVSESSION pSession;
    297220    int rc;
    298221
    299 #if __FreeBSD_version < 800062
    300     Log(("VBoxDrvFreeBSDOpen: fOpen=%#x iUnit=%d\n", fOpen, minor2unit(minor(pDev))));
    301 #else
    302     Log(("VBoxDrvFreeBSDOpen: fOpen=%#x iUnit=%d\n", fOpen, minor(dev2udev(pDev))));
    303 #endif
    304 
    305222    /*
    306223     * Let's be a bit picky about the flags...
     
    311228        return EINVAL;
    312229    }
    313 
    314     /*
    315      * Try grab it (we don't grab the giant, remember).
    316      */
    317     if (!ASMAtomicCmpXchgPtr(&pDev->si_drv1, (void *)0x42, NULL))
    318         return EBUSY;
    319230
    320231    /*
     
    327238        pSession->Uid = stuff;
    328239        pSession->Gid = stuff; */
    329         if (ASMAtomicCmpXchgPtr(&pDev->si_drv1, pSession, (void *)0x42))
    330         {
    331             ASMAtomicIncU32(&g_cUsers);
    332             return 0;
    333         }
    334 
    335         OSDBGPRINT(("VBoxDrvFreeBSDOpen: si_drv1=%p, expected 0x42!\n", pDev->si_drv1));
    336         supdrvCloseSession(&g_VBoxDrvFreeBSDDevExt, pSession);
     240        devfs_set_cdevpriv(pSession, VBoxDrvFreeBSDDtr);
     241        Log(("VBoxDrvFreeBSDOpen: pSession=%p\n", pSession));
     242        ASMAtomicIncU32(&g_cUsers);
     243        return 0;
    337244    }
    338245
     
    350257 * @param   pTd         The calling thread.
    351258 */
    352 static int VBoxDrvFreeBSDClose(struct cdev *pDev, int fFile, int DevType, struct thread *pTd)
    353 {
    354     PSUPDRVSESSION pSession = (PSUPDRVSESSION)pDev->si_drv1;
    355 #if __FreeBSD_version < 800062
    356     Log(("VBoxDrvFreeBSDClose: fFile=%#x iUnit=%d pSession=%p\n", fFile, minor2unit(minor(pDev)), pSession));
    357 #else
    358     Log(("VBoxDrvFreeBSDClose: fFile=%#x iUnit=%d pSession=%p\n", fFile, minor(dev2udev(pDev)), pSession));
    359 #endif
    360 
    361     /*
    362      * Close the session if it's still hanging on to the device...
    363      */
    364     if (VALID_PTR(pSession))
    365     {
    366         supdrvCloseSession(&g_VBoxDrvFreeBSDDevExt, pSession);
    367         if (!ASMAtomicCmpXchgPtr(&pDev->si_drv1, NULL, pSession))
    368             OSDBGPRINT(("VBoxDrvFreeBSDClose: si_drv1=%p expected %p!\n", pDev->si_drv1, pSession));
    369         ASMAtomicDecU32(&g_cUsers);
    370         /* Don't use destroy_dev here because it may sleep resulting in a hanging user process. */
    371         destroy_dev_sched(pDev);
    372     }
    373     else
    374         OSDBGPRINT(("VBoxDrvFreeBSDClose: si_drv1=%p!\n", pSession));
    375     return 0;
     259static void VBoxDrvFreeBSDDtr(void *pData)
     260{
     261    PSUPDRVSESSION pSession = pData;
     262    Log(("VBoxDrvFreeBSDDtr: pSession=%p\n", pSession));
     263
     264    /*
     265     * Close the session.
     266     */
     267    supdrvCloseSession(&g_VBoxDrvFreeBSDDevExt, pSession);
     268    ASMAtomicDecU32(&g_cUsers);
    376269}
    377270
     
    389282static int VBoxDrvFreeBSDIOCtl(struct cdev *pDev, u_long ulCmd, caddr_t pvData, int fFile, struct thread *pTd)
    390283{
    391     /*
    392      * Validate the input.
    393      */
    394     PSUPDRVSESSION pSession = (PSUPDRVSESSION)pDev->si_drv1;
    395     if (RT_UNLIKELY(!VALID_PTR(pSession)))
    396         return EINVAL;
     284    PSUPDRVSESSION pSession;
     285    devfs_get_cdevpriv((void **)&pSession);
    397286
    398287    /*
  • trunk/src/VBox/HostDrivers/Support/freebsd/SUPLib-freebsd.cpp

    r37596 r39521  
    7777     * Try open the BSD device.
    7878     */
    79     int hDevice = -1;
    80     char szDevice[sizeof(DEVICE_NAME) + 16];
    81     for (unsigned iUnit = 0; iUnit < 1024; iUnit++)
    82     {
    83         errno = 0;
    84         snprintf(szDevice, sizeof(szDevice), DEVICE_NAME "%d", iUnit);
    85         hDevice = open(szDevice, O_RDWR, 0);
    86         if (hDevice >= 0 || errno != EBUSY)
    87             break;
    88     }
     79    int hDevice = open(DEVICE_NAME, O_RDWR, 0);
    8980    if (hDevice < 0)
    9081    {
     
    9889            default:        rc = VERR_VM_DRIVER_OPEN_ERROR; break;
    9990        }
    100         LogRel(("Failed to open \"%s\", errno=%d, rc=%Rrc\n", szDevice, errno, rc));
     91        LogRel(("Failed to open \"%s\", errno=%d, rc=%Rrc\n", DEVICE_NAME, errno, rc));
    10192        return rc;
    10293    }
  • trunk/src/VBox/HostDrivers/freebsd/Makefile.kmk

    r39474 r39521  
    2222HostDrivers-scripts_INST    = bin/src/
    2323HostDrivers-scripts_SOURCES = Makefile
    24 HostDrivers-scripts_EXEC_SOURCES = export_modules
    2524
    2625include $(KBUILD_PATH)/subfooter.kmk
  • trunk/src/VBox/Runtime/r0drv/freebsd/memobj-r0drv-freebsd.c

    r36555 r39521  
    392392static void rtR0MemObjFreeBSDPhysPageInit(vm_page_t pPage, vm_pindex_t iPage)
    393393{
     394#if __FreeBSD_version <= 1000000
    394395    pPage->wire_count = 1;
    395396    pPage->pindex     = iPage;
    396397    pPage->act_count  = 0;
    397     pPage->oflags     = 0;
    398     pPage->flags      = PG_UNMANAGED;
    399398    atomic_add_int(&cnt.v_wire_count, 1);
     399
     400#if __FreeBSD_version >= 900040
     401    Assert(pPage->oflags & VPO_UNMANAGED != 0);
     402#else
     403    Assert(pPage->flags & PG_UNMANAGED != 0);
     404#endif
     405#endif
    400406}
    401407
     
    409415    uint32_t   cPages = cb >> PAGE_SHIFT;
    410416    vm_paddr_t VmPhysAddrHigh;
     417#if __FreeBSD_version >= 1000001
     418    int        pFlags = VM_ALLOC_INTERRUPT | VM_ALLOC_NOOBJ | VM_ALLOC_WIRED;
     419#endif
    411420
    412421    /* create the object. */
     
    425434    if (fContiguous)
    426435    {
     436#if __FreeBSD_version >= 1000001
     437        vm_page_t pPage = vm_page_alloc_contig(NULL, 0, pFlags, cPages, 0, VmPhysAddrHigh, uAlignment, 0, VM_MEMATTR_DEFAULT);
     438#else
    427439        vm_page_t pPage = vm_phys_alloc_contig(cPages, 0, VmPhysAddrHigh, uAlignment, 0);
     440#endif
    428441
    429442        if (pPage)
     
    441454        for (uint32_t iPage = 0; iPage < cPages; iPage++)
    442455        {
     456#if __FreeBSD_version >= 1000001
     457            vm_page_t pPage = vm_page_alloc_contig(NULL, iPage, pFlags, 1, 0, VmPhysAddrHigh, uAlignment, 0, VM_MEMATTR_DEFAULT);
     458#else
    443459            vm_page_t pPage = vm_phys_alloc_contig(1, 0, VmPhysAddrHigh, uAlignment, 0);
     460#endif
    444461
    445462            if (!pPage)
Note: See TracChangeset for help on using the changeset viewer.

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