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 kernel libc math math.bitwise namespaces quotations sequences
4 windows windows.advapi32 windows.kernel32 io.backend system
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 )
15 [let | lo [ length HEX: ffffffff bitand ]
16 hi [ length -32 shift HEX: ffffffff bitand ] |
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
24 TUPLE: win32-mapped-file file mapping ;
26 M: win32-mapped-file dispose
27 [ file>> dispose ] [ mapping>> dispose ] bi ;
29 C: <win32-mapped-file> win32-mapped-file
31 M: windows (mapped-file)
33 { GENERIC_WRITE GENERIC_READ } flags
35 { PAGE_READWRITE SEC_COMMIT } flags
36 FILE_MAP_ALL_ACCESS mmap-open
37 -rot <win32-mapped-file>
40 M: windows close-mapped-file ( mapped-file -- )
42 [ handle>> &dispose drop ]
43 [ address>> UnmapViewOfFile win32-error=0/f ] bi