1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- S Y S T E M . W I N 3 2 --
9 -- Copyright (C) 2009, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
30 ------------------------------------------------------------------------------
32 -- This package plus its child provide the low level interface to the Win32
33 -- API. The core part of the Win32 API (common to RTX and Win32) is in this
34 -- package, and an additional part of the Win32 API which is not supported by
35 -- RTX is in package System.Win33.Ext.
39 package System.Win32 is
46 -- The LARGE_INTEGER type is actually a fixed point type
47 -- that only can represent integers. The reason for this is
48 -- easier conversion to Duration or other fixed point types.
49 -- (See Operations.Clock)
51 type LARGE_INTEGER is delta 1.0 range -2.0**63 .. 2.0**63 - 1.0;
53 subtype PVOID is Address;
55 type HANDLE is new Interfaces.C.long;
57 INVALID_HANDLE_VALUE : constant HANDLE := -1;
59 type DWORD is new Interfaces.C.unsigned_long;
60 type WORD is new Interfaces.C.unsigned_short;
61 type BYTE is new Interfaces.C.unsigned_char;
62 type LONG is new Interfaces.C.long;
63 type CHAR is new Interfaces.C.char;
65 type BOOL is new Interfaces.C.int;
66 for BOOL'Size use Interfaces.C.int'Size;
68 type Bits1 is range 0 .. 2 ** 1 - 1;
69 type Bits2 is range 0 .. 2 ** 2 - 1;
70 type Bits17 is range 0 .. 2 ** 17 - 1;
73 for Bits17'Size use 17;
75 FALSE : constant := 0;
78 function GetLastError return DWORD;
79 pragma Import (Stdcall, GetLastError, "GetLastError");
85 GENERIC_READ : constant := 16#80000000#;
86 GENERIC_WRITE : constant := 16#40000000#;
88 CREATE_NEW : constant := 1;
89 CREATE_ALWAYS : constant := 2;
90 OPEN_EXISTING : constant := 3;
91 OPEN_ALWAYS : constant := 4;
92 TRUNCATE_EXISTING : constant := 5;
94 FILE_SHARE_DELETE : constant := 16#00000004#;
95 FILE_SHARE_READ : constant := 16#00000001#;
96 FILE_SHARE_WRITE : constant := 16#00000002#;
98 FILE_BEGIN : constant := 0;
99 FILE_CURRENT : constant := 1;
100 FILE_END : constant := 2;
102 PAGE_NOACCESS : constant := 16#0001#;
103 PAGE_READONLY : constant := 16#0002#;
104 PAGE_READWRITE : constant := 16#0004#;
105 PAGE_WRITECOPY : constant := 16#0008#;
106 PAGE_EXECUTE : constant := 16#0010#;
108 FILE_MAP_ALL_ACCESS : constant := 16#F001f#;
109 FILE_MAP_READ : constant := 4;
110 FILE_MAP_WRITE : constant := 2;
111 FILE_MAP_COPY : constant := 1;
113 FILE_ADD_FILE : constant := 16#0002#;
114 FILE_ADD_SUBDIRECTORY : constant := 16#0004#;
115 FILE_APPEND_DATA : constant := 16#0004#;
116 FILE_CREATE_PIPE_INSTANCE : constant := 16#0004#;
117 FILE_DELETE_CHILD : constant := 16#0040#;
118 FILE_EXECUTE : constant := 16#0020#;
119 FILE_LIST_DIRECTORY : constant := 16#0001#;
120 FILE_READ_ATTRIBUTES : constant := 16#0080#;
121 FILE_READ_DATA : constant := 16#0001#;
122 FILE_READ_EA : constant := 16#0008#;
123 FILE_TRAVERSE : constant := 16#0020#;
124 FILE_WRITE_ATTRIBUTES : constant := 16#0100#;
125 FILE_WRITE_DATA : constant := 16#0002#;
126 FILE_WRITE_EA : constant := 16#0010#;
127 STANDARD_RIGHTS_READ : constant := 16#20000#;
128 STANDARD_RIGHTS_WRITE : constant := 16#20000#;
129 SYNCHRONIZE : constant := 16#100000#;
131 FILE_ATTRIBUTE_READONLY : constant := 16#00000001#;
132 FILE_ATTRIBUTE_HIDDEN : constant := 16#00000002#;
133 FILE_ATTRIBUTE_SYSTEM : constant := 16#00000004#;
134 FILE_ATTRIBUTE_DIRECTORY : constant := 16#00000010#;
135 FILE_ATTRIBUTE_ARCHIVE : constant := 16#00000020#;
136 FILE_ATTRIBUTE_DEVICE : constant := 16#00000040#;
137 FILE_ATTRIBUTE_NORMAL : constant := 16#00000080#;
138 FILE_ATTRIBUTE_TEMPORARY : constant := 16#00000100#;
139 FILE_ATTRIBUTE_SPARSE_FILE : constant := 16#00000200#;
140 FILE_ATTRIBUTE_REPARSE_POINT : constant := 16#00000400#;
141 FILE_ATTRIBUTE_COMPRESSED : constant := 16#00000800#;
142 FILE_ATTRIBUTE_OFFLINE : constant := 16#00001000#;
143 FILE_ATTRIBUTE_NOT_CONTENT_INDEXED : constant := 16#00002000#;
144 FILE_ATTRIBUTE_ENCRYPTED : constant := 16#00004000#;
145 FILE_ATTRIBUTE_VALID_FLAGS : constant := 16#00007fb7#;
146 FILE_ATTRIBUTE_VALID_SET_FLAGS : constant := 16#000031a7#;
148 type OVERLAPPED is record
150 InternalHigh : DWORD;
156 type SECURITY_ATTRIBUTES is record
158 pSecurityDescriptor : PVOID;
159 bInheritHandle : BOOL;
163 (lpFileName : Address;
164 dwDesiredAccess : DWORD;
166 lpSecurityAttributes : access SECURITY_ATTRIBUTES;
167 dwCreationDisposition : DWORD;
168 dwFlagsAndAttributes : DWORD;
169 hTemplateFile : HANDLE) return HANDLE;
170 pragma Import (Stdcall, CreateFile, "CreateFileA");
174 lpFileSizeHigh : access DWORD) return BOOL;
175 pragma Import (Stdcall, GetFileSize, "GetFileSize");
177 function SetFilePointer
179 lDistanceToMove : LONG;
180 lpDistanceToMoveHigh : access LONG;
181 dwMoveMethod : DWORD) return DWORD;
182 pragma Import (Stdcall, SetFilePointer, "SetFilePointer");
187 nNumberOfBytesToWrite : DWORD;
188 lpNumberOfBytesWritten : access DWORD;
189 lpOverlapped : access OVERLAPPED) return BOOL;
190 pragma Import (Stdcall, WriteFile, "WriteFile");
195 nNumberOfBytesToRead : DWORD;
196 lpNumberOfBytesRead : access DWORD;
197 lpOverlapped : access OVERLAPPED) return BOOL;
198 pragma Import (Stdcall, ReadFile, "ReadFile");
200 function CloseHandle (hObject : HANDLE) return BOOL;
201 pragma Import (Stdcall, CloseHandle, "CloseHandle");
203 function CreateFileMapping
205 lpSecurityAttributes : access SECURITY_ATTRIBUTES;
207 dwMaximumSizeHigh : DWORD;
208 dwMaximumSizeLow : DWORD;
209 lpName : Address) return HANDLE;
210 pragma Import (Stdcall, CreateFileMapping, "CreateFileMappingA");
212 function MapViewOfFile
213 (hFileMappingObject : HANDLE;
214 dwDesiredAccess : DWORD;
215 dwFileOffsetHigh : DWORD;
216 dwFileOffsetLow : DWORD;
217 dwNumberOfBytesToMap : DWORD) return System.Address;
218 pragma Import (Stdcall, MapViewOfFile, "MapViewOfFile");
220 function UnmapViewOfFile (lpBaseAddress : System.Address) return BOOL;
221 pragma Import (Stdcall, UnmapViewOfFile, "UnmapViewOfFile");
223 ------------------------
224 -- System Information --
225 ------------------------
227 subtype ProcessorId is DWORD;
229 type SYSTEM_INFO is record
232 lpMinimumApplicationAddress : PVOID;
233 lpMaximumApplicationAddress : PVOID;
234 dwActiveProcessorMask : DWORD;
235 dwNumberOfProcessors : DWORD;
236 dwProcessorType : DWORD;
237 dwAllocationGranularity : DWORD;
241 procedure GetSystemInfo (SI : access SYSTEM_INFO);
242 pragma Import (Stdcall, GetSystemInfo, "GetSystemInfo");
244 ---------------------
245 -- Time Management --
246 ---------------------
248 type SYSTEMTIME is record
256 wMilliseconds : WORD;
259 procedure GetSystemTime (pSystemTime : access SYSTEMTIME);
260 pragma Import (Stdcall, GetSystemTime, "GetSystemTime");
262 procedure GetSystemTimeAsFileTime (lpFileTime : access Long_Long_Integer);
263 pragma Import (Stdcall, GetSystemTimeAsFileTime, "GetSystemTimeAsFileTime");
265 function FileTimeToSystemTime
266 (lpFileTime : access Long_Long_Integer;
267 lpSystemTime : access SYSTEMTIME) return BOOL;
268 pragma Import (Stdcall, FileTimeToSystemTime, "FileTimeToSystemTime");
270 function SystemTimeToFileTime
271 (lpSystemTime : access SYSTEMTIME;
272 lpFileTime : access Long_Long_Integer) return BOOL;
273 pragma Import (Stdcall, SystemTimeToFileTime, "SystemTimeToFileTime");
275 function FileTimeToLocalFileTime
276 (lpFileTime : access Long_Long_Integer;
277 lpLocalFileTime : access Long_Long_Integer) return BOOL;
278 pragma Import (Stdcall, FileTimeToLocalFileTime, "FileTimeToLocalFileTime");
280 function LocalFileTimeToFileTime
281 (lpFileTime : access Long_Long_Integer;
282 lpLocalFileTime : access Long_Long_Integer) return BOOL;
283 pragma Import (Stdcall, LocalFileTimeToFileTime, "LocalFileTimeToFileTime");
285 procedure Sleep (dwMilliseconds : DWORD);
286 pragma Import (Stdcall, Sleep, External_Name => "Sleep");
288 function QueryPerformanceCounter
289 (lpPerformanceCount : access LARGE_INTEGER) return BOOL;
291 (Stdcall, QueryPerformanceCounter, "QueryPerformanceCounter");