[commit: packages/Win32] master: Add VirtualQueryEx and MEMORY_BASIC_INFORMATION (8fc5486)

git at git.haskell.org git at git.haskell.org
Thu Jul 30 06:57:53 UTC 2015


Repository : ssh://git@git.haskell.org/Win32

On branch  : master
Link       : http://git.haskell.org/packages/Win32.git/commitdiff/8fc5486f4e31ddeacd46c6b07d62934c3ce8f378

>---------------------------------------------------------------

commit 8fc5486f4e31ddeacd46c6b07d62934c3ce8f378
Author: Andrii Polishchuk <andriy.s.polishchuk at gmail.com>
Date:   Fri Jul 25 19:18:38 2014 +0300

    Add VirtualQueryEx and MEMORY_BASIC_INFORMATION


>---------------------------------------------------------------

8fc5486f4e31ddeacd46c6b07d62934c3ce8f378
 System/Win32/Mem.hsc | 47 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 46 insertions(+), 1 deletion(-)

diff --git a/System/Win32/Mem.hsc b/System/Win32/Mem.hsc
index d7ae27e..32f02a4 100644
--- a/System/Win32/Mem.hsc
+++ b/System/Win32/Mem.hsc
@@ -28,6 +28,47 @@ import Foreign.C.Types
 
 #include <windows.h>
 
+----------------------------------------------------------------
+-- Data types
+----------------------------------------------------------------
+
+data MEMORY_BASIC_INFORMATION = MEMORY_BASIC_INFORMATION
+    { mbiBaseAddress       :: Addr
+    , mbiAllocationBase    :: Addr
+    , mbiAllocationProtect :: DWORD
+    , mbiRegionSize        :: SIZE_T
+    , mbiState             :: DWORD
+    , mbiProtect           :: DWORD
+    , mbiType              :: DWORD
+    } deriving (Show)
+
+----------------------------------------------------------------
+-- Instances
+----------------------------------------------------------------
+
+instance Storable MEMORY_BASIC_INFORMATION where
+    sizeOf _ = #size MEMORY_BASIC_INFORMATION
+    alignment = sizeOf
+    poke buf mbi = do
+        (#poke MEMORY_BASIC_INFORMATION, BaseAddress)       buf (mbiBaseAddress mbi)
+        (#poke MEMORY_BASIC_INFORMATION, AllocationBase)    buf (mbiAllocationBase mbi)
+        (#poke MEMORY_BASIC_INFORMATION, AllocationProtect) buf (mbiAllocationProtect mbi)
+        (#poke MEMORY_BASIC_INFORMATION, RegionSize)        buf (mbiRegionSize mbi)
+        (#poke MEMORY_BASIC_INFORMATION, State)             buf (mbiState mbi)
+        (#poke MEMORY_BASIC_INFORMATION, Protect)           buf (mbiProtect mbi)
+        (#poke MEMORY_BASIC_INFORMATION, Type)              buf (mbiType mbi)
+    peek buf = do
+        baseAddress       <- (#peek MEMORY_BASIC_INFORMATION, BaseAddress)       buf
+        allocationBase    <- (#peek MEMORY_BASIC_INFORMATION, AllocationBase)    buf
+        allocationProtect <- (#peek MEMORY_BASIC_INFORMATION, AllocationProtect) buf
+        regionSize        <- (#peek MEMORY_BASIC_INFORMATION, RegionSize)        buf
+        state             <- (#peek MEMORY_BASIC_INFORMATION, State)             buf
+        protect           <- (#peek MEMORY_BASIC_INFORMATION, Protect)           buf
+        ty                <- (#peek MEMORY_BASIC_INFORMATION, Type)              buf
+        return $ MEMORY_BASIC_INFORMATION baseAddress allocationBase allocationProtect regionSize state protect ty
+
+----------------------------------------------------------------
+
 copyMemory :: Ptr a -> Ptr a -> DWORD -> IO ()
 copyMemory dest src nbytes = copyBytes dest src (fromIntegral nbytes)
 
@@ -265,7 +306,11 @@ virtualProtectEx proc addr size new_prot =
 foreign import WINDOWS_CCONV unsafe "windows.h VirtualProtectEx"
   c_VirtualProtectEx :: HANDLE -> Addr -> DWORD -> DWORD -> Ptr DWORD -> IO Bool
 
--- No VirtualQuery..()
+virtualQueryEx :: HANDLE -> LPVOID -> Ptr MEMORY_BASIC_INFORMATION -> SIZE_T -> IO DWORD
+virtualQueryEx hProcess lpAddress lpBuffer dwLength =
+  failIfZero "VirtualQueryEx" $ c_VirtualQueryEx hProcess lpAddress lpBuffer dwLength
+foreign import WINDOWS_CCONV unsafe "windows.h VirtualQueryEx"
+  c_VirtualQueryEx :: HANDLE -> LPVOID -> Ptr MEMORY_BASIC_INFORMATION -> SIZE_T -> IO DWORD
 
 virtualUnlock :: Addr -> DWORD -> IO ()
 virtualUnlock addr size =



More information about the ghc-commits mailing list