~ubuntu-branches/ubuntu/trusty/virtualbox/trusty-proposed

« back to all changes in this revision

Viewing changes to src/VBox/VMM/VMMR3/VMMSwitcher.cpp

  • Committer: Package Import Robot
  • Author(s): Felix Geyer
  • Date: 2013-03-07 16:38:36 UTC
  • mfrom: (1.1.13) (3.1.20 experimental)
  • Revision ID: package-import@ubuntu.com-20130307163836-p93jpbgx39tp3gb4
Tags: 4.2.8-dfsg-0ubuntu1
* New upstream release. (Closes: #691148)
  - Fixes compatibility with kernel 3.8. (Closes: #700823; LP: #1101867)
* Switch to my @debian.org email address.
* Move package to contrib as virtualbox 4.2 needs a non-free compiler to
  build the BIOS.
* Build-depend on libdevmapper-dev.
* Refresh patches.
  - Drop 36-fix-ftbfs-xserver-112.patch, cve-2012-3221.patch,
    CVE-2013-0420.patch 37-kcompat-3.6.patch and 38-kcompat-3.7.patch.
* Drop all virtualbox-ose transitional packages.
* Drop the virtualbox-fuse package as vdfuse fails to build with
  virtualbox 4.2.
* Update install files and VBox.sh.
* Bump required kbuild version to 0.1.9998svn2577.
* Fix path to VBoxCreateUSBNode.sh in virtualbox.postinst. (Closes: #700479)
* Add an init script to virtuabox-guest-x11 which loads the vboxvideo
  kernel module. The X Server 1.13 doesn't load it anymore. (Closes: #686994)
* Update man pages. (Closes: #680053)
* Add 36-python-multiarch.patch from Rico Tzschichholz to fix detection of
  python in multiarch paths using pkg-config.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 */
5
5
 
6
6
/*
7
 
 * Copyright (C) 2006-2007 Oracle Corporation
 
7
 * Copyright (C) 2006-2012 Oracle Corporation
8
8
 *
9
9
 * This file is part of VirtualBox Open Source Edition (OSE), as
10
10
 * available from http://www.virtualbox.org. This file is free software;
95
95
 * put on linear contiguous backing.
96
96
 *
97
97
 * @returns VBox status code.
98
 
 * @param   pVM     Pointer to the shared VM structure.
 
98
 * @param   pVM     Pointer to the VM.
99
99
 */
100
100
int vmmR3SwitcherInit(PVM pVM)
101
101
{
228
228
/**
229
229
 * Relocate the switchers, called by VMMR#Relocate.
230
230
 *
231
 
 * @param   pVM         Pointer to the shared VM structure.
 
231
 * @param   pVM         Pointer to the VM.
232
232
 * @param   offDelta    The relocation delta.
233
233
 */
234
234
void vmmR3SwitcherRelocate(PVM pVM, RTGCINTPTR offDelta)
257
257
     */
258
258
    PVMMSWITCHERDEF pSwitcher   = s_apSwitchers[pVM->vmm.s.enmSwitcher];
259
259
    RTRCPTR         RCPtr       = pVM->vmm.s.pvCoreCodeRC + pVM->vmm.s.aoffSwitchers[pVM->vmm.s.enmSwitcher];
260
 
    pVM->vmm.s.pfnGuestToHostRC         = RCPtr + pSwitcher->offGCGuestToHost;
261
 
    pVM->vmm.s.pfnCallTrampolineRC      = RCPtr + pSwitcher->offGCCallTrampoline;
262
 
    pVM->pfnVMMGCGuestToHostAsm         = RCPtr + pSwitcher->offGCGuestToHostAsm;
263
 
    pVM->pfnVMMGCGuestToHostAsmHyperCtx = RCPtr + pSwitcher->offGCGuestToHostAsmHyperCtx;
264
 
    pVM->pfnVMMGCGuestToHostAsmGuestCtx = RCPtr + pSwitcher->offGCGuestToHostAsmGuestCtx;
 
260
    pVM->vmm.s.pfnRCToHost              = RCPtr + pSwitcher->offRCToHost;
 
261
    pVM->vmm.s.pfnCallTrampolineRC      = RCPtr + pSwitcher->offRCCallTrampoline;
 
262
    pVM->pfnVMMRCToHostAsm              = RCPtr + pSwitcher->offRCToHostAsm;
 
263
    pVM->pfnVMMRCToHostAsmNoReturn      = RCPtr + pSwitcher->offRCToHostAsmNoReturn;
265
264
 
266
265
//    AssertFailed();
 
266
#else
 
267
    NOREF(pVM);
267
268
#endif
 
269
    NOREF(offDelta);
268
270
}
269
271
 
270
272
 
 
273
#ifdef VBOX_WITH_RAW_MODE
 
274
 
271
275
/**
272
276
 * Generic switcher code relocator.
273
277
 *
274
 
 * @param   pVM         The VM handle.
 
278
 * @param   pVM         Pointer to the VM.
275
279
 * @param   pSwitcher   The switcher definition.
276
280
 * @param   pu8CodeR3   Pointer to the core code block for the switcher, ring-3 mapping.
277
281
 * @param   R0PtrCode   Pointer to the core code block for the switcher, ring-0 mapping.
533
537
            case FIX_EFER_OR_MASK:
534
538
            {
535
539
                uint32_t u32OrMask = MSR_K6_EFER_LME | MSR_K6_EFER_SCE;
536
 
                /** note: we don't care if cpuid 0x8000001 isn't supported as that implies long mode isn't either, so this switcher would never be used. */
537
 
                if (!!(ASMCpuId_EDX(0x80000001) & X86_CPUID_AMD_FEATURE_EDX_NX))
 
540
                /*
 
541
                 * We don't care if cpuid 0x8000001 isn't supported as that implies
 
542
                 * long mode isn't supported either, so this switched would never be used.
 
543
                 */
 
544
                if (!!(ASMCpuId_EDX(0x80000001) & X86_CPUID_EXT_FEATURE_EDX_NX))
538
545
                    u32OrMask |= MSR_K6_EFER_NXE;
539
546
 
540
547
                *uSrc.pu32 = u32OrMask;
810
817
             * Disassemble it.
811
818
             */
812
819
            RTLogPrintf("  %s: offCode=%#x cbCode=%#x\n", pszDesc, offCode, cbCode);
813
 
            DISCPUSTATE Cpu;
814
820
 
815
 
            memset(&Cpu, 0, sizeof(Cpu));
816
 
            Cpu.mode = CPUMODE_32BIT;
817
821
            while (cbCode > 0)
818
822
            {
819
823
                /* try label it */
820
 
                if (pSwitcher->offR0HostToGuest == offCode)
821
 
                    RTLogPrintf(" *R0HostToGuest:\n");
822
 
                if (pSwitcher->offGCGuestToHost == offCode)
823
 
                    RTLogPrintf(" *GCGuestToHost:\n");
824
 
                if (pSwitcher->offGCCallTrampoline == offCode)
825
 
                    RTLogPrintf(" *GCCallTrampoline:\n");
826
 
                if (pSwitcher->offGCGuestToHostAsm == offCode)
827
 
                    RTLogPrintf(" *GCGuestToHostAsm:\n");
828
 
                if (pSwitcher->offGCGuestToHostAsmHyperCtx == offCode)
829
 
                    RTLogPrintf(" *GCGuestToHostAsmHyperCtx:\n");
830
 
                if (pSwitcher->offGCGuestToHostAsmGuestCtx == offCode)
831
 
                    RTLogPrintf(" *GCGuestToHostAsmGuestCtx:\n");
 
824
                if (pSwitcher->offR0ToRawMode == offCode)
 
825
                    RTLogPrintf(" *R0ToRawMode:\n");
 
826
                if (pSwitcher->offRCToHost == offCode)
 
827
                    RTLogPrintf(" *RCToHost:\n");
 
828
                if (pSwitcher->offRCCallTrampoline == offCode)
 
829
                    RTLogPrintf(" *RCCallTrampoline:\n");
 
830
                if (pSwitcher->offRCToHostAsm == offCode)
 
831
                    RTLogPrintf(" *RCToHostAsm:\n");
 
832
                if (pSwitcher->offRCToHostAsmNoReturn == offCode)
 
833
                    RTLogPrintf(" *RCToHostAsmNoReturn:\n");
832
834
 
833
835
                /* disas */
834
 
                uint32_t cbInstr = 0;
835
 
                char szDisas[256];
836
 
                if (RT_SUCCESS(DISInstr(&Cpu, (uintptr_t)pu8CodeR3 + offCode, uBase - (uintptr_t)pu8CodeR3, &cbInstr, szDisas)))
837
 
                    RTLogPrintf("  %04x: %s", offCode, szDisas); //for whatever reason szDisas includes '\n'.
 
836
                uint32_t    cbInstr = 0;
 
837
                DISCPUSTATE Cpu;
 
838
                char        szDisas[256];
 
839
                int rc = DISInstr(pu8CodeR3 + offCode, DISCPUMODE_32BIT, &Cpu, &cbInstr);
 
840
                if (RT_SUCCESS(rc))
 
841
                {
 
842
                    Cpu.uInstrAddr += uBase - (uintptr_t)pu8CodeR3;
 
843
                    DISFormatYasmEx(&Cpu, szDisas, sizeof(szDisas),
 
844
                                    DIS_FMT_FLAGS_ADDR_LEFT | DIS_FMT_FLAGS_BYTES_LEFT | DIS_FMT_FLAGS_BYTES_SPACED
 
845
                                    | DIS_FMT_FLAGS_RELATIVE_BRANCH,
 
846
                                    NULL, NULL);
 
847
                }
 
848
                if (RT_SUCCESS(rc))
 
849
                    RTLogPrintf("  %04x: %s\n", offCode, szDisas);
838
850
                else
839
851
                {
840
 
                    RTLogPrintf("  %04x: %02x '%c'\n",
841
 
                                offCode, pu8CodeR3[offCode], RT_C_IS_PRINT(pu8CodeR3[offCode]) ? pu8CodeR3[offCode] : ' ');
 
852
                    RTLogPrintf("  %04x: %02x '%c' (rc=%Rrc\n",
 
853
                                offCode, pu8CodeR3[offCode], RT_C_IS_PRINT(pu8CodeR3[offCode]) ? pu8CodeR3[offCode] : ' ', rc);
842
854
                    cbInstr = 1;
843
855
                }
844
856
                offCode += cbInstr;
849
861
#endif
850
862
}
851
863
 
852
 
 
853
864
/**
854
865
 * Relocator for the 32-Bit to 32-Bit world switcher.
855
866
 */
933
944
 * Selects the switcher to be used for switching to raw-mode context.
934
945
 *
935
946
 * @returns VBox status code.
936
 
 * @param   pVM             VM handle.
 
947
 * @param   pVM             Pointer to the VM.
937
948
 * @param   enmSwitcher     The new switcher.
938
949
 * @remark  This function may be called before the VMM is initialized.
939
950
 */
963
974
        pVM->vmm.s.enmSwitcher = enmSwitcher;
964
975
 
965
976
        RTR0PTR     pbCodeR0 = (RTR0PTR)pVM->vmm.s.pvCoreCodeR0 + pVM->vmm.s.aoffSwitchers[enmSwitcher]; /** @todo fix the pvCoreCodeR0 type */
966
 
        pVM->vmm.s.pfnHostToGuestR0 = pbCodeR0 + pSwitcher->offR0HostToGuest;
 
977
        pVM->vmm.s.pfnR0ToRawMode           = pbCodeR0 + pSwitcher->offR0ToRawMode;
967
978
 
968
 
        RTGCPTR     GCPtr = pVM->vmm.s.pvCoreCodeRC + pVM->vmm.s.aoffSwitchers[enmSwitcher];
969
 
        pVM->vmm.s.pfnGuestToHostRC         = GCPtr + pSwitcher->offGCGuestToHost;
970
 
        pVM->vmm.s.pfnCallTrampolineRC      = GCPtr + pSwitcher->offGCCallTrampoline;
971
 
        pVM->pfnVMMGCGuestToHostAsm         = GCPtr + pSwitcher->offGCGuestToHostAsm;
972
 
        pVM->pfnVMMGCGuestToHostAsmHyperCtx = GCPtr + pSwitcher->offGCGuestToHostAsmHyperCtx;
973
 
        pVM->pfnVMMGCGuestToHostAsmGuestCtx = GCPtr + pSwitcher->offGCGuestToHostAsmGuestCtx;
 
979
        RTRCPTR     RCPtr = pVM->vmm.s.pvCoreCodeRC + pVM->vmm.s.aoffSwitchers[enmSwitcher];
 
980
        pVM->vmm.s.pfnRCToHost              = RCPtr + pSwitcher->offRCToHost;
 
981
        pVM->vmm.s.pfnCallTrampolineRC      = RCPtr + pSwitcher->offRCCallTrampoline;
 
982
        pVM->pfnVMMRCToHostAsm              = RCPtr + pSwitcher->offRCToHostAsm;
 
983
        pVM->pfnVMMRCToHostAsmNoReturn      = RCPtr + pSwitcher->offRCToHostAsmNoReturn;
974
984
        return VINF_SUCCESS;
975
985
    }
976
986
 
977
987
    return VERR_NOT_IMPLEMENTED;
978
988
}
979
989
 
 
990
#endif /* VBOX_WITH_RAW_MODE */
 
991
 
980
992
 
981
993
/**
982
994
 * Disable the switcher logic permanently.
983
995
 *
984
996
 * @returns VBox status code.
985
 
 * @param   pVM             VM handle.
 
997
 * @param   pVM             Pointer to the VM.
986
998
 */
987
999
VMMR3_INT_DECL(int) VMMR3DisableSwitcher(PVM pVM)
988
1000
{
1002
1014
 * Gets the switcher to be used for switching to GC.
1003
1015
 *
1004
1016
 * @returns host to guest ring 0 switcher entrypoint
1005
 
 * @param   pVM             VM handle.
 
1017
 * @param   pVM             Pointer to the VM.
1006
1018
 * @param   enmSwitcher     The new switcher.
1007
1019
 */
1008
1020
VMMR3_INT_DECL(RTR0PTR) VMMR3GetHostToGuestSwitcher(PVM pVM, VMMSWITCHER enmSwitcher)
1024
1036
    if (pSwitcher)
1025
1037
    {
1026
1038
        RTR0PTR     pbCodeR0 = (RTR0PTR)pVM->vmm.s.pvCoreCodeR0 + pVM->vmm.s.aoffSwitchers[enmSwitcher]; /** @todo fix the pvCoreCodeR0 type */
1027
 
        return pbCodeR0 + pSwitcher->offR0HostToGuest;
 
1039
        return pbCodeR0 + pSwitcher->offR0ToRawMode;
1028
1040
    }
1029
1041
    return NIL_RTR0PTR;
1030
1042
}