]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/ada/5dosinte.ads
Fix for bug #2944, reported by David Holmes <dholmes@dltech.com.au>
[thirdparty/gcc.git] / gcc / ada / 5dosinte.ads
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 -- Copyright (C) 1992-2001, Free Software Foundation, Inc. --
10 -- --
11 -- GNARL 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. GNARL 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 GNARL; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
21 -- --
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. --
28 -- --
29 -- GNARL was developed by the GNARL team at Florida State University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
31 -- --
32 ------------------------------------------------------------------------------
33
34 -- This is a DOS/DJGPPv2 (FSU THREAD) version of this package.
35
36 -- This package encapsulates all direct interfaces to OS services
37 -- that are needed by children of System.
38
39 -- PLEASE DO NOT add any with-clauses to this package
40 -- or remove the pragma Elaborate_Body.
41 -- It is designed to be a bottom-level (leaf) package.
42
43 with Interfaces.C;
44 package System.OS_Interface is
45 pragma Preelaborate;
46
47 --
48 -- A short name for libgthreads.a to keep Mike Feldman happy.
49 --
50 pragma Linker_Options ("-lgthre");
51
52 subtype int is Interfaces.C.int;
53 subtype short is Interfaces.C.short;
54 subtype long is Interfaces.C.long;
55 subtype unsigned is Interfaces.C.unsigned;
56 subtype unsigned_short is Interfaces.C.unsigned_short;
57 subtype unsigned_long is Interfaces.C.unsigned_long;
58 subtype unsigned_char is Interfaces.C.unsigned_char;
59 subtype plain_char is Interfaces.C.plain_char;
60 subtype size_t is Interfaces.C.size_t;
61
62 -----------
63 -- Errno --
64 -----------
65
66 function errno return int;
67 pragma Import (C, errno, "__get_errno");
68
69 EAGAIN : constant := 5;
70 EINTR : constant := 13;
71 EINVAL : constant := 14;
72 ENOMEM : constant := 25;
73
74 -------------
75 -- Signals --
76 -------------
77
78 Max_Interrupt : constant := 319;
79 type Signal is new int range 0 .. Max_Interrupt;
80
81 SIGHUP : constant := 294; -- hangup
82 SIGINT : constant := 295; -- interrupt (rubout)
83 SIGQUIT : constant := 298; -- quit (ASCD FS)
84 SIGILL : constant := 290; -- illegal instruction (not reset)
85 SIGABRT : constant := 288; -- used by abort
86 SIGFPE : constant := 289; -- floating point exception
87 SIGKILL : constant := 296; -- kill (cannot be caught or ignored)
88 SIGSEGV : constant := 291; -- segmentation violation
89 SIGPIPE : constant := 297; -- write on a pipe with no one to read it
90 SIGALRM : constant := 293; -- alarm clock
91 SIGTERM : constant := 292; -- software termination signal from kill
92 SIGUSR1 : constant := 299; -- user defined signal 1
93 SIGUSR2 : constant := 300; -- user defined signal 2
94 SIGBUS : constant := 0;
95
96 SIGADAABORT : constant := SIGABRT;
97
98 type Signal_Set is array (Natural range <>) of Signal;
99
100 Unmasked : constant Signal_Set := (SIGTRAP, SIGALRM);
101 Reserved : constant Signal_Set := (0 .. 0 => SIGSTOP);
102
103 type sigset_t is private;
104
105 function sigaddset (set : access sigset_t; sig : Signal) return int;
106 pragma Import (C, sigaddset, "sigaddset");
107
108 function sigdelset (set : access sigset_t; sig : Signal) return int;
109 pragma Import (C, sigdelset, "sigdelset");
110
111 function sigfillset (set : access sigset_t) return int;
112 pragma Import (C, sigfillset, "sigfillset");
113
114 function sigismember (set : access sigset_t; sig : Signal) return int;
115 pragma Import (C, sigismember, "sigismember");
116
117 function sigemptyset (set : access sigset_t) return int;
118 pragma Import (C, sigemptyset, "sigemptyset");
119
120 type struct_sigaction is record
121 sa_flags : int;
122 sa_handler : System.Address;
123 sa_mask : sigset_t;
124 end record;
125 pragma Convention (C, struct_sigaction);
126 type struct_sigaction_ptr is access all struct_sigaction;
127
128 SIG_BLOCK : constant := 1;
129 SIG_UNBLOCK : constant := 3;
130 SIG_SETMASK : constant := 2;
131
132 SIG_DFL : constant := 0;
133 SIG_IGN : constant := -1;
134
135 function sigaction
136 (sig : Signal;
137 act : struct_sigaction_ptr;
138 oact : struct_sigaction_ptr) return int;
139 pragma Import (C, sigaction, "sigaction");
140
141 ----------
142 -- Time --
143 ----------
144
145 Time_Slice_Supported : constant Boolean := False;
146 -- Indicates wether time slicing is supported (i.e FSU threads have been
147 -- compiled with DEF_RR)
148
149 type timespec is private;
150
151 function nanosleep (rqtp, rmtp : access timespec) return int;
152 -- FSU_THREADS has nonstandard nanosleep
153 type clockid_t is private;
154
155 CLOCK_REALTIME : constant clockid_t;
156
157 function clock_gettime
158 (clock_id : clockid_t;
159 tp : access timespec) return int;
160 pragma Import (C, clock_gettime, "clock_gettime");
161
162 function To_Duration (TS : timespec) return Duration;
163 pragma Inline (To_Duration);
164
165 function To_Timespec (D : Duration) return timespec;
166 pragma Inline (To_Timespec);
167
168 type struct_timeval is private;
169
170 function To_Duration (TV : struct_timeval) return Duration;
171 pragma Inline (To_Duration);
172
173 function To_Timeval (D : Duration) return struct_timeval;
174 pragma Inline (To_Timeval);
175
176 -------------------------
177 -- Priority Scheduling --
178 -------------------------
179
180 SCHED_FIFO : constant := 0;
181 SCHED_RR : constant := 1;
182 SCHED_OTHER : constant := 2;
183
184 -------------
185 -- Process --
186 -------------
187
188 type pid_t is private;
189
190 function kill (pid : pid_t; sig : Signal) return int;
191 pragma Import (C, kill, "kill");
192
193 function getpid return pid_t;
194 pragma Import (C, getpid, "getpid");
195
196 ---------
197 -- LWP --
198 ---------
199
200 function lwp_self return System.Address;
201 -- lwp_self does not exist on this thread library, revert to pthread_self
202 -- which is the closest approximation (with getpid). This function is
203 -- needed to share 7staprop.adb across POSIX-like targets.
204 pragma Import (C, lwp_self, "pthread_self");
205
206 -------------
207 -- Threads --
208 -------------
209
210 type Thread_Body is access
211 function (arg : System.Address) return System.Address;
212
213 type pthread_t is private;
214 subtype Thread_Id is pthread_t;
215
216 type pthread_mutex_t is limited private;
217 type pthread_cond_t is limited private;
218 type pthread_attr_t is limited private;
219 type pthread_mutexattr_t is limited private;
220 type pthread_condattr_t is limited private;
221 type pthread_key_t is private;
222
223 PTHREAD_CREATE_DETACHED : constant := 1;
224
225 -----------
226 -- Stack --
227 -----------
228
229 Stack_Base_Available : constant Boolean := False;
230 -- Indicates wether the stack base is available on this target.
231 -- This allows us to share s-osinte.adb between all the FSU run time.
232 -- Note that this value can only be true if pthread_t has a complete
233 -- definition that corresponds exactly to the C header files.
234
235 function Get_Stack_Base (thread : pthread_t) return Address;
236 pragma Inline (Get_Stack_Base);
237 -- returns the stack base of the specified thread.
238 -- Only call this function when Stack_Base_Available is True.
239
240 function Get_Page_Size return size_t;
241 function Get_Page_Size return Address;
242 pragma Import (C, Get_Page_Size, "getpagesize");
243 -- returns the size of a page, or 0 if this is not relevant on this
244 -- target
245
246 PROT_NONE : constant := 0;
247 PROT_READ : constant := 1;
248 PROT_WRITE : constant := 2;
249 PROT_EXEC : constant := 4;
250 PROT_ALL : constant := PROT_READ + PROT_WRITE + PROT_EXEC;
251
252 PROT_ON : constant := PROT_NONE;
253 PROT_OFF : constant := PROT_ALL;
254
255 function mprotect
256 (addr : Address; len : size_t; prot : int) return int;
257 pragma Import (C, mprotect);
258
259 ---------------------------------------
260 -- Nonstandard Thread Initialization --
261 ---------------------------------------
262
263 procedure pthread_init;
264 -- FSU_THREADS requires pthread_init, which is nonstandard
265 -- and this should be invoked during the elaboration of s-taprop.adb
266 pragma Import (C, pthread_init, "pthread_init");
267
268 -------------------------
269 -- POSIX.1c Section 3 --
270 -------------------------
271
272 function sigwait (set : access sigset_t; sig : access Signal) return int;
273 -- FSU_THREADS has a nonstandard sigwait
274
275 function pthread_kill (thread : pthread_t; sig : Signal) return int;
276 pragma Import (C, pthread_kill, "pthread_kill");
277
278 type sigset_t_ptr is access all sigset_t;
279
280 function pthread_sigmask
281 (how : int;
282 set : sigset_t_ptr;
283 oset : sigset_t_ptr) return int;
284 pragma Import (C, pthread_sigmask, "sigprocmask");
285
286 --------------------------
287 -- POSIX.1c Section 11 --
288 --------------------------
289
290 function pthread_mutexattr_init
291 (attr : access pthread_mutexattr_t) return int;
292 pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
293
294 function pthread_mutexattr_destroy
295 (attr : access pthread_mutexattr_t) return int;
296 pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
297
298 function pthread_mutex_init
299 (mutex : access pthread_mutex_t;
300 attr : access pthread_mutexattr_t) return int;
301 pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
302
303 function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
304 pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
305
306 function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
307 -- FSU_THREADS has nonstandard pthread_mutex_lock
308
309 function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
310 -- FSU_THREADS has nonstandard pthread_mutex_lock
311
312 function pthread_condattr_init
313 (attr : access pthread_condattr_t) return int;
314 pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
315
316 function pthread_condattr_destroy
317 (attr : access pthread_condattr_t) return int;
318 pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
319
320 function pthread_cond_init
321 (cond : access pthread_cond_t;
322 attr : access pthread_condattr_t) return int;
323 pragma Import (C, pthread_cond_init, "pthread_cond_init");
324
325 function pthread_cond_destroy (cond : access pthread_cond_t) return int;
326 pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
327
328 function pthread_cond_signal (cond : access pthread_cond_t) return int;
329 pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
330
331 function pthread_cond_wait
332 (cond : access pthread_cond_t;
333 mutex : access pthread_mutex_t) return int;
334 -- FSU_THREADS has a nonstandard pthread_cond_wait
335
336 function pthread_cond_timedwait
337 (cond : access pthread_cond_t;
338 mutex : access pthread_mutex_t;
339 abstime : access timespec) return int;
340 -- FSU_THREADS has a nonstandard pthread_cond_timedwait
341
342 Relative_Timed_Wait : constant Boolean := False;
343 -- pthread_cond_timedwait requires an absolute delay time
344
345 --------------------------
346 -- POSIX.1c Section 13 --
347 --------------------------
348
349 PTHREAD_PRIO_NONE : constant := 0;
350 PTHREAD_PRIO_PROTECT : constant := 2;
351 PTHREAD_PRIO_INHERIT : constant := 1;
352
353 function pthread_mutexattr_setprotocol
354 (attr : access pthread_mutexattr_t;
355 protocol : int) return int;
356 pragma Import (C, pthread_mutexattr_setprotocol);
357
358 function pthread_mutexattr_setprioceiling
359 (attr : access pthread_mutexattr_t;
360 prioceiling : int) return int;
361 pragma Import (C, pthread_mutexattr_setprioceiling);
362
363 type struct_sched_param is record
364 sched_priority : int; -- scheduling priority
365 end record;
366
367 function pthread_setschedparam
368 (thread : pthread_t;
369 policy : int;
370 param : access struct_sched_param) return int;
371 -- FSU_THREADS does not have pthread_setschedparam
372
373 function pthread_attr_setscope
374 (attr : access pthread_attr_t;
375 contentionscope : int) return int;
376 pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope");
377
378 function pthread_attr_setinheritsched
379 (attr : access pthread_attr_t;
380 inheritsched : int) return int;
381 pragma Import (C, pthread_attr_setinheritsched);
382
383 function pthread_attr_setschedpolicy
384 (attr : access pthread_attr_t;
385 policy : int) return int;
386 pragma Import (C, pthread_attr_setschedpolicy, "pthread_attr_setsched");
387
388 function sched_yield return int;
389 -- FSU_THREADS does not have sched_yield;
390
391 ---------------------------
392 -- P1003.1c - Section 16 --
393 ---------------------------
394
395 function pthread_attr_init (attributes : access pthread_attr_t) return int;
396 pragma Import (C, pthread_attr_init);
397
398 function pthread_attr_destroy
399 (attributes : access pthread_attr_t) return int;
400 pragma Import (C, pthread_attr_destroy);
401
402 function pthread_attr_setdetachstate
403 (attr : access pthread_attr_t;
404 detachstate : int) return int;
405 -- FSU_THREADS has a nonstandard pthread_attr_setdetachstate
406
407 function pthread_attr_setstacksize
408 (attr : access pthread_attr_t;
409 stacksize : size_t) return int;
410 pragma Import (C, pthread_attr_setstacksize);
411
412 function pthread_create
413 (thread : access pthread_t;
414 attributes : access pthread_attr_t;
415 start_routine : Thread_Body;
416 arg : System.Address) return int;
417 pragma Import (C, pthread_create);
418
419 procedure pthread_exit (status : System.Address);
420 pragma Import (C, pthread_exit, "pthread_exit");
421
422 function pthread_self return pthread_t;
423 pragma Import (C, pthread_self, "pthread_self");
424
425 --------------------------
426 -- POSIX.1c Section 17 --
427 --------------------------
428
429 function pthread_setspecific
430 (key : pthread_key_t;
431 value : System.Address) return int;
432 pragma Import (C, pthread_setspecific, "pthread_setspecific");
433
434 function pthread_getspecific (key : pthread_key_t) return System.Address;
435 -- FSU_THREADS has a nonstandard pthread_getspecific
436
437 type destructor_pointer is access procedure (arg : System.Address);
438
439 function pthread_key_create
440 (key : access pthread_key_t;
441 destructor : destructor_pointer) return int;
442 pragma Import (C, pthread_key_create, "pthread_key_create");
443
444 private
445
446 type bits_arr_t is array (Integer range 1 .. 10) of long;
447 type sigset_t is record
448 bits : bits_arr_t;
449 end record;
450
451 type pid_t is new int;
452
453 type time_t is new long;
454
455 type timespec is record
456 tv_sec : time_t;
457 tv_nsec : long;
458 end record;
459 pragma Convention (C, timespec);
460
461 type clockid_t is new int;
462 CLOCK_REALTIME : constant clockid_t := 0;
463
464 type struct_timeval is record
465 tv_sec : long;
466 tv_usec : long;
467 end record;
468 pragma Convention (C, struct_timeval);
469
470 type pthread_attr_t is record
471 flags : int;
472 stacksize : int;
473 contentionscope : int;
474 inheritsched : int;
475 detachstate : int;
476 sched : int;
477 prio : int;
478 starttime : timespec;
479 deadline : timespec;
480 period : timespec;
481 end record;
482 pragma Convention (C, pthread_attr_t);
483
484 type pthread_condattr_t is record
485 flags : int;
486 end record;
487 pragma Convention (C, pthread_condattr_t);
488
489 type pthread_mutexattr_t is record
490 flags : int;
491 prio_ceiling : int;
492 protocol : int;
493 end record;
494 pragma Convention (C, pthread_mutexattr_t);
495
496 type sigjmp_buf is array (Integer range 0 .. 43) of int;
497
498 type pthread_t_struct is record
499 context : sigjmp_buf;
500 pbody : sigjmp_buf;
501 errno : int;
502 ret : int;
503 stack_base : System.Address;
504 end record;
505 pragma Convention (C, pthread_t_struct);
506
507 type pthread_t is access all pthread_t_struct;
508
509 type queue_t is record
510 head : System.Address;
511 tail : System.Address;
512 end record;
513 pragma Convention (C, queue_t);
514
515 type pthread_mutex_t is record
516 queue : queue_t;
517 lock : plain_char;
518 owner : System.Address;
519 flags : int;
520 prio_ceiling : int;
521 protocol : int;
522 prev_max_ceiling_prio : int;
523 end record;
524 pragma Convention (C, pthread_mutex_t);
525
526 type pthread_cond_t is record
527 queue : queue_t;
528 flags : int;
529 waiters : int;
530 mutex : System.Address;
531 end record;
532 pragma Convention (C, pthread_cond_t);
533
534 type pthread_key_t is new int;
535
536 end System.OS_Interface;