{-# LINE 1 "System/Posix/DynamicLinker/Prim.hsc" #-}
{-# LANGUAGE Trustworthy #-}
{-# OPTIONS_GHC -Wno-trustworthy-safe #-}
module System.Posix.DynamicLinker.Prim (
c_dlopen,
c_dlsym,
c_dlerror,
c_dlclose,
haveRtldNext,
haveRtldLocal,
packRTLDFlags,
RTLDFlags(..),
packDL,
DL(..),
)
where
import Data.Bits ( (.|.) )
import Foreign.Ptr ( Ptr, FunPtr, nullPtr )
import Foreign.C.Types
import Foreign.C.String ( CString )
{-# LINE 49 "System/Posix/DynamicLinker/Prim.hsc" #-}
haveRtldNext :: Bool
{-# LINE 63 "System/Posix/DynamicLinker/Prim.hsc" #-}
haveRtldNext = True
foreign import ccall unsafe "__hsunix_rtldNext" rtldNext :: Ptr a
{-# LINE 68 "System/Posix/DynamicLinker/Prim.hsc" #-}
{-# LINE 70 "System/Posix/DynamicLinker/Prim.hsc" #-}
foreign import ccall unsafe "__hsunix_rtldDefault" rtldDefault :: Ptr a
{-# LINE 72 "System/Posix/DynamicLinker/Prim.hsc" #-}
haveRtldLocal :: Bool
haveRtldLocal = True
{-# DEPRECATED haveRtldLocal "defaults to True" #-}
data RTLDFlags
= RTLD_LAZY
| RTLD_NOW
| RTLD_GLOBAL
| RTLD_LOCAL
deriving (Show, Read)
foreign import ccall unsafe "dlopen" c_dlopen :: CString -> CInt -> IO (Ptr ())
foreign import ccall unsafe "dlsym" c_dlsym :: Ptr () -> CString -> IO (FunPtr a)
foreign import ccall unsafe "dlerror" c_dlerror :: IO CString
foreign import ccall unsafe "dlclose" c_dlclose :: (Ptr ()) -> IO CInt
packRTLDFlags :: [RTLDFlags] -> CInt
packRTLDFlags flags = foldl (\ s f -> (packRTLDFlag f) .|. s) 0 flags
packRTLDFlag :: RTLDFlags -> CInt
{-# LINE 97 "System/Posix/DynamicLinker/Prim.hsc" #-}
packRTLDFlag RTLD_LAZY = 1
{-# LINE 99 "System/Posix/DynamicLinker/Prim.hsc" #-}
packRTLDFlag RTLD_NOW = 2
{-# LINE 100 "System/Posix/DynamicLinker/Prim.hsc" #-}
packRTLDFlag RTLD_GLOBAL = 256
{-# LINE 101 "System/Posix/DynamicLinker/Prim.hsc" #-}
packRTLDFlag RTLD_LOCAL = 0
{-# LINE 102 "System/Posix/DynamicLinker/Prim.hsc" #-}
{-# LINE 110 "System/Posix/DynamicLinker/Prim.hsc" #-}
data DL = Null | Next | Default | DLHandle (Ptr ()) deriving (Show)
packDL :: DL -> Ptr ()
packDL Null = nullPtr
{-# LINE 124 "System/Posix/DynamicLinker/Prim.hsc" #-}
packDL Next = rtldNext
{-# LINE 128 "System/Posix/DynamicLinker/Prim.hsc" #-}
{-# LINE 130 "System/Posix/DynamicLinker/Prim.hsc" #-}
packDL Default = rtldDefault
{-# LINE 134 "System/Posix/DynamicLinker/Prim.hsc" #-}
packDL (DLHandle h) = h