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