cryptol-3.0.0: Cryptol: The Language of Cryptography

Safe Haskell | Safe-Inferred
Language | Haskell2010

Cryptol.Backend.FFI

Description

The implementation of loading and calling external functions from shared libraries.

Synopsis

- data ForeignSrc
- getForeignSrcPath :: ForeignSrc -> Maybe FilePath
- loadForeignSrc :: FilePath -> IO (Either FFILoadError ForeignSrc)
- unloadForeignSrc :: ForeignSrc -> IO ()
- foreignLibPath :: FilePath -> IO (Maybe FilePath)
- data ForeignImpl
- loadForeignImpl :: ForeignSrc -> String -> IO (Either FFILoadError ForeignImpl)
- class Storable a => FFIArg a
- class Storable a => FFIRet a
- data SomeFFIArg = forall a.FFIArg a => SomeFFIArg a
- callForeignImpl :: forall a. FFIRet a => ForeignImpl -> [SomeFFIArg] -> IO a

# Documentation

data ForeignSrc Source #

A source from which we can retrieve implementations of foreign functions.

#### Instances

Instances details

Show ForeignSrc Source # |
Instance details Defined in Cryptol.Backend.FFI Methods showsPrec :: Int -> ForeignSrc -> ShowS Source # show :: ForeignSrc -> String Source # showList :: [ForeignSrc] -> ShowS Source #
NFData ForeignSrc Source # |
Instance details Defined in Cryptol.Backend.FFI Methods rnf :: ForeignSrc -> () Source #

getForeignSrcPath :: ForeignSrc -> Maybe FilePath Source #

Get the file path of the `ForeignSrc`.

loadForeignSrc :: FilePath -> IO (Either FFILoadError ForeignSrc) Source #

Load a `ForeignSrc` for the given Cryptol file path. The file path of the shared library that we try to load is the same as the Cryptol file path except with a platform specific extension.

unloadForeignSrc :: ForeignSrc -> IO () Source #

Explicitly unload a `ForeignSrc` immediately instead of waiting for the garbage collector to do it. This can be useful if you want to immediately load the same library again to pick up new changes.

The `ForeignSrc` must not be used in any way after this is called, including calling `ForeignImpl`s loaded from it.

foreignLibPath :: FilePath -> IO (Maybe FilePath) Source #

Given the path to a Cryptol module, compute the location of the shared library we'd like to load.

data ForeignImpl Source #

An implementation of a foreign function.

loadForeignImpl :: ForeignSrc -> String -> IO (Either FFILoadError ForeignImpl) Source #

Load a `ForeignImpl` with the given name from the given `ForeignSrc`.

class Storable a => FFIArg a Source #

Types which can be converted into libffi arguments.

The Storable constraint is so that we can put them in arrays.

Minimal complete definition

ffiArg

#### Instances

Instances details

FFIArg CDouble Source # |
Instance details Defined in Cryptol.Backend.FFI Methods ffiArg :: CDouble -> Arg
FFIArg CFloat Source # |
Instance details Defined in Cryptol.Backend.FFI Methods ffiArg :: CFloat -> Arg
FFIArg CSize Source # |
Instance details Defined in Cryptol.Backend.FFI Methods ffiArg :: CSize -> Arg
FFIArg Word16 Source # |
Instance details Defined in Cryptol.Backend.FFI Methods ffiArg :: Word16 -> Arg
FFIArg Word32 Source # |
Instance details Defined in Cryptol.Backend.FFI Methods ffiArg :: Word32 -> Arg
FFIArg Word64 Source # |
Instance details Defined in Cryptol.Backend.FFI Methods ffiArg :: Word64 -> Arg
FFIArg Word8 Source # |
Instance details Defined in Cryptol.Backend.FFI Methods ffiArg :: Word8 -> Arg
FFIArg (Ptr a) Source # |
Instance details Defined in Cryptol.Backend.FFI Methods ffiArg :: Ptr a -> Arg

class Storable a => FFIRet a Source #

Types which can be returned from libffi.

The Storable constraint is so that we can put them in arrays.

Minimal complete definition

ffiRet

#### Instances

Instances details

FFIRet CDouble Source # |
Instance details Defined in Cryptol.Backend.FFI Methods ffiRet :: RetType CDouble
FFIRet CFloat Source # |
Instance details Defined in Cryptol.Backend.FFI Methods ffiRet :: RetType CFloat
FFIRet Word16 Source # |
Instance details Defined in Cryptol.Backend.FFI Methods ffiRet :: RetType Word16
FFIRet Word32 Source # |
Instance details Defined in Cryptol.Backend.FFI Methods ffiRet :: RetType Word32
FFIRet Word64 Source # |
Instance details Defined in Cryptol.Backend.FFI Methods ffiRet :: RetType Word64
FFIRet Word8 Source # |
Instance details Defined in Cryptol.Backend.FFI Methods ffiRet :: RetType Word8
FFIRet () Source # |
Instance details Defined in Cryptol.Backend.FFI Methods ffiRet :: RetType ()

data SomeFFIArg Source #

Existential wrapper around a `FFIArg`.

Constructors

forall a.FFIArg a => SomeFFIArg a |

callForeignImpl :: forall a. FFIRet a => ForeignImpl -> [SomeFFIArg] -> IO a Source #

Call a `ForeignImpl` with the given arguments. The type parameter decides how the return value should be converted into a Haskell value.