OSDN Git Service

2010-01-26 Robert Dewar <dewar@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-win32.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                        GNAT RUN-TIME COMPONENTS                          --
4 --                                                                          --
5 --                         S Y S T E M . W I N 3 2                          --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --         Copyright (C) 2008-2009, Free Software Foundation, Inc.          --
10 --                                                                          --
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.                                     --
17 --                                                                          --
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.               --
21 --                                                                          --
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/>.                                          --
26 --                                                                          --
27 -- GNAT was originally developed  by the GNAT team at  New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
29 --                                                                          --
30 ------------------------------------------------------------------------------
31
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.
36
37 with Interfaces.C;
38
39 package System.Win32 is
40    pragma Pure;
41
42    -------------------
43    -- General Types --
44    -------------------
45
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)
50
51    type LARGE_INTEGER is delta 1.0 range -2.0**63 .. 2.0**63 - 1.0;
52
53    subtype PVOID is Address;
54
55    type HANDLE is new Interfaces.C.ptrdiff_t;
56
57    INVALID_HANDLE_VALUE : constant HANDLE := -1;
58
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;
64
65    type BOOL   is new Interfaces.C.int;
66    for BOOL'Size use Interfaces.C.int'Size;
67
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;
71    for Bits1'Size  use 1;
72    for Bits2'Size  use 2;
73    for Bits17'Size use 17;
74
75    FALSE : constant := 0;
76    TRUE  : constant := 1;
77
78    function GetLastError return DWORD;
79    pragma Import (Stdcall, GetLastError, "GetLastError");
80
81    -----------
82    -- Files --
83    -----------
84
85    CP_UTF8                            : constant := 65001;
86
87    GENERIC_READ                       : constant := 16#80000000#;
88    GENERIC_WRITE                      : constant := 16#40000000#;
89
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;
95
96    FILE_SHARE_DELETE                  : constant := 16#00000004#;
97    FILE_SHARE_READ                    : constant := 16#00000001#;
98    FILE_SHARE_WRITE                   : constant := 16#00000002#;
99
100    FILE_BEGIN                         : constant := 0;
101    FILE_CURRENT                       : constant := 1;
102    FILE_END                           : constant := 2;
103
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#;
109
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;
114
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#;
132
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#;
149
150    type OVERLAPPED is record
151       Internal     : DWORD;
152       InternalHigh : DWORD;
153       Offset       : DWORD;
154       OffsetHigh   : DWORD;
155       hEvent       : HANDLE;
156    end record;
157
158    type SECURITY_ATTRIBUTES is record
159       nLength             : DWORD;
160       pSecurityDescriptor : PVOID;
161       bInheritHandle      : BOOL;
162    end record;
163
164    function CreateFileA
165      (lpFileName            : Address;
166       dwDesiredAccess       : DWORD;
167       dwShareMode           : DWORD;
168       lpSecurityAttributes  : access SECURITY_ATTRIBUTES;
169       dwCreationDisposition : DWORD;
170       dwFlagsAndAttributes  : DWORD;
171       hTemplateFile         : HANDLE) return HANDLE;
172    pragma Import (Stdcall, CreateFileA, "CreateFileA");
173
174    function CreateFile
175      (lpFileName            : Address;
176       dwDesiredAccess       : DWORD;
177       dwShareMode           : DWORD;
178       lpSecurityAttributes  : access SECURITY_ATTRIBUTES;
179       dwCreationDisposition : DWORD;
180       dwFlagsAndAttributes  : DWORD;
181       hTemplateFile         : HANDLE) return HANDLE;
182    pragma Import (Stdcall, CreateFile, "CreateFileW");
183
184    function GetFileSize
185      (hFile          : HANDLE;
186       lpFileSizeHigh : access DWORD) return BOOL;
187    pragma Import (Stdcall, GetFileSize, "GetFileSize");
188
189    function SetFilePointer
190      (hFile                : HANDLE;
191       lDistanceToMove      : LONG;
192       lpDistanceToMoveHigh : access LONG;
193       dwMoveMethod         : DWORD) return DWORD;
194    pragma Import (Stdcall, SetFilePointer, "SetFilePointer");
195
196    function WriteFile
197      (hFile                  : HANDLE;
198       lpBuffer               : Address;
199       nNumberOfBytesToWrite  : DWORD;
200       lpNumberOfBytesWritten : access DWORD;
201       lpOverlapped           : access OVERLAPPED) return BOOL;
202    pragma Import (Stdcall, WriteFile, "WriteFile");
203
204    function ReadFile
205      (hFile                : HANDLE;
206       lpBuffer             : Address;
207       nNumberOfBytesToRead : DWORD;
208       lpNumberOfBytesRead  : access DWORD;
209       lpOverlapped         : access OVERLAPPED) return BOOL;
210    pragma Import (Stdcall, ReadFile, "ReadFile");
211
212    function CloseHandle (hObject : HANDLE) return BOOL;
213    pragma Import (Stdcall, CloseHandle, "CloseHandle");
214
215    function CreateFileMapping
216      (hFile                : HANDLE;
217       lpSecurityAttributes : access SECURITY_ATTRIBUTES;
218       flProtect            : DWORD;
219       dwMaximumSizeHigh    : DWORD;
220       dwMaximumSizeLow     : DWORD;
221       lpName               : Address) return HANDLE;
222    pragma Import (Stdcall, CreateFileMapping, "CreateFileMappingA");
223
224    function MapViewOfFile
225      (hFileMappingObject   : HANDLE;
226       dwDesiredAccess      : DWORD;
227       dwFileOffsetHigh     : DWORD;
228       dwFileOffsetLow      : DWORD;
229       dwNumberOfBytesToMap : DWORD) return System.Address;
230    pragma Import (Stdcall, MapViewOfFile, "MapViewOfFile");
231
232    function UnmapViewOfFile (lpBaseAddress : System.Address) return BOOL;
233    pragma Import (Stdcall, UnmapViewOfFile, "UnmapViewOfFile");
234
235    function MultiByteToWideChar
236      (CodePage       : WORD;
237       dwFlags        : DWORD;
238       lpMultiByteStr : System.Address;
239       cchMultiByte   : WORD;
240       lpWideCharStr  : System.Address;
241       cchWideChar    : WORD) return BOOL;
242    pragma Import (Stdcall, MultiByteToWideChar, "MultiByteToWideChar");
243
244    ------------------------
245    -- System Information --
246    ------------------------
247
248    subtype ProcessorId is DWORD;
249
250    type SYSTEM_INFO is record
251       dwOemId                     : DWORD;
252       dwPageSize                  : DWORD;
253       lpMinimumApplicationAddress : PVOID;
254       lpMaximumApplicationAddress : PVOID;
255       dwActiveProcessorMask       : DWORD;
256       dwNumberOfProcessors        : DWORD;
257       dwProcessorType             : DWORD;
258       dwAllocationGranularity     : DWORD;
259       dwReserved                  : DWORD;
260    end record;
261
262    procedure GetSystemInfo (SI : access SYSTEM_INFO);
263    pragma Import (Stdcall, GetSystemInfo, "GetSystemInfo");
264
265    ---------------------
266    -- Time Management --
267    ---------------------
268
269    type SYSTEMTIME is record
270       wYear         : WORD;
271       wMonth        : WORD;
272       wDayOfWeek    : WORD;
273       wDay          : WORD;
274       wHour         : WORD;
275       wMinute       : WORD;
276       wSecond       : WORD;
277       wMilliseconds : WORD;
278    end record;
279
280    procedure GetSystemTime (pSystemTime : access SYSTEMTIME);
281    pragma Import (Stdcall, GetSystemTime, "GetSystemTime");
282
283    procedure GetSystemTimeAsFileTime (lpFileTime : access Long_Long_Integer);
284    pragma Import (Stdcall, GetSystemTimeAsFileTime, "GetSystemTimeAsFileTime");
285
286    function FileTimeToSystemTime
287      (lpFileTime   : access Long_Long_Integer;
288       lpSystemTime : access SYSTEMTIME) return BOOL;
289    pragma Import (Stdcall, FileTimeToSystemTime, "FileTimeToSystemTime");
290
291    function SystemTimeToFileTime
292      (lpSystemTime : access SYSTEMTIME;
293       lpFileTime   : access Long_Long_Integer) return BOOL;
294    pragma Import (Stdcall, SystemTimeToFileTime, "SystemTimeToFileTime");
295
296    function FileTimeToLocalFileTime
297      (lpFileTime      : access Long_Long_Integer;
298       lpLocalFileTime : access Long_Long_Integer) return BOOL;
299    pragma Import (Stdcall, FileTimeToLocalFileTime, "FileTimeToLocalFileTime");
300
301    function LocalFileTimeToFileTime
302      (lpFileTime      : access Long_Long_Integer;
303       lpLocalFileTime : access Long_Long_Integer) return BOOL;
304    pragma Import (Stdcall, LocalFileTimeToFileTime, "LocalFileTimeToFileTime");
305
306    procedure Sleep (dwMilliseconds : DWORD);
307    pragma Import (Stdcall, Sleep, External_Name => "Sleep");
308
309    function QueryPerformanceCounter
310      (lpPerformanceCount : access LARGE_INTEGER) return BOOL;
311    pragma Import
312      (Stdcall, QueryPerformanceCounter, "QueryPerformanceCounter");
313
314 end System.Win32;