]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/ada/libgnarl/s-osinte__qnx.ads
fdbf17460605fd58647ccf7189bef1076c339358
[thirdparty/gcc.git] / gcc / ada / libgnarl / s-osinte__qnx.ads
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT 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) 1995-2017, 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 -- GNARL was developed by the GNARL team at Florida State University. --
28 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
29 -- --
30 ------------------------------------------------------------------------------
31
32 -- This is a QNX/Neutrino version of this package
33
34 -- This package encapsulates all direct interfaces to OS services
35 -- that are needed by the tasking run-time (libgnarl).
36
37 -- PLEASE DO NOT add any with-clauses to this package or remove the pragma
38 -- Preelaborate. This package is designed to be a bottom-level (leaf) package.
39
40 with Ada.Unchecked_Conversion;
41 with Interfaces.C;
42 with System.OS_Constants;
43
44 package System.OS_Interface is
45 pragma Preelaborate;
46
47 subtype int is Interfaces.C.int;
48 subtype char is Interfaces.C.char;
49 subtype short is Interfaces.C.short;
50 subtype long is Interfaces.C.long;
51 subtype unsigned is Interfaces.C.unsigned;
52 subtype unsigned_short is Interfaces.C.unsigned_short;
53 subtype unsigned_long is Interfaces.C.unsigned_long;
54 subtype unsigned_char is Interfaces.C.unsigned_char;
55 subtype plain_char is Interfaces.C.plain_char;
56 subtype size_t is Interfaces.C.size_t;
57
58 -----------
59 -- Errno --
60 -----------
61
62 function errno return int;
63 pragma Import (C, errno, "__get_errno");
64
65 EPERM : constant := 1;
66 EINTR : constant := 4;
67 EAGAIN : constant := 11;
68 ENOMEM : constant := 12;
69 EINVAL : constant := 22;
70 ETIMEDOUT : constant := 260;
71
72 -------------
73 -- Signals --
74 -------------
75
76 Max_Interrupt : constant := 64;
77 type Signal is new int range 0 .. Max_Interrupt;
78 for Signal'Size use int'Size;
79
80 SIGHUP : constant := 1;
81 SIGINT : constant := 2;
82 SIGQUIT : constant := 3;
83 SIGILL : constant := 4;
84 SIGTRAP : constant := 5;
85 SIGIOT : constant := 6;
86 SIGABRT : constant := 6;
87 SIGDEADLK : constant := 7;
88 SIGFPE : constant := 8;
89 SIGKILL : constant := 9;
90 SIGBUS : constant := 10;
91 SIGSEGV : constant := 11;
92 SIGSYS : constant := 12;
93 SIGPIPE : constant := 13;
94 SIGALRM : constant := 14;
95 SIGTERM : constant := 15;
96 SIGUSR1 : constant := 16;
97 SIGUSR2 : constant := 17;
98 SIGCLD : constant := 18;
99 SIGCHLD : constant := 18;
100 SIGPWR : constant := 19;
101 SIGWINCH : constant := 20;
102 SIGURG : constant := 21;
103 SIGPOLL : constant := 22;
104 SIGIO : constant := 22;
105 SIGSTOP : constant := 23;
106 SIGTSTP : constant := 24;
107 SIGCONT : constant := 25;
108 SIGTTIN : constant := 26;
109 SIGTTOU : constant := 27;
110 SIGVTALRM : constant := 28;
111 SIGPROF : constant := 29;
112 SIGXCPU : constant := 30;
113 SIGXFSZ : constant := 31;
114
115 SIGRTMIN : constant := 41;
116 SITRTMAX : constant := 56;
117
118 SIGSELECT : constant := 57;
119 SIGPHOTON : constant := 58;
120
121 SIGADAABORT : constant := SIGABRT;
122 -- Change this to use another signal for task abort. SIGTERM might be a
123 -- good one.
124
125 type Signal_Set is array (Natural range <>) of Signal;
126
127 Unmasked : constant Signal_Set := (
128 SIGTRAP,
129 -- To enable debugging on multithreaded applications, mark SIGTRAP to
130 -- be kept unmasked.
131
132 SIGBUS,
133
134 SIGTTIN, SIGTTOU, SIGTSTP,
135 -- Keep these three signals unmasked so that background processes and IO
136 -- behaves as normal "C" applications
137
138 SIGPROF,
139 -- To avoid confusing the profiler
140
141 SIGKILL, SIGSTOP);
142 -- These two signals actually can't be masked (POSIX won't allow it)
143
144 Reserved : constant Signal_Set := (SIGKILL, SIGSTOP, SIGSEGV);
145
146 type sigset_t is private;
147
148 function sigaddset (set : access sigset_t; sig : Signal) return int;
149 pragma Import (C, sigaddset, "sigaddset");
150
151 function sigdelset (set : access sigset_t; sig : Signal) return int;
152 pragma Import (C, sigdelset, "sigdelset");
153
154 function sigfillset (set : access sigset_t) return int;
155 pragma Import (C, sigfillset, "sigfillset");
156
157 function sigismember (set : access sigset_t; sig : Signal) return int;
158 pragma Import (C, sigismember, "sigismember");
159
160 function sigemptyset (set : access sigset_t) return int;
161 pragma Import (C, sigemptyset, "sigemptyset");
162
163 type union_type_3 is new String (1 .. 116);
164 type siginfo_t is record
165 si_signo : int;
166 si_code : int;
167 si_errno : int;
168 X_data : union_type_3;
169 end record;
170 pragma Convention (C, siginfo_t);
171
172 type struct_sigaction is record
173 sa_handler : System.Address;
174 sa_flags : Interfaces.C.int;
175 sa_mask : sigset_t;
176 end record;
177 pragma Convention (C, struct_sigaction);
178
179 type struct_sigaction_ptr is access all struct_sigaction;
180
181 SIG_BLOCK : constant := 0;
182 SIG_UNBLOCK : constant := 1;
183 SIG_SETMASK : constant := 2;
184 SIG_PENDING : constant := 5;
185
186 SA_NOCLDSTOP : constant := 16#0001#;
187 SA_SIGINFO : constant := 16#0002#;
188 SA_RESETHAND : constant := 16#0004#;
189 SA_ONSTACK : constant := 16#0008#;
190 SA_NODEFER : constant := 16#0010#;
191 SA_NOCLDWAIT : constant := 16#0020#;
192
193 SS_ONSTACK : constant := 1;
194 SS_DISABLE : constant := 2;
195
196 SIG_DFL : constant := 0;
197 SIG_IGN : constant := 1;
198
199 function sigaction
200 (sig : Signal;
201 act : struct_sigaction_ptr;
202 oact : struct_sigaction_ptr) return int;
203 pragma Import (C, sigaction, "sigaction");
204
205 ----------
206 -- Time --
207 ----------
208
209 Time_Slice_Supported : constant Boolean := True;
210 -- Indicates whether time slicing is supported
211
212 type timespec is private;
213
214 type clockid_t is new int;
215
216 function clock_gettime
217 (clock_id : clockid_t; tp : access timespec) return int;
218 pragma Import (C, clock_gettime, "clock_gettime");
219
220 function clock_getres
221 (clock_id : clockid_t;
222 res : access timespec) return int;
223 pragma Import (C, clock_getres, "clock_getres");
224
225 function To_Duration (TS : timespec) return Duration;
226 pragma Inline (To_Duration);
227
228 function To_Timespec (D : Duration) return timespec;
229 pragma Inline (To_Timespec);
230
231 function sysconf (name : int) return long;
232 pragma Import (C, sysconf);
233
234 SC_CLK_TCK : constant := 2;
235 SC_NPROCESSORS_ONLN : constant := 84;
236
237 -------------------------
238 -- Priority Scheduling --
239 -------------------------
240
241 SCHED_OTHER : constant := 3;
242 SCHED_FIFO : constant := 1;
243 SCHED_RR : constant := 2;
244
245 function To_Target_Priority
246 (Prio : System.Any_Priority) return Interfaces.C.int
247 with Inline_Always;
248 -- Maps System.Any_Priority to a POSIX priority
249
250 -------------
251 -- Process --
252 -------------
253
254 type pid_t is private;
255
256 function kill (pid : pid_t; sig : Signal) return int;
257 pragma Import (C, kill, "kill");
258
259 function getpid return pid_t;
260 pragma Import (C, getpid, "getpid");
261
262 -------------
263 -- Threads --
264 -------------
265
266 type Thread_Body is access
267 function (arg : System.Address) return System.Address;
268 pragma Convention (C, Thread_Body);
269
270 function Thread_Body_Access is new
271 Ada.Unchecked_Conversion (System.Address, Thread_Body);
272
273 type pthread_t is new unsigned_long;
274 subtype Thread_Id is pthread_t;
275
276 function To_pthread_t is
277 new Ada.Unchecked_Conversion (unsigned_long, pthread_t);
278
279 type pthread_mutex_t is limited private;
280 type pthread_cond_t is limited private;
281 type pthread_attr_t is limited private;
282 type pthread_mutexattr_t is limited private;
283 type pthread_condattr_t is limited private;
284 type pthread_key_t is private;
285
286 PTHREAD_CREATE_DETACHED : constant := 1;
287
288 PTHREAD_SCOPE_PROCESS : constant := 4;
289 PTHREAD_SCOPE_SYSTEM : constant := 0;
290
291 -- Read/Write lock not supported on Android.
292
293 subtype pthread_rwlock_t is pthread_mutex_t;
294 subtype pthread_rwlockattr_t is pthread_mutexattr_t;
295
296 -----------
297 -- Stack --
298 -----------
299
300 type stack_t is record
301 ss_sp : System.Address;
302 ss_flags : int;
303 ss_size : size_t;
304 end record;
305 pragma Convention (C, stack_t);
306
307 function sigaltstack
308 (ss : not null access stack_t;
309 oss : access stack_t) return int;
310 pragma Import (C, sigaltstack, "sigaltstack");
311
312 Alternate_Stack : aliased System.Address;
313 -- Dummy definition: alternate stack not available due to missing
314 -- sigaltstack
315
316 Alternate_Stack_Size : constant := 0;
317 -- This must be in keeping with init.c:__gnat_alternate_stack
318
319 Stack_Base_Available : constant Boolean := False;
320 -- Indicates whether the stack base is available on this target
321
322 function Get_Stack_Base (thread : pthread_t) return System.Address
323 with Inline_Always;
324 -- This is a dummy procedure to share some GNULLI files
325
326 function Get_Page_Size return int;
327 pragma Import (C, Get_Page_Size, "getpagesize");
328 -- Returns the size of a page
329
330 PROT_NONE : constant := 0;
331 PROT_READ : constant := 1;
332 PROT_WRITE : constant := 2;
333 PROT_EXEC : constant := 4;
334 PROT_ALL : constant := PROT_READ + PROT_WRITE + PROT_EXEC;
335 PROT_ON : constant := PROT_READ;
336 PROT_OFF : constant := PROT_ALL;
337
338 function mprotect (addr : Address; len : size_t; prot : int) return int;
339 pragma Import (C, mprotect);
340
341 ---------------------------------------
342 -- Nonstandard Thread Initialization --
343 ---------------------------------------
344
345 procedure pthread_init with Inline_Always;
346
347 -------------------------
348 -- POSIX.1c Section 3 --
349 -------------------------
350
351 function sigwait (set : access sigset_t; sig : access Signal) return int;
352 pragma Import (C, sigwait, "sigwait");
353
354 function pthread_kill (thread : pthread_t; sig : Signal) return int;
355 pragma Import (C, pthread_kill, "pthread_kill");
356
357 function pthread_sigmask
358 (how : int;
359 set : access sigset_t;
360 oset : access sigset_t) return int;
361 pragma Import (C, pthread_sigmask, "sigprocmask");
362 -- pthread_sigmask maybe be broken due to mismatch between sigset_t and
363 -- kernel_sigset_t, substitute sigprocmask temporarily. ???
364 -- pragma Import (C, pthread_sigmask, "pthread_sigmask");
365
366 --------------------------
367 -- POSIX.1c Section 11 --
368 --------------------------
369
370 function pthread_mutexattr_init
371 (attr : access pthread_mutexattr_t) return int;
372 pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
373
374 function pthread_mutexattr_destroy
375 (attr : access pthread_mutexattr_t) return int;
376 pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
377
378 function pthread_mutex_init
379 (mutex : access pthread_mutex_t;
380 attr : access pthread_mutexattr_t) return int;
381 pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
382
383 function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
384 pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
385
386 function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
387 pragma Import (C, pthread_mutex_lock, "pthread_mutex_lock");
388
389 function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
390 pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock");
391
392 function pthread_condattr_init
393 (attr : access pthread_condattr_t) return int;
394 pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
395
396 function pthread_condattr_destroy
397 (attr : access pthread_condattr_t) return int;
398 pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
399
400 function pthread_cond_init
401 (cond : access pthread_cond_t;
402 attr : access pthread_condattr_t) return int;
403 pragma Import (C, pthread_cond_init, "pthread_cond_init");
404
405 function pthread_cond_destroy (cond : access pthread_cond_t) return int;
406 pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
407
408 function pthread_cond_signal (cond : access pthread_cond_t) return int;
409 pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
410
411 function pthread_cond_wait
412 (cond : access pthread_cond_t;
413 mutex : access pthread_mutex_t) return int;
414 pragma Import (C, pthread_cond_wait, "pthread_cond_wait");
415
416 function pthread_cond_timedwait
417 (cond : access pthread_cond_t;
418 mutex : access pthread_mutex_t;
419 abstime : access timespec) return int;
420 pragma Import (C, pthread_cond_timedwait, "pthread_cond_timedwait");
421
422 Relative_Timed_Wait : constant Boolean := False;
423 -- pthread_cond_timedwait requires an absolute delay time
424
425 --------------------------
426 -- POSIX.1c Section 13 --
427 --------------------------
428
429 PTHREAD_PRIO_INHERIT : constant := 0;
430 PTHREAD_PRIO_NONE : constant := 1;
431 PTHREAD_PRIO_PROTECT : constant := 2;
432
433 function pthread_mutexattr_setprotocol
434 (attr : access pthread_mutexattr_t;
435 protocol : int) return int is (0);
436
437 function pthread_mutexattr_setprioceiling
438 (attr : access pthread_mutexattr_t;
439 prioceiling : int) return int is (0);
440
441 type struct_sched_param is record
442 sched_priority : int; -- scheduling priority
443 end record;
444 pragma Convention (C, struct_sched_param);
445
446 function pthread_setschedparam
447 (thread : pthread_t;
448 policy : int;
449 param : access struct_sched_param) return int;
450 pragma Import (C, pthread_setschedparam, "pthread_setschedparam");
451
452 function pthread_attr_setscope
453 (attr : access pthread_attr_t;
454 scope : int) return int;
455 pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope");
456
457 function pthread_attr_setschedpolicy
458 (attr : access pthread_attr_t;
459 policy : int) return int;
460 pragma Import
461 (C, pthread_attr_setschedpolicy, "pthread_attr_setschedpolicy");
462
463 function sched_yield return int;
464 pragma Import (C, sched_yield, "sched_yield");
465
466 ---------------------------
467 -- P1003.1c - Section 16 --
468 ---------------------------
469
470 function pthread_attr_init
471 (attributes : access pthread_attr_t) return int;
472 pragma Import (C, pthread_attr_init, "pthread_attr_init");
473
474 function pthread_attr_destroy
475 (attributes : access pthread_attr_t) return int;
476 pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
477
478 function pthread_attr_setdetachstate
479 (attr : access pthread_attr_t;
480 detachstate : int) return int;
481 pragma Import
482 (C, pthread_attr_setdetachstate, "pthread_attr_setdetachstate");
483
484 function pthread_attr_setstacksize
485 (attr : access pthread_attr_t;
486 stacksize : size_t) return int;
487 pragma Import (C, pthread_attr_setstacksize, "pthread_attr_setstacksize");
488
489 function pthread_create
490 (thread : access pthread_t;
491 attributes : access pthread_attr_t;
492 start_routine : Thread_Body;
493 arg : System.Address) return int;
494 pragma Import (C, pthread_create, "pthread_create");
495
496 procedure pthread_exit (status : System.Address);
497 pragma Import (C, pthread_exit, "pthread_exit");
498
499 function pthread_self return pthread_t;
500 pragma Import (C, pthread_self, "pthread_self");
501
502 function lwp_self return System.Address;
503 pragma Import (C, lwp_self, "pthread_self");
504
505 --------------------------
506 -- POSIX.1c Section 17 --
507 --------------------------
508
509 function pthread_setspecific
510 (key : pthread_key_t;
511 value : System.Address) return int;
512 pragma Import (C, pthread_setspecific, "pthread_setspecific");
513
514 function pthread_getspecific (key : pthread_key_t) return System.Address;
515 pragma Import (C, pthread_getspecific, "pthread_getspecific");
516
517 type destructor_pointer is access procedure (arg : System.Address);
518 pragma Convention (C, destructor_pointer);
519
520 function pthread_key_create
521 (key : access pthread_key_t;
522 destructor : destructor_pointer) return int;
523 pragma Import (C, pthread_key_create, "pthread_key_create");
524
525 CPU_SETSIZE : constant := 1_024;
526 -- Size of the cpu_set_t mask on most linux systems (SUSE 11 uses 4_096).
527 -- This is kept for backward compatibility (System.Task_Info uses it), but
528 -- the run-time library does no longer rely on static masks, using
529 -- dynamically allocated masks instead.
530
531 type bit_field is array (1 .. CPU_SETSIZE) of Boolean;
532 for bit_field'Size use CPU_SETSIZE;
533 pragma Pack (bit_field);
534 pragma Convention (C, bit_field);
535
536 type cpu_set_t is record
537 bits : bit_field;
538 end record;
539 pragma Convention (C, cpu_set_t);
540
541 type cpu_set_t_ptr is access all cpu_set_t;
542 -- In the run-time library we use this pointer because the size of type
543 -- cpu_set_t varies depending on the glibc version. Hence, objects of type
544 -- cpu_set_t are allocated dynamically using the number of processors
545 -- available in the target machine (value obtained at execution time).
546
547 function CPU_ALLOC (count : size_t) return cpu_set_t_ptr;
548 pragma Import (C, CPU_ALLOC, "__gnat_cpu_alloc");
549 -- Wrapper around the CPU_ALLOC C macro
550
551 function CPU_ALLOC_SIZE (count : size_t) return size_t;
552 pragma Import (C, CPU_ALLOC_SIZE, "__gnat_cpu_alloc_size");
553 -- Wrapper around the CPU_ALLOC_SIZE C macro
554
555 procedure CPU_FREE (cpuset : cpu_set_t_ptr);
556 pragma Import (C, CPU_FREE, "__gnat_cpu_free");
557 -- Wrapper around the CPU_FREE C macro
558
559 procedure CPU_ZERO (count : size_t; cpuset : cpu_set_t_ptr);
560 pragma Import (C, CPU_ZERO, "__gnat_cpu_zero");
561 -- Wrapper around the CPU_ZERO_S C macro
562
563 procedure CPU_SET (cpu : int; count : size_t; cpuset : cpu_set_t_ptr);
564 pragma Import (C, CPU_SET, "__gnat_cpu_set");
565 -- Wrapper around the CPU_SET_S C macro
566
567 private
568
569 type sigset_t is new Interfaces.C.unsigned_long;
570 pragma Convention (C, sigset_t);
571 for sigset_t'Alignment use Interfaces.C.unsigned_long'Alignment;
572
573 type pid_t is new int;
574
575 type time_t is new long;
576
577 type timespec is record
578 tv_sec : time_t;
579 tv_nsec : long;
580 end record;
581 pragma Convention (C, timespec);
582
583 type unsigned_long_long_t is mod 2 ** 64;
584 -- Local type only used to get the alignment of this type below
585
586 subtype char_array is Interfaces.C.char_array;
587
588 type pthread_attr_t is record
589 Data : char_array (1 .. OS_Constants.PTHREAD_ATTR_SIZE);
590 end record;
591 pragma Convention (C, pthread_attr_t);
592 for pthread_attr_t'Alignment use Interfaces.C.unsigned_long'Alignment;
593
594 type pthread_condattr_t is record
595 Data : char_array (1 .. OS_Constants.PTHREAD_CONDATTR_SIZE);
596 end record;
597 pragma Convention (C, pthread_condattr_t);
598 for pthread_condattr_t'Alignment use Interfaces.C.int'Alignment;
599
600 type pthread_mutexattr_t is record
601 Data : char_array (1 .. OS_Constants.PTHREAD_MUTEXATTR_SIZE);
602 end record;
603 pragma Convention (C, pthread_mutexattr_t);
604 for pthread_mutexattr_t'Alignment use Interfaces.C.int'Alignment;
605
606 type pthread_mutex_t is record
607 Data : char_array (1 .. OS_Constants.PTHREAD_MUTEX_SIZE);
608 end record;
609 pragma Convention (C, pthread_mutex_t);
610 for pthread_mutex_t'Alignment use Interfaces.C.unsigned_long'Alignment;
611
612 type pthread_cond_t is record
613 Data : char_array (1 .. OS_Constants.PTHREAD_COND_SIZE);
614 end record;
615 pragma Convention (C, pthread_cond_t);
616 for pthread_cond_t'Alignment use unsigned_long_long_t'Alignment;
617
618 type pthread_key_t is new unsigned;
619
620 end System.OS_Interface;