Debian Codegraph @

gcc/ada/libgnarl/s-osinte__aix.ads

raw
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) 1991-2017, Florida State University --
10 -- Copyright (C) 1995-2025, Free Software Foundation, Inc. --
11 -- --
12 -- GNAT 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 3, or (at your option) any later ver- --
15 -- sion. GNAT 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. --
18 -- --
19 -- As a special exception under Section 7 of GPL version 3, you are granted --
20 -- additional permissions described in the GCC Runtime Library Exception, --
21 -- version 3.1, as published by the Free Software Foundation. --
22 -- --
23 -- You should have received a copy of the GNU General Public License and --
24 -- a copy of the GCC Runtime Library Exception along with this program; --
25 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
26 -- <http://www.gnu.org/licenses/>. --
27 -- --
28 -- GNARL was developed by the GNARL team at Florida State University. --
29 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
30 -- --
31 ------------------------------------------------------------------------------
32
33 -- This is a AIX (Native THREADS) version of this package
34
35 -- This package encapsulates all direct interfaces to OS services that are
36 -- needed by the tasking run-time (libgnarl).
37
38 -- PLEASE DO NOT add any with-clauses to this package or remove the pragma
39 -- Preelaborate. This package is designed to be a bottom-level (leaf) package.
40
41 with Ada.Unchecked_Conversion;
42
43 with Interfaces.C;
44 with Interfaces.C.Extensions;
45
46 with System.OS_Locks;
47 with System.Parameters;
48
49 package System.OS_Interface is
50 pragma Preelaborate;
51
52 pragma Linker_Options ("-pthread");
53 -- This implies -lpthreads + other things depending on the GCC
54 -- configuration, such as the selection of a proper libgcc variant
55 -- for table-based exception handling when it is available.
56
57 pragma Linker_Options ("-lc_r");
58
59 subtype int is Interfaces.C.int;
60 subtype short is Interfaces.C.short;
61 subtype long is Interfaces.C.long;
62 subtype long_long is Interfaces.C.Extensions.long_long;
63 subtype unsigned is Interfaces.C.unsigned;
64 subtype unsigned_short is Interfaces.C.unsigned_short;
65 subtype unsigned_long is Interfaces.C.unsigned_long;
66 subtype unsigned_char is Interfaces.C.unsigned_char;
67 subtype plain_char is Interfaces.C.plain_char;
68 subtype size_t is Interfaces.C.size_t;
69
70 -----------
71 -- Errno --
72 -----------
73
74 function errno return int;
75 pragma Import (C, errno, "__get_errno");
76
77 EAGAIN : constant := 11;
78 EINTR : constant := 4;
79 EINVAL : constant := 22;
80 ENOMEM : constant := 12;
81 ETIMEDOUT : constant := 78;
82
83 -------------
84 -- Signals --
85 -------------
86
87 Max_Interrupt : constant := 63;
88 type Signal is new int range 0 .. Max_Interrupt;
89 for Signal'Size use int'Size;
90
91 SIGHUP : constant := 1; -- hangup
92 SIGINT : constant := 2; -- interrupt (rubout)
93 SIGQUIT : constant := 3; -- quit (ASCD FS)
94 SIGILL : constant := 4; -- illegal instruction (not reset)
95 SIGTRAP : constant := 5; -- trace trap (not reset)
96 SIGIOT : constant := 6; -- IOT instruction
97 SIGABRT : constant := 6; -- used by abort, replace SIGIOT in the future
98 SIGEMT : constant := 7; -- EMT instruction
99 SIGFPE : constant := 8; -- floating point exception
100 SIGKILL : constant := 9; -- kill (cannot be caught or ignored)
101 SIGBUS : constant := 10; -- bus error
102 SIGSEGV : constant := 11; -- segmentation violation
103 SIGSYS : constant := 12; -- bad argument to system call
104 SIGPIPE : constant := 13; -- write on a pipe with no one to read it
105 SIGALRM : constant := 14; -- alarm clock
106 SIGTERM : constant := 15; -- software termination signal from kill
107 SIGUSR1 : constant := 30; -- user defined signal 1
108 SIGUSR2 : constant := 31; -- user defined signal 2
109 SIGCLD : constant := 20; -- alias for SIGCHLD
110 SIGCHLD : constant := 20; -- child status change
111 SIGPWR : constant := 29; -- power-fail restart
112 SIGWINCH : constant := 28; -- window size change
113 SIGURG : constant := 16; -- urgent condition on IO channel
114 SIGPOLL : constant := 23; -- pollable event occurred
115 SIGIO : constant := 23; -- I/O possible (Solaris SIGPOLL alias)
116 SIGSTOP : constant := 17; -- stop (cannot be caught or ignored)
117 SIGTSTP : constant := 18; -- user stop requested from tty
118 SIGCONT : constant := 19; -- stopped process has been continued
119 SIGTTIN : constant := 21; -- background tty read attempted
120 SIGTTOU : constant := 22; -- background tty write attempted
121 SIGVTALRM : constant := 34; -- virtual timer expired
122 SIGPROF : constant := 32; -- profiling timer expired
123 SIGXCPU : constant := 24; -- CPU time limit exceeded
124 SIGXFSZ : constant := 25; -- filesize limit exceeded
125 SIGWAITING : constant := 39; -- m:n scheduling
126
127 -- The following signals are AIX specific
128
129 SIGMSG : constant := 27; -- input data is in the ring buffer
130 SIGDANGER : constant := 33; -- system crash imminent
131 SIGMIGRATE : constant := 35; -- migrate process
132 SIGPRE : constant := 36; -- programming exception
133 SIGVIRT : constant := 37; -- AIX virtual time alarm
134 SIGALRM1 : constant := 38; -- m:n condition variables
135 SIGCPUFAIL : constant := 59; -- Predictive De-configuration of Processors
136 SIGKAP : constant := 60; -- keep alive poll from native keyboard
137 SIGGRANT : constant := SIGKAP; -- monitor mode granted
138 SIGRETRACT : constant := 61; -- monitor mode should be relinquished
139 SIGSOUND : constant := 62; -- sound control has completed
140 SIGSAK : constant := 63; -- secure attention key
141
142 SIGADAABORT : constant := SIGEMT;
143 -- Note: on other targets, we usually use SIGABRT, but on AIX, it appears
144 -- that SIGABRT can't be used in sigwait(), so we use SIGEMT.
145 -- SIGEMT is "Emulator Trap Instruction" from the PDP-11, and does not
146 -- have a standardized usage.
147
148 type Signal_Set is array (Natural range <>) of Signal;
149
150 Unmasked : constant Signal_Set :=
151 (SIGTRAP, SIGTTIN, SIGTTOU, SIGTSTP, SIGPROF);
152 Reserved : constant Signal_Set :=
153 (SIGABRT, SIGKILL, SIGSTOP, SIGALRM1, SIGWAITING, SIGCPUFAIL);
154
155 type sigset_t is private;
156
157 function sigaddset (set : access sigset_t; sig : Signal) return int;
158 pragma Import (C, sigaddset, "sigaddset");
159
160 function sigdelset (set : access sigset_t; sig : Signal) return int;
161 pragma Import (C, sigdelset, "sigdelset");
162
163 function sigfillset (set : access sigset_t) return int;
164 pragma Import (C, sigfillset, "sigfillset");
165
166 function sigismember (set : access sigset_t; sig : Signal) return int;
167 pragma Import (C, sigismember, "sigismember");
168
169 function sigemptyset (set : access sigset_t) return int;
170 pragma Import (C, sigemptyset, "sigemptyset");
171
172 type struct_sigaction is record
173 sa_handler : System.Address;
174 sa_mask : sigset_t;
175 sa_flags : int;
176 end record;
177 pragma Convention (C, struct_sigaction);
178 type struct_sigaction_ptr is access all struct_sigaction;
179
180 SA_SIGINFO : constant := 16#0100#;
181 SA_ONSTACK : constant := 16#0001#;
182
183 SIG_BLOCK : constant := 0;
184 SIG_UNBLOCK : constant := 1;
185 SIG_SETMASK : constant := 2;
186
187 SIG_DFL : constant := 0;
188 SIG_IGN : constant := 1;
189
190 function sigaction
191 (sig : Signal;
192 act : struct_sigaction_ptr;
193 oact : struct_sigaction_ptr) return int;
194 pragma Import (C, sigaction, "sigaction");
195
196 ----------
197 -- Time --
198 ----------
199
200 Time_Slice_Supported : constant Boolean := True;
201 -- Indicates whether time slicing is supported
202
203 type timespec is private;
204
205 type clockid_t is new long_long;
206
207 function clock_gettime
208 (clock_id : clockid_t;
209 tp : access timespec) return int;
210 pragma Import (C, clock_gettime, "clock_gettime");
211
212 function clock_getres
213 (clock_id : clockid_t;
214 res : access timespec) return int;
215 pragma Import (C, clock_getres, "clock_getres");
216
217 function To_Duration (TS : timespec) return Duration;
218 pragma Inline (To_Duration);
219
220 function To_Timespec (D : Duration) return timespec;
221 pragma Inline (To_Timespec);
222
223 type struct_timezone is record
224 tz_minuteswest : int;
225 tz_dsttime : int;
226 end record;
227 pragma Convention (C, struct_timezone);
228 type struct_timezone_ptr is access all struct_timezone;
229
230 -------------------------
231 -- Priority Scheduling --
232 -------------------------
233
234 SCHED_FIFO : constant := 1;
235 SCHED_RR : constant := 2;
236 SCHED_OTHER : constant := 0;
237
238 function To_Target_Priority
239 (Prio : System.Any_Priority) return Interfaces.C.int;
240 -- Maps System.Any_Priority to a POSIX priority
241
242 -------------
243 -- Process --
244 -------------
245
246 type pid_t is private;
247
248 function kill (pid : pid_t; sig : Signal) return int;
249 pragma Import (C, kill, "kill");
250
251 function getpid return pid_t;
252 pragma Import (C, getpid, "getpid");
253
254 ---------
255 -- LWP --
256 ---------
257
258 function lwp_self return System.Address;
259 pragma Import (C, lwp_self, "thread_self");
260
261 -------------
262 -- Threads --
263 -------------
264
265 type Thread_Body is access
266 function (arg : System.Address) return System.Address;
267 pragma Convention (C, Thread_Body);
268
269 function Thread_Body_Access is new
270 Ada.Unchecked_Conversion (System.Address, Thread_Body);
271
272 type pthread_t is private;
273 subtype Thread_Id is pthread_t;
274
275 subtype pthread_mutex_t is System.OS_Locks.pthread_mutex_t;
276 type pthread_cond_t is limited private;
277 type pthread_attr_t is limited private;
278 type pthread_mutexattr_t is limited private;
279 type pthread_condattr_t is limited private;
280 type pthread_key_t is private;
281
282 PTHREAD_CREATE_DETACHED : constant := 1;
283
284 PTHREAD_SCOPE_PROCESS : constant := 1;
285 PTHREAD_SCOPE_SYSTEM : constant := 0;
286
287 -- Read/Write lock not supported on AIX. To add support both types
288 -- pthread_rwlock_t and pthread_rwlockattr_t must properly be defined
289 -- with the associated routines pthread_rwlock_[init/destroy] and
290 -- pthread_rwlock_[rdlock/wrlock/unlock].
291
292 subtype pthread_rwlock_t is pthread_mutex_t;
293 subtype pthread_rwlockattr_t is pthread_mutexattr_t;
294
295 -----------
296 -- Stack --
297 -----------
298
299 type stack_t is record
300 ss_sp : System.Address;
301 ss_size : size_t;
302 ss_flags : int;
303 end record;
304 pragma Convention (C, stack_t);
305
306 function sigaltstack
307 (ss : not null access stack_t;
308 oss : access stack_t) return int;
309 pragma Import (C, sigaltstack, "sigaltstack");
310
311 Alternate_Stack : aliased System.Address;
312 -- This is a dummy definition, never used (Alternate_Stack_Size is null)
313
314 Alternate_Stack_Size : constant := 0;
315 -- No alternate signal stack is used on this platform
316
317 Stack_Base_Available : constant Boolean := False;
318 -- Indicates whether the stack base is available on this target
319
320 function Get_Stack_Base (thread : pthread_t) return Address;
321 pragma Inline (Get_Stack_Base);
322 -- Returns the stack base of the specified thread. Only call this function
323 -- when Stack_Base_Available is True.
324
325 function Get_Page_Size return int;
326 pragma Import (C, Get_Page_Size, "getpagesize");
327 -- Returns the size of a page
328
329 PROT_NONE : constant := 0;
330 PROT_READ : constant := 1;
331 PROT_WRITE : constant := 2;
332 PROT_EXEC : constant := 4;
333 PROT_ALL : constant := PROT_READ + PROT_WRITE + PROT_EXEC;
334 PROT_ON : constant := PROT_READ;
335 PROT_OFF : constant := PROT_ALL;
336
337 function mprotect (addr : Address; len : size_t; prot : int) return int;
338 pragma Import (C, mprotect);
339
340 ---------------------------------------
341 -- Nonstandard Thread Initialization --
342 ---------------------------------------
343
344 -- Though not documented, pthread_init *must* be called before any other
345 -- pthread call.
346
347 procedure pthread_init;
348 pragma Import (C, pthread_init, "pthread_init");
349
350 -------------------------
351 -- POSIX.1c Section 3 --
352 -------------------------
353
354 function sigwait
355 (set : access sigset_t;
356 sig : access Signal) return int;
357 pragma Import (C, sigwait, "sigwait");
358
359 function pthread_kill
360 (thread : pthread_t;
361 sig : Signal) return int;
362 pragma Import (C, pthread_kill, "pthread_kill");
363
364 function pthread_sigmask
365 (how : int;
366 set : access sigset_t;
367 oset : access sigset_t) return int;
368 pragma Import (C, pthread_sigmask, "sigthreadmask");
369
370 --------------------------
371 -- POSIX.1c Section 11 --
372 --------------------------
373
374 function pthread_mutexattr_init
375 (attr : access pthread_mutexattr_t) return int;
376 pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
377
378 function pthread_mutexattr_destroy
379 (attr : access pthread_mutexattr_t) return int;
380 pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
381
382 function pthread_mutex_init
383 (mutex : access pthread_mutex_t;
384 attr : access pthread_mutexattr_t) return int;
385 pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
386
387 function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
388 pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
389
390 function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
391 pragma Import (C, pthread_mutex_lock, "pthread_mutex_lock");
392
393 function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
394 pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock");
395
396 function pthread_condattr_init
397 (attr : access pthread_condattr_t) return int;
398 pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
399
400 function pthread_condattr_destroy
401 (attr : access pthread_condattr_t) return int;
402 pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
403
404 function pthread_cond_init
405 (cond : access pthread_cond_t;
406 attr : access pthread_condattr_t) return int;
407 pragma Import (C, pthread_cond_init, "pthread_cond_init");
408
409 function pthread_cond_destroy (cond : access pthread_cond_t) return int;
410 pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
411
412 function pthread_cond_signal (cond : access pthread_cond_t) return int;
413 pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
414
415 function pthread_cond_wait
416 (cond : access pthread_cond_t;
417 mutex : access pthread_mutex_t) return int;
418 pragma Import (C, pthread_cond_wait, "pthread_cond_wait");
419
420 function pthread_cond_timedwait
421 (cond : access pthread_cond_t;
422 mutex : access pthread_mutex_t;
423 abstime : access timespec) return int;
424 pragma Import (C, pthread_cond_timedwait, "pthread_cond_timedwait");
425
426 --------------------------
427 -- POSIX.1c Section 13 --
428 --------------------------
429
430 PTHREAD_PRIO_PROTECT : constant := 2;
431
432 function PTHREAD_PRIO_INHERIT return int;
433 -- Return value of C macro PTHREAD_PRIO_INHERIT. This function is needed
434 -- since the value is different between AIX versions.
435
436 function pthread_mutexattr_setprotocol
437 (attr : access pthread_mutexattr_t;
438 protocol : int) return int;
439 pragma Import (C, pthread_mutexattr_setprotocol);
440
441 function pthread_mutexattr_setprioceiling
442 (attr : access pthread_mutexattr_t;
443 prioceiling : int) return int;
444 pragma Import (C, pthread_mutexattr_setprioceiling);
445
446 type Array_5_Int is array (0 .. 5) of int;
447 type struct_sched_param is record
448 sched_priority : int;
449 sched_policy : int;
450 sched_reserved : Array_5_Int;
451 end record;
452
453 function pthread_setschedparam
454 (thread : pthread_t;
455 policy : int;
456 param : access struct_sched_param) return int;
457 pragma Import (C, pthread_setschedparam, "pthread_setschedparam");
458
459 function pthread_attr_setscope
460 (attr : access pthread_attr_t;
461 contentionscope : int) return int;
462 pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope");
463
464 function pthread_attr_setinheritsched
465 (attr : access pthread_attr_t;
466 inheritsched : int) return int;
467 pragma Import (C, pthread_attr_setinheritsched);
468
469 function pthread_attr_setschedpolicy
470 (attr : access pthread_attr_t;
471 policy : int) return int;
472 pragma Import (C, pthread_attr_setschedpolicy);
473
474 function pthread_attr_setschedparam
475 (attr : access pthread_attr_t;
476 sched_param : int) return int;
477 pragma Import (C, pthread_attr_setschedparam);
478
479 function sched_yield return int;
480 -- AIX have a nonstandard sched_yield
481
482 --------------------------
483 -- P1003.1c Section 16 --
484 --------------------------
485
486 function pthread_attr_init (attributes : access pthread_attr_t) return int;
487 pragma Import (C, pthread_attr_init, "pthread_attr_init");
488
489 function pthread_attr_destroy
490 (attributes : access pthread_attr_t) return int;
491 pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
492
493 function pthread_attr_setdetachstate
494 (attr : access pthread_attr_t;
495 detachstate : int) return int;
496 pragma Import (C, pthread_attr_setdetachstate);
497
498 function pthread_attr_setstacksize
499 (attr : access pthread_attr_t;
500 stacksize : size_t) return int;
501 pragma Import (C, pthread_attr_setstacksize);
502
503 function pthread_create
504 (thread : access pthread_t;
505 attributes : access pthread_attr_t;
506 start_routine : Thread_Body;
507 arg : System.Address)
508 return int;
509 pragma Import (C, pthread_create, "pthread_create");
510
511 procedure pthread_exit (status : System.Address);
512 pragma Import (C, pthread_exit, "pthread_exit");
513
514 function pthread_self return pthread_t;
515 pragma Import (C, pthread_self, "pthread_self");
516
517 --------------------------
518 -- POSIX.1c Section 17 --
519 --------------------------
520
521 function pthread_setspecific
522 (key : pthread_key_t;
523 value : System.Address) return int;
524 pragma Import (C, pthread_setspecific, "pthread_setspecific");
525
526 function pthread_getspecific (key : pthread_key_t) return System.Address;
527 pragma Import (C, pthread_getspecific, "pthread_getspecific");
528
529 type destructor_pointer is access procedure (arg : System.Address);
530 pragma Convention (C, destructor_pointer);
531
532 function pthread_key_create
533 (key : access pthread_key_t;
534 destructor : destructor_pointer) return int;
535 pragma Import (C, pthread_key_create, "pthread_key_create");
536
537 private
538 type sigset_t is record
539 losigs : unsigned_long;
540 hisigs : unsigned_long;
541 end record;
542 pragma Convention (C_Pass_By_Copy, sigset_t);
543
544 type pid_t is new int;
545
546 type time_t is range -2 ** (System.Parameters.time_t_bits - 1)
547 .. 2 ** (System.Parameters.time_t_bits - 1) - 1;
548
549 type timespec is record
550 tv_sec : time_t;
551 tv_nsec : long;
552 end record;
553 pragma Convention (C, timespec);
554
555 type pthread_attr_t is new System.Address;
556 pragma Convention (C, pthread_attr_t);
557 -- typedef struct __pt_attr *pthread_attr_t;
558
559 type pthread_condattr_t is new System.Address;
560 pragma Convention (C, pthread_condattr_t);
561 -- typedef struct __pt_attr *pthread_condattr_t;
562
563 type pthread_mutexattr_t is new System.Address;
564 pragma Convention (C, pthread_mutexattr_t);
565 -- typedef struct __pt_attr *pthread_mutexattr_t;
566
567 type pthread_t is new System.Address;
568 pragma Convention (C, pthread_t);
569 -- typedef void *pthread_t;
570
571 type ptq_queue;
572 type ptq_queue_ptr is access all ptq_queue;
573
574 type ptq_queue is record
575 ptq_next : ptq_queue_ptr;
576 ptq_prev : ptq_queue_ptr;
577 end record;
578
579 type pthread_mutex_t_ptr is access pthread_mutex_t;
580
581 type pthread_cond_t is record
582 link : ptq_queue;
583 ptcv_lock : int;
584 ptcv_flags : long;
585 ptcv_waiters : ptq_queue;
586 cv_id : int;
587 attr : pthread_attr_t;
588 mutex : pthread_mutex_t_ptr;
589 cptwait : int;
590 reserved : int;
591 end record;
592 pragma Convention (C, pthread_cond_t);
593
594 type pthread_key_t is new unsigned;
595
596 end System.OS_Interface;