Exemple #1
0
    def SetRegisters(self, Registers):
        '''Set registers in a VP.'''
        Success, Ret = hvplat.WHvSetVirtualProcessorRegisters(
            self.Handle, self.Index, Registers)

        assert Success, 'WHvSetVirtualProcessorRegisters failed with: %s.' % hvplat.WHvReturn(
            Ret)
Exemple #2
0
    def ClearGpaRangeDirtyPages(self, Gpa, RangeSize):
        '''Clear the dirty bits on a GPA range.'''
        Success, _, Ret = hvplat.WHvQueryGpaRangeDirtyBitmap(
            self.Handle, Gpa, RangeSize, True)

        assert Success, 'WHvQueryGpaRangeDirtyBitmap failed with: %s.' % hvplat.WHvReturn(
            Ret)
Exemple #3
0
    def Run(self):
        '''Run the virtual processor.'''
        Success, ExitContext, Ret = hvplat.WHvRunVirtualProcessor(
            self.Handle, self.Index)

        assert Success, 'WHvRunVirtualProcessor failed with: %s.' % hvplat.WHvReturn(
            Ret)
        return ExitContext, hvplat.WHvExitReason(ExitContext.ExitReason)
Exemple #4
0
    def GetPartitionCounters(self, Counter):
        '''Get a partition performance counter.'''
        Success, Counters, Ret = hvplat.WHvGetPartitionCounters(
            self.Handle, Counter)

        assert Success, 'WHvGetPartitionCounters failed with: %s.' % hvplat.WHvReturn(
            Ret)
        return Counters
Exemple #5
0
    def QueryGpaRangeDirtyBitmap(self, Gpa, RangeSize):
        '''Get a list of bits describing which physical guest page is dirty. One bit per
        page.'''
        Success, Bits, Ret = hvplat.WHvQueryGpaRangeDirtyBitmap(
            self.Handle, Gpa, RangeSize)

        assert Success, 'WHvQueryGpaRangeDirtyBitmap failed with: %s.' % hvplat.WHvReturn(
            Ret)
        return Bits
Exemple #6
0
    def GetRegisters(self, *Registers):
        '''Get registers of a VP.'''
        if isinstance(Registers[0], (tuple, list)):
            # This is probably the case where GetRegisters is invoked with an
            # array directly. It is useful at times, so we handle this case.
            Registers = Registers[0]

        Success, Registers, Ret = hvplat.WHvGetVirtualProcessorRegisters(
            self.Handle, self.Index, Registers)

        assert Success, 'GetRegisters failed with: %s.' % hvplat.WHvReturn(Ret)
        return Registers
Exemple #7
0
    def GetVpCounters(self, Counter):
        '''Get a virtual processor performance counter.'''
        Success, Counters, Ret = hvplat.WHvGetVirtualProcessorCounters(
            self.Handle, self.Index, Counter)

        assert Success, 'WHvGetVirtualProcessorCounters failed with: %s.' % hvplat.WHvReturn(
            Ret)

        Result = {
            whv.WHvProcessorCounterSetRuntime: Counters.Runtime,
            whv.WHvProcessorCounterSetIntercepts: Counters.Intercepts,
            whv.WHvProcessorCounterSetEvents: Counters.GuestEvents,
            whv.WHvProcessorCounterSetApic: Counters.Apic
        }.get(Counter, None)

        assert Result is not None, 'Counter(%x) has not been added to WHV_PROCESSOR_ALL_COUNTERS?' % Counter

        return Result
Exemple #8
0
    def TranslateGva(self, Gva, Flags=None):
        '''Translate a GVA into a GPA.'''
        if Flags is None:
            Flags = 're'

        WHvFlags = whv.WHvTranslateGvaFlagNone
        if 'r' in Flags:
            WHvFlags |= whv.WHvTranslateGvaFlagValidateRead
        if 'w' in Flags:
            WHvFlags |= whv.WHvTranslateGvaFlagValidateWrite
        if 'x' in Flags:
            WHvFlags |= whv.WHvTranslateGvaFlagValidateExecute
        if 'e' in Flags:
            WHvFlags |= whv.WHvTranslateGvaFlagPrivilegeExempt

        Success, ResultCode, Gpa, Ret = hvplat.WHvTranslateGva(
            self.Handle, self.Index, Gva, WHvFlags)

        assert Success, 'WHvTranslateGva failed with: %s.' % hvplat.WHvReturn(
            Ret)
        return (hvplat.WHvTranslateGvaResultCode(ResultCode), Gpa)
Exemple #9
0
    def MapGpaRangeWithoutContent(self, Gpa, SizeInBytes, Flags):
        '''Map a GPA range in the partition. This takes care of allocating
        memory in the host and mapping it in the guest.'''
        SizeInBytes = utils.Align2Page(SizeInBytes)
        Hva = VirtualAlloc(0, SizeInBytes, MEM_RESERVE | MEM_COMMIT,
                           PAGE_READWRITE)

        assert Hva is not None, 'VirtualAlloc failed.'

        if 'd' not in Flags:
            # Force the 'd' dirty flag that is used for save/restore.
            Flags += 'd'

        WHvFlags = whv.WHvMapGpaRangeFlagNone
        if 'r' in Flags:
            WHvFlags |= whv.WHvMapGpaRangeFlagRead

        if 'w' in Flags:
            WHvFlags |= whv.WHvMapGpaRangeFlagWrite

        if 'x' in Flags:
            WHvFlags |= whv.WHvMapGpaRangeFlagExecute

        if 'd' in Flags:
            WHvFlags |= whv.WHvMapGpaRangeFlagTrackDirtyPages

        Success, Ret = hvplat.WHvMapGpaRange(self.Handle, Hva, Gpa,
                                             SizeInBytes, WHvFlags)

        assert Success, 'WHvMapGpaRange failed with: %s.' % hvplat.WHvReturn(
            Ret)

        # Break the range into a series of pages for the translation table.
        for Idx in range(SizeInBytes / 0x1000):
            CurGpa = Gpa + (Idx * 0x1000)
            CurHva = Hva + (Idx * 0x1000)
            self.TranslationTable[CurGpa] = TranslationTableEntry_t(
                CurGpa, CurHva, Flags)

        return (Hva, Gpa, SizeInBytes)