diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2014-03-26 19:21:20 +0000 |
---|---|---|
committer | <> | 2014-05-08 15:03:54 +0000 |
commit | fb123f93f9f5ce42c8e5785d2f8e0edaf951740e (patch) | |
tree | c2103d76aec5f1f10892cd1d3a38e24f665ae5db /src/VBox/HostDrivers/Support/SUPLib.cpp | |
parent | 58ed4748338f9466599adfc8a9171280ed99e23f (diff) | |
download | VirtualBox-master.tar.gz |
Imported from /home/lorry/working-area/delta_VirtualBox/VirtualBox-4.3.10.tar.bz2.HEADVirtualBox-4.3.10master
Diffstat (limited to 'src/VBox/HostDrivers/Support/SUPLib.cpp')
-rw-r--r-- | src/VBox/HostDrivers/Support/SUPLib.cpp | 185 |
1 files changed, 124 insertions, 61 deletions
diff --git a/src/VBox/HostDrivers/Support/SUPLib.cpp b/src/VBox/HostDrivers/Support/SUPLib.cpp index c7878bcd..d408bf2a 100644 --- a/src/VBox/HostDrivers/Support/SUPLib.cpp +++ b/src/VBox/HostDrivers/Support/SUPLib.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2006-2010 Oracle Corporation + * Copyright (C) 2006-2013 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; @@ -97,11 +97,12 @@ static bool g_fPreInited = false; * via the pre-init mechanism from the hardened executable stub. */ SUPLIBDATA g_supLibData = { - SUP_HDEVICE_NIL + /*.hDevice = */ SUP_HDEVICE_NIL, + /*.fUnrestricted = */ true #if defined(RT_OS_DARWIN) - , NULL + ,/* .uConnection = */ NULL #elif defined(RT_OS_LINUX) - , false + ,/* .fSysMadviseWorks = */ false #endif }; @@ -209,7 +210,7 @@ DECLEXPORT(int) supR3PreInit(PSUPPREINITDATA pPreInitData, uint32_t fFlags) } -SUPR3DECL(int) SUPR3Init(PSUPDRVSESSION *ppSession) +SUPR3DECL(int) SUPR3InitEx(bool fUnrestricted, PSUPDRVSESSION *ppSession) { /* * Perform some sanity checks. @@ -228,7 +229,16 @@ SUPR3DECL(int) SUPR3Init(PSUPDRVSESSION *ppSession) if (ppSession) *ppSession = g_pSession; if (g_cInits++ > 0) + { + if (fUnrestricted && !g_supLibData.fUnrestricted) + { + g_cInits--; + if (ppSession) + *ppSession = NIL_RTR0PTR; + return VERR_VM_DRIVER_NOT_ACCESSIBLE; /** @todo different status code? */ + } return VINF_SUCCESS; + } /* * Check for fake mode. @@ -251,7 +261,7 @@ SUPR3DECL(int) SUPR3Init(PSUPDRVSESSION *ppSession) /* * Open the support driver. */ - int rc = suplibOsInit(&g_supLibData, g_fPreInited); + int rc = suplibOsInit(&g_supLibData, g_fPreInited, fUnrestricted); if (RT_SUCCESS(rc)) { /* @@ -267,8 +277,8 @@ SUPR3DECL(int) SUPR3Init(PSUPDRVSESSION *ppSession) CookieReq.Hdr.rc = VERR_INTERNAL_ERROR; strcpy(CookieReq.u.In.szMagic, SUPCOOKIE_MAGIC); CookieReq.u.In.u32ReqVersion = SUPDRV_IOC_VERSION; - const uint32_t uMinVersion = (SUPDRV_IOC_VERSION & 0xffff0000) == 0x00190000 - ? 0x00190003 + const uint32_t uMinVersion = (SUPDRV_IOC_VERSION & 0xffff0000) == 0x001a0000 + ? 0x001a0005 : SUPDRV_IOC_VERSION & 0xffff0000; CookieReq.u.In.u32MinVersion = uMinVersion; rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_COOKIE, &CookieReq, SUP_IOCTL_COOKIE_SIZE); @@ -281,64 +291,75 @@ SUPR3DECL(int) SUPR3Init(PSUPDRVSESSION *ppSession) /* * Query the functions. */ - PSUPQUERYFUNCS pFuncsReq = (PSUPQUERYFUNCS)RTMemAllocZ(SUP_IOCTL_QUERY_FUNCS_SIZE(CookieReq.u.Out.cFunctions)); - if (pFuncsReq) + PSUPQUERYFUNCS pFuncsReq = NULL; + if (g_supLibData.fUnrestricted) { - pFuncsReq->Hdr.u32Cookie = CookieReq.u.Out.u32Cookie; - pFuncsReq->Hdr.u32SessionCookie = CookieReq.u.Out.u32SessionCookie; - pFuncsReq->Hdr.cbIn = SUP_IOCTL_QUERY_FUNCS_SIZE_IN; - pFuncsReq->Hdr.cbOut = SUP_IOCTL_QUERY_FUNCS_SIZE_OUT(CookieReq.u.Out.cFunctions); - pFuncsReq->Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT; - pFuncsReq->Hdr.rc = VERR_INTERNAL_ERROR; - rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_QUERY_FUNCS(CookieReq.u.Out.cFunctions), pFuncsReq, SUP_IOCTL_QUERY_FUNCS_SIZE(CookieReq.u.Out.cFunctions)); - if (RT_SUCCESS(rc)) - rc = pFuncsReq->Hdr.rc; - if (RT_SUCCESS(rc)) + pFuncsReq = (PSUPQUERYFUNCS)RTMemAllocZ(SUP_IOCTL_QUERY_FUNCS_SIZE(CookieReq.u.Out.cFunctions)); + if (pFuncsReq) { - /* - * Map the GIP into userspace. - */ - Assert(!g_pSUPGlobalInfoPage); - SUPGIPMAP GipMapReq; - GipMapReq.Hdr.u32Cookie = CookieReq.u.Out.u32Cookie; - GipMapReq.Hdr.u32SessionCookie = CookieReq.u.Out.u32SessionCookie; - GipMapReq.Hdr.cbIn = SUP_IOCTL_GIP_MAP_SIZE_IN; - GipMapReq.Hdr.cbOut = SUP_IOCTL_GIP_MAP_SIZE_OUT; - GipMapReq.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT; - GipMapReq.Hdr.rc = VERR_INTERNAL_ERROR; - GipMapReq.u.Out.HCPhysGip = NIL_RTHCPHYS; - GipMapReq.u.Out.pGipR0 = NIL_RTR0PTR; - GipMapReq.u.Out.pGipR3 = NULL; - rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_GIP_MAP, &GipMapReq, SUP_IOCTL_GIP_MAP_SIZE); + pFuncsReq->Hdr.u32Cookie = CookieReq.u.Out.u32Cookie; + pFuncsReq->Hdr.u32SessionCookie = CookieReq.u.Out.u32SessionCookie; + pFuncsReq->Hdr.cbIn = SUP_IOCTL_QUERY_FUNCS_SIZE_IN; + pFuncsReq->Hdr.cbOut = SUP_IOCTL_QUERY_FUNCS_SIZE_OUT(CookieReq.u.Out.cFunctions); + pFuncsReq->Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT; + pFuncsReq->Hdr.rc = VERR_INTERNAL_ERROR; + rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_QUERY_FUNCS(CookieReq.u.Out.cFunctions), pFuncsReq, + SUP_IOCTL_QUERY_FUNCS_SIZE(CookieReq.u.Out.cFunctions)); if (RT_SUCCESS(rc)) - rc = GipMapReq.Hdr.rc; + rc = pFuncsReq->Hdr.rc; if (RT_SUCCESS(rc)) { - AssertRelease(GipMapReq.u.Out.pGipR3->u32Magic == SUPGLOBALINFOPAGE_MAGIC); - AssertRelease(GipMapReq.u.Out.pGipR3->u32Version >= SUPGLOBALINFOPAGE_VERSION); - /* - * Set the globals and return success. + * Map the GIP into userspace. */ - ASMAtomicXchgSize(&g_HCPhysSUPGlobalInfoPage, GipMapReq.u.Out.HCPhysGip); - ASMAtomicCmpXchgPtr((void * volatile *)&g_pSUPGlobalInfoPage, GipMapReq.u.Out.pGipR3, NULL); - ASMAtomicCmpXchgPtr((void * volatile *)&g_pSUPGlobalInfoPageR0, (void *)GipMapReq.u.Out.pGipR0, NULL); - - g_u32Cookie = CookieReq.u.Out.u32Cookie; - g_u32SessionCookie = CookieReq.u.Out.u32SessionCookie; - g_pSession = CookieReq.u.Out.pSession; - g_pFunctions = pFuncsReq; - if (ppSession) - *ppSession = CookieReq.u.Out.pSession; - return VINF_SUCCESS; + Assert(!g_pSUPGlobalInfoPage); + SUPGIPMAP GipMapReq; + GipMapReq.Hdr.u32Cookie = CookieReq.u.Out.u32Cookie; + GipMapReq.Hdr.u32SessionCookie = CookieReq.u.Out.u32SessionCookie; + GipMapReq.Hdr.cbIn = SUP_IOCTL_GIP_MAP_SIZE_IN; + GipMapReq.Hdr.cbOut = SUP_IOCTL_GIP_MAP_SIZE_OUT; + GipMapReq.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT; + GipMapReq.Hdr.rc = VERR_INTERNAL_ERROR; + GipMapReq.u.Out.HCPhysGip = NIL_RTHCPHYS; + GipMapReq.u.Out.pGipR0 = NIL_RTR0PTR; + GipMapReq.u.Out.pGipR3 = NULL; + rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_GIP_MAP, &GipMapReq, SUP_IOCTL_GIP_MAP_SIZE); + if (RT_SUCCESS(rc)) + rc = GipMapReq.Hdr.rc; + if (RT_SUCCESS(rc)) + { + /* + * Set the GIP globals. + */ + AssertRelease(GipMapReq.u.Out.pGipR3->u32Magic == SUPGLOBALINFOPAGE_MAGIC); + AssertRelease(GipMapReq.u.Out.pGipR3->u32Version >= SUPGLOBALINFOPAGE_VERSION); + + ASMAtomicXchgSize(&g_HCPhysSUPGlobalInfoPage, GipMapReq.u.Out.HCPhysGip); + ASMAtomicCmpXchgPtr((void * volatile *)&g_pSUPGlobalInfoPage, GipMapReq.u.Out.pGipR3, NULL); + ASMAtomicCmpXchgPtr((void * volatile *)&g_pSUPGlobalInfoPageR0, (void *)GipMapReq.u.Out.pGipR0, NULL); + } } } + else + rc = VERR_NO_MEMORY; + } - /* bailout */ - RTMemFree(pFuncsReq); + if (RT_SUCCESS(rc)) + { + /* + * Set the globals and return success. + */ + g_u32Cookie = CookieReq.u.Out.u32Cookie; + g_u32SessionCookie = CookieReq.u.Out.u32SessionCookie; + g_pSession = CookieReq.u.Out.pSession; + g_pFunctions = pFuncsReq; + if (ppSession) + *ppSession = CookieReq.u.Out.pSession; + return VINF_SUCCESS; } - else - rc = VERR_NO_MEMORY; + + /* bailout */ + RTMemFree(pFuncsReq); } else { @@ -372,6 +393,12 @@ SUPR3DECL(int) SUPR3Init(PSUPDRVSESSION *ppSession) return rc; } + +SUPR3DECL(int) SUPR3Init(PSUPDRVSESSION *ppSession) +{ + return SUPR3InitEx(true, ppSession); +} + /** * Fake mode init. */ @@ -590,8 +617,8 @@ SUPR3DECL(int) SUPR3CallVMMR0Fast(PVMR0 pVMR0, unsigned uOperation, VMCPUID idCp NOREF(pVMR0); if (RT_LIKELY(uOperation == SUP_VMMR0_DO_RAW_RUN)) return suplibOsIOCtlFast(&g_supLibData, SUP_IOCTL_FAST_DO_RAW_RUN, idCpu); - if (RT_LIKELY(uOperation == SUP_VMMR0_DO_HWACC_RUN)) - return suplibOsIOCtlFast(&g_supLibData, SUP_IOCTL_FAST_DO_HWACC_RUN, idCpu); + if (RT_LIKELY(uOperation == SUP_VMMR0_DO_HM_RUN)) + return suplibOsIOCtlFast(&g_supLibData, SUP_IOCTL_FAST_DO_HM_RUN, idCpu); if (RT_LIKELY(uOperation == SUP_VMMR0_DO_NOP)) return suplibOsIOCtlFast(&g_supLibData, SUP_IOCTL_FAST_DO_NOP, idCpu); @@ -606,7 +633,7 @@ SUPR3DECL(int) SUPR3CallVMMR0Ex(PVMR0 pVMR0, VMCPUID idCpu, unsigned uOperation, * The following operations don't belong here. */ AssertMsgReturn( uOperation != SUP_VMMR0_DO_RAW_RUN - && uOperation != SUP_VMMR0_DO_HWACC_RUN + && uOperation != SUP_VMMR0_DO_HM_RUN && uOperation != SUP_VMMR0_DO_NOP, ("%#x\n", uOperation), VERR_INTERNAL_ERROR); @@ -693,7 +720,7 @@ SUPR3DECL(int) SUPR3CallVMMR0(PVMR0 pVMR0, VMCPUID idCpu, unsigned uOperation, v * The following operations don't belong here. */ AssertMsgReturn( uOperation != SUP_VMMR0_DO_RAW_RUN - && uOperation != SUP_VMMR0_DO_HWACC_RUN + && uOperation != SUP_VMMR0_DO_HM_RUN && uOperation != SUP_VMMR0_DO_NOP, ("%#x\n", uOperation), VERR_INTERNAL_ERROR); @@ -1578,7 +1605,7 @@ SUPR3DECL(int) SUPR3LoadModule(const char *pszFilename, const char *pszModule, v { rc = supLoadModule(pszFilename, pszModule, NULL, ppvImageBase); if (RT_FAILURE(rc)) - RTErrInfoSetF(pErrInfo, rc, "supLoadModule returned %Rrc", rc); + RTErrInfoSetF(pErrInfo, rc, "SUPR3LoadModule: supLoadModule returned %Rrc", rc); } return rc; } @@ -1645,7 +1672,7 @@ static DECLCALLBACK(int) supLoadModuleResolveImport(RTLDRMOD hLdrMod, const char */ /** @todo is this actually used??? */ /* skip the 64-bit ELF import prefix first. */ - if (!strncmp(pszSymbol, "SUPR0$", sizeof("SUPR0$") - 1)) + if (!strncmp(pszSymbol, RT_STR_TUPLE("SUPR0$"))) pszSymbol += sizeof("SUPR0$") - 1; /* @@ -1826,7 +1853,10 @@ static int supLoadModule(const char *pszFilename, const char *pszModule, const c RTLDRMOD hLdrMod; rc = RTLdrOpen(pszFilename, 0, RTLDRARCH_HOST, &hLdrMod); if (!RT_SUCCESS(rc)) + { + LogRel(("SUP: RTLdrOpen failed for %s (%s)\n", pszModule, pszFilename, rc)); return rc; + } SUPLDRCALCSIZEARGS CalcArgs; CalcArgs.cbStrings = 0; @@ -1971,6 +2001,8 @@ static int supLoadModule(const char *pszFilename, const char *pszModule, const c rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_LDR_LOAD, pLoadReq, SUP_IOCTL_LDR_LOAD_SIZE(cbImageWithTabs)); if (RT_SUCCESS(rc)) rc = pLoadReq->Hdr.rc; + else + LogRel(("SUP: SUP_IOCTL_LDR_LOAD ioctl for %s (%s) failed rc=%Rrc\n", pszModule, pszFilename, rc)); } else rc = VINF_SUCCESS; @@ -1995,9 +2027,17 @@ static int supLoadModule(const char *pszFilename, const char *pszModule, const c RTLdrClose(hLdrMod); return VINF_SUCCESS; } + else + LogRel(("SUP: Loading failed for %s (%s) rc=%Rrc\n", pszModule, pszFilename, rc)); } + else + LogRel(("SUP: RTLdrEnumSymbols failed for %s (%s) rc=%Rrc\n", pszModule, pszFilename, rc)); } + else + LogRel(("SUP: Failed to get entry points for %s (%s) rc=%Rrc\n", pszModule, pszFilename, rc)); } + else + LogRel(("SUP: RTLdrGetBits failed for %s (%s). rc=%Rrc\n", pszModule, pszFilename, rc)); RTMemTmpFree(pLoadReq); } else @@ -2701,3 +2741,26 @@ DECLASM(void) suplibTracerFireProbe(PVTGPROBELOC pProbeLoc, PSUPTRACERUMODFIREPR suplibOsIOCtl(&g_supLibData, SUP_IOCTL_TRACER_UMOD_FIRE_PROBE, pReq, SUP_IOCTL_TRACER_UMOD_FIRE_PROBE_SIZE); } + +SUPR3DECL(int) SUPR3ResumeSuspendedKeyboards(void) +{ +#ifdef RT_OS_DARWIN + /* + * Issue IOCtl to the SUPDRV kernel module. + */ + SUPREQHDR Req; + Req.u32Cookie = g_u32Cookie; + Req.u32SessionCookie= g_u32SessionCookie; + Req.cbIn = SUP_IOCTL_RESUME_SUSPENDED_KBDS_SIZE_IN; + Req.cbOut = SUP_IOCTL_RESUME_SUSPENDED_KBDS_SIZE_OUT; + Req.fFlags = SUPREQHDR_FLAGS_DEFAULT; + Req.rc = VERR_INTERNAL_ERROR; + int rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_RESUME_SUSPENDED_KBDS, &Req, SUP_IOCTL_RESUME_SUSPENDED_KBDS_SIZE); + if (RT_SUCCESS(rc)) + rc = Req.rc; + return rc; +#else /* !RT_OS_DARWIN */ + return VERR_NOT_SUPPORTED; +#endif +} + |