Debian Codegraph @

gcc/ada/libgnarl/s-osinte__lynxos178e.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-1994, 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 LynxOS-178 Elf (POSIX-8 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
45 with System.Multiprocessors;
46 with System.OS_Locks;
47 with System.Parameters;
48
49 package System.OS_Interface is
50 pragma Preelaborate;
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 subtype int64 is Interfaces.Integer_64;
62
63 -----------
64 -- Errno --
65 -----------
66
67 function errno return int;
68 pragma Import (C, errno, "__get_errno");
69
70 EAGAIN : constant := 11;
71 EINTR : constant := 4;
72 EINVAL : constant := 22;
73 ENOMEM : constant := 12;
74 ETIMEDOUT : constant := 60;
75 -- Error codes
76
77 -------------
78 -- Signals --
79 -------------
80
81 Max_Interrupt : constant := 63;
82 -- Max_Interrupt is the number of OS signals, as defined in:
83 --
84 -- /usr/include/sys/signal.h
85 --
86 -- The lowest numbered signal is 1, but 0 is a valid argument to some
87 -- library functions, e.g. kill(2). However, 0 is not just another signal:
88 -- For instance 'I in Signal' and similar should be used with caution.
89
90 type Signal is new int range 0 .. Max_Interrupt;
91 for Signal'Size use int'Size;
92
93 SIGHUP : constant := 1; -- hangup
94 SIGINT : constant := 2; -- interrupt (rubout)
95 SIGQUIT : constant := 3; -- quit (ASCD FS)
96 SIGILL : constant := 4; -- illegal instruction (not reset)
97 SIGTRAP : constant := 5; -- trace trap (not reset)
98 SIGBRK : constant := 6; -- break
99 SIGIOT : constant := 6; -- IOT instruction
100 SIGABRT : constant := 6; -- used by abort, replace SIGIOT in future
101 SIGCORE : constant := 7; -- kill with core dump
102 SIGEMT : constant := 7; -- EMT instruction
103 SIGFPE : constant := 8; -- floating point exception
104 SIGKILL : constant := 9; -- kill (cannot be caught or ignored)
105 SIGBUS : constant := 10; -- bus error
106 SIGSEGV : constant := 11; -- segmentation violation
107 SIGSYS : constant := 12; -- bad argument to system call
108 SIGPIPE : constant := 13; -- write on a pipe with no one to read it
109 SIGALRM : constant := 14; -- alarm clock
110 SIGTERM : constant := 15; -- software termination signal from kill
111 SIGURG : constant := 16; -- urgent condition on IO channel
112 SIGSTOP : constant := 17; -- stop (cannot be caught or ignored)
113 SIGTSTP : constant := 18; -- user stop requested from tty
114 SIGCONT : constant := 19; -- stopped process has been continued
115 SIGCLD : constant := 20; -- alias for SIGCHLD
116 SIGCHLD : constant := 20; -- child status change
117 SIGTTIN : constant := 21; -- background tty read attempted
118 SIGTTOU : constant := 22; -- background tty write attempted
119 SIGIO : constant := 23; -- I/O possible (Solaris SIGPOLL alias)
120 SIGPOLL : constant := 23; -- pollable event occurred
121 SIGTHREADKILL : constant := 24; -- Reserved by LynxOS runtime
122 SIGXCPU : constant := 24; -- CPU time limit exceeded
123 SIGXFSZ : constant := 25; -- filesize limit exceeded
124 SIGVTALRM : constant := 26; -- virtual timer expired
125 SIGPROF : constant := 27; -- profiling timer expired
126 SIGWINCH : constant := 28; -- window size change
127 SIGLOST : constant := 29; -- SUN 4.1 compatibility
128 SIGUSR1 : constant := 30; -- user defined signal 1
129 SIGUSR2 : constant := 31; -- user defined signal 2
130
131 SIGPRIO : constant := 32;
132 -- Sent to a process with its priority or group is changed
133
134 SIGADAABORT : constant := SIGABRT;
135 -- Change this if you want to use another signal for task abort. SIGTERM
136 -- might be a good one.
137
138 type Signal_Set is array (Natural range <>) of Signal;
139
140 Unmasked : constant Signal_Set :=
141 (SIGTRAP, SIGTTIN, SIGTTOU, SIGTSTP, SIGPROF, SIGTHREADKILL);
142 Reserved : constant Signal_Set := (SIGABRT, SIGKILL, SIGSTOP, SIGPRIO);
143
144 type sigset_t is private;
145
146 function sigaddset (set : access sigset_t; sig : Signal) return int;
147 pragma Import (C, sigaddset, "sigaddset");
148
149 function sigdelset (set : access sigset_t; sig : Signal) return int;
150 pragma Import (C, sigdelset, "sigdelset");
151
152 function sigfillset (set : access sigset_t) return int;
153 pragma Import (C, sigfillset, "sigfillset");
154
155 function sigismember (set : access sigset_t; sig : Signal) return int;
156 pragma Import (C, sigismember, "sigismember");
157
158 function sigemptyset (set : access sigset_t) return int;
159 pragma Import (C, sigemptyset, "sigemptyset");
160
161 type struct_sigaction is record
162 sa_handler : System.Address;
163 sa_mask : sigset_t;
164 sa_flags : int;
165 end record;
166 pragma Convention (C, struct_sigaction);
167 type struct_sigaction_ptr is access all struct_sigaction;
168
169 SA_SIGINFO : constant := 16#80#;
170
171 SA_ONSTACK : constant := 16#00#;
172 -- SA_ONSTACK is not defined on LynxOS, but it is referred to in the POSIX
173 -- implementation of System.Interrupt_Management. Therefore we define a
174 -- dummy value of zero here so that setting this flag is a nop.
175
176 SIG_BLOCK : constant := 0;
177 SIG_UNBLOCK : constant := 1;
178 SIG_SETMASK : constant := 2;
179
180 SIG_DFL : constant := 0;
181 SIG_IGN : constant := 1;
182
183 function sigaction
184 (sig : Signal;
185 act : struct_sigaction_ptr;
186 oact : struct_sigaction_ptr) return int;
187 pragma Import (C, sigaction, "sigaction");
188
189 ----------
190 -- Time --
191 ----------
192
193 Time_Slice_Supported : constant Boolean := True;
194 -- Indicates whether time slicing is supported
195
196 type timespec is private;
197
198 type clockid_t is new int;
199
200 function clock_gettime
201 (clock_id : clockid_t;
202 tp : access timespec) return int;
203 pragma Import (C, clock_gettime, "clock_gettime");
204
205 function clock_getres
206 (clock_id : clockid_t;
207 res : access timespec) return int;
208 pragma Import (C, clock_getres, "clock_getres");
209
210 function To_Duration (TS : timespec) return Duration;
211 pragma Inline (To_Duration);
212
213 function To_Timespec (D : Duration) return timespec;
214 pragma Inline (To_Timespec);
215
216 type struct_timezone is record
217 tz_minuteswest : int;
218 tz_dsttime : int;
219 end record;
220 pragma Convention (C, struct_timezone);
221 type struct_timezone_ptr is access all struct_timezone;
222
223 type struct_timeval is private;
224
225 -------------------------
226 -- Priority Scheduling --
227 -------------------------
228
229 SCHED_RR : constant := 16#100_000#;
230 SCHED_FIFO : constant := 16#200_000#;
231 SCHED_OTHER : constant := 16#400_000#;
232
233 function To_Target_Priority
234 (Prio : System.Any_Priority) return Interfaces.C.int;
235 -- Maps System.Any_Priority to a POSIX priority
236
237 -------------
238 -- Process --
239 -------------
240
241 type pid_t is private;
242
243 function kill (pid : pid_t; sig : Signal) return int;
244 pragma Import (C, kill, "kill");
245
246 function getpid return pid_t;
247 pragma Import (C, getpid, "getpid");
248
249 ---------
250 -- LWP --
251 ---------
252
253 type pthread_t is private;
254
255 function lwp_self return pthread_t;
256 pragma Import (C, lwp_self, "pthread_self");
257
258 -------------
259 -- Threads --
260 -------------
261
262 type Thread_Body is access
263 function (arg : System.Address) return System.Address;
264 pragma Convention (C, Thread_Body);
265
266 function Thread_Body_Access is new
267 Ada.Unchecked_Conversion (System.Address, Thread_Body);
268
269 subtype Thread_Id is pthread_t;
270
271 subtype pthread_mutex_t is System.OS_Locks.pthread_mutex_t;
272 type pthread_cond_t is limited private;
273 type pthread_attr_t is limited private;
274 type pthread_mutexattr_t is limited private;
275 type pthread_condattr_t is limited private;
276 type pthread_key_t is private;
277
278 PTHREAD_CREATE_DETACHED : constant := 1;
279 PTHREAD_CREATE_JOINABLE : constant := 0;
280
281 PTHREAD_SCOPE_PROCESS : constant := 0; -- not supported by LynxOS178
282 PTHREAD_SCOPE_SYSTEM : constant := 1;
283
284 -- Read/Write lock not supported on LynxOS. To add support both types
285 -- pthread_rwlock_t and pthread_rwlockattr_t must properly be defined
286 -- with the associated routines pthread_rwlock_[init/destroy] and
287 -- pthread_rwlock_[rdlock/wrlock/unlock].
288
289 subtype pthread_rwlock_t is pthread_mutex_t;
290 subtype pthread_rwlockattr_t is pthread_mutexattr_t;
291
292 -----------
293 -- Stack --
294 -----------
295
296 type stack_t is record
297 ss_sp : System.Address;
298 ss_flags : int;
299 ss_size : size_t;
300 end record;
301 pragma Convention (C, stack_t);
302
303 function sigaltstack
304 (ss : not null access stack_t;
305 oss : access stack_t) return int;
306 pragma Import (C, sigaltstack, "sigaltstack");
307 -- Neither stack_t nor sigaltstack are available on LynxOS-178
308
309 Alternate_Stack : aliased System.Address;
310 -- This is a dummy definition, never used (Alternate_Stack_Size is 0)
311
312 Alternate_Stack_Size : constant := 0;
313 -- No alternate signal stack is used on this platform
314
315 Stack_Base_Available : constant Boolean := False;
316 -- Indicates whether the stack base is available on this target
317
318 function Get_Stack_Base (thread : pthread_t) return Address;
319 pragma Inline (Get_Stack_Base);
320 -- Returns the stack base of the specified thread. Only call this function
321 -- when Stack_Base_Available is True.
322
323 function Get_Page_Size return int;
324 -- Returns the size of a page in bytes
325
326 PROT_NONE : constant := 1;
327 PROT_READ : constant := 2;
328 PROT_WRITE : constant := 4;
329 PROT_EXEC : constant := 8;
330 PROT_ALL : constant := PROT_READ + PROT_WRITE + PROT_EXEC;
331
332 PROT_ON : constant := PROT_READ;
333 PROT_OFF : constant := PROT_ALL;
334
335 function mprotect (addr : Address; len : size_t; prot : int) return int;
336 pragma Import (C, mprotect);
337
338 ---------------------------------------
339 -- Nonstandard Thread Initialization --
340 ---------------------------------------
341
342 procedure pthread_init;
343 -- This is a dummy procedure to share some GNULLI files
344
345 -------------------------
346 -- POSIX.1c Section 3 --
347 -------------------------
348 function sigwait
349 (set : access sigset_t;
350 sig : access Signal) return int;
351 pragma Inline (sigwait);
352 -- LynxOS has non standard sigwait
353
354 function pthread_kill
355 (thread : pthread_t;
356 sig : Signal) return int;
357 pragma Import (C, pthread_kill, "pthread_kill");
358
359 function pthread_sigmask
360 (how : int;
361 set : access sigset_t;
362 oset : access sigset_t) return int;
363 pragma Import (C, pthread_sigmask, "pthread_sigmask");
364
365 ----------------------------
366 -- POSIX.1c Section 11 --
367 ----------------------------
368
369 function pthread_mutexattr_init
370 (attr : access pthread_mutexattr_t) return int;
371 pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
372
373 function pthread_mutexattr_destroy
374 (attr : access pthread_mutexattr_t) return int;
375 pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
376
377 function pthread_mutex_init
378 (mutex : access pthread_mutex_t;
379 attr : access pthread_mutexattr_t) return int;
380 pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
381
382 function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
383 pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
384
385 function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
386 pragma Import (C, pthread_mutex_lock, "pthread_mutex_lock");
387
388 function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
389 pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock");
390
391 function pthread_condattr_init
392 (attr : access pthread_condattr_t) return int;
393 pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
394
395 function pthread_condattr_destroy
396 (attr : access pthread_condattr_t) return int;
397 pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
398
399 function pthread_cond_init
400 (cond : access pthread_cond_t;
401 attr : access pthread_condattr_t) return int;
402 pragma Import (C, pthread_cond_init, "pthread_cond_init");
403
404 function pthread_cond_destroy (cond : access pthread_cond_t) return int;
405 pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
406
407 function pthread_cond_signal (cond : access pthread_cond_t) return int;
408 pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
409
410 function pthread_cond_wait
411 (cond : access pthread_cond_t;
412 mutex : access pthread_mutex_t) return int;
413 pragma Import (C, pthread_cond_wait, "pthread_cond_wait");
414
415 function pthread_cond_timedwait
416 (cond : access pthread_cond_t;
417 mutex : access pthread_mutex_t;
418 abstime : access timespec) return int;
419 pragma Import (C, pthread_cond_timedwait, "pthread_cond_timedwait");
420
421 --------------------------
422 -- POSIX.1c Section 13 --
423 --------------------------
424
425 PTHREAD_PRIO_NONE : constant := 0;
426 PTHREAD_PRIO_INHERIT : constant := 1;
427 PTHREAD_PRIO_PROTECT : constant := 2;
428
429 function pthread_mutexattr_setprotocol
430 (attr : access pthread_mutexattr_t;
431 protocol : int) return int;
432 pragma Import (C, pthread_mutexattr_setprotocol);
433
434 function pthread_mutexattr_setprioceiling
435 (attr : access pthread_mutexattr_t;
436 prioceiling : int) return int;
437 pragma Import (C, pthread_mutexattr_setprioceiling);
438
439 type struct_sched_param is record
440 sched_priority : int;
441 end record;
442 pragma Convention (C, struct_sched_param);
443
444 function pthread_setschedparam
445 (thread : pthread_t;
446 policy : int;
447 param : access struct_sched_param) return int;
448 pragma Import (C, pthread_setschedparam, "pthread_setschedparam");
449
450 function pthread_attr_setscope
451 (Unused_attr : access pthread_attr_t;
452 Unused_contentionscope : int) return int is (0);
453 -- pthread_attr_setscope is not implemented in production mode
454
455 function pthread_attr_setinheritsched
456 (attr : access pthread_attr_t;
457 inheritsched : int) return int;
458 pragma Import (C, pthread_attr_setinheritsched);
459
460 function pthread_attr_setschedpolicy
461 (attr : access pthread_attr_t;
462 policy : int) return int;
463 pragma Import (C, pthread_attr_setschedpolicy);
464
465 function sched_yield return int;
466 pragma Import (C, sched_yield, "sched_yield");
467
468 --------------------------
469 -- P1003.1c Section 16 --
470 --------------------------
471
472 function pthread_attr_init (attributes : access pthread_attr_t) return int;
473 pragma Import (C, pthread_attr_init, "pthread_attr_init");
474
475 function pthread_attr_destroy
476 (attributes : access pthread_attr_t) return int;
477 pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
478
479 function pthread_attr_setdetachstate
480 (attr : access pthread_attr_t;
481 detachstate : int) return int;
482 pragma Import (C, 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);
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 --------------------------
503 -- POSIX.1c Section 17 --
504 --------------------------
505
506 function pthread_setspecific
507 (key : pthread_key_t;
508 value : System.Address) return int;
509 pragma Import (C, pthread_setspecific, "pthread_setspecific");
510
511 function pthread_getspecific
512 (key : pthread_key_t) return System.Address;
513 pragma Import (C, pthread_getspecific, "pthread_getspecific");
514
515 type destructor_pointer is access procedure (arg : System.Address);
516 pragma Convention (C, destructor_pointer);
517
518 function pthread_key_create
519 (key : access pthread_key_t;
520 destructor : destructor_pointer
521 ) return int;
522 pragma Import (C, pthread_key_create, "pthread_key_create");
523
524 ---------------------
525 -- Multiprocessors --
526 ---------------------
527
528 function Current_CPU return Multiprocessors.CPU;
529 -- Return the id of the current CPU
530
531 function Get_Affinity (Id : Thread_Id) return Multiprocessors.CPU_Range;
532 -- Return CPU affinity of the given thread (maybe Not_A_Specific_CPU)
533
534 function Get_CPU (Id : Thread_Id) return Multiprocessors.CPU;
535 -- Return the CPU in charge of the given thread (always a valid CPU)
536
537 private
538
539 type sigset_t is array (1 .. 2) of long;
540 pragma Convention (C, sigset_t);
541
542 type pid_t is new long;
543
544 type time_t is range -2 ** (System.Parameters.time_t_bits - 1)
545 .. 2 ** (System.Parameters.time_t_bits - 1) - 1;
546
547 type suseconds_t is new int;
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 struct_timeval is record
556 tv_sec : time_t;
557 tv_usec : suseconds_t;
558 end record;
559 pragma Convention (C, struct_timeval);
560
561 type st_attr is record
562 stksize : int;
563 prio : int;
564 inheritsched : int;
565 state : int;
566 sched : int;
567 detachstate : int;
568 guardsize : int;
569 end record;
570 pragma Convention (C, st_attr);
571 subtype st_attr_t is st_attr;
572
573 type pthread_attr_t is record
574 pthread_attr_magic : unsigned;
575 st : st_attr_t;
576 pthread_attr_scope : int;
577 end record;
578 pragma Convention (C, pthread_attr_t);
579
580 type pthread_condattr_t is record
581 cv_magic : unsigned;
582 cv_pshared : unsigned;
583 end record;
584 pragma Convention (C, pthread_condattr_t);
585
586 type pthread_mutexattr_t is record
587 m_flags : unsigned;
588 m_prio_c : int;
589 m_pshared : int;
590 end record;
591 pragma Convention (C, pthread_mutexattr_t);
592
593 type tid_t is new short;
594 type pthread_t is new tid_t;
595
596 type block_obj_t is record
597 b_head : int;
598 end record;
599 pragma Convention (C, block_obj_t);
600
601 type pthread_cond_t is record
602 cv_magic : unsigned;
603 cv_wait : block_obj_t;
604 cv_mutex : pthread_mutex_t_ptr;
605 cv_refcnt : int;
606 end record;
607 pragma Convention (C, pthread_cond_t);
608
609 type pthread_key_t is new int;
610
611 end System.OS_Interface;