module System.Xen.CBindings
( xc_interface_open
, xc_interface_close
, xc_find_device_number
, xc_domain_create
, xc_domain_dumpcore
, xc_domain_dumpcore_via_callback
, xc_domain_max_vcpus
, xc_domain_pause
, xc_domain_unpause
, xc_domain_destroy
, xc_domain_resume
, xc_domain_shutdown
, xc_vcpu_setaffinity
, xc_vcpu_getaffinity
, xc_domain_getinfo
, xc_domain_getinfolist
, xc_domain_hvm_getcontext
, xc_domain_hvm_setcontext
, xc_domain_setcpuweight
, xc_domain_get_cpu_usage
, xc_domain_sethandle
, xc_sedf_domain_set
, xc_sedf_domain_get
, xc_domain_send_trigger
, xc_vcpu_getinfo
, VCPUInfo(..)
, xc_evtchn_alloc_unbound
, xc_evtchn_reset
, xc_evtchn_open
, xc_evtchn_close
, xc_evtchn_fd
, xc_evtchn_notify
, xc_evtchn_bind_unbound_port
, xc_evtchn_bind_interdomain
, xc_evtchn_bind_virq
, xc_evtchn_unbind
, xc_evtchn_pending
, xc_evtchn_unmask
, xc_physdev_pci_access_modify
, xc_readconsolering
, xc_send_debug_keys
, xc_physinfo
, xc_sched_id
, xc_getcpuinfo
, xc_domain_setmaxmem
, xc_domain_set_memmap_limit
, xc_domain_set_time_offset
, xc_domain_memory_increase_reservation
, xc_domain_memory_decrease_reservation
, xc_domain_memory_populate_physmap
, xc_domain_ioport_permission
, xc_domain_irq_permission
, xc_make_page_below_4G
, xc_perfc_control
, xc_map_foreign_range
, xc_map_foreign_batch
, xc_translate_foreign_address
, xc_get_pfn_list
, xc_copy_to_domain_page
, xc_clear_domain_page
, xc_mmuext_op
, xc_memory_op
, xc_get_pfn_type_batch
, xc_get_tot_pages
, xc_tbuf_enable
, xc_tbuf_disable
, xc_tbuf_get_size
, xc_tbuf_set_cpu_mask
, xc_tbuf_set_evt_mask
, xc_domctl
, xc_sysctl
, xc_version
, xc_acm_op
, GTHandle (..)
, xc_gnttab_open
, xc_gnttab_close
, xc_gnttab_map_grant_ref
, xc_gnttab_map_grant_refs
, xc_gnttab_munmap
, DomId_t
, xc_hvm_set_pci_intx_level
, xc_hvm_set_isa_irq_level
, xc_hvm_set_pci_link_route
, XCErrorCode(..)
, xcMaxErrorMsgLen
, XCError(..)
, xc_get_last_error
, xc_clear_last_error
, XCErrorHandler
, xc_default_error_handler
, xc_error_code_to_desc
, xc_set_error_handler
, xc_set_hvm_param
, xc_get_hvm_param
, xc_CORE_MAGIC
, xc_CORE_MAGIC_HVM
, DomId(..)
, XCHandle(..)
, XCShutdown(..)
, XCDomInfo
, EventChanPortOrError
, Dumpcore_rtn_t
, XCEHandle(..)
, EventChannelPort(..)
, XCPhysInfo(..)
, XCCPUInfo(..)
, XCperfcDesc(..)
, XCperfcVal
, XenPFN
, PerfcOp
, perfcOpReset
, perfcOpQuery
, MemoryProtectionFlags
, MMUExtOp(..)
, XenDomainHandleT
, XenVersion
, xENVER_extraversion
, xENVER_compile_info
, xENVER_capabilities
, xENVER_changeset
, xENVER_platform_parameters
, xENVER_get_features
, xENVER_pagesize
, xENVER_guest_handle
, xENVER_version
) where
import Data.Bits
import Data.List (foldl1')
import Data.Word
import Data.Int
import qualified Data.ByteString as B
import Data.Array.IArray
import Foreign.C
import Foreign.Ptr
import Foreign.Storable
import Foreign.Marshal.Array (peekArray, pokeArray)
xc_CORE_MAGIC :: CInt
xc_CORE_MAGIC = 0xF00FEBED
xc_CORE_MAGIC_HVM :: CInt
xc_CORE_MAGIC_HVM = 0xF00FEBEE
data DomainFlag = Dying | Crashed | Shutdown | Paused | Blocked | Running | HVM | Debugged deriving (Eq, Ord, Show, Enum)
instance Storable [DomainFlag] where
sizeOf _ = sizeOf (undefined :: CUInt)
alignment _ = alignment (undefined :: CUInt)
peek ptr = do
v <- peek (castPtr ptr)
return $ fromBits v
poke ptr a = poke (castPtr ptr) (toBits a)
toBits :: [DomainFlag] -> CUInt
toBits flgs = foldl1' (.|.) (map (bit . fromEnum) flgs)
fromBits :: CUInt -> [DomainFlag]
fromBits v = map (toEnum . fst) flagsSet
where
flagsSet :: [(Int,Bool)]
flagsSet = filter ((==True) . snd) (zip [0..] flgVals)
flgVals :: [Bool]
flgVals = map (uncurry testBit) (zip (repeat v) [0..31])
data XCDomInfo = XCDomInfo {
diDomId :: Word32,
diSSIDRef :: Word32,
diFlags :: [DomainFlag],
diShutdownReason :: XCShutdown,
diNrPages :: CUInt,
diSharedInfoFrame :: CUInt,
diCpuTime :: Word64,
diMaxMemKB :: CULong,
diNrOnlineVCPUs :: CUInt,
diMaxVCPUId :: CUInt,
diDomHandle :: [XenDomainHandle]
} deriving (Eq, Ord, Show)
type XenDomainHandle = Word8
type XenDomainHandleT = Ptr Word8
instance Storable XCDomInfo where
sizeOf _= ((64))
alignment _ = alignment (undefined :: Word64)
peek ptr = do
domId <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) ptr
ssidRef <- ((\hsc_ptr -> peekByteOff hsc_ptr 4)) ptr
flags <- peekByteOff ptr (sizeOf domId + sizeOf ssidRef)
sr <- ((\hsc_ptr -> peekByteOff hsc_ptr 12)) ptr
nrPgs <- ((\hsc_ptr -> peekByteOff hsc_ptr 16)) ptr
infoF <- ((\hsc_ptr -> peekByteOff hsc_ptr 24)) ptr
cpuT <- ((\hsc_ptr -> peekByteOff hsc_ptr 28)) ptr
maxM <- ((\hsc_ptr -> peekByteOff hsc_ptr 36)) ptr
nrOC <- ((\hsc_ptr -> peekByteOff hsc_ptr 40)) ptr
maxCI <- ((\hsc_ptr -> peekByteOff hsc_ptr 44)) ptr
dh <- peekArray 16 (plusPtr ptr ((48)))
return $ XCDomInfo domId ssidRef flags sr nrPgs infoF cpuT maxM nrOC maxCI dh
poke ptr a = do
((\hsc_ptr -> pokeByteOff hsc_ptr 0)) ptr (diDomId a)
((\hsc_ptr -> pokeByteOff hsc_ptr 4)) ptr (diSSIDRef a)
pokeByteOff ptr (sizeOf (diDomId a) + sizeOf (diSSIDRef a)) (diFlags a)
((\hsc_ptr -> pokeByteOff hsc_ptr 12)) ptr (diShutdownReason a)
((\hsc_ptr -> pokeByteOff hsc_ptr 16)) ptr (diNrPages a)
((\hsc_ptr -> pokeByteOff hsc_ptr 24)) ptr (diSharedInfoFrame a)
((\hsc_ptr -> pokeByteOff hsc_ptr 28)) ptr (diCpuTime a)
((\hsc_ptr -> pokeByteOff hsc_ptr 36)) ptr (diMaxMemKB a)
((\hsc_ptr -> pokeByteOff hsc_ptr 40)) ptr (diNrOnlineVCPUs a)
((\hsc_ptr -> pokeByteOff hsc_ptr 44)) ptr (diMaxVCPUId a)
let p = plusPtr ptr 76
domHandles = take 16 $ diDomHandle a ++ repeat 0
pokeArray p domHandles
data XCShutdown = SHUTDOWN_poweroff | SHUTDOWN_reboot | SHUTDOWN_suspend | SHUTDOWN_crash
deriving (Eq, Ord, Show, Read, Enum)
instance Storable XCShutdown where
sizeOf _ = sizeOf (undefined :: CInt)
alignment _ = alignment (undefined :: CInt)
peek ptr = peek (castPtr ptr :: Ptr CInt) >>= return . toEnum . fromIntegral
poke ptr a = poke (castPtr ptr :: Ptr CInt) (fromIntegral (fromEnum a))
newtype XCHandle = XCHdl CInt deriving (Eq, Ord, Show)
instance Storable XCHandle where
sizeOf _ = sizeOf (undefined :: CInt)
alignment _ = alignment (undefined :: CInt)
peek ptr = peek (castPtr ptr) >>= return . XCHdl
poke ptr (XCHdl h) = poke (castPtr ptr) h
newtype DomId = DomId Word32 deriving (Eq, Ord, Show)
instance Storable DomId where
sizeOf _ = sizeOf (undefined :: Word32)
alignment _ = alignment (undefined :: Word32)
peek ptr = peek (castPtr ptr) >>= return . DomId
poke ptr i = poke (castPtr ptr) i
foreign import ccall unsafe "xc_interface_open"
xc_interface_open :: IO CInt
foreign import ccall unsafe "xc_interface_close"
xc_interface_close :: XCHandle -> IO CInt
foreign import ccall unsafe "xc_find_device_number"
xc_find_device_number :: CString -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_domain_create"
xc_domain_create :: XCHandle -> Word32 -> XenDomainHandleT -> Word32 -> Ptr Word32 -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_domain_dumpcore"
xc_domain_dumpcore :: XCHandle -> DomId -> CString -> IO CInt
type Dumpcore_rtn_t = (Ptr Word8 -> CString -> CUInt -> IO CInt)
foreign import ccall safe "xenctrl.h xc_domain_dumpcore_via_callback"
xc_domain_dumpcore_via_callback :: XCHandle -> DomId -> Ptr Word8 -> FunPtr Dumpcore_rtn_t -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_domain_max_vcpus"
xc_domain_max_vcpus :: XCHandle -> DomId -> CUInt -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_domain_pause"
xc_domain_pause :: XCHandle -> DomId -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_domain_unpause"
xc_domain_unpause :: XCHandle -> DomId -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_domain_destroy"
xc_domain_destroy :: XCHandle -> DomId -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_domain_resume"
xc_domain_resume :: XCHandle -> DomId -> CInt -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_domain_shutdown"
xc_domain_shutdown :: XCHandle -> DomId -> CInt -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_vcpu_setaffinity"
xc_vcpu_setaffinity :: XCHandle -> DomId -> CInt -> Word64 -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_vcpu_getaffinity"
xc_vcpu_getaffinity :: XCHandle -> DomId -> CInt -> Ptr Word64 -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_domain_getinfo"
xc_domain_getinfo :: XCHandle -> DomId -> CUInt -> Ptr XCDomInfo -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_domain_getinfolist"
xc_domain_getinfolist :: XCHandle -> DomId -> CUInt -> Ptr XCDomInfo -> CInt
foreign import ccall unsafe "xenctrl.h xc_domain_hvm_getcontext"
xc_domain_hvm_getcontext :: XCHandle -> DomId -> Ptr Word8 -> Word32 -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_domain_hvm_setcontext"
xc_domain_hvm_setcontext :: XCHandle -> DomId -> Ptr Word8 -> Word32 -> IO CInt
data VCPUInfo =
VCPUInfo {
viVCPU :: Word32,
viOnline :: Word8,
viBlocked :: Word8,
viRunning :: Word8,
viCPUTime :: Word64,
viCPU :: Word32
} deriving (Eq, Ord, Show)
instance Storable VCPUInfo where
sizeOf _ = ((24))
alignment _ = alignment (undefined :: Word64)
peek ptr = do
v <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) ptr
o <- ((\hsc_ptr -> peekByteOff hsc_ptr 4)) ptr
b <- ((\hsc_ptr -> peekByteOff hsc_ptr 5)) ptr
r <- ((\hsc_ptr -> peekByteOff hsc_ptr 6)) ptr
t <- ((\hsc_ptr -> peekByteOff hsc_ptr 8)) ptr
c <- ((\hsc_ptr -> peekByteOff hsc_ptr 16)) ptr
return $ VCPUInfo v o b r t c
poke ptr (VCPUInfo v o b r t c) = do
((\hsc_ptr -> pokeByteOff hsc_ptr 0)) ptr v
((\hsc_ptr -> pokeByteOff hsc_ptr 4)) ptr o
((\hsc_ptr -> pokeByteOff hsc_ptr 5)) ptr b
((\hsc_ptr -> pokeByteOff hsc_ptr 6)) ptr r
((\hsc_ptr -> pokeByteOff hsc_ptr 8)) ptr t
((\hsc_ptr -> pokeByteOff hsc_ptr 16)) ptr c
foreign import ccall unsafe "xenctrl.h xc_vcpu_getinfo"
xc_vcpu_getinfo :: XCHandle -> DomId -> Word32 -> Ptr VCPUInfo -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_domain_setcpuweight"
xc_domain_setcpuweight :: XCHandle -> DomId -> CFloat -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_domain_get_cpu_usage"
xc_domain_get_cpu_usage :: XCHandle -> DomId -> CInt -> IO CLLong
foreign import ccall unsafe "xenctrl.h xc_domain_sethandle"
xc_domain_sethandle :: XCHandle -> DomId -> XenDomainHandleT -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_sedf_domain_set"
xc_sedf_domain_set :: XCHandle -> DomId -> Word64 -> Word64 -> Word64 -> Word16 -> Word16 -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_sedf_domain_get"
xc_sedf_domain_get :: XCHandle -> DomId -> Ptr Word64 -> Ptr Word64 -> Ptr Word64 -> Ptr Word16 -> Ptr Word16 -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_domain_send_trigger"
xc_domain_send_trigger :: XCHandle -> DomId -> Word32 -> Word32 -> IO CInt
type EventChanPortOrError = CInt
newtype XCEHandle = XCEHandle CInt deriving (Eq, Ord, Show)
instance Storable XCEHandle where
sizeOf _ = sizeOf (undefined :: CInt)
alignment _ = alignment (undefined :: CInt)
peek ptr = peek (castPtr ptr) >>= return . XCEHandle
poke ptr (XCEHandle h) = poke (castPtr ptr) h
foreign import ccall unsafe "xenctrl.h xc_evtchn_alloc_unbound"
xc_evtchn_alloc_unbound :: XCHandle -> DomId -> DomId -> IO EventChanPortOrError
foreign import ccall unsafe "xenctrl.h xc_evtchn_reset"
xc_evtchn_reset :: XCHandle -> DomId -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_evtchn_open"
xc_evtchn_open :: IO CInt
foreign import ccall unsafe "xenctrl.h xc_evtchn_close"
xc_evtchn_close :: XCEHandle -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_evtchn_fd"
xc_evtchn_fd :: CInt -> IO CInt
newtype EventChannelPort = ECPort Word32 deriving (Eq, Ord, Show)
instance Storable EventChannelPort where
sizeOf _ = sizeOf (undefined :: Word32)
alignment _ = alignment (undefined :: Word32)
peek ptr = peek (castPtr ptr) >>= return . ECPort
poke ptr (ECPort p) = poke (castPtr ptr) p
foreign import ccall unsafe "xenctrl.h xc_evtchn_notify"
xc_evtchn_notify :: XCEHandle -> EventChannelPort -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_evtchn_bind_unbound_port"
xc_evtchn_bind_unbound_port :: XCEHandle -> DomId -> IO EventChanPortOrError
foreign import ccall unsafe "xenctrl.h xc_evtchn_bind_interdomain"
xc_evtchn_bind_interdomain :: XCEHandle -> DomId -> EventChannelPort -> IO EventChanPortOrError
foreign import ccall unsafe "xenctrl.h xc_evtchn_bind_virq"
xc_evtchn_bind_virq :: XCEHandle -> CUInt -> IO EventChanPortOrError
foreign import ccall unsafe "xenctrl.h xc_evtchn_unbind"
xc_evtchn_unbind :: XCEHandle -> EventChannelPort -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_evtchn_pending"
xc_evtchn_pending :: XCEHandle -> IO EventChanPortOrError
foreign import ccall unsafe "xenctrl.h xc_evtchn_unmask"
xc_evtchn_unmask :: XCEHandle -> EventChannelPort -> IO CInt
type Bus = CInt
type Dev = CInt
type Function = CInt
type Enable = CInt
foreign import ccall unsafe "xenctrl.h xc_physdev_pci_access_modify"
xc_physdev_pci_access_modify :: XCHandle -> DomId -> Bus -> Dev -> Function -> Enable -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_readconsolering"
xc_readconsolering :: XCHandle -> Ptr CString -> Ptr CUInt -> CInt -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_send_debug_keys"
xc_send_debug_keys :: XCHandle -> CString -> IO CInt
data XCPhysInfo = XCPhysInfo {
piThreadsPerCore :: Word32,
piCoresPerSocket :: Word32,
piNrCPUs :: Word32,
piMaxNodeId :: Word32,
piCPUkhz :: Word32,
piTotalPages :: Word64,
piFreePages :: Word64,
piScrubPages :: Word64,
piHWCap :: [Word32]
} deriving (Eq, Ord, Show)
instance Storable XCPhysInfo where
sizeOf _ = ((104))
alignment _ = alignment (undefined :: Word64)
peek ptr = do
t <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) ptr
c <- ((\hsc_ptr -> peekByteOff hsc_ptr 4)) ptr
s <- ((\hsc_ptr -> peekByteOff hsc_ptr 8)) ptr
nr <- ((\hsc_ptr -> peekByteOff hsc_ptr 12)) ptr
cpu <- ((\hsc_ptr -> peekByteOff hsc_ptr 16)) ptr
tp <- ((\hsc_ptr -> peekByteOff hsc_ptr 24)) ptr
fp <- ((\hsc_ptr -> peekByteOff hsc_ptr 32)) ptr
sp <- ((\hsc_ptr -> peekByteOff hsc_ptr 40)) ptr
let p = castPtr (plusPtr ptr ((48))) :: Ptr Word32
hw <- (peekArray 8 p) :: IO [Word32]
return $ XCPhysInfo t c s nr cpu tp fp sp hw
poke ptr (XCPhysInfo t c s nr cpu tp fp sp hw) = do
((\hsc_ptr -> pokeByteOff hsc_ptr 0)) ptr t
((\hsc_ptr -> pokeByteOff hsc_ptr 4)) ptr c
((\hsc_ptr -> pokeByteOff hsc_ptr 8)) ptr s
((\hsc_ptr -> pokeByteOff hsc_ptr 12)) ptr nr
((\hsc_ptr -> pokeByteOff hsc_ptr 16)) ptr cpu
((\hsc_ptr -> pokeByteOff hsc_ptr 24)) ptr tp
((\hsc_ptr -> pokeByteOff hsc_ptr 32)) ptr fp
((\hsc_ptr -> pokeByteOff hsc_ptr 40)) ptr sp
let p = castPtr $ plusPtr ptr ((48))
pokeArray p hw
foreign import ccall unsafe "xenctrl.h xc_physinfo"
xc_physinfo :: XCHandle -> Ptr XCPhysInfo -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_sched_id"
xc_sched_id :: XCHandle -> Ptr CInt -> IO CInt
data XCCPUInfo = XCCPUInfo { ciIdleTime :: Word64 } deriving (Eq, Ord, Show)
instance Storable XCCPUInfo where
sizeOf _ = ((8))
alignment _ = alignment (undefined :: Word64)
peek ptr = ((\hsc_ptr -> peekByteOff hsc_ptr 0)) ptr >>= return . XCCPUInfo
poke ptr (XCCPUInfo i) = ((\hsc_ptr -> pokeByteOff hsc_ptr 0)) ptr i
foreign import ccall unsafe "xenctrl.h xc_getcpuinfo"
xc_getcpuinfo :: XCHandle -> CInt -> Ptr XCCPUInfo -> Ptr CInt -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_domain_setmaxmem"
xc_domain_setmaxmem :: XCHandle -> DomId -> CUInt -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_domain_set_memmap_limit"
xc_domain_set_memmap_limit :: XCHandle -> DomId -> CULong -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_domain_set_time_offset"
xc_domain_set_time_offset :: XCHandle -> DomId -> Int32 -> IO CInt
type XenPFN = CULong
foreign import ccall unsafe "xenctrl.h xc_domain_memory_increase_reservation"
xc_domain_memory_increase_reservation :: XCHandle -> DomId -> CULong -> CUInt -> CUInt -> Ptr XenPFN -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_domain_memory_decrease_reservation"
xc_domain_memory_decrease_reservation :: XCHandle -> DomId -> CULong -> CUInt -> Ptr XenPFN -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_domain_memory_populate_physmap"
xc_domain_memory_populate_physmap :: XCHandle -> DomId -> CULong -> CUInt -> CUInt -> Ptr XenPFN -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_domain_ioport_permission"
xc_domain_ioport_permission :: XCHandle -> DomId -> Word32 -> Word32 -> Word32 -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_domain_irq_permission"
xc_domain_irq_permission :: XCHandle -> DomId -> Word8 -> Word8 -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_domain_iomem_permission"
xc_domain_iomem_permission :: XCHandle -> DomId -> CULong -> CULong -> Word8 -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_make_page_below_4G"
xc_make_page_below_4G :: XCHandle -> DomId -> CULong -> IO CULong
data XCperfcDesc = XCperfcDesc B.ByteString Word32
type XCperfcVal = Word32
instance Storable XCperfcDesc where
sizeOf _ = ((84))
alignment _ = alignment (undefined :: Word32)
peek ptr = do
bs <- B.packCStringLen (castPtr ptr,80)
w <- ((\hsc_ptr -> peekByteOff hsc_ptr 80)) ptr
return $ XCperfcDesc bs w
poke ptr (XCperfcDesc bs w) = do
pokeArray (castPtr ptr) (take 80 (B.unpack bs ++ repeat 0))
((\hsc_ptr -> pokeByteOff hsc_ptr 80)) ptr w
type PerfcOp = Word32
perfcOpReset = 1
perfcOpQuery = 2
foreign import ccall unsafe "xenctrl.h xc_perfc_control"
xc_perfc_control :: XCHandle -> PerfcOp -> Ptr XCperfcDesc -> Ptr XCperfcVal -> Ptr CInt -> Ptr CInt -> IO CInt
type MemoryProtectionFlags = CInt
foreign import ccall unsafe "xenctrl.h xc_map_foreign_range"
xc_map_foreign_range :: XCHandle -> DomId -> CInt -> MemoryProtectionFlags -> CULong -> IO ()
foreign import ccall unsafe "xenctrl.h xc_map_foreign_batch"
xc_map_foreign_batch :: XCHandle -> DomId -> MemoryProtectionFlags -> Ptr XenPFN -> CInt -> IO ()
foreign import ccall unsafe "xenctrl.h xc_translate_foreign_address"
xc_translate_foreign_address :: XCHandle -> DomId -> CInt -> CULLong -> IO CULong
foreign import ccall unsafe "xenctrl.h xc_get_pfn_list"
xc_get_pfn_list :: XCHandle -> DomId -> Ptr Word64 -> CULong -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_copy_to_domain_page"
xc_copy_to_domain_page :: XCHandle -> DomId -> CULong -> CString -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_clear_domain_page"
xc_clear_domain_page :: XCHandle -> DomId -> CULong -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_get_max_pages"
xc_get_max_pages :: XCHandle -> DomId -> IO CLong
data MMUExtOp =
MMUExtOp { opCmd :: CUInt,
opArg1 :: Either XenPFN CULong,
opArg2 :: Either CUInt (Ptr ())
} deriving (Eq, Ord, Show)
foreign import ccall unsafe "xenctrl.h xc_mmuext_op"
xc_mmuext_op :: XCHandle -> Ptr MMUExtOp -> CUInt -> DomId -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_memory_op"
xc_memory_op :: XCHandle -> CInt -> Ptr () -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_get_pfn_type_batch"
xc_get_pfn_type_batch :: XCHandle -> DomId -> CInt -> Ptr Word32 -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_get_tot_pages"
xc_get_tot_pages :: XCHandle -> DomId -> IO CLong
foreign import ccall unsafe "xenctrl.h xc_tbuf_enable"
xc_tbuf_enable :: XCHandle -> CULong -> Ptr CULong -> Ptr CULong -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_tbuf_disable"
xc_tbuf_disable :: XCHandle -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_tbuf_get_size"
xc_tbuf_get_size :: XCHandle -> Ptr CULong -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_tbuf_set_cpu_mask"
xc_tbuf_set_cpu_mask :: XCHandle -> Word32 -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_tbuf_set_evt_mask"
xc_tbuf_set_evt_mask :: XCHandle -> Word32 -> IO CInt
data XenDomCtl = XenDomCtl
data XenSysCtl = XenSysCtl
foreign import ccall unsafe "xenctrl.h xc_domctl"
xc_domctl :: XCHandle -> Ptr XenDomCtl -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_sysctl"
xc_sysctl :: XCHandle -> Ptr XenSysCtl -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_version"
xc_version :: XCHandle -> XenVersion -> Ptr () -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_acm_op"
xc_acm_op :: XCHandle -> CInt -> Ptr () -> CULong -> IO CInt
newtype GTHandle = GTHandle CInt deriving (Eq, Ord, Show)
instance Storable GTHandle where
sizeOf _ = sizeOf (undefined :: CInt)
alignment _ = alignment (undefined :: CInt)
peek ptr = peek (castPtr ptr) >>= return . GTHandle
poke ptr (GTHandle h) = poke (castPtr ptr) h
foreign import ccall unsafe "xenctrl.h xc_gnttab_open"
xc_gnttab_open :: IO CInt
foreign import ccall unsafe "xenctrl.h xc_gnttab_close"
xc_gnttab_close :: GTHandle -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_gnttab_map_grant_ref"
xc_gnttab_map_grant_ref :: GTHandle -> DomId -> Word32 -> CInt -> IO (Ptr a)
foreign import ccall unsafe "xenctrl.h xc_gnttab_map_grant_refs"
xc_gnttab_map_grant_refs :: GTHandle -> Word32 -> Ptr Word32 -> Ptr Word32 -> CInt -> IO (Ptr a)
foreign import ccall unsafe "xenctrl.h xc_gnttab_munmap"
xc_gnttab_munmap :: GTHandle -> Ptr a -> Word32 -> IO CInt
type DomId_t = Word16
foreign import ccall unsafe "xenctrl.h xc_hvm_set_pci_intx_level"
xc_hvm_set_pci_intx_level :: XCHandle -> DomId_t -> Word8 -> Word8 -> Word8 -> Word8 -> CUInt -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_hvm_set_isa_irq_level"
xc_hvm_set_isa_irq_level :: XCHandle -> DomId_t -> Word8 -> CUInt -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_hvm_set_pci_link_route"
xc_hvm_set_pci_link_route :: XCHandle -> DomId_t -> Word8 -> Word8 -> IO CInt
data XCErrorCode = XCErrorNone | XCInternalError | XCInvalidKernel | XCInvalidParam | XCOutOfMemory
deriving (Eq, Ord, Show, Enum)
instance Storable XCErrorCode where
sizeOf _ = sizeOf (undefined :: CInt)
alignment _ = alignment (undefined :: CInt)
peek ptr = peek (castPtr ptr :: Ptr CInt) >>= return . toEnum . fromIntegral
poke ptr a = poke (castPtr ptr) (fromIntegral (fromEnum a) :: CInt)
xcMaxErrorMsgLen = 1024
data XCError = XCError { xceCode :: XCErrorCode, xceMsg :: B.ByteString } deriving (Eq, Ord, Show)
foreign import ccall unsafe "xenctrl.h xc_get_last_error"
xc_get_last_error :: IO (Ptr XCError)
foreign import ccall unsafe "xenctrl.h xc_clear_last_error"
xc_clear_last_error :: IO ()
type XCErrorHandler = FunPtr (XCError -> IO ())
foreign import ccall unsafe "xenctrl.h xc_default_error_handler"
xc_default_error_handler :: Ptr XCErrorHandler -> IO ()
foreign import ccall unsafe "xenctrl.h xc_error_code_to_desc"
xc_error_code_to_desc_c :: CInt -> IO CString
xc_error_code_to_desc :: XCErrorCode -> IO CString
xc_error_code_to_desc = xc_error_code_to_desc_c . fromIntegral . fromEnum
foreign import ccall unsafe "xenctrl.h xc_set_error_handler"
xc_set_error_handler :: XCErrorHandler -> IO XCErrorHandler
foreign import ccall unsafe "xenctrl.h xc_set_hvm_param"
xc_set_hvm_param :: XCHandle -> DomId_t -> CInt -> CULong -> IO CInt
foreign import ccall unsafe "xenctrl.h xc_get_hvm_param"
xc_get_hvm_param :: XCHandle -> DomId_t -> CInt -> Ptr CULong -> IO CInt
data XC_Core_Header = XC_Core_Header {
xchMagic :: CInt
, xchNrVCPUs :: CInt
, xchNrPages :: CInt
, xchCTXTOffset :: CInt
, xchIndexOffset :: CInt
, xchPagesOffset :: CInt } deriving (Eq, Ord, Show)
instance Storable XC_Core_Header where
sizeOf _ = ((24))
alignment _ = alignment (undefined :: CInt)
peek ptr = do
m <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) ptr
v <- ((\hsc_ptr -> peekByteOff hsc_ptr 4)) ptr
p <- ((\hsc_ptr -> peekByteOff hsc_ptr 8)) ptr
c <- ((\hsc_ptr -> peekByteOff hsc_ptr 12)) ptr
i <- ((\hsc_ptr -> peekByteOff hsc_ptr 16)) ptr
g <- ((\hsc_ptr -> peekByteOff hsc_ptr 20)) ptr
return (XC_Core_Header m v p c i g)
poke ptr (XC_Core_Header m v p c i g) = do
((\hsc_ptr -> pokeByteOff hsc_ptr 0)) ptr m
((\hsc_ptr -> pokeByteOff hsc_ptr 4)) ptr v
((\hsc_ptr -> pokeByteOff hsc_ptr 8)) ptr p
((\hsc_ptr -> pokeByteOff hsc_ptr 12)) ptr c
((\hsc_ptr -> pokeByteOff hsc_ptr 16)) ptr i
((\hsc_ptr -> pokeByteOff hsc_ptr 20)) ptr g
newtype XenVersion = XV CInt deriving (Eq, Ord, Show, Enum)
instance Storable XenVersion where
sizeOf _ = sizeOf (undefined :: CInt)
alignment _ = alignment (undefined :: CInt)
peek ptr = peek (castPtr ptr :: Ptr CInt) >>= return . toEnum . fromIntegral
poke ptr a = poke (castPtr ptr) (fromIntegral (fromEnum a) :: CInt)
xENVER_version = XV 0
xENVER_extraversion = XV 1
xENVER_compile_info = XV 2
xENVER_capabilities = XV 3
xENVER_changeset = XV 4
xENVER_platform_parameters = XV 5
xENVER_get_features = XV 6
xENVER_pagesize = XV 7
xENVER_guest_handle = XV 8