1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- S Y S T E M . W I N 3 2 --
9 -- Copyright (C) 2008, 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 2, 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. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 ------------------------------------------------------------------------------
34 -- This package plus its child provide the low level interface to the Win32
35 -- API. The core part of the Win32 API (common to RTX and Win32) is in this
36 -- package, and an additional part of the Win32 API which is not supported by
37 -- RTX is in package System.Win33.Ext.
41 package System
.Win32
is
48 -- The LARGE_INTEGER type is actually a fixed point type
49 -- that only can represent integers. The reason for this is
50 -- easier conversion to Duration or other fixed point types.
51 -- (See Operations.Clock)
53 type LARGE_INTEGER
is delta 1.0 range -2.0**63 .. 2.0**63 - 1.0;
55 subtype PVOID
is Address
;
57 type HANDLE
is new Interfaces
.C
.long
;
59 INVALID_HANDLE_VALUE
: constant HANDLE
:= -1;
61 type DWORD
is new Interfaces
.C
.unsigned_long
;
62 type WORD
is new Interfaces
.C
.unsigned_short
;
63 type BYTE
is new Interfaces
.C
.unsigned_char
;
64 type LONG
is new Interfaces
.C
.long
;
65 type CHAR
is new Interfaces
.C
.char
;
67 type BOOL
is new Interfaces
.C
.int
;
68 for BOOL
'Size use Interfaces
.C
.int
'Size;
70 type Bits1
is range 0 .. 2 ** 1 - 1;
71 type Bits2
is range 0 .. 2 ** 2 - 1;
72 type Bits17
is range 0 .. 2 ** 17 - 1;
75 for Bits17
'Size use 17;
77 FALSE : constant := 0;
80 function GetLastError
return DWORD
;
81 pragma Import
(Stdcall
, GetLastError
, "GetLastError");
87 GENERIC_READ
: constant := 16#
80000000#
;
88 GENERIC_WRITE
: constant := 16#
40000000#
;
90 CREATE_NEW
: constant := 1;
91 CREATE_ALWAYS
: constant := 2;
92 OPEN_EXISTING
: constant := 3;
93 OPEN_ALWAYS
: constant := 4;
94 TRUNCATE_EXISTING
: constant := 5;
96 FILE_SHARE_DELETE
: constant := 16#
00000004#
;
97 FILE_SHARE_READ
: constant := 16#
00000001#
;
98 FILE_SHARE_WRITE
: constant := 16#
00000002#
;
100 FILE_BEGIN
: constant := 0;
101 FILE_CURRENT
: constant := 1;
102 FILE_END
: constant := 2;
104 PAGE_NOACCESS
: constant := 16#
0001#
;
105 PAGE_READONLY
: constant := 16#
0002#
;
106 PAGE_READWRITE
: constant := 16#
0004#
;
107 PAGE_WRITECOPY
: constant := 16#
0008#
;
108 PAGE_EXECUTE
: constant := 16#
0010#
;
110 FILE_MAP_ALL_ACCESS
: constant := 16#F001f#
;
111 FILE_MAP_READ
: constant := 4;
112 FILE_MAP_WRITE
: constant := 2;
113 FILE_MAP_COPY
: constant := 1;
115 FILE_ADD_FILE
: constant := 16#
0002#
;
116 FILE_ADD_SUBDIRECTORY
: constant := 16#
0004#
;
117 FILE_APPEND_DATA
: constant := 16#
0004#
;
118 FILE_CREATE_PIPE_INSTANCE
: constant := 16#
0004#
;
119 FILE_DELETE_CHILD
: constant := 16#
0040#
;
120 FILE_EXECUTE
: constant := 16#
0020#
;
121 FILE_LIST_DIRECTORY
: constant := 16#
0001#
;
122 FILE_READ_ATTRIBUTES
: constant := 16#
0080#
;
123 FILE_READ_DATA
: constant := 16#
0001#
;
124 FILE_READ_EA
: constant := 16#
0008#
;
125 FILE_TRAVERSE
: constant := 16#
0020#
;
126 FILE_WRITE_ATTRIBUTES
: constant := 16#
0100#
;
127 FILE_WRITE_DATA
: constant := 16#
0002#
;
128 FILE_WRITE_EA
: constant := 16#
0010#
;
129 STANDARD_RIGHTS_READ
: constant := 16#
20000#
;
130 STANDARD_RIGHTS_WRITE
: constant := 16#
20000#
;
131 SYNCHRONIZE
: constant := 16#
100000#
;
133 FILE_ATTRIBUTE_READONLY
: constant := 16#
00000001#
;
134 FILE_ATTRIBUTE_HIDDEN
: constant := 16#
00000002#
;
135 FILE_ATTRIBUTE_SYSTEM
: constant := 16#
00000004#
;
136 FILE_ATTRIBUTE_DIRECTORY
: constant := 16#
00000010#
;
137 FILE_ATTRIBUTE_ARCHIVE
: constant := 16#
00000020#
;
138 FILE_ATTRIBUTE_DEVICE
: constant := 16#
00000040#
;
139 FILE_ATTRIBUTE_NORMAL
: constant := 16#
00000080#
;
140 FILE_ATTRIBUTE_TEMPORARY
: constant := 16#
00000100#
;
141 FILE_ATTRIBUTE_SPARSE_FILE
: constant := 16#
00000200#
;
142 FILE_ATTRIBUTE_REPARSE_POINT
: constant := 16#
00000400#
;
143 FILE_ATTRIBUTE_COMPRESSED
: constant := 16#
00000800#
;
144 FILE_ATTRIBUTE_OFFLINE
: constant := 16#
00001000#
;
145 FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
: constant := 16#
00002000#
;
146 FILE_ATTRIBUTE_ENCRYPTED
: constant := 16#
00004000#
;
147 FILE_ATTRIBUTE_VALID_FLAGS
: constant := 16#
00007fb7#
;
148 FILE_ATTRIBUTE_VALID_SET_FLAGS
: constant := 16#
000031a7#
;
150 type OVERLAPPED
is record
152 InternalHigh
: DWORD
;
158 type SECURITY_ATTRIBUTES
is record
160 pSecurityDescriptor
: PVOID
;
161 bInheritHandle
: BOOL
;
165 (lpFileName
: Address
;
166 dwDesiredAccess
: DWORD
;
168 lpSecurityAttributes
: access SECURITY_ATTRIBUTES
;
169 dwCreationDisposition
: DWORD
;
170 dwFlagsAndAttributes
: DWORD
;
171 hTemplateFile
: HANDLE
) return HANDLE
;
172 pragma Import
(Stdcall
, CreateFile
, "CreateFileA");
176 lpFileSizeHigh
: access DWORD
) return BOOL
;
177 pragma Import
(Stdcall
, GetFileSize
, "GetFileSize");
179 function SetFilePointer
181 lDistanceToMove
: LONG
;
182 lpDistanceToMoveHigh
: access LONG
;
183 dwMoveMethod
: DWORD
) return DWORD
;
184 pragma Import
(Stdcall
, SetFilePointer
, "SetFilePointer");
189 nNumberOfBytesToWrite
: DWORD
;
190 lpNumberOfBytesWritten
: access DWORD
;
191 lpOverlapped
: access OVERLAPPED
) return BOOL
;
192 pragma Import
(Stdcall
, WriteFile
, "WriteFile");
197 nNumberOfBytesToRead
: DWORD
;
198 lpNumberOfBytesRead
: access DWORD
;
199 lpOverlapped
: access OVERLAPPED
) return BOOL
;
200 pragma Import
(Stdcall
, ReadFile
, "ReadFile");
202 function CloseHandle
(hObject
: HANDLE
) return BOOL
;
203 pragma Import
(Stdcall
, CloseHandle
, "CloseHandle");
205 function CreateFileMapping
207 lpSecurityAttributes
: access SECURITY_ATTRIBUTES
;
209 dwMaximumSizeHigh
: DWORD
;
210 dwMaximumSizeLow
: DWORD
;
211 lpName
: Address
) return HANDLE
;
212 pragma Import
(Stdcall
, CreateFileMapping
, "CreateFileMappingA");
214 function MapViewOfFile
215 (hFileMappingObject
: HANDLE
;
216 dwDesiredAccess
: DWORD
;
217 dwFileOffsetHigh
: DWORD
;
218 dwFileOffsetLow
: DWORD
;
219 dwNumberOfBytesToMap
: DWORD
) return System
.Address
;
220 pragma Import
(Stdcall
, MapViewOfFile
, "MapViewOfFile");
222 function UnmapViewOfFile
(lpBaseAddress
: System
.Address
) return BOOL
;
223 pragma Import
(Stdcall
, UnmapViewOfFile
, "UnmapViewOfFile");
225 ------------------------
226 -- System Information --
227 ------------------------
229 subtype ProcessorId
is DWORD
;
231 type SYSTEM_INFO
is record
234 lpMinimumApplicationAddress
: PVOID
;
235 lpMaximumApplicationAddress
: PVOID
;
236 dwActiveProcessorMask
: DWORD
;
237 dwNumberOfProcessors
: DWORD
;
238 dwProcessorType
: DWORD
;
239 dwAllocationGranularity
: DWORD
;
243 procedure GetSystemInfo
(SI
: access SYSTEM_INFO
);
244 pragma Import
(Stdcall
, GetSystemInfo
, "GetSystemInfo");
246 ---------------------
247 -- Time Management --
248 ---------------------
250 type SYSTEMTIME
is record
258 wMilliseconds
: WORD
;
261 procedure GetSystemTime
(pSystemTime
: access SYSTEMTIME
);
262 pragma Import
(Stdcall
, GetSystemTime
, "GetSystemTime");
264 procedure GetSystemTimeAsFileTime
(lpFileTime
: access Long_Long_Integer);
265 pragma Import
(Stdcall
, GetSystemTimeAsFileTime
, "GetSystemTimeAsFileTime");
267 function FileTimeToSystemTime
268 (lpFileTime
: access Long_Long_Integer;
269 lpSystemTime
: access SYSTEMTIME
) return BOOL
;
270 pragma Import
(Stdcall
, FileTimeToSystemTime
, "FileTimeToSystemTime");
272 function SystemTimeToFileTime
273 (lpSystemTime
: access SYSTEMTIME
;
274 lpFileTime
: access Long_Long_Integer) return BOOL
;
275 pragma Import
(Stdcall
, SystemTimeToFileTime
, "SystemTimeToFileTime");
277 function FileTimeToLocalFileTime
278 (lpFileTime
: access Long_Long_Integer;
279 lpLocalFileTime
: access Long_Long_Integer) return BOOL
;
280 pragma Import
(Stdcall
, FileTimeToLocalFileTime
, "FileTimeToLocalFileTime");
282 function LocalFileTimeToFileTime
283 (lpFileTime
: access Long_Long_Integer;
284 lpLocalFileTime
: access Long_Long_Integer) return BOOL
;
285 pragma Import
(Stdcall
, LocalFileTimeToFileTime
, "LocalFileTimeToFileTime");
287 procedure Sleep
(dwMilliseconds
: DWORD
);
288 pragma Import
(Stdcall
, Sleep
, External_Name
=> "Sleep");
290 function QueryPerformanceCounter
291 (lpPerformanceCount
: access LARGE_INTEGER
) return BOOL
;
293 (Stdcall
, QueryPerformanceCounter
, "QueryPerformanceCounter");