annotate gcc/ada/libgnat/s-mmosin__mingw.ads @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT RUN-TIME COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- S Y S T E M . M M A P . O S _ I N T E R F A C E --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
9 -- Copyright (C) 2007-2019, AdaCore --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- This library is free software; you can redistribute it and/or modify it --
kono
parents:
diff changeset
12 -- under terms of the GNU General Public License as published by the Free --
kono
parents:
diff changeset
13 -- Software Foundation; either version 3, or (at your option) any later --
kono
parents:
diff changeset
14 -- version. This library is distributed in the hope that it will be useful, --
kono
parents:
diff changeset
15 -- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- --
kono
parents:
diff changeset
16 -- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. --
kono
parents:
diff changeset
17 -- --
kono
parents:
diff changeset
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
kono
parents:
diff changeset
19 -- additional permissions described in the GCC Runtime Library Exception, --
kono
parents:
diff changeset
20 -- version 3.1, as published by the Free Software Foundation. --
kono
parents:
diff changeset
21 -- --
kono
parents:
diff changeset
22 -- You should have received a copy of the GNU General Public License and --
kono
parents:
diff changeset
23 -- a copy of the GCC Runtime Library Exception along with this program; --
kono
parents:
diff changeset
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
kono
parents:
diff changeset
25 -- <http://www.gnu.org/licenses/>. --
kono
parents:
diff changeset
26 -- --
kono
parents:
diff changeset
27 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
29 -- --
kono
parents:
diff changeset
30 ------------------------------------------------------------------------------
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 -- OS pecularities abstraction package for Win32 systems.
kono
parents:
diff changeset
33
kono
parents:
diff changeset
34 package System.Mmap.OS_Interface is
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 -- The Win package contains copy of definition found in recent System.Win32
kono
parents:
diff changeset
37 -- unit provided with the GNAT compiler. The copy is needed to be able to
kono
parents:
diff changeset
38 -- compile this unit with older compilers. Note that this internal Win
kono
parents:
diff changeset
39 -- package can be removed when GNAT 6.1.0 is not supported anymore.
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 package Win is
kono
parents:
diff changeset
42
kono
parents:
diff changeset
43 subtype PVOID is Standard.System.Address;
kono
parents:
diff changeset
44
kono
parents:
diff changeset
45 type HANDLE is new Interfaces.C.ptrdiff_t;
kono
parents:
diff changeset
46
kono
parents:
diff changeset
47 type WORD is new Interfaces.C.unsigned_short;
kono
parents:
diff changeset
48 type DWORD is new Interfaces.C.unsigned_long;
kono
parents:
diff changeset
49 type LONG is new Interfaces.C.long;
kono
parents:
diff changeset
50 type SIZE_T is new Interfaces.C.size_t;
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 type BOOL is new Interfaces.C.int;
kono
parents:
diff changeset
53 for BOOL'Size use Interfaces.C.int'Size;
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 FALSE : constant := 0;
kono
parents:
diff changeset
56
kono
parents:
diff changeset
57 GENERIC_READ : constant := 16#80000000#;
kono
parents:
diff changeset
58 GENERIC_WRITE : constant := 16#40000000#;
kono
parents:
diff changeset
59 OPEN_EXISTING : constant := 3;
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 type OVERLAPPED is record
kono
parents:
diff changeset
62 Internal : DWORD;
kono
parents:
diff changeset
63 InternalHigh : DWORD;
kono
parents:
diff changeset
64 Offset : DWORD;
kono
parents:
diff changeset
65 OffsetHigh : DWORD;
kono
parents:
diff changeset
66 hEvent : HANDLE;
kono
parents:
diff changeset
67 end record;
kono
parents:
diff changeset
68
kono
parents:
diff changeset
69 type SECURITY_ATTRIBUTES is record
kono
parents:
diff changeset
70 nLength : DWORD;
kono
parents:
diff changeset
71 pSecurityDescriptor : PVOID;
kono
parents:
diff changeset
72 bInheritHandle : BOOL;
kono
parents:
diff changeset
73 end record;
kono
parents:
diff changeset
74
kono
parents:
diff changeset
75 type SYSTEM_INFO is record
kono
parents:
diff changeset
76 dwOemId : DWORD;
kono
parents:
diff changeset
77 dwPageSize : DWORD;
kono
parents:
diff changeset
78 lpMinimumApplicationAddress : PVOID;
kono
parents:
diff changeset
79 lpMaximumApplicationAddress : PVOID;
kono
parents:
diff changeset
80 dwActiveProcessorMask : PVOID;
kono
parents:
diff changeset
81 dwNumberOfProcessors : DWORD;
kono
parents:
diff changeset
82 dwProcessorType : DWORD;
kono
parents:
diff changeset
83 dwAllocationGranularity : DWORD;
kono
parents:
diff changeset
84 wProcessorLevel : WORD;
kono
parents:
diff changeset
85 wProcessorRevision : WORD;
kono
parents:
diff changeset
86 end record;
kono
parents:
diff changeset
87 type LP_SYSTEM_INFO is access all SYSTEM_INFO;
kono
parents:
diff changeset
88
kono
parents:
diff changeset
89 INVALID_HANDLE_VALUE : constant HANDLE := -1;
kono
parents:
diff changeset
90 FILE_BEGIN : constant := 0;
kono
parents:
diff changeset
91 FILE_SHARE_READ : constant := 16#00000001#;
kono
parents:
diff changeset
92 FILE_ATTRIBUTE_NORMAL : constant := 16#00000080#;
kono
parents:
diff changeset
93 FILE_MAP_COPY : constant := 1;
kono
parents:
diff changeset
94 FILE_MAP_READ : constant := 4;
kono
parents:
diff changeset
95 FILE_MAP_WRITE : constant := 2;
kono
parents:
diff changeset
96 PAGE_READONLY : constant := 16#0002#;
kono
parents:
diff changeset
97 PAGE_READWRITE : constant := 16#0004#;
kono
parents:
diff changeset
98 INVALID_FILE_SIZE : constant := 16#FFFFFFFF#;
kono
parents:
diff changeset
99
kono
parents:
diff changeset
100 function CreateFile
kono
parents:
diff changeset
101 (lpFileName : Standard.System.Address;
kono
parents:
diff changeset
102 dwDesiredAccess : DWORD;
kono
parents:
diff changeset
103 dwShareMode : DWORD;
kono
parents:
diff changeset
104 lpSecurityAttributes : access SECURITY_ATTRIBUTES;
kono
parents:
diff changeset
105 dwCreationDisposition : DWORD;
kono
parents:
diff changeset
106 dwFlagsAndAttributes : DWORD;
kono
parents:
diff changeset
107 hTemplateFile : HANDLE) return HANDLE;
kono
parents:
diff changeset
108 pragma Import (Stdcall, CreateFile, "CreateFileW");
kono
parents:
diff changeset
109
kono
parents:
diff changeset
110 function WriteFile
kono
parents:
diff changeset
111 (hFile : HANDLE;
kono
parents:
diff changeset
112 lpBuffer : Standard.System.Address;
kono
parents:
diff changeset
113 nNumberOfBytesToWrite : DWORD;
kono
parents:
diff changeset
114 lpNumberOfBytesWritten : access DWORD;
kono
parents:
diff changeset
115 lpOverlapped : access OVERLAPPED) return BOOL;
kono
parents:
diff changeset
116 pragma Import (Stdcall, WriteFile, "WriteFile");
kono
parents:
diff changeset
117
kono
parents:
diff changeset
118 function ReadFile
kono
parents:
diff changeset
119 (hFile : HANDLE;
kono
parents:
diff changeset
120 lpBuffer : Standard.System.Address;
kono
parents:
diff changeset
121 nNumberOfBytesToRead : DWORD;
kono
parents:
diff changeset
122 lpNumberOfBytesRead : access DWORD;
kono
parents:
diff changeset
123 lpOverlapped : access OVERLAPPED) return BOOL;
kono
parents:
diff changeset
124 pragma Import (Stdcall, ReadFile, "ReadFile");
kono
parents:
diff changeset
125
kono
parents:
diff changeset
126 function CloseHandle (hObject : HANDLE) return BOOL;
kono
parents:
diff changeset
127 pragma Import (Stdcall, CloseHandle, "CloseHandle");
kono
parents:
diff changeset
128
kono
parents:
diff changeset
129 function GetFileSize
kono
parents:
diff changeset
130 (hFile : HANDLE; lpFileSizeHigh : access DWORD) return DWORD;
kono
parents:
diff changeset
131 pragma Import (Stdcall, GetFileSize, "GetFileSize");
kono
parents:
diff changeset
132
kono
parents:
diff changeset
133 function SetFilePointer
kono
parents:
diff changeset
134 (hFile : HANDLE;
kono
parents:
diff changeset
135 lDistanceToMove : LONG;
kono
parents:
diff changeset
136 lpDistanceToMoveHigh : access LONG;
kono
parents:
diff changeset
137 dwMoveMethod : DWORD) return DWORD;
kono
parents:
diff changeset
138 pragma Import (Stdcall, SetFilePointer, "SetFilePointer");
kono
parents:
diff changeset
139
kono
parents:
diff changeset
140 function CreateFileMapping
kono
parents:
diff changeset
141 (hFile : HANDLE;
kono
parents:
diff changeset
142 lpSecurityAttributes : access SECURITY_ATTRIBUTES;
kono
parents:
diff changeset
143 flProtect : DWORD;
kono
parents:
diff changeset
144 dwMaximumSizeHigh : DWORD;
kono
parents:
diff changeset
145 dwMaximumSizeLow : DWORD;
kono
parents:
diff changeset
146 lpName : Standard.System.Address) return HANDLE;
kono
parents:
diff changeset
147 pragma Import (Stdcall, CreateFileMapping, "CreateFileMappingW");
kono
parents:
diff changeset
148
kono
parents:
diff changeset
149 function MapViewOfFile
kono
parents:
diff changeset
150 (hFileMappingObject : HANDLE;
kono
parents:
diff changeset
151 dwDesiredAccess : DWORD;
kono
parents:
diff changeset
152 dwFileOffsetHigh : DWORD;
kono
parents:
diff changeset
153 dwFileOffsetLow : DWORD;
kono
parents:
diff changeset
154 dwNumberOfBytesToMap : SIZE_T) return Standard.System.Address;
kono
parents:
diff changeset
155 pragma Import (Stdcall, MapViewOfFile, "MapViewOfFile");
kono
parents:
diff changeset
156
kono
parents:
diff changeset
157 function UnmapViewOfFile
kono
parents:
diff changeset
158 (lpBaseAddress : Standard.System.Address) return BOOL;
kono
parents:
diff changeset
159 pragma Import (Stdcall, UnmapViewOfFile, "UnmapViewOfFile");
kono
parents:
diff changeset
160
kono
parents:
diff changeset
161 procedure GetSystemInfo (lpSystemInfo : LP_SYSTEM_INFO);
kono
parents:
diff changeset
162 pragma Import (Stdcall, GetSystemInfo, "GetSystemInfo");
kono
parents:
diff changeset
163
kono
parents:
diff changeset
164 end Win;
kono
parents:
diff changeset
165
kono
parents:
diff changeset
166 type System_File is record
kono
parents:
diff changeset
167 Handle : Win.HANDLE;
kono
parents:
diff changeset
168
kono
parents:
diff changeset
169 Mapped : Boolean;
kono
parents:
diff changeset
170 -- Whether mapping is requested by the user and available on the system
kono
parents:
diff changeset
171
kono
parents:
diff changeset
172 Mapping_Handle : Win.HANDLE;
kono
parents:
diff changeset
173
kono
parents:
diff changeset
174 Write : Boolean;
kono
parents:
diff changeset
175 -- Whether this file can be written to
kono
parents:
diff changeset
176
kono
parents:
diff changeset
177 Length : File_Size;
kono
parents:
diff changeset
178 -- Length of the file. Used to know what can be mapped in the file
kono
parents:
diff changeset
179 end record;
kono
parents:
diff changeset
180
kono
parents:
diff changeset
181 type System_Mapping is record
kono
parents:
diff changeset
182 Address : Standard.System.Address;
kono
parents:
diff changeset
183 Length : File_Size;
kono
parents:
diff changeset
184 end record;
kono
parents:
diff changeset
185
kono
parents:
diff changeset
186 Invalid_System_File : constant System_File :=
kono
parents:
diff changeset
187 (Win.INVALID_HANDLE_VALUE, False, Win.INVALID_HANDLE_VALUE, False, 0);
kono
parents:
diff changeset
188 Invalid_System_Mapping : constant System_Mapping :=
kono
parents:
diff changeset
189 (Standard.System.Null_Address, 0);
kono
parents:
diff changeset
190
kono
parents:
diff changeset
191 function Open_Read
kono
parents:
diff changeset
192 (Filename : String;
kono
parents:
diff changeset
193 Use_Mmap_If_Available : Boolean := True) return System_File;
kono
parents:
diff changeset
194 -- Open a file for reading and return the corresponding System_File. Return
kono
parents:
diff changeset
195 -- Invalid_System_File if unsuccessful.
kono
parents:
diff changeset
196
kono
parents:
diff changeset
197 function Open_Write
kono
parents:
diff changeset
198 (Filename : String;
kono
parents:
diff changeset
199 Use_Mmap_If_Available : Boolean := True) return System_File;
kono
parents:
diff changeset
200 -- Likewise for writing to a file
kono
parents:
diff changeset
201
kono
parents:
diff changeset
202 procedure Close (File : in out System_File);
kono
parents:
diff changeset
203 -- Close a system file
kono
parents:
diff changeset
204
kono
parents:
diff changeset
205 function Read_From_Disk
kono
parents:
diff changeset
206 (File : System_File;
kono
parents:
diff changeset
207 Offset, Length : File_Size) return System.Strings.String_Access;
kono
parents:
diff changeset
208 -- Read a fragment of a file. It is up to the caller to free the result
kono
parents:
diff changeset
209 -- when done with it.
kono
parents:
diff changeset
210
kono
parents:
diff changeset
211 procedure Write_To_Disk
kono
parents:
diff changeset
212 (File : System_File;
kono
parents:
diff changeset
213 Offset, Length : File_Size;
kono
parents:
diff changeset
214 Buffer : System.Strings.String_Access);
kono
parents:
diff changeset
215 -- Write some content to a fragment of a file
kono
parents:
diff changeset
216
kono
parents:
diff changeset
217 procedure Create_Mapping
kono
parents:
diff changeset
218 (File : System_File;
kono
parents:
diff changeset
219 Offset, Length : in out File_Size;
kono
parents:
diff changeset
220 Mutable : Boolean;
kono
parents:
diff changeset
221 Mapping : out System_Mapping);
kono
parents:
diff changeset
222 -- Create a memory mapping for the given File, for the area starting at
kono
parents:
diff changeset
223 -- Offset and containing Length bytes. Store it to Mapping.
kono
parents:
diff changeset
224 -- Note that Offset and Length may be modified according to the system
kono
parents:
diff changeset
225 -- needs (for boudaries, for instance). The caller must cope with actually
kono
parents:
diff changeset
226 -- wider mapped areas.
kono
parents:
diff changeset
227
kono
parents:
diff changeset
228 procedure Dispose_Mapping
kono
parents:
diff changeset
229 (Mapping : in out System_Mapping);
kono
parents:
diff changeset
230 -- Unmap a previously-created mapping
kono
parents:
diff changeset
231
kono
parents:
diff changeset
232 function Get_Page_Size return File_Size;
kono
parents:
diff changeset
233 -- Return the number of bytes in a system page.
kono
parents:
diff changeset
234
kono
parents:
diff changeset
235 end System.Mmap.OS_Interface;