{-# LINE 1 "libraries\\Win32\\System\\Win32\\FileMapping\\Internal.hsc" #-}

{-# LINE 2 "libraries\\Win32\\System\\Win32\\FileMapping\\Internal.hsc" #-}
{-# LANGUAGE Safe #-}

{-# LINE 6 "libraries\\Win32\\System\\Win32\\FileMapping\\Internal.hsc" #-}
-----------------------------------------------------------------------------

-- |

-- Module      :  System.Win32.FileMapping.Internal

-- Copyright   :  (c) Esa Ilari Vuokko, 2006

-- License     :  BSD-style (see the file LICENSE)

--

-- Maintainer  :  Esa Ilari Vuokko <ei@vuokko.info>

-- Stability   :  provisional

-- Portability :  portable

--

-- A collection of FFI declarations for interfacing with Win32 mapped files.

--

-----------------------------------------------------------------------------

module System.Win32.FileMapping.Internal where

import System.Win32.Types   ( HANDLE, DWORD, BOOL, SIZE_T, LPCTSTR )

import Foreign                  ( Ptr, FunPtr )
import Foreign.C.Types (CUIntPtr(..))

#include "windows_cconv.h"



---------------------------------------------------------------------------

-- Derived functions

---------------------------------------------------------------------------


data MappedObject = MappedObject HANDLE HANDLE FileMapAccess


---------------------------------------------------------------------------

-- Enums

---------------------------------------------------------------------------

type ProtectSectionFlags = DWORD
sEC_COMMIT     :: ProtectSectionFlags
sEC_COMMIT     =  134217728
sEC_IMAGE      :: ProtectSectionFlags
sEC_IMAGE      =  16777216
sEC_NOCACHE    :: ProtectSectionFlags
sEC_NOCACHE    =  268435456
sEC_NOCACHE :: FileMapAccess
sEC_RESERVE    :: ProtectSectionFlags
sEC_RESERVE    =  67108864

{-# LINE 47 "libraries\\Win32\\System\\Win32\\FileMapping\\Internal.hsc" #-}
type FileMapAccess = DWORD
fILE_MAP_ALL_ACCESS    :: FileMapAccess
fILE_MAP_ALL_ACCESS    =  983071
fILE_MAP_COPY          :: FileMapAccess
fILE_MAP_COPY          =  1
fILE_MAP_READ          :: FileMapAccess
fILE_MAP_READ          =  4
fILE_MAP_WRITE         :: FileMapAccess
fILE_MAP_WRITE         =  2

{-# LINE 54 "libraries\\Win32\\System\\Win32\\FileMapping\\Internal.hsc" #-}

---------------------------------------------------------------------------

-- Imports

---------------------------------------------------------------------------

foreign import WINDOWS_CCONV "windows.h OpenFileMappingW"
    c_OpenFileMapping :: DWORD -> BOOL -> LPCTSTR -> IO HANDLE

foreign import WINDOWS_CCONV "windows.h CreateFileMappingW"
    c_CreateFileMapping :: HANDLE -> Ptr () -> DWORD -> DWORD -> DWORD -> LPCTSTR -> IO HANDLE

foreign import WINDOWS_CCONV "windows.h MapViewOfFileEx"
    c_MapViewOfFileEx :: HANDLE -> DWORD -> DWORD -> DWORD -> SIZE_T -> Ptr a -> IO (Ptr b)

foreign import WINDOWS_CCONV "windows.h UnmapViewOfFile"
    c_UnmapViewOfFile :: Ptr a -> IO BOOL

{-# CFILES cbits/HsWin32.c #-}
foreign import ccall "HsWin32.h &UnmapViewOfFileFinaliser"
    c_UnmapViewOfFileFinaliser :: FunPtr (Ptr a -> IO ())