Add hppa-openbsd target
[official-gcc.git] / gcc / ada / 5wosinte.ads
blob13040eef986004447169f99f91457b8af2ec5725
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNU ADA RUN-TIME LIBRARY (GNARL) COMPONENTS --
4 -- --
5 -- S Y S T E M . O S _ I N T E R F A C E --
6 -- --
7 -- S p e c --
8 -- --
9 -- --
10 -- Copyright (C) 1997-2001, Free Software Foundation, Inc. --
11 -- --
12 -- GNARL is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNARL; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
22 -- --
23 -- As a special exception, if other files instantiate generics from this --
24 -- unit, or you link this unit with other files to produce an executable, --
25 -- this unit does not by itself cause the resulting executable to be --
26 -- covered by the GNU General Public License. This exception does not --
27 -- however invalidate any other reasons why the executable file might be --
28 -- covered by the GNU Public License. --
29 -- --
30 -- GNARL was developed by the GNARL team at Florida State University. It is --
31 -- now maintained by Ada Core Technologies Inc. in cooperation with Florida --
32 -- State University (http://www.gnat.com). --
33 -- --
34 ------------------------------------------------------------------------------
36 -- This is a NT (native) version of this package.
38 -- This package encapsulates all direct interfaces to OS services
39 -- that are needed by children of System.
41 -- PLEASE DO NOT add any with-clauses to this package
42 -- or remove the pragma Elaborate_Body.
43 -- It is designed to be a bottom-level (leaf) package.
45 with Interfaces.C;
46 with Interfaces.C.Strings;
48 package System.OS_Interface is
49 pragma Preelaborate;
51 subtype int is Interfaces.C.int;
52 subtype long is Interfaces.C.long;
54 -------------------
55 -- General Types --
56 -------------------
58 type DWORD is new Interfaces.C.unsigned_long;
59 type WORD is new Interfaces.C.unsigned_short;
61 -- The LARGE_INTEGER type is actually a fixed point type
62 -- that only can represent integers. The reason for this is
63 -- easier conversion to Duration or other fixed point types.
64 -- (See Operations.Clock)
66 type LARGE_INTEGER is delta 1.0 range -2.0**63 .. 2.0**63 - 1.0;
67 for LARGE_INTEGER'Alignment use 4;
69 subtype PSZ is Interfaces.C.Strings.chars_ptr;
70 subtype PCHAR is Interfaces.C.Strings.chars_ptr;
71 subtype PVOID is System.Address;
72 Null_Void : constant PVOID := System.Null_Address;
74 type PLONG is access all Interfaces.C.long;
75 type PDWORD is access all DWORD;
77 type BOOL is new Boolean;
78 for BOOL'Size use Interfaces.C.unsigned_long'Size;
80 -------------------------
81 -- Handles for objects --
82 -------------------------
84 type HANDLE is new Interfaces.C.long;
85 type PHANDLE is access all HANDLE;
87 subtype Thread_Id is HANDLE;
89 -----------
90 -- Errno --
91 -----------
93 NO_ERROR : constant := 0;
94 FUNC_ERR : constant := -1;
96 -------------
97 -- Signals --
98 -------------
100 Max_Interrupt : constant := 31;
101 type Signal is new int range 0 .. Max_Interrupt;
102 for Signal'Size use int'Size;
104 SIGINT : constant := 2; -- interrupt (Ctrl-C)
105 SIGILL : constant := 4; -- illegal instruction (not reset)
106 SIGFPE : constant := 8; -- floating point exception
107 SIGSEGV : constant := 11; -- segmentation violation
108 SIGTERM : constant := 15; -- software termination signal from kill
109 SIGBREAK : constant := 21; -- break (Ctrl-Break)
110 SIGABRT : constant := 22; -- used by abort, replace SIGIOT in the future
112 type sigset_t is private;
114 type isr_address is access procedure (sig : int);
116 function intr_attach (sig : int; handler : isr_address) return long;
117 pragma Import (C, intr_attach, "signal");
119 Intr_Attach_Reset : constant Boolean := True;
120 -- True if intr_attach is reset after an interrupt handler is called
122 procedure kill (sig : Signal);
123 pragma Import (C, kill, "raise");
125 ---------------------
126 -- Time Management --
127 ---------------------
129 procedure Sleep (dwMilliseconds : DWORD);
130 pragma Import (Stdcall, Sleep, External_Name => "Sleep");
132 type SYSTEMTIME is record
133 wYear : WORD;
134 wMonth : WORD;
135 wDayOfWeek : WORD;
136 wDay : WORD;
137 wHour : WORD;
138 wMinute : WORD;
139 wSecond : WORD;
140 wMilliseconds : WORD;
141 end record;
143 procedure GetSystemTime (pSystemTime : access SYSTEMTIME);
144 pragma Import (Stdcall, GetSystemTime, "GetSystemTime");
146 procedure GetSystemTimeAsFileTime (lpFileTime : access Long_Long_Integer);
147 pragma Import (Stdcall, GetSystemTimeAsFileTime, "GetSystemTimeAsFileTime");
149 function SetSystemTime (pSystemTime : access SYSTEMTIME) return BOOL;
150 pragma Import (Stdcall, SetSystemTime, "SetSystemTime");
152 function FileTimeToSystemTime
153 (lpFileTime : access Long_Long_Integer;
154 lpSystemTime : access SYSTEMTIME) return BOOL;
155 pragma Import (Stdcall, FileTimeToSystemTime, "FileTimeToSystemTime");
157 function SystemTimeToFileTime
158 (lpSystemTime : access SYSTEMTIME;
159 lpFileTime : access Long_Long_Integer) return BOOL;
160 pragma Import (Stdcall, SystemTimeToFileTime, "SystemTimeToFileTime");
162 function FileTimeToLocalFileTime
163 (lpFileTime : access Long_Long_Integer;
164 lpLocalFileTime : access Long_Long_Integer) return BOOL;
165 pragma Import (Stdcall, FileTimeToLocalFileTime, "FileTimeToLocalFileTime");
167 function LocalFileTimeToFileTime
168 (lpFileTime : access Long_Long_Integer;
169 lpLocalFileTime : access Long_Long_Integer) return BOOL;
170 pragma Import (Stdcall, LocalFileTimeToFileTime, "LocalFileTimeToFileTime");
172 function QueryPerformanceCounter
173 (lpPerformanceCount : access LARGE_INTEGER) return BOOL;
174 pragma Import
175 (Stdcall, QueryPerformanceCounter, "QueryPerformanceCounter");
177 function QueryPerformanceFrequency
178 (lpFrequency : access LARGE_INTEGER) return BOOL;
179 pragma Import
180 (Stdcall, QueryPerformanceFrequency, "QueryPerformanceFrequency");
182 -------------
183 -- Threads --
184 -------------
186 type Thread_Body is access
187 function (arg : System.Address) return System.Address;
189 -----------------------
190 -- Critical sections --
191 -----------------------
193 type CRITICAL_SECTION is private;
194 type PCRITICAL_SECTION is access all CRITICAL_SECTION;
196 procedure InitializeCriticalSection (pCriticalSection : PCRITICAL_SECTION);
197 pragma Import
198 (Stdcall, InitializeCriticalSection, "InitializeCriticalSection");
200 procedure EnterCriticalSection (pCriticalSection : PCRITICAL_SECTION);
201 pragma Import (Stdcall, EnterCriticalSection, "EnterCriticalSection");
203 procedure LeaveCriticalSection (pCriticalSection : PCRITICAL_SECTION);
204 pragma Import (Stdcall, LeaveCriticalSection, "LeaveCriticalSection");
206 procedure DeleteCriticalSection (pCriticalSection : PCRITICAL_SECTION);
207 pragma Import (Stdcall, DeleteCriticalSection, "DeleteCriticalSection");
209 -------------------------------------------------------------
210 -- Thread Creation, Activation, Suspension And Termination --
211 -------------------------------------------------------------
213 type PTHREAD_START_ROUTINE is access function
214 (pThreadParameter : PVOID) return DWORD;
215 pragma Convention (Stdcall, PTHREAD_START_ROUTINE);
217 type SECURITY_ATTRIBUTES is record
218 nLength : DWORD;
219 pSecurityDescriptor : PVOID;
220 bInheritHandle : BOOL;
221 end record;
223 type PSECURITY_ATTRIBUTES is access all SECURITY_ATTRIBUTES;
225 function CreateThread
226 (pThreadAttributes : PSECURITY_ATTRIBUTES;
227 dwStackSize : DWORD;
228 pStartAddress : PTHREAD_START_ROUTINE;
229 pParameter : PVOID;
230 dwCreationFlags : DWORD;
231 pThreadId : PDWORD) return HANDLE;
232 pragma Import (Stdcall, CreateThread, "CreateThread");
234 function BeginThreadEx
235 (pThreadAttributes : PSECURITY_ATTRIBUTES;
236 dwStackSize : DWORD;
237 pStartAddress : PTHREAD_START_ROUTINE;
238 pParameter : PVOID;
239 dwCreationFlags : DWORD;
240 pThreadId : PDWORD) return HANDLE;
241 pragma Import (C, BeginThreadEx, "_beginthreadex");
243 Debug_Process : constant := 16#00000001#;
244 Debug_Only_This_Process : constant := 16#00000002#;
245 Create_Suspended : constant := 16#00000004#;
246 Detached_Process : constant := 16#00000008#;
247 Create_New_Console : constant := 16#00000010#;
249 Create_New_Process_Group : constant := 16#00000200#;
251 Create_No_window : constant := 16#08000000#;
253 Profile_User : constant := 16#10000000#;
254 Profile_Kernel : constant := 16#20000000#;
255 Profile_Server : constant := 16#40000000#;
257 function GetExitCodeThread
258 (hThread : HANDLE;
259 pExitCode : PDWORD) return BOOL;
260 pragma Import (Stdcall, GetExitCodeThread, "GetExitCodeThread");
262 function ResumeThread (hThread : HANDLE) return DWORD;
263 pragma Import (Stdcall, ResumeThread, "ResumeThread");
265 function SuspendThread (hThread : HANDLE) return DWORD;
266 pragma Import (Stdcall, SuspendThread, "SuspendThread");
268 procedure ExitThread (dwExitCode : DWORD);
269 pragma Import (Stdcall, ExitThread, "ExitThread");
271 procedure EndThreadEx (dwExitCode : DWORD);
272 pragma Import (C, EndThreadEx, "_endthreadex");
274 function TerminateThread
275 (hThread : HANDLE;
276 dwExitCode : DWORD) return BOOL;
277 pragma Import (Stdcall, TerminateThread, "TerminateThread");
279 function GetCurrentThread return HANDLE;
280 pragma Import (Stdcall, GetCurrentThread, "GetCurrentThread");
282 function GetCurrentProcess return HANDLE;
283 pragma Import (Stdcall, GetCurrentProcess, "GetCurrentProcess");
285 function GetCurrentThreadId return DWORD;
286 pragma Import (Stdcall, GetCurrentThreadId, "GetCurrentThreadId");
288 function TlsAlloc return DWORD;
289 pragma Import (Stdcall, TlsAlloc, "TlsAlloc");
291 function TlsGetValue (dwTlsIndex : DWORD) return PVOID;
292 pragma Import (Stdcall, TlsGetValue, "TlsGetValue");
294 function TlsSetValue (dwTlsIndex : DWORD; pTlsValue : PVOID) return BOOL;
295 pragma Import (Stdcall, TlsSetValue, "TlsSetValue");
297 function TlsFree (dwTlsIndex : DWORD) return BOOL;
298 pragma Import (Stdcall, TlsFree, "TlsFree");
300 TLS_Nothing : constant := DWORD'Last;
302 procedure ExitProcess (uExitCode : Interfaces.C.unsigned);
303 pragma Import (Stdcall, ExitProcess, "ExitProcess");
305 function WaitForSingleObject
306 (hHandle : HANDLE;
307 dwMilliseconds : DWORD) return DWORD;
308 pragma Import (Stdcall, WaitForSingleObject, "WaitForSingleObject");
310 function WaitForSingleObjectEx
311 (hHandle : HANDLE;
312 dwMilliseconds : DWORD;
313 fAlertable : BOOL) return DWORD;
314 pragma Import (Stdcall, WaitForSingleObjectEx, "WaitForSingleObjectEx");
316 Wait_Infinite : constant := DWORD'Last;
317 WAIT_TIMEOUT : constant := 16#0000_0102#;
318 WAIT_FAILED : constant := 16#FFFF_FFFF#;
320 ------------------------------------
321 -- Semaphores, Events and Mutexes --
322 ------------------------------------
324 function CloseHandle (hObject : HANDLE) return BOOL;
325 pragma Import (Stdcall, CloseHandle, "CloseHandle");
327 function CreateSemaphore
328 (pSemaphoreAttributes : PSECURITY_ATTRIBUTES;
329 lInitialCount : Interfaces.C.long;
330 lMaximumCount : Interfaces.C.long;
331 pName : PSZ) return HANDLE;
332 pragma Import (Stdcall, CreateSemaphore, "CreateSemaphoreA");
334 function OpenSemaphore
335 (dwDesiredAccess : DWORD;
336 bInheritHandle : BOOL;
337 pName : PSZ) return HANDLE;
338 pragma Import (Stdcall, OpenSemaphore, "OpenSemaphoreA");
340 function ReleaseSemaphore
341 (hSemaphore : HANDLE;
342 lReleaseCount : Interfaces.C.long;
343 pPreviousCount : PLONG) return BOOL;
344 pragma Import (Stdcall, ReleaseSemaphore, "ReleaseSemaphore");
346 function CreateEvent
347 (pEventAttributes : PSECURITY_ATTRIBUTES;
348 bManualReset : BOOL;
349 bInitialState : BOOL;
350 pName : PSZ) return HANDLE;
351 pragma Import (Stdcall, CreateEvent, "CreateEventA");
353 function OpenEvent
354 (dwDesiredAccess : DWORD;
355 bInheritHandle : BOOL;
356 pName : PSZ) return HANDLE;
357 pragma Import (Stdcall, OpenEvent, "OpenEventA");
359 function SetEvent (hEvent : HANDLE) return BOOL;
360 pragma Import (Stdcall, SetEvent, "SetEvent");
362 function ResetEvent (hEvent : HANDLE) return BOOL;
363 pragma Import (Stdcall, ResetEvent, "ResetEvent");
365 function PulseEvent (hEvent : HANDLE) return BOOL;
366 pragma Import (Stdcall, PulseEvent, "PulseEvent");
368 function CreateMutex
369 (pMutexAttributes : PSECURITY_ATTRIBUTES;
370 bInitialOwner : BOOL;
371 pName : PSZ) return HANDLE;
372 pragma Import (Stdcall, CreateMutex, "CreateMutexA");
374 function OpenMutex
375 (dwDesiredAccess : DWORD;
376 bInheritHandle : BOOL;
377 pName : PSZ) return HANDLE;
378 pragma Import (Stdcall, OpenMutex, "OpenMutexA");
380 function ReleaseMutex (hMutex : HANDLE) return BOOL;
381 pragma Import (Stdcall, ReleaseMutex, "ReleaseMutex");
383 ---------------------------------------------------
384 -- Accessing properties of Threads and Processes --
385 ---------------------------------------------------
387 -----------------
388 -- Priorities --
389 -----------------
391 function SetThreadPriority
392 (hThread : HANDLE;
393 nPriority : Interfaces.C.int) return BOOL;
394 pragma Import (Stdcall, SetThreadPriority, "SetThreadPriority");
396 function GetThreadPriority (hThread : HANDLE) return Interfaces.C.int;
397 pragma Import (Stdcall, GetThreadPriority, "GetThreadPriority");
399 function SetPriorityClass
400 (hProcess : HANDLE;
401 dwPriorityClass : DWORD) return BOOL;
402 pragma Import (Stdcall, SetPriorityClass, "SetPriorityClass");
404 Normal_Priority_Class : constant := 16#00000020#;
405 Idle_Priority_Class : constant := 16#00000040#;
406 High_Priority_Class : constant := 16#00000080#;
407 Realtime_Priority_Class : constant := 16#00000100#;
409 Thread_Priority_Idle : constant := -15;
410 Thread_Priority_Lowest : constant := -2;
411 Thread_Priority_Below_Normal : constant := -1;
412 Thread_Priority_Normal : constant := 0;
413 Thread_Priority_Above_Normal : constant := 1;
414 Thread_Priority_Highest : constant := 2;
415 Thread_Priority_Time_Critical : constant := 15;
416 Thread_Priority_Error_Return : constant := Interfaces.C.long'Last;
418 function GetLastError return DWORD;
419 pragma Import (Stdcall, GetLastError, "GetLastError");
421 private
423 type sigset_t is new Interfaces.C.unsigned_long;
425 type CRITICAL_SECTION is record
426 DebugInfo : System.Address;
427 -- The following three fields control entering and
428 -- exiting the critical section for the resource
429 LockCount : Long_Integer;
430 RecursionCount : Long_Integer;
431 OwningThread : HANDLE;
432 LockSemaphore : HANDLE;
433 Reserved : DWORD;
434 end record;
436 end System.OS_Interface;