1 USING: alien alien.c-types arrays destructors generic io.mmap
2 io.ports io.backend.windows io.files.windows io.backend.windows.privileges
3 io.mmap.private kernel libc math math.bitwise namespaces quotations sequences
4 windows windows.advapi32 windows.kernel32 io.backend system
5 accessors locals windows.errors ;
8 : create-file-mapping ( hFile lpAttributes flProtect dwMaximumSizeHigh dwMaximumSizeLow lpName -- HANDLE )
9 CreateFileMapping [ win32-error=0/f ] keep <win32-handle> ;
11 : map-view-of-file ( hFileMappingObject dwDesiredAccess dwFileOffsetHigh dwFileOffsetLow dwNumberOfBytesToMap -- HANDLE )
12 MapViewOfFile [ win32-error=0/f ] keep ;
14 :: mmap-open ( path length access-mode create-mode protect access -- handle handle address )
16 length -32 shift 32 bits :> hi
17 { "SeCreateGlobalPrivilege" "SeLockMemoryPrivilege" } [
18 path access-mode create-mode 0 open-file |dispose
19 dup handle>> f protect hi lo f create-file-mapping |dispose
20 dup handle>> access 0 0 0 map-view-of-file
23 TUPLE: win32-mapped-file file mapping ;
25 M: win32-mapped-file dispose
26 [ file>> dispose ] [ mapping>> dispose ] bi ;
28 C: <win32-mapped-file> win32-mapped-file
30 M: windows (mapped-file-r/w)
32 { GENERIC_WRITE GENERIC_READ } flags
34 { PAGE_READWRITE SEC_COMMIT } flags
35 FILE_MAP_ALL_ACCESS mmap-open
36 -rot <win32-mapped-file>
39 M: windows (mapped-file-reader)
43 { PAGE_READONLY SEC_COMMIT } flags
44 FILE_MAP_READ mmap-open
45 -rot <win32-mapped-file>
48 M: windows close-mapped-file ( mapped-file -- )
50 [ handle>> &dispose drop ]
51 [ address>> UnmapViewOfFile win32-error=0/f ] bi