- Timestamp:
- Dec 3, 2011 10:59:46 PM (13 years ago)
- Location:
- trunk/src/VBox
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/Support/freebsd/SUPDrv-freebsd.c
r37249 r39521 70 70 static int VBoxDrvFreeBSDLoad(void); 71 71 static 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 73 static d_open_t VBoxDrvFreeBSDOpen; 74 static void VBoxDrvFreeBSDDtr(void *pData); 76 75 static d_ioctl_t VBoxDrvFreeBSDIOCtl; 77 76 static int VBoxDrvFreeBSDIOCtlSlow(PSUPDRVSESSION pSession, u_long ulCmd, caddr_t pvData, struct thread *pTd); … … 101 100 { 102 101 .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, 110 103 .d_ioctl = VBoxDrvFreeBSDIOCtl, 111 104 .d_name = "vboxdrv" 112 105 }; 113 106 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. */ 108 static struct cdev *g_pVBoxDrvFreeBSDChrDev; 118 109 /** Reference counter. */ 119 110 static volatile uint32_t g_cUsers; … … 177 168 { 178 169 /* 179 * Configure device cloning.170 * Configure character device. Add symbolic link for compatibility. 180 171 */ 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; 193 174 } 194 175 else … … 211 192 * Reserve what we did in VBoxDrvFreeBSDInit. 212 193 */ 213 EVENTHANDLER_DEREGISTER(dev_clone, g_VBoxDrvFreeBSDEHTag); 214 clone_cleanup(&g_pVBoxDrvFreeBSDClones); 194 destroy_dev(g_pVBoxDrvFreeBSDChrDev); 215 195 216 196 supdrvDeleteDevExt(&g_VBoxDrvFreeBSDDevExt); … … 223 203 return VINF_SUCCESS; 224 204 } 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 > 800061258 *ppDev = make_dev(&g_VBoxDrvFreeBSDChrDevSW, iUnit, UID_ROOT, GID_WHEEL, VBOXDRV_PERM, "vboxdrv%d", iUnit);259 #else260 *ppDev = make_dev(&g_VBoxDrvFreeBSDChrDevSW, unit2minor(iUnit), UID_ROOT, GID_WHEEL, VBOXDRV_PERM, "vboxdrv%d", iUnit);261 #endif262 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 else271 OSDBGPRINT(("VBoxDrvFreeBSDClone: make_dev iUnit=%d failed\n", iUnit));272 }273 else274 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 278 205 279 206 … … 288 215 * @param iFd The file descriptor index(?). Pre FreeBSD 7.0. 289 216 */ 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 217 static int VBoxDrvFreeBSDOpen(struct cdev *pDev, int fOpen, int iDevtype, struct thread *pTd) 295 218 { 296 219 PSUPDRVSESSION pSession; 297 220 int rc; 298 221 299 #if __FreeBSD_version < 800062300 Log(("VBoxDrvFreeBSDOpen: fOpen=%#x iUnit=%d\n", fOpen, minor2unit(minor(pDev))));301 #else302 Log(("VBoxDrvFreeBSDOpen: fOpen=%#x iUnit=%d\n", fOpen, minor(dev2udev(pDev))));303 #endif304 305 222 /* 306 223 * Let's be a bit picky about the flags... … … 311 228 return EINVAL; 312 229 } 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;319 230 320 231 /* … … 327 238 pSession->Uid = stuff; 328 239 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; 337 244 } 338 245 … … 350 257 * @param pTd The calling thread. 351 258 */ 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; 259 static 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); 376 269 } 377 270 … … 389 282 static int VBoxDrvFreeBSDIOCtl(struct cdev *pDev, u_long ulCmd, caddr_t pvData, int fFile, struct thread *pTd) 390 283 { 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); 397 286 398 287 /* -
trunk/src/VBox/HostDrivers/Support/freebsd/SUPLib-freebsd.cpp
r37596 r39521 77 77 * Try open the BSD device. 78 78 */ 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); 89 80 if (hDevice < 0) 90 81 { … … 98 89 default: rc = VERR_VM_DRIVER_OPEN_ERROR; break; 99 90 } 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)); 101 92 return rc; 102 93 } -
trunk/src/VBox/HostDrivers/freebsd/Makefile.kmk
r39474 r39521 22 22 HostDrivers-scripts_INST = bin/src/ 23 23 HostDrivers-scripts_SOURCES = Makefile 24 HostDrivers-scripts_EXEC_SOURCES = export_modules25 24 26 25 include $(KBUILD_PATH)/subfooter.kmk -
trunk/src/VBox/Runtime/r0drv/freebsd/memobj-r0drv-freebsd.c
r36555 r39521 392 392 static void rtR0MemObjFreeBSDPhysPageInit(vm_page_t pPage, vm_pindex_t iPage) 393 393 { 394 #if __FreeBSD_version <= 1000000 394 395 pPage->wire_count = 1; 395 396 pPage->pindex = iPage; 396 397 pPage->act_count = 0; 397 pPage->oflags = 0;398 pPage->flags = PG_UNMANAGED;399 398 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 400 406 } 401 407 … … 409 415 uint32_t cPages = cb >> PAGE_SHIFT; 410 416 vm_paddr_t VmPhysAddrHigh; 417 #if __FreeBSD_version >= 1000001 418 int pFlags = VM_ALLOC_INTERRUPT | VM_ALLOC_NOOBJ | VM_ALLOC_WIRED; 419 #endif 411 420 412 421 /* create the object. */ … … 425 434 if (fContiguous) 426 435 { 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 427 439 vm_page_t pPage = vm_phys_alloc_contig(cPages, 0, VmPhysAddrHigh, uAlignment, 0); 440 #endif 428 441 429 442 if (pPage) … … 441 454 for (uint32_t iPage = 0; iPage < cPages; iPage++) 442 455 { 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 443 459 vm_page_t pPage = vm_phys_alloc_contig(1, 0, VmPhysAddrHigh, uAlignment, 0); 460 #endif 444 461 445 462 if (!pPage)
Note:
See TracChangeset
for help on using the changeset viewer.