/** * Stop the kernel module. */ static kern_return_t VBoxNetFltDarwinStop(struct kmod_info *pKModInfo, void *pvData) { Log(("VBoxNetFltDarwinStop\n")); /* * Refuse to unload if anyone is currently using the filter driver. * This is important as I/O kit / xnu will to be able to do usage * tracking for us! */ int rc = vboxNetFltTryDeleteIdcAndGlobals(&g_VBoxNetFltGlobals); if (RT_FAILURE(rc)) { Log(("VBoxNetFltDarwinStop - failed, busy.\n")); return KMOD_RETURN_FAILURE; } /* * Undo the work done during start (in reverse order). */ memset(&g_VBoxNetFltGlobals, 0, sizeof(g_VBoxNetFltGlobals)); RTR0Term(); return KMOD_RETURN_SUCCESS; }
static int vgdrvFreeBSDDetach(device_t pDevice) { struct VBoxGuestDeviceState *pState = device_get_softc(pDevice); if (cUsers > 0) return EBUSY; /* * Reverse what we did in vgdrvFreeBSDAttach. */ if (g_vgdrvFreeBSDEHTag != NULL) EVENTHANDLER_DEREGISTER(dev_clone, g_vgdrvFreeBSDEHTag); clone_cleanup(&g_pvgdrvFreeBSDClones); vgdrvFreeBSDRemoveIRQ(pDevice, pState); if (pState->pVMMDevMemRes) bus_release_resource(pDevice, SYS_RES_MEMORY, pState->iVMMDevMemResId, pState->pVMMDevMemRes); if (pState->pIOPortRes) bus_release_resource(pDevice, SYS_RES_IOPORT, pState->iIOPortResId, pState->pIOPortRes); VGDrvCommonDeleteDevExt(&g_DevExt); RTR0Term(); return 0; }
static status_t VBoxGuestHaikuDetach(void) { struct VBoxGuestDeviceState *pState = &sState; if (cUsers > 0) return EBUSY; /* * Reverse what we did in VBoxGuestHaikuAttach. */ VBoxGuestHaikuRemoveIRQ(pState); if (pState->iVMMDevMemAreaId) delete_area(pState->iVMMDevMemAreaId); VBoxGuestDeleteDevExt(&g_DevExt); #ifdef DO_LOG RTLogDestroy(RTLogRelSetDefaultInstance(NULL)); RTLogSetDefaultInstance(NULL); // RTLogDestroy(RTLogSetDefaultInstance(NULL)); #endif RTSpinlockDestroy(g_Spinlock); g_Spinlock = NIL_RTSPINLOCK; RTR0Term(); return B_OK; }
static int VBoxDrvFreeBSDLoad(void) { g_cUsers = 0; /* * Initialize the runtime. */ int rc = RTR0Init(0); if (RT_SUCCESS(rc)) { Log(("VBoxDrvFreeBSDLoad:\n")); /* * Initialize the device extension. */ rc = supdrvInitDevExt(&g_VBoxDrvFreeBSDDevExt, sizeof(SUPDRVSESSION)); if (RT_SUCCESS(rc)) { /* * Configure character devices. Add symbolic links for compatibility. */ g_pVBoxDrvFreeBSDChrDevSys = make_dev(&g_VBoxDrvFreeBSDChrDevSwSys, 0, UID_ROOT, GID_WHEEL, VBOXDRV_PERM, "vboxdrv"); g_pVBoxDrvFreeBSDChrDevUsr = make_dev(&g_VBoxDrvFreeBSDChrDevSwUsr, 1, UID_ROOT, GID_WHEEL, 0666, "vboxdrvu"); return VINF_SUCCESS; } printf("vboxdrv: supdrvInitDevExt failed, rc=%d\n", rc); RTR0Term(); } else printf("vboxdrv: RTR0Init failed, rc=%d\n", rc); return rc; }
/** * Unload the driver. * * @param pDrvObj Driver object. */ void _stdcall VBoxDrvNtUnload(PDRIVER_OBJECT pDrvObj) { PSUPDRVDEVEXT pDevExt = (PSUPDRVDEVEXT)pDrvObj->DeviceObject->DeviceExtension; Log(("VBoxDrvNtUnload at irql %d\n", KeGetCurrentIrql())); /* Clean up the power callback registration. */ if (pDevExt->hPowerCallback) ExUnregisterCallback(pDevExt->hPowerCallback); if (pDevExt->pObjPowerCallback) ObDereferenceObject(pDevExt->pObjPowerCallback); /* * We ASSUME that it's not possible to unload a driver with open handles. * Start by deleting the symbolic link */ UNICODE_STRING DosName; RtlInitUnicodeString(&DosName, DEVICE_NAME_DOS); NTSTATUS rc = IoDeleteSymbolicLink(&DosName); /* * Terminate the GIP page and delete the device extension. */ supdrvDeleteDevExt(pDevExt); RTR0Term(); IoDeleteDevice(pDrvObj->DeviceObject); }
/** * Kernel entry points */ int _init(void) { LogFunc((DEVICE_NAME ":_init\n")); /* * Prevent module autounloading. */ modctl_t *pModCtl = mod_getctl(&g_VBoxNetAdpSolarisModLinkage); if (pModCtl) pModCtl->mod_loadflags |= MOD_NOAUTOUNLOAD; else LogRel((DEVICE_NAME ":failed to disable autounloading!\n")); /* * Initialize IPRT. */ int rc = RTR0Init(0); if (RT_SUCCESS(rc)) { rc = mod_install(&g_VBoxNetAdpSolarisModLinkage); if (!rc) return rc; LogRel((DEVICE_NAME ":mod_install failed. rc=%d\n", rc)); RTR0Term(); } else LogRel((DEVICE_NAME ":failed to initialize IPRT (rc=%d)\n", rc)); return RTErrConvertToErrno(rc); }
/** * Start the kernel module. */ static kern_return_t vboxSfDwnModuleLoad(struct kmod_info *pKModInfo, void *pvData) { RT_NOREF(pKModInfo, pvData); #ifdef DEBUG printf("vboxSfDwnModuleLoad\n"); RTLogBackdoorPrintf("vboxSfDwnModuleLoad\n"); #endif /* * Initialize IPRT and the ring-0 guest library. */ int rc = RTR0Init(0); if (RT_SUCCESS(rc)) { rc = VbglR0SfInit(); if (RT_SUCCESS(rc)) { /* * Register the file system. */ rc = vfs_fsadd(&g_VBoxSfFsEntry, &g_pVBoxSfVfsTableEntry); if (rc == 0) { /* * Try find VBoxGuest and connect to the shared folders service on the host. */ /** @todo should we just ignore the error here and retry at mount time? * Technically, VBoxGuest should be available since it's one of our * dependencies... */ vboxSfDwnConnect(); /* * We're done for now. We'll deal with */ LogRel(("VBoxSF: loaded\n")); return KERN_SUCCESS; } printf("VBoxSF: vfs_fsadd failed: %d\n", rc); RTLogBackdoorPrintf("VBoxSF: vfs_fsadd failed: %d\n", rc); VbglR0SfTerm(); } else { printf("VBoxSF: VbglR0SfInit failed: %d\n", rc); RTLogBackdoorPrintf("VBoxSF: VbglR0SfInit failed: %Rrc\n", rc); } RTR0Term(); } else { printf("VBoxSF: RTR0Init failed: %d\n", rc); RTLogBackdoorPrintf("VBoxSF: RTR0Init failed: %Rrc\n", rc); } return KERN_FAILURE; }
/** * Kernel entry points */ int _init(void) { int rc; LogFunc((DEVICE_NAME ":_init\n")); g_pDip = NULL; /* * Prevent module autounloading. */ modctl_t *pModCtl = mod_getctl(&g_VBoxUSBMonSolarisModLinkage); if (pModCtl) pModCtl->mod_loadflags |= MOD_NOAUTOUNLOAD; else LogRel((DEVICE_NAME ":failed to disable autounloading!\n")); /* * Initialize IPRT R0 driver, which internally calls OS-specific r0 init. */ rc = RTR0Init(0); if (RT_SUCCESS(rc)) { /* * Initialize global mutex. */ mutex_init(&g_VBoxUSBMonSolarisMtx, NULL, MUTEX_DRIVER, NULL); rc = VBoxUSBFilterInit(); if (RT_SUCCESS(rc)) { rc = ddi_soft_state_init(&g_pVBoxUSBMonSolarisState, sizeof(vboxusbmon_state_t), 1); if (!rc) { rc = mod_install(&g_VBoxUSBMonSolarisModLinkage); if (!rc) return rc; LogRel((DEVICE_NAME ":mod_install failed! rc=%d\n", rc)); ddi_soft_state_fini(&g_pVBoxUSBMonSolarisState); } else LogRel((DEVICE_NAME ":ddi_soft_state_init failed! rc=%d\n", rc)); } else LogRel((DEVICE_NAME ":VBoxUSBFilterInit failed! rc=%d\n", rc)); mutex_destroy(&g_VBoxUSBMonSolarisMtx); RTR0Term(); } else LogRel((DEVICE_NAME ":RTR0Init failed! rc=%d\n", rc)); return -1; }
int _fini(void) { LogFunc((DEVICE_NAME ":_fini\n")); /* * Undo the work done during start (in reverse order). */ RTR0Term(); return mod_remove(&g_VBoxNetAdpSolarisModLinkage); }
/** * 32-bit Ring-0 initialization. * * @returns 0 on success, non-zero on failure. * @param pszArgs Pointer to the device arguments. */ DECLASM(int) VBoxDrvInit(const char *pszArgs) { /* * Initialize the runtime. */ int rc = RTR0Init(0); if (RT_SUCCESS(rc)) { Log(("VBoxDrvInit: pszArgs=%s\n", pszArgs)); /* * Initialize the device extension. */ rc = supdrvInitDevExt(&g_DevExt, sizeof(SUPDRVSESSION)); if (RT_SUCCESS(rc)) { /* * Initialize the session hash table. */ rc = RTSpinlockCreate(&g_Spinlock, RTSPINLOCK_FLAGS_INTERRUPT_SAFE, "VBoxDrvOS2"); if (RT_SUCCESS(rc)) { /* * Process the commandline. Later. */ bool fVerbose = true; /* * Success */ if (fVerbose) { strcpy(&g_szInitText[0], "\r\n" "VirtualBox.org Support Driver for OS/2 version " VBOX_VERSION_STRING "\r\n" "Copyright (C) 2007 Knut St. Osmundsen\r\n" "Copyright (C) 2007 Oracle Corporation\r\n"); g_cchInitText = strlen(&g_szInitText[0]); } return VINF_SUCCESS; } g_cchInitText = RTStrPrintf(&g_szInitText[0], g_cchInitTextMax, "VBoxDrv.sys: RTSpinlockCreate failed, rc=%Rrc\n", rc); supdrvDeleteDevExt(&g_DevExt); } else g_cchInitText = RTStrPrintf(&g_szInitText[0], g_cchInitTextMax, "VBoxDrv.sys: supdrvInitDevExt failed, rc=%Rrc\n", rc); RTR0Term(); } else g_cchInitText = RTStrPrintf(&g_szInitText[0], g_cchInitTextMax, "VBoxDrv.sys: RTR0Init failed, rc=%Rrc\n", rc); return rc; }
int _fini(void) { int rc; LogFlowFunc((VIRTIOLOGNAME ":_fini\n")); rc = mod_remove(&g_VirtioNetModLinkage); if (!rc) { mac_fini_ops(&g_VirtioNetDevOps); RTR0Term(); } return rc; }
/** * Stop the kernel module. */ static kern_return_t VBoxNetAdpDarwinStop(struct kmod_info *pKModInfo, void *pvData) { Log(("VBoxNetAdpDarwinStop\n")); vboxNetAdpShutdown(); /* Remove control device */ devfs_remove(g_hCtlDev); cdevsw_remove(g_nCtlDev, &g_ChDev); RTR0Term(); return KMOD_RETURN_SUCCESS; }
int _fini(void) { LogFlow((DEVICE_NAME ":_fini\n")); int rc = mod_remove(&g_VBoxGuestSolarisModLinkage); if (!rc) ddi_soft_state_fini(&g_pVBoxGuestSolarisState); RTLogDestroy(RTLogRelSetDefaultInstance(NULL)); RTLogDestroy(RTLogSetDefaultInstance(NULL)); RTR0Term(); return rc; }
VOID VBoxDrvUnload(IN PDRIVER_OBJECT Driver) { NOREF(Driver); PAGED_CODE(); LOGF_ENTER(); NTSTATUS tmpStatus = VBoxNewProtTerm(); if (!NT_SUCCESS(tmpStatus)) { WARN(("VBoxNewProtTerm failed Status (0x%x)", tmpStatus)); } RTR0Term(); }
/** * Unload the module. * * @todo We have to prevent this if we're busy! */ static void __exit VBoxNetAdpLinuxUnload(void) { Log(("VBoxNetAdpLinuxUnload\n")); /* * Undo the work done during start (in reverse order). */ vboxNetAdpShutdown(); /* Remove control device */ misc_deregister(&g_CtlDev); RTR0Term(); Log(("VBoxNetAdpLinuxUnload - done\n")); }
/** * Stop the kernel module. */ static kern_return_t vboxSfDwnModuleUnload(struct kmod_info *pKModInfo, void *pvData) { RT_NOREF(pKModInfo, pvData); #ifdef DEBUG printf("vboxSfDwnModuleUnload\n"); RTLogBackdoorPrintf("vboxSfDwnModuleUnload\n"); #endif /* * Are we busy? If so fail. Otherwise try deregister the file system. */ if (g_cVBoxSfMounts > 0) { LogRel(("VBoxSF: Refusing to unload with %u active mounts\n", g_cVBoxSfMounts)); return KERN_NO_ACCESS; } if (g_pVBoxSfVfsTableEntry) { int rc = vfs_fsremove(g_pVBoxSfVfsTableEntry); if (rc != 0) { LogRel(("VBoxSF: vfs_fsremove failed: %d\n", rc)); return KERN_NO_ACCESS; } } /* * Disconnect and terminate libraries we're using. */ if (g_SfClientDarwin.handle != NULL) { VbglR0SfDisconnect(&g_SfClientDarwin); g_SfClientDarwin.handle = NULL; } if (g_pVBoxGuest) { g_pVBoxGuest->release(); g_pVBoxGuest = NULL; } VbglR0SfTerm(); RTR0Term(); return KERN_SUCCESS; }
/** * Start the kernel module. */ static kern_return_t VBoxNetAdpDarwinStart(struct kmod_info *pKModInfo, void *pvData) { int rc; /* * Initialize IPRT and find our module tag id. * (IPRT is shared with VBoxDrv, it creates the loggers.) */ rc = RTR0Init(0); if (RT_SUCCESS(rc)) { Log(("VBoxNetAdpDarwinStart\n")); rc = vboxNetAdpInit(); if (RT_SUCCESS(rc)) { g_nCtlDev = cdevsw_add(-1, &g_ChDev); if (g_nCtlDev < 0) { LogRel(("VBoxAdp: failed to register control device.")); rc = VERR_CANT_CREATE; } else { g_hCtlDev = devfs_make_node(makedev(g_nCtlDev, 0), DEVFS_CHAR, UID_ROOT, GID_WHEEL, 0600, VBOXNETADP_CTL_DEV_NAME); if (!g_hCtlDev) { LogRel(("VBoxAdp: failed to create FS node for control device.")); rc = VERR_CANT_CREATE; } } } if (RT_SUCCESS(rc)) { LogRel(("VBoxAdpDrv: version " VBOX_VERSION_STRING " r%d\n", VBOX_SVN_REV)); return KMOD_RETURN_SUCCESS; } LogRel(("VBoxAdpDrv: failed to initialize device extension (rc=%d)\n", rc)); RTR0Term(); } else printf("VBoxAdpDrv: failed to initialize IPRT (rc=%d)\n", rc); return KMOD_RETURN_FAILURE; }
int _fini(void) { int rc; LogFunc((DEVICE_NAME ":_fini\n")); rc = mod_remove(&g_VBoxUSBMonSolarisModLinkage); if (!rc) { ddi_soft_state_fini(&g_pVBoxUSBMonSolarisState); VBoxUSBFilterTerm(); mutex_destroy(&g_VBoxUSBMonSolarisMtx); RTR0Term(); } return rc; }
/** * Unload the module. */ static void __exit vboxguestLinuxModExit(void) { /* * Inverse order of init. */ vboxguestLinuxTermDeviceNodes(); #ifdef VBOXGUEST_WITH_INPUT_DRIVER vboxguestLinuxTermInputDevice(); #endif VbgdCommonCloseSession(&g_DevExt, g_pKernelSession); VbgdCommonDeleteDevExt(&g_DevExt); vboxguestLinuxTermISR(); pci_unregister_driver(&g_PciDriver); RTLogDestroy(RTLogRelSetDefaultInstance(NULL)); RTLogDestroy(RTLogSetDefaultInstance(NULL)); RTR0Term(); }
/** * Unload the module. */ static void __exit VBoxPciLinuxUnload(void) { LogRel(("VBoxPciLinuxLinuxUnload\n")); /* * Undo the work done during start (in reverse order). */ vboxPciShutdown(&g_VBoxPciGlobals); RTR0Term(); if (g_VBoxPciGlobals.pciStubModule) { module_put(g_VBoxPciGlobals.pciStubModule); g_VBoxPciGlobals.pciStubModule = NULL; } Log(("VBoxPciLinuxUnload - done\n")); }
/** * Module event handler, called from netgraph subsystem. */ static int vboxnetflt_modevent(struct module *pMod, int enmEventType, void *pvArg) { int rc; Log(("VBoxNetFltFreeBSDModuleEvent\n")); switch (enmEventType) { case MOD_LOAD: rc = RTR0Init(0); if (RT_FAILURE(rc)) { printf("RTR0Init failed %d\n", rc); return RTErrConvertToErrno(rc); } memset(&g_VBoxNetFltGlobals, 0, sizeof(VBOXNETFLTGLOBALS)); rc = vboxNetFltInitGlobalsAndIdc(&g_VBoxNetFltGlobals); if (RT_FAILURE(rc)) { printf("vboxNetFltInitGlobalsAndIdc failed %d\n", rc); return RTErrConvertToErrno(rc); } /* No MODULE_VERSION in ng_ether so we can't MODULE_DEPEND it */ kern_kldload(curthread, "ng_ether", NULL); break; case MOD_UNLOAD: rc = vboxNetFltTryDeleteIdcAndGlobals(&g_VBoxNetFltGlobals); memset(&g_VBoxNetFltGlobals, 0, sizeof(VBOXNETFLTGLOBALS)); RTR0Term(); break; case MOD_SHUTDOWN: case MOD_QUIESCE: default: return EOPNOTSUPP; } if (RT_SUCCESS(rc)) return 0; return RTErrConvertToErrno(rc); }
static int VBoxDrvFreeBSDLoad(void) { g_cUsers = 0; /* * Initialize the runtime. */ int rc = RTR0Init(0); if (RT_SUCCESS(rc)) { Log(("VBoxDrvFreeBSDLoad:\n")); /* * Initialize the device extension. */ rc = supdrvInitDevExt(&g_VBoxDrvFreeBSDDevExt, sizeof(SUPDRVSESSION)); if (RT_SUCCESS(rc)) { /* * Configure device cloning. */ clone_setup(&g_pVBoxDrvFreeBSDClones); g_VBoxDrvFreeBSDEHTag = EVENTHANDLER_REGISTER(dev_clone, VBoxDrvFreeBSDClone, 0, 1000); if (g_VBoxDrvFreeBSDEHTag) { Log(("VBoxDrvFreeBSDLoad: returns successfully\n")); return VINF_SUCCESS; } printf("vboxdrv: EVENTHANDLER_REGISTER(dev_clone,,,) failed\n"); clone_cleanup(&g_pVBoxDrvFreeBSDClones); rc = VERR_ALREADY_LOADED; supdrvDeleteDevExt(&g_VBoxDrvFreeBSDDevExt); } else printf("vboxdrv: supdrvInitDevExt failed, rc=%d\n", rc); RTR0Term(); } else printf("vboxdrv: RTR0Init failed, rc=%d\n", rc); return rc; }
/** * Start the kernel module. */ static kern_return_t VBoxNetFltDarwinStart(struct kmod_info *pKModInfo, void *pvData) { int rc; /* * Initialize IPRT and find our module tag id. * (IPRT is shared with VBoxDrv, it creates the loggers.) */ rc = RTR0Init(0); if (RT_SUCCESS(rc)) { Log(("VBoxNetFltDarwinStart\n")); errno_t err = mbuf_tag_id_find("org.VirtualBox.kext.VBoxFltDrv", &g_idTag); if (!err) { /* * Initialize the globals and connect to the support driver. * * This will call back vboxNetFltOsOpenSupDrv (and maybe vboxNetFltOsCloseSupDrv) * for establishing the connect to the support driver. */ memset(&g_VBoxNetFltGlobals, 0, sizeof(g_VBoxNetFltGlobals)); rc = vboxNetFltInitGlobalsAndIdc(&g_VBoxNetFltGlobals); if (RT_SUCCESS(rc)) { LogRel(("VBoxFltDrv: version " VBOX_VERSION_STRING " r%d\n", VBOX_SVN_REV)); return KMOD_RETURN_SUCCESS; } LogRel(("VBoxFltDrv: failed to initialize device extension (rc=%d)\n", rc)); } else LogRel(("VBoxFltDrv: mbuf_tag_id_find failed, err=%d\n", err)); RTR0Term(); } else printf("VBoxFltDrv: failed to initialize IPRT (rc=%d)\n", rc); memset(&g_VBoxNetFltGlobals, 0, sizeof(g_VBoxNetFltGlobals)); return KMOD_RETURN_FAILURE; }
/** * Unload the driver. * * @param pDrvObj Driver object. */ void _stdcall VBoxDrvNtUnload(PDRIVER_OBJECT pDrvObj) { PSUPDRVDEVEXT pDevExt = (PSUPDRVDEVEXT)g_pDevObjSys->DeviceExtension; Log(("VBoxDrvNtUnload at irql %d\n", KeGetCurrentIrql())); /* Clean up the power callback registration. */ if (pDevExt->hPowerCallback) ExUnregisterCallback(pDevExt->hPowerCallback); if (pDevExt->pObjPowerCallback) ObDereferenceObject(pDevExt->pObjPowerCallback); /* * We ASSUME that it's not possible to unload a driver with open handles. */ supdrvDeleteDevExt(pDevExt); RTR0Term(); vboxdrvNtDestroyDevices(); NOREF(pDrvObj); }
/** * Unload the module. * * @todo We have to prevent this if we're busy! */ static void __exit VBoxNetAdpLinuxUnload(void) { int rc; Log(("VBoxNetAdpLinuxUnload\n")); /* * Undo the work done during start (in reverse order). */ vboxNetAdpShutdown(); /* Remove control device */ rc = misc_deregister(&g_CtlDev); if (rc < 0) { printk(KERN_ERR "misc_deregister failed with rc=%x\n", rc); } RTR0Term(); Log(("VBoxNetAdpLinuxUnload - done\n")); }
static int VBoxDrvFreeBSDUnload(void) { Log(("VBoxDrvFreeBSDUnload:\n")); if (g_cUsers > 0) return EBUSY; /* * Reserve what we did in VBoxDrvFreeBSDInit. */ EVENTHANDLER_DEREGISTER(dev_clone, g_VBoxDrvFreeBSDEHTag); clone_cleanup(&g_pVBoxDrvFreeBSDClones); supdrvDeleteDevExt(&g_VBoxDrvFreeBSDDevExt); RTR0Term(); memset(&g_VBoxDrvFreeBSDDevExt, 0, sizeof(g_VBoxDrvFreeBSDDevExt)); Log(("VBoxDrvFreeBSDUnload: returns\n")); return VINF_SUCCESS; }
/** * Kernel entry points */ int _init(void) { LogFlowFunc((VIRTIOLOGNAME ":_init\n")); /* * Prevent module autounloading. */ modctl_t *pModCtl = mod_getctl(&g_VirtioNetModLinkage); if (pModCtl) pModCtl->mod_loadflags |= MOD_NOAUTOUNLOAD; else LogRel((VIRTIOLOGNAME ":failed to disable autounloading!\n")); /* * Initialize IPRT. */ int rc = RTR0Init(0); if (RT_SUCCESS(rc)) { /* * Initialize Solaris specific globals here. */ mac_init_ops(&g_VirtioNetDevOps, DEVICE_NAME); rc = mod_install(&g_VirtioNetModLinkage); if (!rc) return rc; LogRel((VIRTIOLOGNAME ":mod_install failed. rc=%d\n", rc)); mac_fini_ops(&g_VirtioNetDevOps); RTR0Term(); return rc; } else LogRel((VIRTIOLOGNAME ":failed to initialize IPRT (rc=%d)\n", rc)); return RTErrConvertToErrno(rc); }
RT_C_DECLS_END /** * Driver entry point. * * @returns appropriate status code. * @param pDrvObj Pointer to driver object. * @param pRegPath Registry base path. */ ULONG _stdcall DriverEntry(PDRIVER_OBJECT pDrvObj, PUNICODE_STRING pRegPath) { NTSTATUS rc; /* * Create device. * (That means creating a device object and a symbolic link so the DOS * subsystems (OS/2, win32, ++) can access the device.) */ UNICODE_STRING DevName; RtlInitUnicodeString(&DevName, DEVICE_NAME_NT); PDEVICE_OBJECT pDevObj; rc = IoCreateDevice(pDrvObj, sizeof(SUPDRVDEVEXT), &DevName, FILE_DEVICE_UNKNOWN, 0, FALSE, &pDevObj); if (NT_SUCCESS(rc)) { UNICODE_STRING DosName; RtlInitUnicodeString(&DosName, DEVICE_NAME_DOS); rc = IoCreateSymbolicLink(&DosName, &DevName); if (NT_SUCCESS(rc)) { int vrc = RTR0Init(0); if (RT_SUCCESS(vrc)) { Log(("VBoxDrv::DriverEntry\n")); /* * Initialize the device extension. */ PSUPDRVDEVEXT pDevExt = (PSUPDRVDEVEXT)pDevObj->DeviceExtension; memset(pDevExt, 0, sizeof(*pDevExt)); vrc = supdrvInitDevExt(pDevExt, sizeof(SUPDRVSESSION)); if (!vrc) { /* * Setup the driver entry points in pDrvObj. */ pDrvObj->DriverUnload = VBoxDrvNtUnload; pDrvObj->MajorFunction[IRP_MJ_CREATE] = VBoxDrvNtCreate; pDrvObj->MajorFunction[IRP_MJ_CLEANUP] = VBoxDrvNtCleanup; pDrvObj->MajorFunction[IRP_MJ_CLOSE] = VBoxDrvNtClose; pDrvObj->MajorFunction[IRP_MJ_DEVICE_CONTROL] = VBoxDrvNtDeviceControl; pDrvObj->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] = VBoxDrvNtInternalDeviceControl; pDrvObj->MajorFunction[IRP_MJ_READ] = VBoxDrvNtNotSupportedStub; pDrvObj->MajorFunction[IRP_MJ_WRITE] = VBoxDrvNtNotSupportedStub; /* more? */ /* Register ourselves for power state changes. */ UNICODE_STRING CallbackName; OBJECT_ATTRIBUTES Attr; RtlInitUnicodeString(&CallbackName, L"\\Callback\\PowerState"); InitializeObjectAttributes(&Attr, &CallbackName, OBJ_CASE_INSENSITIVE, NULL, NULL); rc = ExCreateCallback(&pDevExt->pObjPowerCallback, &Attr, TRUE, TRUE); if (rc == STATUS_SUCCESS) pDevExt->hPowerCallback = ExRegisterCallback(pDevExt->pObjPowerCallback, VBoxPowerDispatchCallback, pDevObj); Log(("VBoxDrv::DriverEntry returning STATUS_SUCCESS\n")); return STATUS_SUCCESS; } Log(("supdrvInitDevExit failed with vrc=%d!\n", vrc)); rc = VBoxDrvNtErr2NtStatus(vrc); IoDeleteSymbolicLink(&DosName); RTR0Term(); } else { Log(("RTR0Init failed with vrc=%d!\n", vrc)); rc = VBoxDrvNtErr2NtStatus(vrc); } } else Log(("IoCreateSymbolicLink failed with rc=%#x!\n", rc)); IoDeleteDevice(pDevObj); } else Log(("IoCreateDevice failed with rc=%#x!\n", rc)); if (NT_SUCCESS(rc)) rc = STATUS_INVALID_PARAMETER; Log(("VBoxDrv::DriverEntry returning %#x\n", rc)); return rc; }
/** * Initialize module. * * @returns appropriate status code. */ static int __init vboxguestLinuxModInit(void) { static const char * const s_apszGroups[] = VBOX_LOGGROUP_NAMES; PRTLOGGER pRelLogger; int rc; /* * Initialize IPRT first. */ rc = RTR0Init(0); if (RT_FAILURE(rc)) { printk(KERN_ERR DEVICE_NAME ": RTR0Init failed, rc=%d.\n", rc); return -EINVAL; } /* * Create the release log. * (We do that here instead of common code because we want to log * early failures using the LogRel macro.) */ rc = RTLogCreate(&pRelLogger, 0 /* fFlags */, "all", "VBOX_RELEASE_LOG", RT_ELEMENTS(s_apszGroups), s_apszGroups, RTLOGDEST_STDOUT | RTLOGDEST_DEBUGGER | RTLOGDEST_USER, NULL); if (RT_SUCCESS(rc)) { #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0) RTLogGroupSettings(pRelLogger, g_szLogGrp); RTLogFlags(pRelLogger, g_szLogFlags); RTLogDestinations(pRelLogger, g_szLogDst); #endif RTLogRelSetDefaultInstance(pRelLogger); } #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0) g_fLoggerCreated = true; #endif /* * Locate and initialize the PCI device. */ rc = pci_register_driver(&g_PciDriver); if (rc >= 0 && g_pPciDev) { /* * Register the interrupt service routine for it. */ rc = vboxguestLinuxInitISR(); if (rc >= 0) { /* * Call the common device extension initializer. */ #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0) && defined(RT_ARCH_X86) VBOXOSTYPE enmOSType = VBOXOSTYPE_Linux26; #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0) && defined(RT_ARCH_AMD64) VBOXOSTYPE enmOSType = VBOXOSTYPE_Linux26_x64; #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 0) && defined(RT_ARCH_X86) VBOXOSTYPE enmOSType = VBOXOSTYPE_Linux24; #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 0) && defined(RT_ARCH_AMD64) VBOXOSTYPE enmOSType = VBOXOSTYPE_Linux24_x64; #else # warning "huh? which arch + version is this?" VBOXOSTYPE enmOsType = VBOXOSTYPE_Linux; #endif rc = VbgdCommonInitDevExt(&g_DevExt, g_IOPortBase, g_pvMMIOBase, g_cbMMIO, enmOSType, VMMDEV_EVENT_MOUSE_POSITION_CHANGED); if (RT_SUCCESS(rc)) { /* * Create the kernel session for this driver. */ rc = VbgdCommonCreateKernelSession(&g_DevExt, &g_pKernelSession); if (RT_SUCCESS(rc)) { /* * Create the kernel input device. */ #ifdef VBOXGUEST_WITH_INPUT_DRIVER rc = vboxguestLinuxCreateInputDevice(); if (rc >= 0) { #endif /* * Finally, create the device nodes. */ rc = vboxguestLinuxInitDeviceNodes(); if (rc >= 0) { /* some useful information for the user but don't show this on the console */ LogRel((DEVICE_NAME ": misc device minor %d, IRQ %d, I/O port %RTiop, MMIO at %RHp (size 0x%x)\n", g_MiscDevice.minor, g_pPciDev->irq, g_IOPortBase, g_MMIOPhysAddr, g_cbMMIO)); printk(KERN_DEBUG DEVICE_NAME ": Successfully loaded version " VBOX_VERSION_STRING " (interface " RT_XSTR(VMMDEV_VERSION) ")\n"); return rc; } /* bail out */ #ifdef VBOXGUEST_WITH_INPUT_DRIVER vboxguestLinuxTermInputDevice(); } else { LogRel((DEVICE_NAME ": vboxguestCreateInputDevice failed with rc=%Rrc\n", rc)); rc = RTErrConvertFromErrno(rc); } #endif VbgdCommonCloseSession(&g_DevExt, g_pKernelSession); } VbgdCommonDeleteDevExt(&g_DevExt); } else { LogRel((DEVICE_NAME ": VbgdCommonInitDevExt failed with rc=%Rrc\n", rc)); rc = RTErrConvertFromErrno(rc); } vboxguestLinuxTermISR(); } } else { LogRel((DEVICE_NAME ": PCI device not found, probably running on physical hardware.\n")); rc = -ENODEV; } pci_unregister_driver(&g_PciDriver); RTLogDestroy(RTLogRelSetDefaultInstance(NULL)); RTLogDestroy(RTLogSetDefaultInstance(NULL)); RTR0Term(); return rc; }
static int vgdrvFreeBSDAttach(device_t pDevice) { int rc; int iResId; struct VBoxGuestDeviceState *pState; cUsers = 0; /* * Initialize IPRT R0 driver, which internally calls OS-specific r0 init. */ rc = RTR0Init(0); if (RT_FAILURE(rc)) { LogFunc(("RTR0Init failed.\n")); return ENXIO; } pState = device_get_softc(pDevice); /* * Allocate I/O port resource. */ iResId = PCIR_BAR(0); pState->pIOPortRes = bus_alloc_resource_any(pDevice, SYS_RES_IOPORT, &iResId, RF_ACTIVE); pState->uIOPortBase = rman_get_start(pState->pIOPortRes); pState->iIOPortResId = iResId; if (pState->uIOPortBase) { /* * Map the MMIO region. */ iResId = PCIR_BAR(1); pState->pVMMDevMemRes = bus_alloc_resource_any(pDevice, SYS_RES_MEMORY, &iResId, RF_ACTIVE); pState->VMMDevMemHandle = rman_get_bushandle(pState->pVMMDevMemRes); pState->VMMDevMemSize = rman_get_size(pState->pVMMDevMemRes); pState->pMMIOBase = rman_get_virtual(pState->pVMMDevMemRes); pState->iVMMDevMemResId = iResId; if (pState->pMMIOBase) { /* * Call the common device extension initializer. */ rc = VGDrvCommonInitDevExt(&g_DevExt, pState->uIOPortBase, pState->pMMIOBase, pState->VMMDevMemSize, #if ARCH_BITS == 64 VBOXOSTYPE_FreeBSD_x64, #else VBOXOSTYPE_FreeBSD, #endif VMMDEV_EVENT_MOUSE_POSITION_CHANGED); if (RT_SUCCESS(rc)) { /* * Add IRQ of VMMDev. */ rc = vgdrvFreeBSDAddIRQ(pDevice, pState); if (RT_SUCCESS(rc)) { /* * Read host configuration. */ VGDrvCommonProcessOptionsFromHost(&g_DevExt); /* * Configure device cloning. */ clone_setup(&g_pvgdrvFreeBSDClones); g_vgdrvFreeBSDEHTag = EVENTHANDLER_REGISTER(dev_clone, vgdrvFreeBSDClone, 0, 1000); if (g_vgdrvFreeBSDEHTag) { printf(DEVICE_NAME ": loaded successfully\n"); return 0; } printf(DEVICE_NAME ": EVENTHANDLER_REGISTER(dev_clone,,,) failed\n"); clone_cleanup(&g_pvgdrvFreeBSDClones); vgdrvFreeBSDRemoveIRQ(pDevice, pState); } else printf((DEVICE_NAME ": VGDrvCommonInitDevExt failed.\n")); VGDrvCommonDeleteDevExt(&g_DevExt); } else printf((DEVICE_NAME ": vgdrvFreeBSDAddIRQ failed.\n")); } else printf((DEVICE_NAME ": MMIO region setup failed.\n")); } else printf((DEVICE_NAME ": IOport setup failed.\n")); RTR0Term(); return ENXIO; }