1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
5 -- S Y S T E M . O S _ I N T E R F A C E --
9 -- Copyright (C) 1991-1994, Florida State University --
10 -- Copyright (C) 1995-2008, Free Software Foundation, Inc. --
12 -- GNARL 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 2, or (at your option) any later ver- --
15 -- sion. GNARL 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. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNARL; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
21 -- Boston, MA 02110-1301, USA. --
23 -- As a special exception, if other files instantiate generics from this --
24 -- unit, or you link this unit with other files to produce an executable, --
25 -- this unit does not by itself cause the resulting executable to be --
26 -- covered by the GNU General Public License. This exception does not --
27 -- however invalidate any other reasons why the executable file might be --
28 -- covered by the GNU Public License. --
30 -- GNARL was developed by the GNARL team at Florida State University. --
31 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
33 ------------------------------------------------------------------------------
35 -- This is a OpenVMS/Alpha version of this package
37 -- This package encapsulates all direct interfaces to OS services
38 -- that are needed by the tasking run-time (libgnarl).
40 -- PLEASE DO NOT add any with-clauses to this package or remove the pragma
41 -- Preelaborate. This package is designed to be a bottom-level (leaf) package.
45 with Ada
.Unchecked_Conversion
;
49 package System
.OS_Interface
is
52 pragma Linker_Options
("--for-linker=sys$library:pthread$rtl.exe");
53 -- Link in the DEC threads library
55 -- pragma Linker_Options ("--for-linker=/threads_enable");
56 -- Enable upcalls and multiple kernel threads.
58 subtype int
is Interfaces
.C
.int
;
59 subtype short
is Interfaces
.C
.short
;
60 subtype long
is Interfaces
.C
.long
;
61 subtype unsigned
is Interfaces
.C
.unsigned
;
62 subtype unsigned_short
is Interfaces
.C
.unsigned_short
;
63 subtype unsigned_long
is Interfaces
.C
.unsigned_long
;
64 subtype unsigned_char
is Interfaces
.C
.unsigned_char
;
65 subtype plain_char
is Interfaces
.C
.plain_char
;
66 subtype size_t
is Interfaces
.C
.size_t
;
68 -----------------------------
69 -- Signals (Interrupt IDs) --
70 -----------------------------
72 -- Type signal has an arbitrary limit of 31
74 Max_Interrupt
: constant := 31;
75 type Signal
is new unsigned
range 0 .. Max_Interrupt
;
76 for Signal
'Size use unsigned
'Size;
78 type sigset_t
is array (Signal
) of Boolean;
79 pragma Pack
(sigset_t
);
81 -- Interrupt_Number_Type
82 -- Unsigned long integer denoting the number of an interrupt
84 subtype Interrupt_Number_Type
is unsigned_long
;
86 -- OpenVMS system services return values of type Cond_Value_Type
88 subtype Cond_Value_Type
is unsigned_long
;
89 subtype Short_Cond_Value_Type
is unsigned_short
;
91 type IO_Status_Block_Type
is record
92 Status
: Short_Cond_Value_Type
;
93 Count
: unsigned_short
;
94 Dev_Info
: unsigned_long
;
97 type AST_Handler
is access procedure (Param
: Address
);
98 pragma Convention
(C
, AST_Handler
);
99 No_AST_Handler
: constant AST_Handler
:= null;
101 CMB_M_READONLY
: constant := 16#
00000001#
;
102 CMB_M_WRITEONLY
: constant := 16#
00000002#
;
103 AGN_M_READONLY
: constant := 16#
00000001#
;
104 AGN_M_WRITEONLY
: constant := 16#
00000002#
;
106 IO_WRITEVBLK
: constant := 48; -- WRITE VIRTUAL BLOCK
107 IO_READVBLK
: constant := 49; -- READ VIRTUAL BLOCK
113 -- Assign I/O Channel
115 -- Status = returned status
116 -- Devnam = address of device name or logical name string
118 -- Chan = address of word to receive channel number assigned
119 -- Acmode = access mode associated with channel
120 -- Mbxnam = address of mailbox logical name string descriptor, if
121 -- mailbox associated with device
122 -- Flags = optional channel flags longword for specifying options
123 -- for the $ASSIGN operation
127 (Status
: out Cond_Value_Type
;
129 Chan
: out unsigned_short
;
130 Acmode
: unsigned_short
:= 0;
131 Mbxnam
: String := String'Null_Parameter;
132 Flags
: unsigned_long
:= 0);
133 pragma Interface
(External
, Sys_Assign
);
134 pragma Import_Valued_Procedure
135 (Sys_Assign
, "SYS$ASSIGN",
136 (Cond_Value_Type
, String, unsigned_short
,
137 unsigned_short
, String, unsigned_long
),
138 (Value
, Descriptor
(s
), Reference
,
139 Value
, Descriptor
(s
), Value
),
148 -- Status = returned status
149 -- Reqidt = ID of timer to be cancelled
150 -- Acmode = Access mode
153 (Status
: out Cond_Value_Type
;
156 pragma Interface
(External
, Sys_Cantim
);
157 pragma Import_Valued_Procedure
158 (Sys_Cantim
, "SYS$CANTIM",
159 (Cond_Value_Type
, Address
, unsigned
),
160 (Value
, Value
, Value
));
168 -- Status = returned status
169 -- Prmflg = permanent flag
171 -- Maxmsg = maximum message
172 -- Bufquo = buufer quote
173 -- Promsk = protection mast
174 -- Acmode = access mode
175 -- Lognam = logical name
179 (Status
: out Cond_Value_Type
;
180 Prmflg
: unsigned_char
;
181 Chan
: out unsigned_short
;
182 Maxmsg
: unsigned_long
:= 0;
183 Bufquo
: unsigned_long
:= 0;
184 Promsk
: unsigned_short
:= 0;
185 Acmode
: unsigned_short
:= 0;
187 Flags
: unsigned_long
:= 0);
188 pragma Interface
(External
, Sys_Crembx
);
189 pragma Import_Valued_Procedure
190 (Sys_Crembx
, "SYS$CREMBX",
191 (Cond_Value_Type
, unsigned_char
, unsigned_short
,
192 unsigned_long
, unsigned_long
, unsigned_short
,
193 unsigned_short
, String, unsigned_long
),
194 (Value
, Value
, Reference
,
196 Value
, Descriptor
(s
), Value
));
204 -- Status = Returned status of call
205 -- EFN = event flag to be set when I/O completes
208 -- Iosb = I/O status block
209 -- Astadr = system trap to be generated when I/O completes
210 -- Astprm = AST parameter
211 -- P1-6 = optional parameters
214 (Status
: out Cond_Value_Type
;
215 EFN
: unsigned_long
:= 0;
216 Chan
: unsigned_short
;
217 Func
: unsigned_long
:= 0;
218 Iosb
: out IO_Status_Block_Type
;
219 Astadr
: AST_Handler
:= No_AST_Handler
;
220 Astprm
: Address
:= Null_Address
;
221 P1
: unsigned_long
:= 0;
222 P2
: unsigned_long
:= 0;
223 P3
: unsigned_long
:= 0;
224 P4
: unsigned_long
:= 0;
225 P5
: unsigned_long
:= 0;
226 P6
: unsigned_long
:= 0);
229 (Status
: out Cond_Value_Type
;
230 EFN
: unsigned_long
:= 0;
231 Chan
: unsigned_short
;
232 Func
: unsigned_long
:= 0;
233 Iosb
: Address
:= Null_Address
;
234 Astadr
: AST_Handler
:= No_AST_Handler
;
235 Astprm
: Address
:= Null_Address
;
236 P1
: unsigned_long
:= 0;
237 P2
: unsigned_long
:= 0;
238 P3
: unsigned_long
:= 0;
239 P4
: unsigned_long
:= 0;
240 P5
: unsigned_long
:= 0;
241 P6
: unsigned_long
:= 0);
243 pragma Interface
(External
, Sys_QIO
);
244 pragma Import_Valued_Procedure
246 (Cond_Value_Type
, unsigned_long
, unsigned_short
, unsigned_long
,
247 IO_Status_Block_Type
, AST_Handler
, Address
,
248 unsigned_long
, unsigned_long
, unsigned_long
,
249 unsigned_long
, unsigned_long
, unsigned_long
),
250 (Value
, Value
, Value
, Value
,
251 Reference
, Value
, Value
,
253 Value
, Value
, Value
));
255 pragma Import_Valued_Procedure
257 (Cond_Value_Type
, unsigned_long
, unsigned_short
, unsigned_long
,
258 Address
, AST_Handler
, Address
,
259 unsigned_long
, unsigned_long
, unsigned_long
,
260 unsigned_long
, unsigned_long
, unsigned_long
),
261 (Value
, Value
, Value
, Value
,
264 Value
, Value
, Value
));
272 -- Status = Returned status of call
273 -- EFN = event flag to be set when timer expires
274 -- Tim = expiration time
275 -- AST = system trap to be generated when timer expires
276 -- Redidt = returned ID of timer (e.g. to cancel timer)
280 (Status
: out Cond_Value_Type
;
285 Flags
: unsigned_long
);
286 pragma Interface
(External
, Sys_Setimr
);
287 pragma Import_Valued_Procedure
288 (Sys_Setimr
, "SYS$SETIMR",
289 (Cond_Value_Type
, unsigned_long
, Long_Integer,
290 AST_Handler
, Address
, unsigned_long
),
291 (Value
, Value
, Reference
,
292 Value
, Value
, Value
));
294 Interrupt_ID_0
: constant := 0;
295 Interrupt_ID_1
: constant := 1;
296 Interrupt_ID_2
: constant := 2;
297 Interrupt_ID_3
: constant := 3;
298 Interrupt_ID_4
: constant := 4;
299 Interrupt_ID_5
: constant := 5;
300 Interrupt_ID_6
: constant := 6;
301 Interrupt_ID_7
: constant := 7;
302 Interrupt_ID_8
: constant := 8;
303 Interrupt_ID_9
: constant := 9;
304 Interrupt_ID_10
: constant := 10;
305 Interrupt_ID_11
: constant := 11;
306 Interrupt_ID_12
: constant := 12;
307 Interrupt_ID_13
: constant := 13;
308 Interrupt_ID_14
: constant := 14;
309 Interrupt_ID_15
: constant := 15;
310 Interrupt_ID_16
: constant := 16;
311 Interrupt_ID_17
: constant := 17;
312 Interrupt_ID_18
: constant := 18;
313 Interrupt_ID_19
: constant := 19;
314 Interrupt_ID_20
: constant := 20;
315 Interrupt_ID_21
: constant := 21;
316 Interrupt_ID_22
: constant := 22;
317 Interrupt_ID_23
: constant := 23;
318 Interrupt_ID_24
: constant := 24;
319 Interrupt_ID_25
: constant := 25;
320 Interrupt_ID_26
: constant := 26;
321 Interrupt_ID_27
: constant := 27;
322 Interrupt_ID_28
: constant := 28;
323 Interrupt_ID_29
: constant := 29;
324 Interrupt_ID_30
: constant := 30;
325 Interrupt_ID_31
: constant := 31;
331 function errno
return int
;
332 pragma Import
(C
, errno
, "__get_errno");
334 EINTR
: constant := 4; -- Interrupted system call
335 EAGAIN
: constant := 11; -- No more processes
336 ENOMEM
: constant := 12; -- Not enough core
338 -------------------------
339 -- Priority Scheduling --
340 -------------------------
342 SCHED_FIFO
: constant := 1;
343 SCHED_RR
: constant := 2;
344 SCHED_OTHER
: constant := 3;
345 SCHED_BG
: constant := 4;
346 SCHED_LFI
: constant := 5;
347 SCHED_LRR
: constant := 6;
353 type pid_t
is private;
355 function kill
(pid
: pid_t
; sig
: Signal
) return int
;
356 pragma Import
(C
, kill
);
358 function getpid
return pid_t
;
359 pragma Import
(C
, getpid
);
365 type Thread_Body
is access
366 function (arg
: System
.Address
) return System
.Address
;
367 pragma Convention
(C
, Thread_Body
);
369 function Thread_Body_Access
is new
370 Ada
.Unchecked_Conversion
(System
.Aux_DEC
.Short_Address
, Thread_Body
);
372 type pthread_t
is private;
373 subtype Thread_Id
is pthread_t
;
375 type pthread_mutex_t
is limited private;
376 type pthread_cond_t
is limited private;
377 type pthread_attr_t
is limited private;
378 type pthread_mutexattr_t
is limited private;
379 type pthread_condattr_t
is limited private;
380 type pthread_key_t
is private;
382 PTHREAD_CREATE_JOINABLE
: constant := 0;
383 PTHREAD_CREATE_DETACHED
: constant := 1;
385 PTHREAD_CANCEL_DISABLE
: constant := 0;
386 PTHREAD_CANCEL_ENABLE
: constant := 1;
388 PTHREAD_CANCEL_DEFERRED
: constant := 0;
389 PTHREAD_CANCEL_ASYNCHRONOUS
: constant := 1;
391 -- Don't use ERRORCHECK mutexes, they don't work when a thread is not
392 -- the owner. AST's, at least, unlock others threads mutexes. Even
393 -- if the error is ignored, they don't work.
394 PTHREAD_MUTEX_NORMAL_NP
: constant := 0;
395 PTHREAD_MUTEX_RECURSIVE_NP
: constant := 1;
396 PTHREAD_MUTEX_ERRORCHECK_NP
: constant := 2;
398 PTHREAD_INHERIT_SCHED
: constant := 0;
399 PTHREAD_EXPLICIT_SCHED
: constant := 1;
401 function pthread_cancel
(thread
: pthread_t
) return int
;
402 pragma Import
(C
, pthread_cancel
, "PTHREAD_CANCEL");
404 procedure pthread_testcancel
;
405 pragma Import
(C
, pthread_testcancel
, "PTHREAD_TESTCANCEL");
407 function pthread_setcancelstate
408 (newstate
: int
; oldstate
: access int
) return int
;
409 pragma Import
(C
, pthread_setcancelstate
, "PTHREAD_SETCANCELSTATE");
411 function pthread_setcanceltype
412 (newtype
: int
; oldtype
: access int
) return int
;
413 pragma Import
(C
, pthread_setcanceltype
, "PTHREAD_SETCANCELTYPE");
415 -------------------------
416 -- POSIX.1c Section 3 --
417 -------------------------
419 function pthread_lock_global_np
return int
;
420 pragma Import
(C
, pthread_lock_global_np
, "PTHREAD_LOCK_GLOBAL_NP");
422 function pthread_unlock_global_np
return int
;
423 pragma Import
(C
, pthread_unlock_global_np
, "PTHREAD_UNLOCK_GLOBAL_NP");
425 --------------------------
426 -- POSIX.1c Section 11 --
427 --------------------------
429 function pthread_mutexattr_init
430 (attr
: access pthread_mutexattr_t
) return int
;
431 pragma Import
(C
, pthread_mutexattr_init
, "PTHREAD_MUTEXATTR_INIT");
433 function pthread_mutexattr_destroy
434 (attr
: access pthread_mutexattr_t
) return int
;
435 pragma Import
(C
, pthread_mutexattr_destroy
, "PTHREAD_MUTEXATTR_DESTROY");
437 function pthread_mutexattr_settype_np
438 (attr
: access pthread_mutexattr_t
;
439 mutextype
: int
) return int
;
440 pragma Import
(C
, pthread_mutexattr_settype_np
,
441 "PTHREAD_MUTEXATTR_SETTYPE_NP");
443 function pthread_mutex_init
444 (mutex
: access pthread_mutex_t
;
445 attr
: access pthread_mutexattr_t
) return int
;
446 pragma Import
(C
, pthread_mutex_init
, "PTHREAD_MUTEX_INIT");
448 function pthread_mutex_destroy
(mutex
: access pthread_mutex_t
) return int
;
449 pragma Import
(C
, pthread_mutex_destroy
, "PTHREAD_MUTEX_DESTROY");
451 function pthread_mutex_lock
(mutex
: access pthread_mutex_t
) return int
;
452 pragma Import
(C
, pthread_mutex_lock
, "PTHREAD_MUTEX_LOCK");
454 function pthread_mutex_unlock
(mutex
: access pthread_mutex_t
) return int
;
455 pragma Import
(C
, pthread_mutex_unlock
, "PTHREAD_MUTEX_UNLOCK");
457 function pthread_condattr_init
458 (attr
: access pthread_condattr_t
) return int
;
459 pragma Import
(C
, pthread_condattr_init
, "PTHREAD_CONDATTR_INIT");
461 function pthread_condattr_destroy
462 (attr
: access pthread_condattr_t
) return int
;
463 pragma Import
(C
, pthread_condattr_destroy
, "PTHREAD_CONDATTR_DESTROY");
465 function pthread_cond_init
466 (cond
: access pthread_cond_t
;
467 attr
: access pthread_condattr_t
) return int
;
468 pragma Import
(C
, pthread_cond_init
, "PTHREAD_COND_INIT");
470 function pthread_cond_destroy
(cond
: access pthread_cond_t
) return int
;
471 pragma Import
(C
, pthread_cond_destroy
, "PTHREAD_COND_DESTROY");
473 function pthread_cond_signal
(cond
: access pthread_cond_t
) return int
;
474 pragma Import
(C
, pthread_cond_signal
, "PTHREAD_COND_SIGNAL");
476 function pthread_cond_signal_int_np
477 (cond
: access pthread_cond_t
) return int
;
478 pragma Import
(C
, pthread_cond_signal_int_np
,
479 "PTHREAD_COND_SIGNAL_INT_NP");
481 function pthread_cond_wait
482 (cond
: access pthread_cond_t
;
483 mutex
: access pthread_mutex_t
) return int
;
484 pragma Import
(C
, pthread_cond_wait
, "PTHREAD_COND_WAIT");
486 --------------------------
487 -- POSIX.1c Section 13 --
488 --------------------------
490 function pthread_mutexattr_setprotocol
491 (attr
: access pthread_mutexattr_t
; protocol
: int
) return int
;
492 pragma Import
(C
, pthread_mutexattr_setprotocol
,
493 "PTHREAD_MUTEXATTR_SETPROTOCOL");
495 type struct_sched_param
is record
496 sched_priority
: int
; -- scheduling priority
498 for struct_sched_param
'Size use 8*4;
499 pragma Convention
(C
, struct_sched_param
);
501 function pthread_setschedparam
504 param
: access struct_sched_param
) return int
;
505 pragma Import
(C
, pthread_setschedparam
, "PTHREAD_SETSCHEDPARAM");
507 function pthread_attr_setscope
508 (attr
: access pthread_attr_t
;
509 contentionscope
: int
) return int
;
510 pragma Import
(C
, pthread_attr_setscope
, "PTHREAD_ATTR_SETSCOPE");
512 function pthread_attr_setinheritsched
513 (attr
: access pthread_attr_t
;
514 inheritsched
: int
) return int
;
515 pragma Import
(C
, pthread_attr_setinheritsched
,
516 "PTHREAD_ATTR_SETINHERITSCHED");
518 function pthread_attr_setschedpolicy
519 (attr
: access pthread_attr_t
; policy
: int
) return int
;
520 pragma Import
(C
, pthread_attr_setschedpolicy
,
521 "PTHREAD_ATTR_SETSCHEDPOLICY");
523 function pthread_attr_setschedparam
524 (attr
: access pthread_attr_t
;
525 sched_param
: int
) return int
;
526 pragma Import
(C
, pthread_attr_setschedparam
, "PTHREAD_ATTR_SETSCHEDPARAM");
528 function sched_yield
return int
;
530 --------------------------
531 -- P1003.1c Section 16 --
532 --------------------------
534 function pthread_attr_init
(attributes
: access pthread_attr_t
) return int
;
535 pragma Import
(C
, pthread_attr_init
, "PTHREAD_ATTR_INIT");
537 function pthread_attr_destroy
538 (attributes
: access pthread_attr_t
) return int
;
539 pragma Import
(C
, pthread_attr_destroy
, "PTHREAD_ATTR_DESTROY");
541 function pthread_attr_setdetachstate
542 (attr
: access pthread_attr_t
;
543 detachstate
: int
) return int
;
544 pragma Import
(C
, pthread_attr_setdetachstate
,
545 "PTHREAD_ATTR_SETDETACHSTATE");
547 function pthread_attr_setstacksize
548 (attr
: access pthread_attr_t
;
549 stacksize
: size_t
) return int
;
550 pragma Import
(C
, pthread_attr_setstacksize
, "PTHREAD_ATTR_SETSTACKSIZE");
552 function pthread_create
553 (thread
: access pthread_t
;
554 attributes
: access pthread_attr_t
;
555 start_routine
: Thread_Body
;
556 arg
: System
.Address
) return int
;
557 pragma Import
(C
, pthread_create
, "PTHREAD_CREATE");
559 procedure pthread_exit
(status
: System
.Address
);
560 pragma Import
(C
, pthread_exit
, "PTHREAD_EXIT");
562 function pthread_self
return pthread_t
;
564 --------------------------
565 -- POSIX.1c Section 17 --
566 --------------------------
568 function pthread_setspecific
569 (key
: pthread_key_t
;
570 value
: System
.Address
) return int
;
571 pragma Import
(C
, pthread_setspecific
, "PTHREAD_SETSPECIFIC");
573 function pthread_getspecific
(key
: pthread_key_t
) return System
.Address
;
574 pragma Import
(C
, pthread_getspecific
, "PTHREAD_GETSPECIFIC");
576 type destructor_pointer
is access procedure (arg
: System
.Address
);
577 pragma Convention
(C
, destructor_pointer
);
579 function pthread_key_create
580 (key
: access pthread_key_t
;
581 destructor
: destructor_pointer
) return int
;
582 pragma Import
(C
, pthread_key_create
, "PTHREAD_KEY_CREATE");
586 type pid_t
is new int
;
588 type pthreadLongAddr_p
is mod 2 ** Long_Integer'Size;
590 type pthreadLongAddr_t
is mod 2 ** Long_Integer'Size;
591 type pthreadLongAddr_t_ptr
is mod 2 ** Long_Integer'Size;
593 type pthreadLongString_t
is mod 2 ** Long_Integer'Size;
595 type pthreadLongUint_t
is mod 2 ** Long_Integer'Size;
596 type pthreadLongUint_array
is array (Natural range <>)
597 of pthreadLongUint_t
;
599 type pthread_t
is mod 2 ** Long_Integer'Size;
601 type pthread_cond_t
is record
604 name
: pthreadLongString_t
;
607 block
: pthreadLongAddr_t_ptr
;
609 for pthread_cond_t
'Size use 8*32;
610 pragma Convention
(C
, pthread_cond_t
);
612 type pthread_attr_t
is record
614 name
: pthreadLongString_t
;
615 arg
: pthreadLongUint_t
;
616 reserved
: pthreadLongUint_array
(0 .. 18);
618 for pthread_attr_t
'Size use 8*176;
619 pragma Convention
(C
, pthread_attr_t
);
621 type pthread_mutex_t
is record
624 name
: pthreadLongString_t
;
627 block
: pthreadLongAddr_p
;
631 for pthread_mutex_t
'Size use 8*40;
632 pragma Convention
(C
, pthread_mutex_t
);
634 type pthread_mutexattr_t
is record
636 reserved
: pthreadLongUint_array
(0 .. 14);
638 for pthread_mutexattr_t
'Size use 8*128;
639 pragma Convention
(C
, pthread_mutexattr_t
);
641 type pthread_condattr_t
is record
643 reserved
: pthreadLongUint_array
(0 .. 12);
645 for pthread_condattr_t
'Size use 8*112;
646 pragma Convention
(C
, pthread_condattr_t
);
648 type pthread_key_t
is new unsigned
;
650 pragma Inline
(pthread_self
);
652 end System
.OS_Interface
;