1 USING: accessors destructors windows.privileges
2 io.files.windows io.mmap io.mmap.private kernel literals
3 math math.bitwise system windows.errors windows.handles
7 : create-file-mapping ( hFile lpAttributes flProtect dwMaximumSizeHigh dwMaximumSizeLow lpName -- HANDLE )
8 CreateFileMapping [ win32-error=0/f ] keep <win32-handle> ;
10 : map-view-of-file ( hFileMappingObject dwDesiredAccess dwFileOffsetHigh dwFileOffsetLow dwNumberOfBytesToMap -- HANDLE )
11 MapViewOfFile [ win32-error=0/f ] keep ;
13 :: mmap-open ( path length access-mode create-mode protect access -- handle handle address )
15 length -32 shift 32 bits :> hi
16 { "SeCreateGlobalPrivilege" "SeLockMemoryPrivilege" } [
17 path access-mode create-mode 0 open-file |dispose
18 dup handle>> f protect hi lo f create-file-mapping |dispose
19 dup handle>> access 0 0 0 map-view-of-file
22 TUPLE: win32-mapped-file file mapping ;
24 M: win32-mapped-file dispose
25 [ file>> dispose ] [ mapping>> dispose ] bi ;
27 C: <win32-mapped-file> win32-mapped-file
29 M: windows (mapped-file-r/w)
31 flags{ GENERIC_WRITE GENERIC_READ }
33 flags{ PAGE_READWRITE SEC_COMMIT }
34 FILE_MAP_ALL_ACCESS mmap-open
35 -rot <win32-mapped-file>
38 M: windows (mapped-file-reader)
42 flags{ PAGE_READONLY SEC_COMMIT }
43 FILE_MAP_READ mmap-open
44 -rot <win32-mapped-file>
47 M: windows close-mapped-file
49 [ handle>> &dispose drop ]
50 [ address>> UnmapViewOfFile win32-error=0/f ] bi