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