111
|
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 --
|
145
|
10 -- Copyright (C) 1995-2019, Free Software Foundation, Inc. --
|
111
|
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
|
145
|
33 -- This is a GNU/Linux version of this package
|
111
|
34
|
|
35 -- This package encapsulates all direct interfaces to OS services
|
|
36 -- that are 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 with Interfaces.C;
|
|
43 with System.Linux;
|
|
44 with System.OS_Constants;
|
|
45
|
|
46 package System.OS_Interface is
|
|
47 pragma Preelaborate;
|
|
48
|
|
49 pragma Linker_Options ("-lrt");
|
|
50 -- Needed for clock_getres with glibc versions prior to 2.17
|
|
51
|
145
|
52 pragma Linker_Options ("-lpthread");
|
|
53
|
111
|
54 subtype int is Interfaces.C.int;
|
|
55 subtype char is Interfaces.C.char;
|
|
56 subtype short is Interfaces.C.short;
|
|
57 subtype long is Interfaces.C.long;
|
|
58 subtype unsigned is Interfaces.C.unsigned;
|
|
59 subtype unsigned_short is Interfaces.C.unsigned_short;
|
|
60 subtype unsigned_long is Interfaces.C.unsigned_long;
|
|
61 subtype unsigned_char is Interfaces.C.unsigned_char;
|
|
62 subtype plain_char is Interfaces.C.plain_char;
|
|
63 subtype size_t is Interfaces.C.size_t;
|
|
64
|
|
65 -----------
|
|
66 -- Errno --
|
|
67 -----------
|
|
68
|
|
69 function errno return int;
|
|
70 pragma Import (C, errno, "__get_errno");
|
|
71
|
|
72 EAGAIN : constant := System.Linux.EAGAIN;
|
|
73 EINTR : constant := System.Linux.EINTR;
|
|
74 EINVAL : constant := System.Linux.EINVAL;
|
|
75 ENOMEM : constant := System.Linux.ENOMEM;
|
|
76 EPERM : constant := System.Linux.EPERM;
|
|
77 ETIMEDOUT : constant := System.Linux.ETIMEDOUT;
|
|
78
|
|
79 -------------
|
|
80 -- Signals --
|
|
81 -------------
|
|
82
|
|
83 Max_Interrupt : constant := 63;
|
|
84 type Signal is new int range 0 .. Max_Interrupt;
|
|
85 for Signal'Size use int'Size;
|
|
86
|
|
87 SIGHUP : constant := System.Linux.SIGHUP;
|
|
88 SIGINT : constant := System.Linux.SIGINT;
|
|
89 SIGQUIT : constant := System.Linux.SIGQUIT;
|
|
90 SIGILL : constant := System.Linux.SIGILL;
|
|
91 SIGTRAP : constant := System.Linux.SIGTRAP;
|
|
92 SIGIOT : constant := System.Linux.SIGIOT;
|
|
93 SIGABRT : constant := System.Linux.SIGABRT;
|
145
|
94 SIGBUS : constant := System.Linux.SIGBUS;
|
111
|
95 SIGFPE : constant := System.Linux.SIGFPE;
|
|
96 SIGKILL : constant := System.Linux.SIGKILL;
|
145
|
97 SIGUSR1 : constant := System.Linux.SIGUSR1;
|
111
|
98 SIGSEGV : constant := System.Linux.SIGSEGV;
|
145
|
99 SIGUSR2 : constant := System.Linux.SIGUSR2;
|
111
|
100 SIGPIPE : constant := System.Linux.SIGPIPE;
|
|
101 SIGALRM : constant := System.Linux.SIGALRM;
|
|
102 SIGTERM : constant := System.Linux.SIGTERM;
|
145
|
103 SIGSTKFLT : constant := System.Linux.SIGSTKFLT;
|
111
|
104 SIGCLD : constant := System.Linux.SIGCLD;
|
|
105 SIGCHLD : constant := System.Linux.SIGCHLD;
|
145
|
106 SIGCONT : constant := System.Linux.SIGCONT;
|
|
107 SIGSTOP : constant := System.Linux.SIGSTOP;
|
|
108 SIGTSTP : constant := System.Linux.SIGTSTP;
|
|
109 SIGTTIN : constant := System.Linux.SIGTTIN;
|
|
110 SIGTTOU : constant := System.Linux.SIGTTOU;
|
|
111 SIGURG : constant := System.Linux.SIGURG;
|
|
112 SIGXCPU : constant := System.Linux.SIGXCPU;
|
|
113 SIGXFSZ : constant := System.Linux.SIGXFSZ;
|
|
114 SIGVTALRM : constant := System.Linux.SIGVTALRM;
|
|
115 SIGPROF : constant := System.Linux.SIGPROF;
|
111
|
116 SIGWINCH : constant := System.Linux.SIGWINCH;
|
|
117 SIGPOLL : constant := System.Linux.SIGPOLL;
|
|
118 SIGIO : constant := System.Linux.SIGIO;
|
|
119 SIGLOST : constant := System.Linux.SIGLOST;
|
145
|
120 SIGPWR : constant := System.Linux.SIGPWR;
|
|
121 SIGSYS : constant := System.Linux.SIGSYS;
|
111
|
122 SIGUNUSED : constant := System.Linux.SIGUNUSED;
|
145
|
123 SIG32 : constant := System.Linux.SIG32;
|
|
124 SIG33 : constant := System.Linux.SIG33;
|
|
125 SIG34 : constant := System.Linux.SIG34;
|
111
|
126
|
|
127 SIGADAABORT : constant := SIGABRT;
|
|
128 -- Change this to use another signal for task abort. SIGTERM might be a
|
|
129 -- good one.
|
|
130
|
|
131 type Signal_Set is array (Natural range <>) of Signal;
|
|
132
|
|
133 Unmasked : constant Signal_Set := (
|
|
134 SIGTRAP,
|
|
135 -- To enable debugging on multithreaded applications, mark SIGTRAP to
|
|
136 -- be kept unmasked.
|
|
137
|
|
138 SIGBUS,
|
|
139
|
|
140 SIGTTIN, SIGTTOU, SIGTSTP,
|
|
141 -- Keep these three signals unmasked so that background processes and IO
|
|
142 -- behaves as normal "C" applications
|
|
143
|
|
144 SIGPROF,
|
|
145 -- To avoid confusing the profiler
|
|
146
|
145
|
147 SIGKILL, SIGSTOP
|
111
|
148 -- These two signals actually can't be masked (POSIX won't allow it)
|
145
|
149 );
|
111
|
150
|
145
|
151 Reserved : constant Signal_Set := (
|
|
152 SIG32, SIG33, SIG34
|
|
153 -- glibc POSIX threads implementation uses two (NPTL) or three
|
|
154 -- (LinuxThreads) real-time signals for its own use (see SIGNAL(7)).
|
|
155 -- These signals are considered reserved and not unmasked as glibc does
|
|
156 -- not permit these signals to be used by the public signal.h API.
|
|
157 -- While LinuxThreads is mostly likely unused now, SIG34 is still
|
|
158 -- reserved as this behavior is consistent with past GNAT releases.
|
|
159 );
|
111
|
160
|
|
161 type sigset_t is private;
|
|
162
|
|
163 function sigaddset (set : access sigset_t; sig : Signal) return int;
|
|
164 pragma Import (C, sigaddset, "sigaddset");
|
|
165
|
|
166 function sigdelset (set : access sigset_t; sig : Signal) return int;
|
|
167 pragma Import (C, sigdelset, "sigdelset");
|
|
168
|
|
169 function sigfillset (set : access sigset_t) return int;
|
|
170 pragma Import (C, sigfillset, "sigfillset");
|
|
171
|
|
172 function sigismember (set : access sigset_t; sig : Signal) return int;
|
|
173 pragma Import (C, sigismember, "sigismember");
|
|
174
|
|
175 function sigemptyset (set : access sigset_t) return int;
|
|
176 pragma Import (C, sigemptyset, "sigemptyset");
|
|
177
|
|
178 type union_type_3 is new String (1 .. 116);
|
|
179 type siginfo_t is record
|
|
180 si_signo : int;
|
|
181 si_code : int;
|
|
182 si_errno : int;
|
|
183 X_data : union_type_3;
|
|
184 end record;
|
|
185 pragma Convention (C, siginfo_t);
|
|
186
|
|
187 type struct_sigaction is record
|
|
188 sa_handler : System.Address;
|
|
189 sa_mask : sigset_t;
|
|
190 sa_flags : int;
|
|
191 sa_restorer : System.Address;
|
|
192 end record;
|
|
193 pragma Convention (C, struct_sigaction);
|
|
194
|
|
195 type struct_sigaction_ptr is access all struct_sigaction;
|
|
196
|
|
197 type Machine_State is record
|
|
198 eip : unsigned_long;
|
|
199 ebx : unsigned_long;
|
|
200 esp : unsigned_long;
|
|
201 ebp : unsigned_long;
|
|
202 esi : unsigned_long;
|
|
203 edi : unsigned_long;
|
|
204 end record;
|
|
205 type Machine_State_Ptr is access all Machine_State;
|
|
206
|
|
207 SA_SIGINFO : constant := System.Linux.SA_SIGINFO;
|
|
208 SA_ONSTACK : constant := System.Linux.SA_ONSTACK;
|
|
209
|
|
210 SIG_BLOCK : constant := 0;
|
|
211 SIG_UNBLOCK : constant := 1;
|
|
212 SIG_SETMASK : constant := 2;
|
|
213
|
|
214 SIG_DFL : constant := 0;
|
|
215 SIG_IGN : constant := 1;
|
|
216
|
|
217 function sigaction
|
|
218 (sig : Signal;
|
|
219 act : struct_sigaction_ptr;
|
|
220 oact : struct_sigaction_ptr) return int;
|
|
221 pragma Import (C, sigaction, "sigaction");
|
|
222
|
|
223 ----------
|
|
224 -- Time --
|
|
225 ----------
|
|
226
|
|
227 subtype time_t is System.Linux.time_t;
|
|
228 subtype timespec is System.Linux.timespec;
|
|
229 subtype timeval is System.Linux.timeval;
|
|
230 subtype clockid_t is System.Linux.clockid_t;
|
|
231
|
|
232 function clock_gettime
|
|
233 (clock_id : clockid_t; tp : access timespec) return int;
|
|
234 pragma Import (C, clock_gettime, "clock_gettime");
|
|
235
|
|
236 function clock_getres
|
|
237 (clock_id : clockid_t;
|
|
238 res : access timespec) return int;
|
|
239 pragma Import (C, clock_getres, "clock_getres");
|
|
240
|
|
241 function To_Duration (TS : timespec) return Duration;
|
|
242 pragma Inline (To_Duration);
|
|
243
|
|
244 function To_Timespec (D : Duration) return timespec;
|
|
245 pragma Inline (To_Timespec);
|
|
246
|
|
247 function sysconf (name : int) return long;
|
|
248 pragma Import (C, sysconf);
|
|
249
|
|
250 SC_CLK_TCK : constant := 2;
|
|
251 SC_NPROCESSORS_ONLN : constant := 84;
|
|
252
|
|
253 -------------------------
|
|
254 -- Priority Scheduling --
|
|
255 -------------------------
|
|
256
|
|
257 SCHED_OTHER : constant := 0;
|
|
258 SCHED_FIFO : constant := 1;
|
|
259 SCHED_RR : constant := 2;
|
|
260
|
|
261 function To_Target_Priority
|
|
262 (Prio : System.Any_Priority) return Interfaces.C.int;
|
|
263 -- Maps System.Any_Priority to a POSIX priority
|
|
264
|
|
265 -------------
|
|
266 -- Process --
|
|
267 -------------
|
|
268
|
|
269 type pid_t is private;
|
|
270
|
|
271 function kill (pid : pid_t; sig : Signal) return int;
|
|
272 pragma Import (C, kill, "kill");
|
|
273
|
|
274 function getpid return pid_t;
|
|
275 pragma Import (C, getpid, "getpid");
|
|
276
|
|
277 PR_SET_NAME : constant := 15;
|
|
278 PR_GET_NAME : constant := 16;
|
|
279
|
|
280 function prctl
|
|
281 (option : int;
|
|
282 arg2, arg3, arg4, arg5 : unsigned_long := 0) return int;
|
|
283 pragma Import (C, prctl);
|
|
284
|
|
285 -------------
|
|
286 -- Threads --
|
|
287 -------------
|
|
288
|
|
289 type Thread_Body is access
|
|
290 function (arg : System.Address) return System.Address;
|
|
291 pragma Convention (C, Thread_Body);
|
|
292
|
|
293 function Thread_Body_Access is new
|
|
294 Ada.Unchecked_Conversion (System.Address, Thread_Body);
|
|
295
|
|
296 type pthread_t is new unsigned_long;
|
|
297 subtype Thread_Id is pthread_t;
|
|
298
|
|
299 function To_pthread_t is
|
|
300 new Ada.Unchecked_Conversion (unsigned_long, pthread_t);
|
|
301
|
|
302 type pthread_mutex_t is limited private;
|
|
303 type pthread_rwlock_t is limited private;
|
|
304 type pthread_cond_t is limited private;
|
|
305 type pthread_attr_t is limited private;
|
|
306 type pthread_mutexattr_t is limited private;
|
|
307 type pthread_rwlockattr_t is limited private;
|
|
308 type pthread_condattr_t is limited private;
|
|
309 type pthread_key_t is private;
|
|
310
|
|
311 PTHREAD_CREATE_DETACHED : constant := 1;
|
|
312
|
|
313 -----------
|
|
314 -- Stack --
|
|
315 -----------
|
|
316
|
|
317 type stack_t is record
|
|
318 ss_sp : System.Address;
|
|
319 ss_flags : int;
|
|
320 ss_size : size_t;
|
|
321 end record;
|
|
322 pragma Convention (C, stack_t);
|
|
323
|
|
324 function sigaltstack
|
|
325 (ss : not null access stack_t;
|
|
326 oss : access stack_t) return int;
|
|
327 pragma Import (C, sigaltstack, "sigaltstack");
|
|
328
|
|
329 Alternate_Stack : aliased System.Address;
|
|
330 pragma Import (C, Alternate_Stack, "__gnat_alternate_stack");
|
|
331 -- The alternate signal stack for stack overflows
|
|
332
|
|
333 Alternate_Stack_Size : constant := 16 * 1024;
|
|
334 -- This must be in keeping with init.c:__gnat_alternate_stack
|
|
335
|
|
336 function Get_Stack_Base (thread : pthread_t) return Address;
|
|
337 pragma Inline (Get_Stack_Base);
|
|
338 -- This is a dummy procedure to share some GNULLI files
|
|
339
|
|
340 ---------------------------------------
|
|
341 -- Nonstandard Thread Initialization --
|
|
342 ---------------------------------------
|
|
343
|
|
344 procedure pthread_init;
|
|
345 pragma Inline (pthread_init);
|
|
346 -- This is a dummy procedure to share some GNULLI files
|
|
347
|
|
348 -------------------------
|
|
349 -- POSIX.1c Section 3 --
|
|
350 -------------------------
|
|
351
|
|
352 function sigwait (set : access sigset_t; sig : access Signal) return int;
|
|
353 pragma Import (C, sigwait, "sigwait");
|
|
354
|
|
355 function pthread_kill (thread : pthread_t; sig : Signal) return int;
|
|
356 pragma Import (C, pthread_kill, "pthread_kill");
|
|
357
|
|
358 function pthread_sigmask
|
|
359 (how : int;
|
|
360 set : access sigset_t;
|
|
361 oset : access sigset_t) return int;
|
|
362 pragma Import (C, pthread_sigmask, "pthread_sigmask");
|
|
363
|
|
364 --------------------------
|
|
365 -- POSIX.1c Section 11 --
|
|
366 --------------------------
|
|
367
|
|
368 function pthread_mutexattr_init
|
|
369 (attr : access pthread_mutexattr_t) return int;
|
|
370 pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
|
|
371
|
|
372 function pthread_mutexattr_destroy
|
|
373 (attr : access pthread_mutexattr_t) return int;
|
|
374 pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
|
|
375
|
|
376 function pthread_mutex_init
|
|
377 (mutex : access pthread_mutex_t;
|
|
378 attr : access pthread_mutexattr_t) return int;
|
|
379 pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
|
|
380
|
|
381 function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
|
|
382 pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
|
|
383
|
|
384 function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
|
|
385 pragma Import (C, pthread_mutex_lock, "pthread_mutex_lock");
|
|
386
|
|
387 function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
|
|
388 pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock");
|
|
389
|
|
390 function pthread_rwlockattr_init
|
|
391 (attr : access pthread_rwlockattr_t) return int;
|
|
392 pragma Import (C, pthread_rwlockattr_init, "pthread_rwlockattr_init");
|
|
393
|
|
394 function pthread_rwlockattr_destroy
|
|
395 (attr : access pthread_rwlockattr_t) return int;
|
|
396 pragma Import (C, pthread_rwlockattr_destroy, "pthread_rwlockattr_destroy");
|
|
397
|
|
398 PTHREAD_RWLOCK_PREFER_READER_NP : constant := 0;
|
|
399 PTHREAD_RWLOCK_PREFER_WRITER_NP : constant := 1;
|
|
400 PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP : constant := 2;
|
|
401
|
|
402 function pthread_rwlockattr_setkind_np
|
|
403 (attr : access pthread_rwlockattr_t;
|
|
404 pref : int) return int;
|
|
405 pragma Import
|
|
406 (C, pthread_rwlockattr_setkind_np, "pthread_rwlockattr_setkind_np");
|
|
407
|
|
408 function pthread_rwlock_init
|
|
409 (mutex : access pthread_rwlock_t;
|
|
410 attr : access pthread_rwlockattr_t) return int;
|
|
411 pragma Import (C, pthread_rwlock_init, "pthread_rwlock_init");
|
|
412
|
|
413 function pthread_rwlock_destroy
|
|
414 (mutex : access pthread_rwlock_t) return int;
|
|
415 pragma Import (C, pthread_rwlock_destroy, "pthread_rwlock_destroy");
|
|
416
|
|
417 function pthread_rwlock_rdlock (mutex : access pthread_rwlock_t) return int;
|
|
418 pragma Import (C, pthread_rwlock_rdlock, "pthread_rwlock_rdlock");
|
|
419
|
|
420 function pthread_rwlock_wrlock (mutex : access pthread_rwlock_t) return int;
|
|
421 pragma Import (C, pthread_rwlock_wrlock, "pthread_rwlock_wrlock");
|
|
422
|
|
423 function pthread_rwlock_unlock (mutex : access pthread_rwlock_t) return int;
|
|
424 pragma Import (C, pthread_rwlock_unlock, "pthread_rwlock_unlock");
|
|
425
|
|
426 function pthread_condattr_init
|
|
427 (attr : access pthread_condattr_t) return int;
|
|
428 pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
|
|
429
|
|
430 function pthread_condattr_destroy
|
|
431 (attr : access pthread_condattr_t) return int;
|
|
432 pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
|
|
433
|
|
434 function pthread_cond_init
|
|
435 (cond : access pthread_cond_t;
|
|
436 attr : access pthread_condattr_t) return int;
|
|
437 pragma Import (C, pthread_cond_init, "pthread_cond_init");
|
|
438
|
|
439 function pthread_cond_destroy (cond : access pthread_cond_t) return int;
|
|
440 pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
|
|
441
|
|
442 function pthread_cond_signal (cond : access pthread_cond_t) return int;
|
|
443 pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
|
|
444
|
|
445 function pthread_cond_wait
|
|
446 (cond : access pthread_cond_t;
|
|
447 mutex : access pthread_mutex_t) return int;
|
|
448 pragma Import (C, pthread_cond_wait, "pthread_cond_wait");
|
|
449
|
|
450 function pthread_cond_timedwait
|
|
451 (cond : access pthread_cond_t;
|
|
452 mutex : access pthread_mutex_t;
|
|
453 abstime : access timespec) return int;
|
|
454 pragma Import (C, pthread_cond_timedwait, "pthread_cond_timedwait");
|
|
455
|
|
456 --------------------------
|
|
457 -- POSIX.1c Section 13 --
|
|
458 --------------------------
|
|
459
|
|
460 PTHREAD_PRIO_NONE : constant := 0;
|
|
461 PTHREAD_PRIO_INHERIT : constant := 1;
|
|
462 PTHREAD_PRIO_PROTECT : constant := 2;
|
|
463
|
|
464 function pthread_mutexattr_setprotocol
|
|
465 (attr : access pthread_mutexattr_t;
|
|
466 protocol : int) return int;
|
|
467 pragma Import (C, pthread_mutexattr_setprotocol);
|
|
468
|
|
469 function pthread_mutexattr_setprioceiling
|
|
470 (attr : access pthread_mutexattr_t;
|
|
471 prioceiling : int) return int;
|
|
472 pragma Import (C, pthread_mutexattr_setprioceiling);
|
|
473
|
|
474 type struct_sched_param is record
|
|
475 sched_priority : int; -- scheduling priority
|
|
476 end record;
|
|
477 pragma Convention (C, struct_sched_param);
|
|
478
|
|
479 function pthread_setschedparam
|
|
480 (thread : pthread_t;
|
|
481 policy : int;
|
|
482 param : access struct_sched_param) return int;
|
|
483 pragma Import (C, pthread_setschedparam, "pthread_setschedparam");
|
|
484
|
|
485 function pthread_attr_setschedpolicy
|
|
486 (attr : access pthread_attr_t;
|
|
487 policy : int) return int;
|
|
488 pragma Import
|
|
489 (C, pthread_attr_setschedpolicy, "pthread_attr_setschedpolicy");
|
|
490
|
|
491 function sched_yield return int;
|
|
492 pragma Import (C, sched_yield, "sched_yield");
|
|
493
|
|
494 ---------------------------
|
|
495 -- P1003.1c - Section 16 --
|
|
496 ---------------------------
|
|
497
|
|
498 function pthread_attr_init
|
|
499 (attributes : access pthread_attr_t) return int;
|
|
500 pragma Import (C, pthread_attr_init, "pthread_attr_init");
|
|
501
|
|
502 function pthread_attr_destroy
|
|
503 (attributes : access pthread_attr_t) return int;
|
|
504 pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
|
|
505
|
|
506 function pthread_attr_setdetachstate
|
|
507 (attr : access pthread_attr_t;
|
|
508 detachstate : int) return int;
|
|
509 pragma Import
|
|
510 (C, pthread_attr_setdetachstate, "pthread_attr_setdetachstate");
|
|
511
|
|
512 function pthread_attr_setstacksize
|
|
513 (attr : access pthread_attr_t;
|
|
514 stacksize : size_t) return int;
|
|
515 pragma Import (C, pthread_attr_setstacksize, "pthread_attr_setstacksize");
|
|
516
|
|
517 function pthread_create
|
|
518 (thread : access pthread_t;
|
|
519 attributes : access pthread_attr_t;
|
|
520 start_routine : Thread_Body;
|
|
521 arg : System.Address) return int;
|
|
522 pragma Import (C, pthread_create, "pthread_create");
|
|
523
|
|
524 procedure pthread_exit (status : System.Address);
|
|
525 pragma Import (C, pthread_exit, "pthread_exit");
|
|
526
|
|
527 function pthread_self return pthread_t;
|
|
528 pragma Import (C, pthread_self, "pthread_self");
|
|
529
|
|
530 function lwp_self return System.Address;
|
|
531 pragma Import (C, lwp_self, "__gnat_lwp_self");
|
|
532
|
|
533 --------------------------
|
|
534 -- POSIX.1c Section 17 --
|
|
535 --------------------------
|
|
536
|
|
537 function pthread_setspecific
|
|
538 (key : pthread_key_t;
|
|
539 value : System.Address) return int;
|
|
540 pragma Import (C, pthread_setspecific, "pthread_setspecific");
|
|
541
|
|
542 function pthread_getspecific (key : pthread_key_t) return System.Address;
|
|
543 pragma Import (C, pthread_getspecific, "pthread_getspecific");
|
|
544
|
|
545 type destructor_pointer is access procedure (arg : System.Address);
|
|
546 pragma Convention (C, destructor_pointer);
|
|
547
|
|
548 function pthread_key_create
|
|
549 (key : access pthread_key_t;
|
|
550 destructor : destructor_pointer) return int;
|
|
551 pragma Import (C, pthread_key_create, "pthread_key_create");
|
|
552
|
|
553 ----------------
|
|
554 -- Extensions --
|
|
555 ----------------
|
|
556
|
|
557 CPU_SETSIZE : constant := 1_024;
|
|
558 -- Size of the cpu_set_t mask on most linux systems (SUSE 11 uses 4_096).
|
|
559 -- This is kept for backward compatibility (System.Task_Info uses it), but
|
|
560 -- the run-time library does no longer rely on static masks, using
|
|
561 -- dynamically allocated masks instead.
|
|
562
|
|
563 type bit_field is array (1 .. CPU_SETSIZE) of Boolean;
|
|
564 for bit_field'Size use CPU_SETSIZE;
|
|
565 pragma Pack (bit_field);
|
|
566 pragma Convention (C, bit_field);
|
|
567
|
|
568 type cpu_set_t is record
|
|
569 bits : bit_field;
|
|
570 end record;
|
|
571 pragma Convention (C, cpu_set_t);
|
|
572
|
|
573 type cpu_set_t_ptr is access all cpu_set_t;
|
|
574 -- In the run-time library we use this pointer because the size of type
|
|
575 -- cpu_set_t varies depending on the glibc version. Hence, objects of type
|
|
576 -- cpu_set_t are allocated dynamically using the number of processors
|
|
577 -- available in the target machine (value obtained at execution time).
|
|
578
|
|
579 function CPU_ALLOC (count : size_t) return cpu_set_t_ptr;
|
|
580 pragma Import (C, CPU_ALLOC, "__gnat_cpu_alloc");
|
|
581 -- Wrapper around the CPU_ALLOC C macro
|
|
582
|
|
583 function CPU_ALLOC_SIZE (count : size_t) return size_t;
|
|
584 pragma Import (C, CPU_ALLOC_SIZE, "__gnat_cpu_alloc_size");
|
|
585 -- Wrapper around the CPU_ALLOC_SIZE C macro
|
|
586
|
|
587 procedure CPU_FREE (cpuset : cpu_set_t_ptr);
|
|
588 pragma Import (C, CPU_FREE, "__gnat_cpu_free");
|
|
589 -- Wrapper around the CPU_FREE C macro
|
|
590
|
|
591 procedure CPU_ZERO (count : size_t; cpuset : cpu_set_t_ptr);
|
|
592 pragma Import (C, CPU_ZERO, "__gnat_cpu_zero");
|
|
593 -- Wrapper around the CPU_ZERO_S C macro
|
|
594
|
|
595 procedure CPU_SET (cpu : int; count : size_t; cpuset : cpu_set_t_ptr);
|
|
596 pragma Import (C, CPU_SET, "__gnat_cpu_set");
|
|
597 -- Wrapper around the CPU_SET_S C macro
|
|
598
|
|
599 function pthread_setaffinity_np
|
|
600 (thread : pthread_t;
|
|
601 cpusetsize : size_t;
|
|
602 cpuset : cpu_set_t_ptr) return int;
|
|
603 pragma Import (C, pthread_setaffinity_np, "pthread_setaffinity_np");
|
|
604 pragma Weak_External (pthread_setaffinity_np);
|
|
605 -- Use a weak symbol because this function may be available or not,
|
|
606 -- depending on the version of the system.
|
|
607
|
|
608 function pthread_attr_setaffinity_np
|
|
609 (attr : access pthread_attr_t;
|
|
610 cpusetsize : size_t;
|
|
611 cpuset : cpu_set_t_ptr) return int;
|
|
612 pragma Import (C, pthread_attr_setaffinity_np,
|
|
613 "pthread_attr_setaffinity_np");
|
|
614 pragma Weak_External (pthread_attr_setaffinity_np);
|
|
615 -- Use a weak symbol because this function may be available or not,
|
|
616 -- depending on the version of the system.
|
|
617
|
|
618 private
|
|
619
|
|
620 type sigset_t is
|
|
621 array (0 .. OS_Constants.SIZEOF_sigset - 1) of unsigned_char;
|
|
622 pragma Convention (C, sigset_t);
|
|
623 for sigset_t'Alignment use Interfaces.C.unsigned_long'Alignment;
|
|
624
|
|
625 pragma Warnings (Off);
|
|
626 for struct_sigaction use record
|
|
627 sa_handler at Linux.sa_handler_pos range 0 .. Standard'Address_Size - 1;
|
|
628 sa_mask at Linux.sa_mask_pos range 0 .. 1023;
|
|
629 sa_flags at Linux.sa_flags_pos range 0 .. int'Size - 1;
|
|
630 end record;
|
|
631 -- We intentionally leave sa_restorer unspecified and let the compiler
|
|
632 -- append it after the last field, so disable corresponding warning.
|
|
633 pragma Warnings (On);
|
|
634
|
|
635 type pid_t is new int;
|
|
636
|
|
637 subtype char_array is Interfaces.C.char_array;
|
|
638
|
|
639 type pthread_attr_t is record
|
|
640 Data : char_array (1 .. OS_Constants.PTHREAD_ATTR_SIZE);
|
|
641 end record;
|
|
642 pragma Convention (C, pthread_attr_t);
|
|
643 for pthread_attr_t'Alignment use Interfaces.C.unsigned_long'Alignment;
|
|
644
|
|
645 type pthread_condattr_t is record
|
|
646 Data : char_array (1 .. OS_Constants.PTHREAD_CONDATTR_SIZE);
|
|
647 end record;
|
|
648 pragma Convention (C, pthread_condattr_t);
|
|
649 for pthread_condattr_t'Alignment use Interfaces.C.int'Alignment;
|
|
650
|
|
651 type pthread_mutexattr_t is record
|
|
652 Data : char_array (1 .. OS_Constants.PTHREAD_MUTEXATTR_SIZE);
|
|
653 end record;
|
|
654 pragma Convention (C, pthread_mutexattr_t);
|
|
655 for pthread_mutexattr_t'Alignment use Interfaces.C.int'Alignment;
|
|
656
|
|
657 type pthread_mutex_t is record
|
|
658 Data : char_array (1 .. OS_Constants.PTHREAD_MUTEX_SIZE);
|
|
659 end record;
|
|
660 pragma Convention (C, pthread_mutex_t);
|
|
661 for pthread_mutex_t'Alignment use Interfaces.C.unsigned_long'Alignment;
|
|
662
|
|
663 type pthread_rwlockattr_t is record
|
|
664 Data : char_array (1 .. OS_Constants.PTHREAD_RWLOCKATTR_SIZE);
|
|
665 end record;
|
|
666 pragma Convention (C, pthread_rwlockattr_t);
|
|
667 for pthread_rwlockattr_t'Alignment use Interfaces.C.unsigned_long'Alignment;
|
|
668
|
|
669 type pthread_rwlock_t is record
|
|
670 Data : char_array (1 .. OS_Constants.PTHREAD_RWLOCK_SIZE);
|
|
671 end record;
|
|
672 pragma Convention (C, pthread_rwlock_t);
|
|
673 for pthread_rwlock_t'Alignment use Interfaces.C.unsigned_long'Alignment;
|
|
674
|
|
675 type pthread_cond_t is record
|
|
676 Data : char_array (1 .. OS_Constants.PTHREAD_COND_SIZE);
|
|
677 end record;
|
|
678 pragma Convention (C, pthread_cond_t);
|
|
679 for pthread_cond_t'Alignment use Interfaces.Unsigned_64'Alignment;
|
|
680
|
|
681 type pthread_key_t is new unsigned;
|
|
682
|
|
683 end System.OS_Interface;
|