]> gitweb.factorcode.org Git - factor.git/blob - basis/io/mmap/windows/windows.factor
factor: trim using lists
[factor.git] / basis / io / mmap / windows / windows.factor
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
4 windows.kernel32 ;
5 IN: io.mmap.windows
6
7 : create-file-mapping ( hFile lpAttributes flProtect dwMaximumSizeHigh dwMaximumSizeLow lpName -- HANDLE )
8     CreateFileMapping [ win32-error=0/f ] keep <win32-handle> ;
9
10 : map-view-of-file ( hFileMappingObject dwDesiredAccess dwFileOffsetHigh dwFileOffsetLow dwNumberOfBytesToMap -- HANDLE )
11     MapViewOfFile [ win32-error=0/f ] keep ;
12
13 :: mmap-open ( path length access-mode create-mode protect access -- handle handle address )
14     length 32 bits :> lo
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
20     ] with-privileges ;
21
22 TUPLE: win32-mapped-file file mapping ;
23
24 M: win32-mapped-file dispose
25     [ file>> dispose ] [ mapping>> dispose ] bi ;
26
27 C: <win32-mapped-file> win32-mapped-file
28
29 M: windows (mapped-file-r/w)
30     [
31         flags{ GENERIC_WRITE GENERIC_READ }
32         OPEN_ALWAYS
33         flags{ PAGE_READWRITE SEC_COMMIT }
34         FILE_MAP_ALL_ACCESS mmap-open
35         -rot <win32-mapped-file>
36     ] with-destructors ;
37
38 M: windows (mapped-file-reader)
39     [
40         GENERIC_READ
41         OPEN_ALWAYS
42         flags{ PAGE_READONLY SEC_COMMIT }
43         FILE_MAP_READ mmap-open
44         -rot <win32-mapped-file>
45     ] with-destructors ;
46
47 M: windows close-mapped-file
48     [
49         [ handle>> &dispose drop ]
50         [ address>> UnmapViewOfFile win32-error=0/f ] bi
51     ] with-destructors ;