]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/io/mmap/windows/windows.factor
factor: trim using lists
[factor.git] / basis / io / mmap / windows / windows.factor
index fcdf4165115d779b392e04df24ee8475473c3c94..1b57d13dd2eac4b78c98757cb11fbf92fc62c162 100644 (file)
@@ -1,8 +1,7 @@
-USING: alien alien.c-types arrays destructors generic io.mmap
-io.ports io.backend.windows io.files.windows io.backend.windows.privileges
-kernel libc math math.bitwise namespaces quotations sequences
-windows windows.advapi32 windows.kernel32 io.backend system
-accessors locals ;
+USING: accessors destructors windows.privileges
+io.files.windows io.mmap io.mmap.private kernel literals
+math math.bitwise system windows.errors windows.handles
+windows.kernel32 ;
 IN: io.mmap.windows
 
 : create-file-mapping ( hFile lpAttributes flProtect dwMaximumSizeHigh dwMaximumSizeLow lpName -- HANDLE )
@@ -12,14 +11,13 @@ IN: io.mmap.windows
     MapViewOfFile [ win32-error=0/f ] keep ;
 
 :: mmap-open ( path length access-mode create-mode protect access -- handle handle address )
-    [let | lo [ length HEX: ffffffff bitand ]
-           hi [ length -32 shift HEX: ffffffff bitand ] |
-        { "SeCreateGlobalPrivilege" "SeLockMemoryPrivilege" } [
-            path access-mode create-mode 0 open-file |dispose
-            dup handle>> f protect hi lo f create-file-mapping |dispose
-            dup handle>> access 0 0 0 map-view-of-file
-        ] with-privileges
-    ] ;
+    length 32 bits :> lo
+    length -32 shift 32 bits :> hi
+    { "SeCreateGlobalPrivilege" "SeLockMemoryPrivilege" } [
+        path access-mode create-mode 0 open-file |dispose
+        dup handle>> f protect hi lo f create-file-mapping |dispose
+        dup handle>> access 0 0 0 map-view-of-file
+    ] with-privileges ;
 
 TUPLE: win32-mapped-file file mapping ;
 
@@ -28,16 +26,25 @@ M: win32-mapped-file dispose
 
 C: <win32-mapped-file> win32-mapped-file
 
-M: windows (mapped-file)
+M: windows (mapped-file-r/w)
     [
-        { GENERIC_WRITE GENERIC_READ } flags
+        flags{ GENERIC_WRITE GENERIC_READ }
         OPEN_ALWAYS
-        { PAGE_READWRITE SEC_COMMIT } flags
+        flags{ PAGE_READWRITE SEC_COMMIT }
         FILE_MAP_ALL_ACCESS mmap-open
         -rot <win32-mapped-file>
     ] with-destructors ;
 
-M: windows close-mapped-file ( mapped-file -- )
+M: windows (mapped-file-reader)
+    [
+        GENERIC_READ
+        OPEN_ALWAYS
+        flags{ PAGE_READONLY SEC_COMMIT }
+        FILE_MAP_READ mmap-open
+        -rot <win32-mapped-file>
+    ] with-destructors ;
+
+M: windows close-mapped-file
     [
         [ handle>> &dispose drop ]
         [ address>> UnmapViewOfFile win32-error=0/f ] bi