/** * User context entry points */ static int VBoxGuestSolarisOpen(dev_t *pDev, int fFlag, int fType, cred_t *pCred) { int rc; PVBOXGUESTSESSION pSession = NULL; LogFlow((DEVICE_NAME "::Open\n")); /* * Verify we are being opened as a character device. */ if (fType != OTYP_CHR) return EINVAL; vboxguest_state_t *pState = NULL; unsigned iOpenInstance; for (iOpenInstance = 0; iOpenInstance < 4096; iOpenInstance++) { if ( !ddi_get_soft_state(g_pVBoxGuestSolarisState, iOpenInstance) /* faster */ && ddi_soft_state_zalloc(g_pVBoxGuestSolarisState, iOpenInstance) == DDI_SUCCESS) { pState = ddi_get_soft_state(g_pVBoxGuestSolarisState, iOpenInstance); break; } } if (!pState) { Log((DEVICE_NAME "::Open: too many open instances.")); return ENXIO; } /* * Create a new session. */ rc = VBoxGuestCreateUserSession(&g_DevExt, &pSession); if (RT_SUCCESS(rc)) { pState->pvProcRef = proc_ref(); pState->pSession = pSession; *pDev = makedevice(getmajor(*pDev), iOpenInstance); Log((DEVICE_NAME "::Open: pSession=%p pState=%p pid=%d\n", pSession, pState, (int)RTProcSelf())); return 0; } /* Failed, clean up. */ ddi_soft_state_free(g_pVBoxGuestSolarisState, iOpenInstance); LogRel((DEVICE_NAME "::Open: VBoxGuestCreateUserSession failed. rc=%d\n", rc)); return EFAULT; }
/** * Device open. Called on open /dev/vboxdrv * * @param pInode Pointer to inode info structure. * @param pFilp Associated file pointer. */ static int vboxguestLinuxOpen(struct inode *pInode, struct file *pFilp) { int rc; PVBOXGUESTSESSION pSession; Log((DEVICE_NAME ": pFilp=%p pid=%d/%d %s\n", pFilp, RTProcSelf(), current->pid, current->comm)); /* * Call common code to create the user session. Associate it with * the file so we can access it in the other methods. */ rc = VBoxGuestCreateUserSession(&g_DevExt, &pSession); if (RT_SUCCESS(rc)) pFilp->private_data = pSession; Log(("vboxguestLinuxOpen: g_DevExt=%p pSession=%p rc=%d/%d (pid=%d/%d %s)\n", &g_DevExt, pSession, rc, vboxguestLinuxConvertToNegErrno(rc), RTProcSelf(), current->pid, current->comm)); return vboxguestLinuxConvertToNegErrno(rc); }
/** * Driver open hook. * * @param name The name of the device as returned by publish_devices. * @param flags Open flags. * @param cookie Where to store the session pointer. * * @return Haiku status code. */ static status_t VBoxGuestHaikuOpen(const char *name, uint32 flags, void **cookie) { int rc; PVBOXGUESTSESSION pSession; LogFlow((DRIVER_NAME ":VBoxGuestHaikuOpen\n")); /* * Create a new session. */ rc = VBoxGuestCreateUserSession(&g_DevExt, &pSession); if (RT_SUCCESS(rc)) { Log((DRIVER_NAME ":VBoxGuestHaikuOpen success: g_DevExt=%p pSession=%p rc=%d pid=%d\n",&g_DevExt, pSession, rc,(int)RTProcSelf())); ASMAtomicIncU32(&cUsers); *cookie = pSession; return B_OK; } LogRel((DRIVER_NAME ":VBoxGuestHaikuOpen: failed. rc=%d\n", rc)); return RTErrConvertToErrno(rc); }
/** * Create (i.e. Open) file entry point. * * @param pDevObj Device object. * @param pIrp Request packet. */ static NTSTATUS vboxguestwinCreate(PDEVICE_OBJECT pDevObj, PIRP pIrp) { /** @todo AssertPtrReturn(pIrp); */ PIO_STACK_LOCATION pStack = IoGetCurrentIrpStackLocation(pIrp); /** @todo AssertPtrReturn(pStack); */ PFILE_OBJECT pFileObj = pStack->FileObject; PVBOXGUESTDEVEXT pDevExt = (PVBOXGUESTDEVEXT)pDevObj->DeviceExtension; NTSTATUS rc = STATUS_SUCCESS; if (pDevExt->win.s.devState != WORKING) { Log(("VBoxGuest::vboxguestwinGuestCreate: device is not working currently: %d!\n", pDevExt->win.s.devState)); rc = STATUS_UNSUCCESSFUL; } else if (pStack->Parameters.Create.Options & FILE_DIRECTORY_FILE) { /* * We are not remotely similar to a directory... * (But this is possible.) */ Log(("VBoxGuest::vboxguestwinGuestCreate: Uhm, we're not a directory!\n")); rc = STATUS_NOT_A_DIRECTORY; } else { #ifdef VBOX_WITH_HGCM if (pFileObj) { Log(("VBoxGuest::vboxguestwinGuestCreate: File object type = %d\n", pFileObj->Type)); int vrc; PVBOXGUESTSESSION pSession; if (pFileObj->Type == 5 /* File Object */) { /* * Create a session object if we have a valid file object. This session object * exists for every R3 process. */ vrc = VBoxGuestCreateUserSession(pDevExt, &pSession); } else { /* ... otherwise we've been called from R0! */ vrc = VBoxGuestCreateKernelSession(pDevExt, &pSession); } if (RT_SUCCESS(vrc)) pFileObj->FsContext = pSession; } #endif } /* Complete the request! */ pIrp->IoStatus.Information = 0; pIrp->IoStatus.Status = rc; IoCompleteRequest(pIrp, IO_NO_INCREMENT); Log(("VBoxGuest::vboxguestwinGuestCreate: Returning 0x%x\n", rc)); return rc; }