/** * The SUPDRV IDC entry point. * * @returns VBox status code, see supdrvIDC. * @param iReq The request code. * @param pReq The request. */ int VBOXCALL SUPDrvSolarisIDC(uint32_t uReq, PSUPDRVIDCREQHDR pReq) { PSUPDRVSESSION pSession; /* * Some quick validations. */ if (RT_UNLIKELY(!VALID_PTR(pReq))) return VERR_INVALID_POINTER; pSession = pReq->pSession; if (pSession) { if (RT_UNLIKELY(!VALID_PTR(pSession))) return VERR_INVALID_PARAMETER; if (RT_UNLIKELY(pSession->pDevExt != &g_DevExt)) return VERR_INVALID_PARAMETER; } else if (RT_UNLIKELY(uReq != SUPDRV_IDC_REQ_CONNECT)) return VERR_INVALID_PARAMETER; /* * Do the job. */ return supdrvIDC(uReq, &g_DevExt, pSession, pReq); }
VBGLR3DECL(int) VbglR3GuestPropWait(uint32_t u32ClientId, const char *pszPatterns, void *pvBuf, uint32_t cbBuf, uint64_t u64Timestamp, uint32_t u32Timeout, char ** ppszName, char **ppszValue, uint64_t *pu64Timestamp, char **ppszFlags, uint32_t *pcbBufActual) { if (u32Timeout == RT_INDEFINITE_WAIT) RTPrintf("Called GET_NOTIFICATION, client %d, patterns %s, timestamp %llu,\n" " timeout RT_INDEFINITE_WAIT...\n", u32ClientId, pszPatterns, u64Timestamp); else RTPrintf("Called GET_NOTIFICATION, client %d, patterns %s, timestamp %llu,\n" " timeout %u...\n", u32ClientId, pszPatterns, u64Timestamp, u32Timeout); static char szName[] = "Name"; static char szValue[] = "Value"; static char szFlags[] = "TRANSIENT"; if (VALID_PTR(ppszName)) *ppszName = szName; if (VALID_PTR(ppszValue)) *ppszValue = szValue; if (VALID_PTR(pu64Timestamp)) *pu64Timestamp = 12345; if (VALID_PTR(ppszFlags)) *ppszFlags = szFlags; if (VALID_PTR(pcbBufActual)) *pcbBufActual = 256; return VINF_SUCCESS; }
RTR3DECL(int) RTFsQuerySerial(const char *pszFsPath, uint32_t *pu32Serial) { /* * Validate input. */ AssertMsgReturn(VALID_PTR(pszFsPath) && *pszFsPath, ("%p", pszFsPath), VERR_INVALID_PARAMETER); AssertMsgReturn(VALID_PTR(pu32Serial), ("%p", pu32Serial), VERR_INVALID_PARAMETER); /* * Convert the path and query the stats. * We're simply return the device id. */ char const *pszNativeFsPath; int rc = rtPathToNative(&pszNativeFsPath, pszFsPath, NULL); if (RT_SUCCESS(rc)) { struct stat Stat; if (!stat(pszNativeFsPath, &Stat)) { if (pu32Serial) *pu32Serial = (uint32_t)Stat.st_dev; } else rc = RTErrConvertFromErrno(errno); rtPathFreeNative(pszNativeFsPath, pszFsPath); } LogFlow(("RTFsQuerySerial(%p:{%s}, %p:{%RX32}: returns %Rrc\n", pszFsPath, pszFsPath, pu32Serial, pu32Serial ? *pu32Serial : 0, rc)); return rc; }
/** * Query the serial number of a filesystem. * * @returns iprt status code. * @param pszFsPath Path within the mounted filesystem. * @param pu32Serial Where to store the serial number. */ RTR3DECL(int) RTFsQuerySerial(const char *pszFsPath, uint32_t *pu32Serial) { /* * Validate & get valid root path. */ AssertMsgReturn(VALID_PTR(pszFsPath) && *pszFsPath, ("%p", pszFsPath), VERR_INVALID_PARAMETER); AssertMsgReturn(VALID_PTR(pu32Serial), ("%p", pu32Serial), VERR_INVALID_PARAMETER); PRTUTF16 pwszFsRoot; int rc = rtFsGetRoot(pszFsPath, &pwszFsRoot); if (RT_FAILURE(rc)) return rc; /* * Do work. */ DWORD dwMaxName; DWORD dwFlags; DWORD dwSerial; if (GetVolumeInformationW(pwszFsRoot, NULL, 0, &dwSerial, &dwMaxName, &dwFlags, NULL, 0)) *pu32Serial = dwSerial; else { DWORD Err = GetLastError(); rc = RTErrConvertFromWin32(Err); Log(("RTFsQuerySizes(%s,): GetDiskFreeSpaceEx failed with lasterr %d (%Rrc)\n", pszFsPath, Err, rc)); } RTUtf16Free(pwszFsRoot); return rc; }
DECLEXPORT(EGLBoolean) eglQueryContext(EGLDisplay hDisplay, EGLContext hContext, EGLint cAttribute, EGLint *pcValue) { Display *pDisplay = (Display *)hDisplay; if (!VALID_PTR(hDisplay)) return setEGLError(EGL_NOT_INITIALIZED); if (!VALID_PTR(pcValue)) return setEGLError(EGL_BAD_PARAMETER); switch (cAttribute) { case EGL_CONFIG_ID: { int cValue = 0; if (glXQueryContext(pDisplay, (GLXContext)hContext, GLX_FBCONFIG_ID, &cValue) == Success) { *pcValue = cValue; return clearEGLError(); } return setEGLError(EGL_BAD_MATCH); } case EGL_CONTEXT_CLIENT_TYPE: *pcValue = EGL_OPENGL_API; return clearEGLError(); case EGL_CONTEXT_CLIENT_VERSION: *pcValue = 0; return clearEGLError(); case EGL_RENDER_BUFFER: *pcValue = EGL_BACK_BUFFER; return clearEGLError(); default: return setEGLError(EGL_BAD_ATTRIBUTE); } }
STDMETHODIMP Session::AccessGuestProperty(IN_BSTR aName, IN_BSTR aValue, IN_BSTR aFlags, BOOL aIsSetter, BSTR *aRetValue, LONG64 *aRetTimestamp, BSTR *aRetFlags) { #ifdef VBOX_WITH_GUEST_PROPS AutoCaller autoCaller(this); AssertComRCReturn(autoCaller.rc(), autoCaller.rc()); if (mState != SessionState_Locked) return setError(VBOX_E_INVALID_VM_STATE, tr("Machine is not locked by session (session state: %s)."), Global::stringifySessionState(mState)); AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE); CheckComArgStrNotEmptyOrNull(aName); if (!aIsSetter && !VALID_PTR(aRetValue)) return E_POINTER; if (!aIsSetter && !VALID_PTR(aRetTimestamp)) return E_POINTER; if (!aIsSetter && !VALID_PTR(aRetFlags)) return E_POINTER; /* aValue can be NULL for a setter call if the property is to be deleted. */ if (aIsSetter && (aValue != NULL) && !VALID_PTR(aValue)) return E_INVALIDARG; /* aFlags can be null if it is to be left as is */ if (aIsSetter && (aFlags != NULL) && !VALID_PTR(aFlags)) return E_INVALIDARG; if (!aIsSetter) return mConsole->getGuestProperty(aName, aRetValue, aRetTimestamp, aRetFlags); else return mConsole->setGuestProperty(aName, aValue, aFlags); #else /* VBOX_WITH_GUEST_PROPS not defined */ ReturnComNotImplemented(); #endif /* VBOX_WITH_GUEST_PROPS not defined */ }
VBGLR3DECL(int) VbglR3GuestPropEnum(uint32_t u32ClientId, char const * const *ppaszPatterns, uint32_t cPatterns, PVBGLR3GUESTPROPENUM *ppHandle, char const **ppszName, char const **ppszValue, uint64_t *pu64Timestamp, char const **ppszFlags) { RTPrintf("Called ENUM_PROPS, client %d...\n", u32ClientId); AssertPtrReturn(ppHandle, VERR_INVALID_POINTER); static VBGLR3GUESTPROPENUM Handle = { 0 }; static char szName[] = "Name"; static char szValue[] = "Value"; static char szFlags[] = "TRANSIENT"; *ppHandle = &Handle; if (VALID_PTR(ppszName)) *ppszName = szName; if (VALID_PTR(ppszValue)) *ppszValue = szValue; if (VALID_PTR(pu64Timestamp)) *pu64Timestamp = 12345; if (VALID_PTR(ppszFlags)) *ppszFlags = szFlags; return VINF_SUCCESS; }
RTDECL(int) RTLatin1ToUtf16ExTag(const char *pszString, size_t cchString, PRTUTF16 *ppwsz, size_t cwc, size_t *pcwc, const char *pszTag) { /* * Validate input. */ Assert(VALID_PTR(pszString)); Assert(VALID_PTR(ppwsz)); Assert(!pcwc || VALID_PTR(pcwc)); /* * Validate the input and calculate the length of the UTF-16 string. */ size_t cwcResult; int rc = rtLatin1CalcUtf16Length(pszString, cchString, &cwcResult); if (RT_SUCCESS(rc)) { if (pcwc) *pcwc = cwcResult; /* * Check buffer size / Allocate buffer. */ bool fShouldFree; PRTUTF16 pwszResult; if (cwc > 0 && *ppwsz) { fShouldFree = false; if (cwc <= cwcResult) return VERR_BUFFER_OVERFLOW; pwszResult = *ppwsz; } else { *ppwsz = NULL; fShouldFree = true; cwc = RT_MAX(cwcResult + 1, cwc); pwszResult = (PRTUTF16)RTMemAllocTag(cwc * sizeof(RTUTF16), pszTag); } if (pwszResult) { /* * Encode the UTF-16 string. */ rc = rtLatin1RecodeAsUtf16(pszString, cchString, pwszResult, cwc - 1); if (RT_SUCCESS(rc)) { *ppwsz = pwszResult; return rc; } if (fShouldFree) RTMemFree(pwszResult); } else rc = VERR_NO_UTF16_MEMORY; } return rc; }
RT_C_DECLS_END # endif int vbglDriverOpen (VBGLDRIVER *pDriver) { # ifdef RT_OS_WINDOWS UNICODE_STRING uszDeviceName; RtlInitUnicodeString (&uszDeviceName, L"\\Device\\VBoxGuest"); PDEVICE_OBJECT pDeviceObject = NULL; PFILE_OBJECT pFileObject = NULL; NTSTATUS rc = IoGetDeviceObjectPointer (&uszDeviceName, FILE_ALL_ACCESS, &pFileObject, &pDeviceObject); if (NT_SUCCESS (rc)) { Log(("vbglDriverOpen VBoxGuest successful pDeviceObject=%x\n", pDeviceObject)); pDriver->pDeviceObject = pDeviceObject; pDriver->pFileObject = pFileObject; return VINF_SUCCESS; } /** @todo return RTErrConvertFromNtStatus(rc)! */ Log(("vbglDriverOpen VBoxGuest failed with ntstatus=%x\n", rc)); return rc; # elif defined (RT_OS_OS2) /* * Just check whether the connection was made or not. */ if ( g_VBoxGuestIDC.u32Version == VMMDEV_VERSION && VALID_PTR(g_VBoxGuestIDC.u32Session) && VALID_PTR(g_VBoxGuestIDC.pfnServiceEP)) { pDriver->u32Session = g_VBoxGuestIDC.u32Session; return VINF_SUCCESS; } pDriver->u32Session = UINT32_MAX; Log(("vbglDriverOpen: failed\n")); return VERR_FILE_NOT_FOUND; # else uint32_t u32VMMDevVersion; pDriver->pvOpaque = VBoxGuestIDCOpen (&u32VMMDevVersion); if ( pDriver->pvOpaque && u32VMMDevVersion == VMMDEV_VERSION) return VINF_SUCCESS; Log(("vbglDriverOpen: failed\n")); return VERR_FILE_NOT_FOUND; # endif }
RTDECL(int) RTFileCopyEx(const char *pszSrc, const char *pszDst, uint32_t fFlags, PFNRTPROGRESS pfnProgress, void *pvUser) { /* * Validate input. */ AssertMsgReturn(VALID_PTR(pszSrc), ("pszSrc=%p\n", pszSrc), VERR_INVALID_PARAMETER); AssertMsgReturn(*pszSrc, ("pszSrc=%p\n", pszSrc), VERR_INVALID_PARAMETER); AssertMsgReturn(VALID_PTR(pszDst), ("pszDst=%p\n", pszDst), VERR_INVALID_PARAMETER); AssertMsgReturn(*pszDst, ("pszDst=%p\n", pszDst), VERR_INVALID_PARAMETER); AssertMsgReturn(!pfnProgress || VALID_PTR(pfnProgress), ("pfnProgress=%p\n", pfnProgress), VERR_INVALID_PARAMETER); AssertMsgReturn(!(fFlags & ~RTFILECOPY_FLAGS_MASK), ("%#x\n", fFlags), VERR_INVALID_PARAMETER); /* * Open the files. */ RTFILE FileSrc; int rc = RTFileOpen(&FileSrc, pszSrc, RTFILE_O_READ | RTFILE_O_OPEN | (fFlags & RTFILECOPY_FLAGS_NO_SRC_DENY_WRITE ? RTFILE_O_DENY_NONE : RTFILE_O_DENY_WRITE)); if (RT_SUCCESS(rc)) { RTFILE FileDst; rc = RTFileOpen(&FileDst, pszDst, RTFILE_O_WRITE | RTFILE_O_CREATE | (fFlags & RTFILECOPY_FLAGS_NO_DST_DENY_WRITE ? RTFILE_O_DENY_NONE : RTFILE_O_DENY_WRITE)); if (RT_SUCCESS(rc)) { /* * Call the ByHandles version and let it do the job. */ rc = RTFileCopyByHandlesEx(FileSrc, FileDst, pfnProgress, pvUser); /* * Close the files regardless of the result. * Don't bother cleaning up or anything like that. */ int rc2 = RTFileClose(FileDst); AssertRC(rc2); if (RT_FAILURE(rc2) && RT_SUCCESS(rc)) rc = rc2; } int rc2 = RTFileClose(FileSrc); AssertRC(rc2); if (RT_FAILURE(rc2) && RT_SUCCESS(rc)) rc = rc2; } return rc; }
RTDECL(int) RTDirOpen(PRTDIR *ppDir, const char *pszPath) { /* * Validate input. */ AssertMsgReturn(VALID_PTR(ppDir), ("%p\n", ppDir), VERR_INVALID_POINTER); AssertMsgReturn(VALID_PTR(pszPath), ("%p\n", pszPath), VERR_INVALID_POINTER); /* * Take common cause with RTDirOpenFiltered(). */ int rc = rtDirOpenCommon(ppDir, pszPath, NULL, RTDIRFILTER_NONE); LogFlow(("RTDirOpen(%p:{%p}, %p:{%s}): return %Rrc\n", ppDir, *ppDir, pszPath, pszPath, rc)); return rc; }
STDMETHODIMP Session::AccessGuestProperty(IN_BSTR aName, IN_BSTR aValue, IN_BSTR aFlags, BOOL aIsSetter, BSTR *aRetValue, LONG64 *aRetTimestamp, BSTR *aRetFlags) { #ifdef VBOX_WITH_GUEST_PROPS # ifndef VBOX_COM_INPROC_API_CLIENT AutoCaller autoCaller(this); AssertComRCReturn(autoCaller.rc(), autoCaller.rc()); if (mState != SessionState_Locked) return setError(VBOX_E_INVALID_VM_STATE, tr("Machine is not locked by session (session state: %s)."), Global::stringifySessionState(mState)); AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE); CheckComArgStrNotEmptyOrNull(aName); if (!aIsSetter && !VALID_PTR(aRetValue)) return E_POINTER; if (!aIsSetter && !VALID_PTR(aRetTimestamp)) return E_POINTER; if (!aIsSetter && !VALID_PTR(aRetFlags)) return E_POINTER; /* aValue can be NULL for a setter call if the property is to be deleted. */ if (aIsSetter && (aValue != NULL) && !VALID_PTR(aValue)) return setError(E_INVALIDARG, tr("Invalid value pointer")); /* aFlags can be null if it is to be left as is */ if (aIsSetter && (aFlags != NULL) && !VALID_PTR(aFlags)) return setError(E_INVALIDARG, tr("Invalid flags pointer")); /* If this session is not in a VM process fend off the call. The caller * handles this correctly, by doing the operation in VBoxSVC. */ if (!mConsole) return E_ACCESSDENIED; if (!aIsSetter) return mConsole->getGuestProperty(aName, aRetValue, aRetTimestamp, aRetFlags); else return mConsole->setGuestProperty(aName, aValue, aFlags); # else /* VBOX_COM_INPROC_API_CLIENT */ /** @todo This is nonsense, non-VM API users shouldn't need to deal with this * method call, VBoxSVC should be clever enough to see that the * session doesn't have a console! */ return E_ACCESSDENIED; # endif /* VBOX_COM_INPROC_API_CLIENT */ #else /* VBOX_WITH_GUEST_PROPS */ ReturnComNotImplemented(); #endif /* VBOX_WITH_GUEST_PROPS */ }
DECLEXPORT(EGLSurface) eglCreateWindowSurface(EGLDisplay hDisplay, EGLConfig config, EGLNativeWindowType hWindow, const EGLint *paAttributes) { Display *pDisplay = (Display *)hDisplay; GLXWindow hGLXWindow; if (!VALID_PTR(hDisplay)) { setEGLError(EGL_NOT_INITIALIZED); return EGL_NO_SURFACE; } if (paAttributes != NULL) /* Sanity test only. */ while (*paAttributes != EGL_NONE) { if (*paAttributes != EGL_RENDER_BUFFER) { setEGLError(EGL_BAD_MATCH); return EGL_NO_SURFACE; } paAttributes += 2; } hGLXWindow = glXCreateWindow(pDisplay, (GLXFBConfig)config, (Window)hWindow, NULL); if (hGLXWindow == None) { setEGLError(EGL_BAD_ALLOC); return EGL_NO_SURFACE; } EGL_ASSERT(hGLXWindow < VBEGL_WINDOW_SURFACE); /* Greater than the maximum XID. */ clearEGLError(); return (EGLSurface)(hGLXWindow | VBEGL_WINDOW_SURFACE); }
DECLEXPORT(EGLContext) eglCreateContext(EGLDisplay hDisplay, EGLConfig hConfig, EGLContext hSharedContext, const EGLint *paAttribs) { Display *pDisplay = (Display *)hDisplay; GLXContext hNewContext; if (!VALID_PTR(hDisplay)) { setEGLError(EGL_NOT_INITIALIZED); return EGL_NO_CONTEXT; } if (paAttribs != NULL && *paAttribs != EGL_NONE) { setEGLError(EGL_BAD_ATTRIBUTE); return EGL_NO_CONTEXT; } hNewContext = glXCreateNewContext(pDisplay, (GLXFBConfig)hConfig, GLX_RGBA_TYPE, (GLXContext)hSharedContext, true); if (hNewContext) { clearEGLError(); return (EGLContext)hNewContext; } setEGLError(EGL_BAD_MATCH); return EGL_NO_CONTEXT; }
RTDECL(int) RTFileAioReqCancel(RTFILEAIOREQ hReq) { PRTFILEAIOREQINTERNAL pReqInt = hReq; RTFILEAIOREQ_VALID_RETURN(pReqInt); RTFILEAIOREQ_STATE_RETURN_RC(pReqInt, SUBMITTED, VERR_FILE_AIO_NOT_SUBMITTED); LNXKAIOIOEVENT AioEvent; int rc = rtFileAsyncIoLinuxCancel(pReqInt->AioContext, &pReqInt->AioCB, &AioEvent); if (RT_SUCCESS(rc)) { /* * Decrement request count because the request will never arrive at the * completion port. */ AssertMsg(VALID_PTR(pReqInt->pCtxInt), ("Invalid state. Request was canceled but wasn't submitted\n")); ASMAtomicDecS32(&pReqInt->pCtxInt->cRequests); pReqInt->Rc = VERR_FILE_AIO_CANCELED; RTFILEAIOREQ_SET_STATE(pReqInt, COMPLETED); return VINF_SUCCESS; } if (rc == VERR_TRY_AGAIN) return VERR_FILE_AIO_IN_PROGRESS; return rc; }
RTDECL(int) RTLdrGetSymbol(RTLDRMOD hLdrMod, const char *pszSymbol, void **ppvValue) { LogFlow(("RTLdrGetSymbol: hLdrMod=%RTldrm pszSymbol=%p:{%s} ppvValue=%p\n", hLdrMod, pszSymbol, pszSymbol, ppvValue)); /* * Validate input. */ AssertMsgReturn(rtldrIsValid(hLdrMod), ("hLdrMod=%p\n", hLdrMod), VERR_INVALID_HANDLE); AssertMsgReturn(pszSymbol, ("pszSymbol=%p\n", pszSymbol), VERR_INVALID_PARAMETER); AssertMsgReturn(VALID_PTR(ppvValue), ("ppvValue=%p\n", ppvValue), VERR_INVALID_PARAMETER); PRTLDRMODINTERNAL pMod = (PRTLDRMODINTERNAL)hLdrMod; //AssertMsgReturn(pMod->eState == LDR_STATE_OPENED, ("eState=%d\n", pMod->eState), VERR_WRONG_ORDER); /* * Do it. */ int rc; if (pMod->pOps->pfnGetSymbol) rc = pMod->pOps->pfnGetSymbol(pMod, pszSymbol, ppvValue); else { RTUINTPTR Value = 0; rc = pMod->pOps->pfnGetSymbolEx(pMod, NULL, 0, UINT32_MAX, pszSymbol, &Value); if (RT_SUCCESS(rc)) { *ppvValue = (void *)(uintptr_t)Value; if ((uintptr_t)*ppvValue != Value) rc = VERR_BUFFER_OVERFLOW; } } LogFlow(("RTLdrGetSymbol: return %Rrc *ppvValue=%p\n", rc, *ppvValue)); return rc; }
static int vgdrvFreeBSDPoll(struct cdev *pDev, int fEvents, struct thread *td) { int fEventsProcessed; LogFlow(("vgdrvFreeBSDPoll: fEvents=%d\n", fEvents)); PVBOXGUESTSESSION pSession = (PVBOXGUESTSESSION)pDev->si_drv1; if (RT_UNLIKELY(!VALID_PTR(pSession))) { Log(("vgdrvFreeBSDPoll: no state data for %s\n", devtoname(pDev))); return (fEvents & (POLLHUP|POLLIN|POLLRDNORM|POLLOUT|POLLWRNORM)); } uint32_t u32CurSeq = ASMAtomicUoReadU32(&g_DevExt.u32MousePosChangedSeq); if (pSession->u32MousePosChangedSeq != u32CurSeq) { fEventsProcessed = fEvents & (POLLIN | POLLRDNORM); pSession->u32MousePosChangedSeq = u32CurSeq; } else { fEventsProcessed = 0; selrecord(td, &g_SelInfo); } return fEventsProcessed; }
/** * EMT worker for DBGFR3BpEnum(). * * @returns VBox status code. * @param pVM The VM handle. * @param pfnCallback The callback function. * @param pvUser The user argument to pass to the callback. * @thread EMT * @internal */ static DECLCALLBACK(int) dbgfR3BpEnum(PVM pVM, PFNDBGFBPENUM pfnCallback, void *pvUser) { /* * Validate input. */ AssertMsgReturn(VALID_PTR(pfnCallback), ("pfnCallback=%p\n", pfnCallback), VERR_INVALID_POINTER); /* * Enumerate the hardware breakpoints. */ unsigned i; for (i = 0; i < RT_ELEMENTS(pVM->dbgf.s.aHwBreakpoints); i++) if (pVM->dbgf.s.aHwBreakpoints[i].enmType != DBGFBPTYPE_FREE) { int rc = pfnCallback(pVM, pvUser, &pVM->dbgf.s.aHwBreakpoints[i]); if (RT_FAILURE(rc)) return rc; } /* * Enumerate the other breakpoints. */ for (i = 0; i < RT_ELEMENTS(pVM->dbgf.s.aBreakpoints); i++) if (pVM->dbgf.s.aBreakpoints[i].enmType != DBGFBPTYPE_FREE) { int rc = pfnCallback(pVM, pvUser, &pVM->dbgf.s.aBreakpoints[i]); if (RT_FAILURE(rc)) return rc; } return VINF_SUCCESS; }
RTDECL(int) RTFileAioReqCancel(RTFILEAIOREQ hReq) { PRTFILEAIOREQINTERNAL pReqInt = hReq; RTFILEAIOREQ_VALID_RETURN(pReqInt); RTFILEAIOREQ_STATE_RETURN_RC(pReqInt, SUBMITTED, VERR_FILE_AIO_NOT_SUBMITTED); int rcBSD = aio_cancel(pReqInt->AioCB.aio_fildes, &pReqInt->AioCB); if (rcBSD == AIO_CANCELED) { /* * Decrement request count because the request will never arrive at the * completion port. */ AssertMsg(VALID_PTR(pReqInt->pCtxInt), ("Invalid state. Request was canceled but wasn't submitted\n")); ASMAtomicDecS32(&pReqInt->pCtxInt->cRequests); pReqInt->Rc = VERR_FILE_AIO_CANCELED; RTFILEAIOREQ_SET_STATE(pReqInt, COMPLETED); return VINF_SUCCESS; } else if (rcBSD == AIO_ALLDONE) return VERR_FILE_AIO_COMPLETED; else if (rcBSD == AIO_NOTCANCELED) return VERR_FILE_AIO_IN_PROGRESS; else return RTErrConvertFromErrno(errno); }
RTDECL(int) RTSemEventMultiSignal(RTSEMEVENTMULTI hEventMultiSem) { /* * Validate input. */ struct RTSEMEVENTMULTIINTERNAL *pThis = hEventMultiSem; AssertReturn(VALID_PTR(pThis) && pThis->u32Magic == RTSEMEVENTMULTI_MAGIC, VERR_INVALID_HANDLE); #ifdef RTSEMEVENTMULTI_STRICT if (pThis->fEverHadSignallers) { int rc9 = RTLockValidatorRecSharedCheckSignaller(&pThis->Signallers, NIL_RTTHREAD); if (RT_FAILURE(rc9)) return rc9; } #endif /* * Signal it. */ int32_t iOld = ASMAtomicXchgS32(&pThis->iState, -1); if (iOld > 0) { /* wake up sleeping threads. */ long cWoken = sys_futex(&pThis->iState, FUTEX_WAKE, INT_MAX, NULL, NULL, 0); AssertMsg(cWoken >= 0, ("%ld\n", cWoken)); NOREF(cWoken); } Assert(iOld == 0 || iOld == -1 || iOld == 1); return VINF_SUCCESS; }
STDMETHODIMP Session::EnumerateGuestProperties(IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames), ComSafeArrayOut(BSTR, aValues), ComSafeArrayOut(LONG64, aTimestamps), ComSafeArrayOut(BSTR, aFlags)) { #ifdef VBOX_WITH_GUEST_PROPS AutoCaller autoCaller(this); AssertComRCReturn(autoCaller.rc(), autoCaller.rc()); if (mState != SessionState_Locked) return setError(VBOX_E_INVALID_VM_STATE, tr("Machine is not locked by session (session state: %s)."), Global::stringifySessionState(mState)); AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE); if (!VALID_PTR(aPatterns) && (aPatterns != NULL)) return E_POINTER; if (ComSafeArrayOutIsNull(aNames)) return E_POINTER; if (ComSafeArrayOutIsNull(aValues)) return E_POINTER; if (ComSafeArrayOutIsNull(aTimestamps)) return E_POINTER; if (ComSafeArrayOutIsNull(aFlags)) return E_POINTER; return mConsole->enumerateGuestProperties(aPatterns, ComSafeArrayOutArg(aNames), ComSafeArrayOutArg(aValues), ComSafeArrayOutArg(aTimestamps), ComSafeArrayOutArg(aFlags)); #else /* VBOX_WITH_GUEST_PROPS not defined */ ReturnComNotImplemented(); #endif /* VBOX_WITH_GUEST_PROPS not defined */ }
/** * Close a file device previously opened by VBoxDrvFreeBSDOpen * * @returns 0 on success. * @param pDev The device. * @param fFile The file descriptor flags. * @param DevType The device type (CHR. * @param pTd The calling thread. */ static int VBoxDrvFreeBSDClose(struct cdev *pDev, int fFile, int DevType, struct thread *pTd) { PSUPDRVSESSION pSession = (PSUPDRVSESSION)pDev->si_drv1; #if __FreeBSD_version < 800062 Log(("VBoxDrvFreeBSDClose: fFile=%#x iUnit=%d pSession=%p\n", fFile, minor2unit(minor(pDev)), pSession)); #else Log(("VBoxDrvFreeBSDClose: fFile=%#x iUnit=%d pSession=%p\n", fFile, minor(dev2udev(pDev)), pSession)); #endif /* * Close the session if it's still hanging on to the device... */ if (VALID_PTR(pSession)) { supdrvCloseSession(&g_VBoxDrvFreeBSDDevExt, pSession); if (!ASMAtomicCmpXchgPtr(&pDev->si_drv1, NULL, pSession)) OSDBGPRINT(("VBoxDrvFreeBSDClose: si_drv1=%p expected %p!\n", pDev->si_drv1, pSession)); ASMAtomicDecU32(&g_cUsers); /* Don't use destroy_dev here because it may sleep resulting in a hanging user process. */ destroy_dev_sched(pDev); } else OSDBGPRINT(("VBoxDrvFreeBSDClose: si_drv1=%p!\n", pSession)); return 0; }
/** * Read a zero terminated string from guest memory. * * @returns VBox status code. * * @param pVM Pointer to the shared VM structure. * @param idCpu The ID of the source CPU context (for the address). * @param pAddress Where to start reading. * @param pszBuf Where to store the string. * @param cchBuf The size of the buffer. */ static DECLCALLBACK(int) dbgfR3MemReadString(PVM pVM, VMCPUID idCpu, PCDBGFADDRESS pAddress, char *pszBuf, size_t cchBuf) { /* * Validate the input we use, PGM does the rest. */ if (!DBGFR3AddrIsValid(pVM, pAddress)) return VERR_INVALID_POINTER; if (!VALID_PTR(pszBuf)) return VERR_INVALID_POINTER; /* * Let dbgfR3MemRead do the job. */ int rc = dbgfR3MemRead(pVM, idCpu, pAddress, pszBuf, cchBuf); /* * Make sure the result is terminated and that overflow is signaled. * This may look a bit reckless with the rc but, it should be fine. */ if (!RTStrEnd(pszBuf, cchBuf)) { pszBuf[cchBuf - 1] = '\0'; rc = VINF_BUFFER_OVERFLOW; } /* * Handle partial reads (not perfect). */ else if (RT_FAILURE(rc)) { if (pszBuf[0]) rc = VINF_SUCCESS; } return rc; }
DECLEXPORT(EGLSurface) eglCreatePixmapSurface(EGLDisplay hDisplay, EGLConfig config, EGLNativePixmapType hPixmap, const EGLint *paAttributes) { Display *pDisplay = (Display *)hDisplay; GLXPixmap hGLXPixmap; if (!VALID_PTR(hDisplay)) { setEGLError(EGL_NOT_INITIALIZED); return EGL_NO_SURFACE; } if (paAttributes != NULL) /* Sanity test only. */ if (*paAttributes != EGL_NONE) { if (*paAttributes == EGL_VG_COLORSPACE || *paAttributes == EGL_VG_ALPHA_FORMAT) { setEGLError(EGL_BAD_MATCH); return EGL_NO_SURFACE; } else { setEGLError(EGL_BAD_ATTRIBUTE); return EGL_NO_SURFACE; } } hGLXPixmap = glXCreatePixmap(pDisplay, (GLXFBConfig)config, (Pixmap)hPixmap, NULL); if (hGLXPixmap == None) { setEGLError(EGL_BAD_MATCH); return EGL_NO_SURFACE; } EGL_ASSERT(hGLXPixmap < VBEGL_WINDOW_SURFACE); /* Greater than the maximum XID. */ clearEGLError(); return (EGLSurface)(hGLXPixmap | VBEGL_PIXMAP_SURFACE); }
int vboxClipboardUtf16GetLinSize(PRTUTF16 pwszSrc, size_t cwSrc, size_t *pcwDest) { size_t cwDest; LogFlowFunc(("pwszSrc=%.*ls, cwSrc=%u\n", cwSrc, pwszSrc, cwSrc)); if (!VALID_PTR(pwszSrc)) { LogRel(("vboxClipboardUtf16GetLinSize: received an invalid Utf16 string %p. Returning VERR_INVALID_PARAMETER.\n", pwszSrc)); AssertReturn(VALID_PTR(pwszSrc), VERR_INVALID_PARAMETER); } if (cwSrc == 0) { LogFlowFunc(("empty source string, returning VINF_SUCCESS\n")); *pcwDest = 0; return VINF_SUCCESS; } /* We only take little endian Utf16 */ if (pwszSrc[0] == UTF16BEMARKER) { LogRel(("vboxClipboardUtf16GetLinSize: received a big endian Utf16 string. Returning VERR_INVALID_PARAMETER.\n")); AssertReturn(pwszSrc[0] != UTF16BEMARKER, VERR_INVALID_PARAMETER); } /* Calculate the size of the destination text string. */ /* Is this Utf16 or Utf16-LE? */ if (pwszSrc[0] == UTF16LEMARKER) cwDest = 0; else cwDest = 1; for (size_t i = 0; i < cwSrc; ++i, ++cwDest) { if ( (i + 1 < cwSrc) && (pwszSrc[i] == CARRIAGERETURN) && (pwszSrc[i + 1] == LINEFEED)) { ++i; } if (pwszSrc[i] == 0) { break; } } /* Terminating zero */ ++cwDest; LogFlowFunc(("returning %d\n", cwDest)); *pcwDest = cwDest; return VINF_SUCCESS; }
/** * Looks up a IDC handle by session. * * @returns The IDC handle on success, NULL on failure. * @param pSession The session to lookup. * * @internal */ PSUPDRVIDCHANDLE supR0IdcGetHandleFromSession(PSUPDRVSESSION pSession) { PSUPDRVIDCHANDLE pHandle = ASMAtomicUoReadPtrT(&g_pMainHandle, PSUPDRVIDCHANDLE); if ( VALID_PTR(pHandle) && pHandle->s.pSession == pSession) return pHandle; return NULL; }
DECLEXPORT(EGLBoolean) eglSwapBuffers(EGLDisplay hDisplay, EGLSurface hSurface) { Display *pDisplay = (Display *)hDisplay; if (!VALID_PTR(hDisplay)) return setEGLError(EGL_NOT_INITIALIZED); glXSwapBuffers(pDisplay, (GLXDrawable)hSurface & ~VBEGL_ANY_SURFACE); return clearEGLError(); }
DECLEXPORT(EGLBoolean) eglDestroyContext(EGLDisplay hDisplay, EGLContext hContext) { Display *pDisplay = (Display *)hDisplay; if (!VALID_PTR(hDisplay)) return setEGLError(EGL_NOT_INITIALIZED); glXDestroyContext(pDisplay, (GLXContext) hContext); return clearEGLError(); }
DECLEXPORT(EGLContext) eglGetCurrentContext(void) { struct VBEGLTLS *pTls = getTls(); if (!VALID_PTR(pTls)) return EGL_NO_CONTEXT; clearEGLError(); return pTls->hCurrent; }
static EGLBoolean clearEGLError(void) { struct VBEGLTLS *pTls = getTls(); if (!VALID_PTR(pTls)) return EGL_FALSE; pTls->cErr = EGL_SUCCESS; return EGL_TRUE; }