コード例 #1
0
ファイル: kvm.py プロジェクト: Soft/nitro
class VCPU(IOCTL):
    __slots__ = ('vcpu_nb', )

    KVM_NITRO_GET_EVENT = IOR(KVMIO, 0xE5, NitroEventStr)
    KVM_NITRO_CONTINUE = IO(KVMIO, 0xE6)
    KVM_NITRO_GET_REGS = IOR(KVMIO, 0xE7, Regs)
    KVM_NITRO_SET_REGS = IOW(KVMIO, 0xE8, Regs)
    KVM_NITRO_GET_SREGS = IOR(KVMIO, 0xE9, SRegs)
    KVM_NITRO_SET_SREGS = IOW(KVMIO, 0xEA, SRegs)

    def __init__(self, vcpu_nb, vcpu_fd):
        super().__init__()
        self.vcpu_nb = vcpu_nb
        self.fd = vcpu_fd

    def get_event(self):
        # logging.debug('get_event %s, self.vcpu_nb)
        nitro_ev = NitroEventStr()
        ret = self.make_ioctl(self.KVM_NITRO_GET_EVENT, byref(nitro_ev))
        if ret != 0:
            logging.error("get_event failed (vcpu: %d; returned: %d)",
                          self.vcpu_nb, ret)
            raise ValueError("get_event failed")
        return nitro_ev

    def continue_vm(self):
        # logging.debug('continue_vm %s', self.vcpu_nb)
        return self.make_ioctl(self.KVM_NITRO_CONTINUE, 0)

    def get_regs(self):
        regs = Regs()
        self.make_ioctl(self.KVM_NITRO_GET_REGS, byref(regs))
        return regs

    def get_sregs(self):
        sregs = SRegs()
        self.make_ioctl(self.KVM_NITRO_GET_SREGS, byref(sregs))
        return sregs

    def set_regs(self, regs):
        ret = self.make_ioctl(self.KVM_NITRO_SET_REGS, byref(regs))
        return ret

    def set_sregs(self, sregs):
        ret = self.make_ioctl(self.KVM_NITRO_SET_SREGS, byref(sregs))
        return ret
コード例 #2
0
class VCPU(IOCTL):

    KVM_NITRO_GET_EVENT = IOR(KVMIO, 0xE5, NitroEventStr)
    KVM_NITRO_CONTINUE = IO(KVMIO, 0xE6)

    def __init__(self, vcpu_nb, vcpu_fd):
        super().__init__()
        self.vcpu_nb = vcpu_nb
        self.fd = vcpu_fd

    def get_event(self):
        # logging.debug('get_event {}'.format(self.vcpu_nb))
        nitro_ev = NitroEventStr()
        self.make_ioctl(self.KVM_NITRO_GET_EVENT, byref(nitro_ev))
        return nitro_ev

    def continue_vm(self):
        # logging.debug('continue_vm {}'.format(self.vcpu_nb))
        return self.make_ioctl(self.KVM_NITRO_CONTINUE, None)
コード例 #3
0
ファイル: skunk.py プロジェクト: carmeli-tamir/skunk
 def __init__(self, device_name="/dev/skunk"):
     self.device_name = device_name
     self.func_call_ioctl_num = IOWR(0xEE, 0, ctypes.c_char_p)
     self.mock_create_ioctl_num = IOW(0xEE, 1, ctypes.c_char_p)
     self.mock_destroy_ioctl_num = IO(0xEE, 2)
     self.mock_return_values = skunk_pb2.ReturnValueMock()
コード例 #4
0
ファイル: kvm.py プロジェクト: S4Lab/oxpecker
class VCPU(IOCTL):
    """Class that allows controlling and inspecting the state of an individual virtual CPU."""

    __slots__ = (
        'vcpu_nb',
    )

    #: Request for retrieving event
    KVM_NITRO_GET_EVENT = IOR(KVMIO, 0xE5, NitroEventStr)
    #: Request to continue
    KVM_NITRO_CONTINUE = IO(KVMIO, 0xE6)
    #: Request to get register state
    KVM_NITRO_GET_REGS = IOR(KVMIO, 0xE7, Regs)
    #: Request to set register state
    KVM_NITRO_SET_REGS = IOW(KVMIO, 0xE8, Regs)
    #: Request to get special registers
    KVM_NITRO_GET_SREGS = IOR(KVMIO, 0xE9, SRegs)
    #: Request to set special registers
    KVM_NITRO_SET_SREGS = IOW(KVMIO, 0xEA, SRegs)

    def __init__(self, vcpu_nb, vcpu_fd):
        super().__init__()
        self.vcpu_nb = vcpu_nb
        self.fd = vcpu_fd

    def get_event(self):
        """
        Retrieve event from the virtual machine
        :rtype: NitroEventStr
        """
        # logging.debug('get_event %s, self.vcpu_nb)
        nitro_ev = NitroEventStr()
        ret = self.make_ioctl(self.KVM_NITRO_GET_EVENT, byref(nitro_ev))
        if ret != 0:
            raise ValueError("get_event failed on vcpu %d (%d)".format(self.vcpu_nb, ret))
        return nitro_ev

    def continue_vm(self):
        """Continue virtual machine execution"""
        # logging.debug('continue_vm %s', self.vcpu_nb)
        return self.make_ioctl(self.KVM_NITRO_CONTINUE, 0)

    def get_regs(self):
        """
        Get registers from the virtual machine.
        :rtype: Regs
        """
        regs = Regs()
        self.make_ioctl(self.KVM_NITRO_GET_REGS, byref(regs))
        return regs

    def get_sregs(self):
        """
        Get special registers from the virtual machine.
        :rtype: SRegs
        """
        sregs = SRegs()
        self.make_ioctl(self.KVM_NITRO_GET_SREGS, byref(sregs))
        return sregs

    def set_regs(self, regs):
        """
        Set registers for the virtual machine.
        :param Regs regs: Values for registers
        """
        ret = self.make_ioctl(self.KVM_NITRO_SET_REGS, byref(regs))
        return ret

    def set_sregs(self, sregs):
        """
        Set special registers for the virtual machine.
        :param SRegs sregs: Values for special registers
        """
        ret = self.make_ioctl(self.KVM_NITRO_SET_SREGS, byref(sregs))
        return ret
コード例 #5
0
        ('exit_reason', c_uint32),
        ('ready_for_interrupt_injection', c_uint8),
        ('if_flag', c_uint8),
        ('padding1', c_uint8 * 2),

        # in (pre_KVMRun), out (post_KVMRun)
        ('cr8', c_uint64),
        ('apic_base', c_uint64),
        ('exit_reasons', KVMRunExitReasons)
    ]


KVMIO = 0xae

# KVM IOCTLs
KVM_GET_API_VERSION = IO(KVMIO, 0x00)
KVM_CREATE_VM = IO(KVMIO, 0x01)
KVM_CHECK_EXTENSION = IO(KVMIO, 0x03)
KVM_GET_VCPU_MMAP_SIZE = IO(KVMIO, 0x04)

# KVM VM IOCTLs
KVM_CREATE_VCPU = IO(KVMIO, 0x41)
KVM_SET_TSS_ADDR = IO(KVMIO, 0x47)
KVM_SET_USER_MEMORY_REGION = IOW(KVMIO, 0x46, KVMUserSpaceMemoryRegion)

# KVM CPU IOCTLs
KVM_RUN = IO(KVMIO, 0x80)

KVM_GET_REGS = IOR(KVMIO, 0x81, KVMRegs)
KVM_SET_REGS = IOW(KVMIO, 0x82, KVMRegs)
KVM_GET_SREGS = IOR(KVMIO, 0x83, KVMSRegs)