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-2012, Free Software Foundation, Inc. --
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. --
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. --
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/>. --
28 -- GNARL was developed by the GNARL team at Florida State University. --
29 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
31 ------------------------------------------------------------------------------
33 -- This is the OpenVMS version of this package
35 -- This package encapsulates all direct interfaces to OS services
36 -- that are needed by the tasking run-time (libgnarl).
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.
43 with Ada
.Unchecked_Conversion
;
47 package System
.OS_Interface
is
50 -- pragma Linker_Options ("--for-linker=/threads_enable");
51 -- Enable upcalls and multiple kernel threads.
53 subtype int
is Interfaces
.C
.int
;
54 subtype short
is Interfaces
.C
.short
;
55 subtype long
is Interfaces
.C
.long
;
56 subtype unsigned
is Interfaces
.C
.unsigned
;
57 subtype unsigned_short
is Interfaces
.C
.unsigned_short
;
58 subtype unsigned_long
is Interfaces
.C
.unsigned_long
;
59 subtype unsigned_char
is Interfaces
.C
.unsigned_char
;
60 subtype plain_char
is Interfaces
.C
.plain_char
;
61 subtype size_t
is Interfaces
.C
.size_t
;
63 -----------------------------
64 -- Signals (Interrupt IDs) --
65 -----------------------------
67 -- Type signal has an arbitrary limit of 31
69 Max_Interrupt
: constant := 31;
70 type Signal
is new unsigned
range 0 .. Max_Interrupt
;
71 for Signal
'Size use unsigned
'Size;
73 type sigset_t
is array (Signal
) of Boolean;
74 pragma Pack
(sigset_t
);
76 -- Interrupt_Number_Type
77 -- Unsigned long integer denoting the number of an interrupt
79 subtype Interrupt_Number_Type
is unsigned_long
;
81 -- OpenVMS system services return values of type Cond_Value_Type
83 subtype Cond_Value_Type
is unsigned_long
;
84 subtype Short_Cond_Value_Type
is unsigned_short
;
86 type IO_Status_Block_Type
is record
87 Status
: Short_Cond_Value_Type
;
88 Count
: unsigned_short
;
89 Dev_Info
: unsigned_long
;
92 type AST_Handler
is access procedure (Param
: Address
);
93 pragma Convention
(C
, AST_Handler
);
94 No_AST_Handler
: constant AST_Handler
:= null;
96 CMB_M_READONLY
: constant := 16#
00000001#
;
97 CMB_M_WRITEONLY
: constant := 16#
00000002#
;
98 AGN_M_READONLY
: constant := 16#
00000001#
;
99 AGN_M_WRITEONLY
: constant := 16#
00000002#
;
101 IO_WRITEVBLK
: constant := 48; -- WRITE VIRTUAL BLOCK
102 IO_READVBLK
: constant := 49; -- READ VIRTUAL BLOCK
108 -- Assign I/O Channel
110 -- Status = returned status
111 -- Devnam = address of device name or logical name string
113 -- Chan = address of word to receive channel number assigned
114 -- Acmode = access mode associated with channel
115 -- Mbxnam = address of mailbox logical name string descriptor, if
116 -- mailbox associated with device
117 -- Flags = optional channel flags longword for specifying options
118 -- for the $ASSIGN operation
122 (Status
: out Cond_Value_Type
;
124 Chan
: out unsigned_short
;
125 Acmode
: unsigned_short
:= 0;
126 Mbxnam
: String := String'Null_Parameter;
127 Flags
: unsigned_long
:= 0);
128 pragma Import
(External
, Sys_Assign
);
129 pragma Import_Valued_Procedure
130 (Sys_Assign
, "SYS$ASSIGN",
131 (Cond_Value_Type
, String, unsigned_short
,
132 unsigned_short
, String, unsigned_long
),
133 (Value
, Descriptor
(s
), Reference
,
134 Value
, Descriptor
(s
), Value
),
143 -- Status = returned status
144 -- Reqidt = ID of timer to be cancelled
145 -- Acmode = Access mode
148 (Status
: out Cond_Value_Type
;
151 pragma Import
(External
, Sys_Cantim
);
152 pragma Import_Valued_Procedure
153 (Sys_Cantim
, "SYS$CANTIM",
154 (Cond_Value_Type
, Address
, unsigned
),
155 (Value
, Value
, Value
));
163 -- Status = returned status
164 -- Prmflg = permanent flag
166 -- Maxmsg = maximum message
167 -- Bufquo = buufer quote
168 -- Promsk = protection mast
169 -- Acmode = access mode
170 -- Lognam = logical name
174 (Status
: out Cond_Value_Type
;
175 Prmflg
: unsigned_char
;
176 Chan
: out unsigned_short
;
177 Maxmsg
: unsigned_long
:= 0;
178 Bufquo
: unsigned_long
:= 0;
179 Promsk
: unsigned_short
:= 0;
180 Acmode
: unsigned_short
:= 0;
182 Flags
: unsigned_long
:= 0);
183 pragma Import
(External
, Sys_Crembx
);
184 pragma Import_Valued_Procedure
185 (Sys_Crembx
, "SYS$CREMBX",
186 (Cond_Value_Type
, unsigned_char
, unsigned_short
,
187 unsigned_long
, unsigned_long
, unsigned_short
,
188 unsigned_short
, String, unsigned_long
),
189 (Value
, Value
, Reference
,
191 Value
, Descriptor
(s
), Value
));
199 -- Status = Returned status of call
200 -- EFN = event flag to be set when I/O completes
203 -- Iosb = I/O status block
204 -- Astadr = system trap to be generated when I/O completes
205 -- Astprm = AST parameter
206 -- P1-6 = optional parameters
209 (Status
: out Cond_Value_Type
;
210 EFN
: unsigned_long
:= 0;
211 Chan
: unsigned_short
;
212 Func
: unsigned_long
:= 0;
213 Iosb
: out IO_Status_Block_Type
;
214 Astadr
: AST_Handler
:= No_AST_Handler
;
215 Astprm
: Address
:= Null_Address
;
216 P1
: unsigned_long
:= 0;
217 P2
: unsigned_long
:= 0;
218 P3
: unsigned_long
:= 0;
219 P4
: unsigned_long
:= 0;
220 P5
: unsigned_long
:= 0;
221 P6
: unsigned_long
:= 0);
224 (Status
: out Cond_Value_Type
;
225 EFN
: unsigned_long
:= 0;
226 Chan
: unsigned_short
;
227 Func
: unsigned_long
:= 0;
228 Iosb
: Address
:= Null_Address
;
229 Astadr
: AST_Handler
:= No_AST_Handler
;
230 Astprm
: Address
:= Null_Address
;
231 P1
: unsigned_long
:= 0;
232 P2
: unsigned_long
:= 0;
233 P3
: unsigned_long
:= 0;
234 P4
: unsigned_long
:= 0;
235 P5
: unsigned_long
:= 0;
236 P6
: unsigned_long
:= 0);
238 pragma Import
(External
, Sys_QIO
);
239 pragma Import_Valued_Procedure
241 (Cond_Value_Type
, unsigned_long
, unsigned_short
, unsigned_long
,
242 IO_Status_Block_Type
, AST_Handler
, Address
,
243 unsigned_long
, unsigned_long
, unsigned_long
,
244 unsigned_long
, unsigned_long
, unsigned_long
),
245 (Value
, Value
, Value
, Value
,
246 Reference
, Value
, Value
,
248 Value
, Value
, Value
));
250 pragma Import_Valued_Procedure
252 (Cond_Value_Type
, unsigned_long
, unsigned_short
, unsigned_long
,
253 Address
, AST_Handler
, Address
,
254 unsigned_long
, unsigned_long
, unsigned_long
,
255 unsigned_long
, unsigned_long
, unsigned_long
),
256 (Value
, Value
, Value
, Value
,
259 Value
, Value
, Value
));
267 -- Status = Returned status of call
268 -- EFN = event flag to be set when timer expires
269 -- Tim = expiration time
270 -- AST = system trap to be generated when timer expires
271 -- Redidt = returned ID of timer (e.g. to cancel timer)
275 (Status
: out Cond_Value_Type
;
280 Flags
: unsigned_long
);
281 pragma Import
(External
, Sys_Setimr
);
282 pragma Import_Valued_Procedure
283 (Sys_Setimr
, "SYS$SETIMR",
284 (Cond_Value_Type
, unsigned_long
, Long_Integer,
285 AST_Handler
, Address
, unsigned_long
),
286 (Value
, Value
, Reference
,
287 Value
, Value
, Value
));
289 Interrupt_ID_0
: constant := 0;
290 Interrupt_ID_1
: constant := 1;
291 Interrupt_ID_2
: constant := 2;
292 Interrupt_ID_3
: constant := 3;
293 Interrupt_ID_4
: constant := 4;
294 Interrupt_ID_5
: constant := 5;
295 Interrupt_ID_6
: constant := 6;
296 Interrupt_ID_7
: constant := 7;
297 Interrupt_ID_8
: constant := 8;
298 Interrupt_ID_9
: constant := 9;
299 Interrupt_ID_10
: constant := 10;
300 Interrupt_ID_11
: constant := 11;
301 Interrupt_ID_12
: constant := 12;
302 Interrupt_ID_13
: constant := 13;
303 Interrupt_ID_14
: constant := 14;
304 Interrupt_ID_15
: constant := 15;
305 Interrupt_ID_16
: constant := 16;
306 Interrupt_ID_17
: constant := 17;
307 Interrupt_ID_18
: constant := 18;
308 Interrupt_ID_19
: constant := 19;
309 Interrupt_ID_20
: constant := 20;
310 Interrupt_ID_21
: constant := 21;
311 Interrupt_ID_22
: constant := 22;
312 Interrupt_ID_23
: constant := 23;
313 Interrupt_ID_24
: constant := 24;
314 Interrupt_ID_25
: constant := 25;
315 Interrupt_ID_26
: constant := 26;
316 Interrupt_ID_27
: constant := 27;
317 Interrupt_ID_28
: constant := 28;
318 Interrupt_ID_29
: constant := 29;
319 Interrupt_ID_30
: constant := 30;
320 Interrupt_ID_31
: constant := 31;
326 function errno
return int
;
327 pragma Import
(C
, errno
, "__get_errno");
329 EINTR
: constant := 4; -- Interrupted system call
330 EAGAIN
: constant := 11; -- No more processes
331 ENOMEM
: constant := 12; -- Not enough core
333 -------------------------
334 -- Priority Scheduling --
335 -------------------------
337 SCHED_FIFO
: constant := 1;
338 SCHED_RR
: constant := 2;
339 SCHED_OTHER
: constant := 3;
340 SCHED_BG
: constant := 4;
341 SCHED_LFI
: constant := 5;
342 SCHED_LRR
: constant := 6;
348 type pid_t
is private;
350 function kill
(pid
: pid_t
; sig
: Signal
) return int
;
351 pragma Import
(C
, kill
);
353 function getpid
return pid_t
;
354 pragma Import
(C
, getpid
);
360 type Thread_Body
is access
361 function (arg
: System
.Address
) return System
.Address
;
362 pragma Convention
(C
, Thread_Body
);
364 function Thread_Body_Access
is new
365 Ada
.Unchecked_Conversion
(System
.Aux_DEC
.Short_Address
, Thread_Body
);
367 type pthread_t
is private;
368 subtype Thread_Id
is pthread_t
;
370 type pthread_mutex_t
is limited private;
371 type pthread_cond_t
is limited private;
372 type pthread_attr_t
is limited private;
373 type pthread_mutexattr_t
is limited private;
374 type pthread_condattr_t
is limited private;
375 type pthread_key_t
is private;
377 PTHREAD_CREATE_JOINABLE
: constant := 0;
378 PTHREAD_CREATE_DETACHED
: constant := 1;
380 PTHREAD_CANCEL_DISABLE
: constant := 0;
381 PTHREAD_CANCEL_ENABLE
: constant := 1;
383 PTHREAD_CANCEL_DEFERRED
: constant := 0;
384 PTHREAD_CANCEL_ASYNCHRONOUS
: constant := 1;
386 -- Don't use ERRORCHECK mutexes, they don't work when a thread is not
387 -- the owner. AST's, at least, unlock others threads mutexes. Even
388 -- if the error is ignored, they don't work.
389 PTHREAD_MUTEX_NORMAL_NP
: constant := 0;
390 PTHREAD_MUTEX_RECURSIVE_NP
: constant := 1;
391 PTHREAD_MUTEX_ERRORCHECK_NP
: constant := 2;
393 PTHREAD_INHERIT_SCHED
: constant := 0;
394 PTHREAD_EXPLICIT_SCHED
: constant := 1;
396 function pthread_cancel
(thread
: pthread_t
) return int
;
397 pragma Import
(C
, pthread_cancel
, "PTHREAD_CANCEL");
399 procedure pthread_testcancel
;
400 pragma Import
(C
, pthread_testcancel
, "PTHREAD_TESTCANCEL");
402 function pthread_setcancelstate
403 (newstate
: int
; oldstate
: access int
) return int
;
404 pragma Import
(C
, pthread_setcancelstate
, "PTHREAD_SETCANCELSTATE");
406 function pthread_setcanceltype
407 (newtype
: int
; oldtype
: access int
) return int
;
408 pragma Import
(C
, pthread_setcanceltype
, "PTHREAD_SETCANCELTYPE");
410 -------------------------
411 -- POSIX.1c Section 3 --
412 -------------------------
414 function pthread_lock_global_np
return int
;
415 pragma Import
(C
, pthread_lock_global_np
, "PTHREAD_LOCK_GLOBAL_NP");
417 function pthread_unlock_global_np
return int
;
418 pragma Import
(C
, pthread_unlock_global_np
, "PTHREAD_UNLOCK_GLOBAL_NP");
420 --------------------------
421 -- POSIX.1c Section 11 --
422 --------------------------
424 function pthread_mutexattr_init
425 (attr
: access pthread_mutexattr_t
) return int
;
426 pragma Import
(C
, pthread_mutexattr_init
, "PTHREAD_MUTEXATTR_INIT");
428 function pthread_mutexattr_destroy
429 (attr
: access pthread_mutexattr_t
) return int
;
430 pragma Import
(C
, pthread_mutexattr_destroy
, "PTHREAD_MUTEXATTR_DESTROY");
432 function pthread_mutexattr_settype_np
433 (attr
: access pthread_mutexattr_t
;
434 mutextype
: int
) return int
;
435 pragma Import
(C
, pthread_mutexattr_settype_np
,
436 "PTHREAD_MUTEXATTR_SETTYPE_NP");
438 function pthread_mutex_init
439 (mutex
: access pthread_mutex_t
;
440 attr
: access pthread_mutexattr_t
) return int
;
441 pragma Import
(C
, pthread_mutex_init
, "PTHREAD_MUTEX_INIT");
443 function pthread_mutex_destroy
(mutex
: access pthread_mutex_t
) return int
;
444 pragma Import
(C
, pthread_mutex_destroy
, "PTHREAD_MUTEX_DESTROY");
446 function pthread_mutex_lock
(mutex
: access pthread_mutex_t
) return int
;
447 pragma Import
(C
, pthread_mutex_lock
, "PTHREAD_MUTEX_LOCK");
449 function pthread_mutex_unlock
(mutex
: access pthread_mutex_t
) return int
;
450 pragma Import
(C
, pthread_mutex_unlock
, "PTHREAD_MUTEX_UNLOCK");
452 function pthread_mutex_setname_np
453 (attr
: access pthread_mutex_t
;
454 name
: System
.Address
;
455 mbz
: System
.Address
) return int
;
456 pragma Import
(C
, pthread_mutex_setname_np
, "PTHREAD_MUTEX_SETNAME_NP");
458 function pthread_condattr_init
459 (attr
: access pthread_condattr_t
) return int
;
460 pragma Import
(C
, pthread_condattr_init
, "PTHREAD_CONDATTR_INIT");
462 function pthread_condattr_destroy
463 (attr
: access pthread_condattr_t
) return int
;
464 pragma Import
(C
, pthread_condattr_destroy
, "PTHREAD_CONDATTR_DESTROY");
466 function pthread_cond_init
467 (cond
: access pthread_cond_t
;
468 attr
: access pthread_condattr_t
) return int
;
469 pragma Import
(C
, pthread_cond_init
, "PTHREAD_COND_INIT");
471 function pthread_cond_destroy
(cond
: access pthread_cond_t
) return int
;
472 pragma Import
(C
, pthread_cond_destroy
, "PTHREAD_COND_DESTROY");
474 function pthread_cond_signal
(cond
: access pthread_cond_t
) return int
;
475 pragma Import
(C
, pthread_cond_signal
, "PTHREAD_COND_SIGNAL");
477 function pthread_cond_signal_int_np
478 (cond
: access pthread_cond_t
) return int
;
479 pragma Import
(C
, pthread_cond_signal_int_np
,
480 "PTHREAD_COND_SIGNAL_INT_NP");
482 function pthread_cond_wait
483 (cond
: access pthread_cond_t
;
484 mutex
: access pthread_mutex_t
) return int
;
485 pragma Import
(C
, pthread_cond_wait
, "PTHREAD_COND_WAIT");
487 --------------------------
488 -- POSIX.1c Section 13 --
489 --------------------------
491 function pthread_mutexattr_setprotocol
492 (attr
: access pthread_mutexattr_t
; protocol
: int
) return int
;
493 pragma Import
(C
, pthread_mutexattr_setprotocol
,
494 "PTHREAD_MUTEXATTR_SETPROTOCOL");
496 type struct_sched_param
is record
497 sched_priority
: int
; -- scheduling priority
499 for struct_sched_param
'Size use 8*4;
500 pragma Convention
(C
, struct_sched_param
);
502 function pthread_setschedparam
505 param
: access struct_sched_param
) return int
;
506 pragma Import
(C
, pthread_setschedparam
, "PTHREAD_SETSCHEDPARAM");
508 function pthread_attr_setscope
509 (attr
: access pthread_attr_t
;
510 contentionscope
: int
) return int
;
511 pragma Import
(C
, pthread_attr_setscope
, "PTHREAD_ATTR_SETSCOPE");
513 function pthread_attr_setinheritsched
514 (attr
: access pthread_attr_t
;
515 inheritsched
: int
) return int
;
516 pragma Import
(C
, pthread_attr_setinheritsched
,
517 "PTHREAD_ATTR_SETINHERITSCHED");
519 function pthread_attr_setschedpolicy
520 (attr
: access pthread_attr_t
; policy
: int
) return int
;
521 pragma Import
(C
, pthread_attr_setschedpolicy
,
522 "PTHREAD_ATTR_SETSCHEDPOLICY");
524 function pthread_attr_setschedparam
525 (attr
: access pthread_attr_t
;
526 sched_param
: int
) return int
;
527 pragma Import
(C
, pthread_attr_setschedparam
, "PTHREAD_ATTR_SETSCHEDPARAM");
529 function pthread_attr_setname_np
530 (attr
: access pthread_attr_t
;
531 name
: System
.Address
;
532 mbz
: System
.Address
) return int
;
533 pragma Import
(C
, pthread_attr_setname_np
, "PTHREAD_ATTR_SETNAME_NP");
535 function sched_yield
return int
;
537 --------------------------
538 -- P1003.1c Section 16 --
539 --------------------------
541 function pthread_attr_init
(attributes
: access pthread_attr_t
) return int
;
542 pragma Import
(C
, pthread_attr_init
, "PTHREAD_ATTR_INIT");
544 function pthread_attr_destroy
545 (attributes
: access pthread_attr_t
) return int
;
546 pragma Import
(C
, pthread_attr_destroy
, "PTHREAD_ATTR_DESTROY");
548 function pthread_attr_setdetachstate
549 (attr
: access pthread_attr_t
;
550 detachstate
: int
) return int
;
551 pragma Import
(C
, pthread_attr_setdetachstate
,
552 "PTHREAD_ATTR_SETDETACHSTATE");
554 function pthread_attr_setstacksize
555 (attr
: access pthread_attr_t
;
556 stacksize
: size_t
) return int
;
557 pragma Import
(C
, pthread_attr_setstacksize
, "PTHREAD_ATTR_SETSTACKSIZE");
559 function pthread_create
560 (thread
: access pthread_t
;
561 attributes
: access pthread_attr_t
;
562 start_routine
: Thread_Body
;
563 arg
: System
.Address
) return int
;
564 pragma Import
(C
, pthread_create
, "PTHREAD_CREATE");
566 procedure pthread_exit
(status
: System
.Address
);
567 pragma Import
(C
, pthread_exit
, "PTHREAD_EXIT");
569 function pthread_self
return pthread_t
;
570 pragma Import
(C
, pthread_self
, "PTHREAD_SELF");
572 --------------------------
573 -- POSIX.1c Section 17 --
574 --------------------------
576 function pthread_setspecific
577 (key
: pthread_key_t
;
578 value
: System
.Address
) return int
;
579 pragma Import
(C
, pthread_setspecific
, "PTHREAD_SETSPECIFIC");
581 function pthread_getspecific
(key
: pthread_key_t
) return System
.Address
;
582 pragma Import
(C
, pthread_getspecific
, "PTHREAD_GETSPECIFIC");
584 type destructor_pointer
is access procedure (arg
: System
.Address
);
585 pragma Convention
(C
, destructor_pointer
);
587 function pthread_key_create
588 (key
: access pthread_key_t
;
589 destructor
: destructor_pointer
) return int
;
590 pragma Import
(C
, pthread_key_create
, "PTHREAD_KEY_CREATE");
594 type pid_t
is new int
;
596 type pthreadLongAddr_p
is mod 2 ** Long_Integer'Size;
598 type pthreadLongAddr_t
is mod 2 ** Long_Integer'Size;
599 type pthreadLongAddr_t_ptr
is mod 2 ** Long_Integer'Size;
601 type pthreadLongString_t
is mod 2 ** Long_Integer'Size;
603 type pthreadLongUint_t
is mod 2 ** Long_Integer'Size;
604 type pthreadLongUint_array
is array (Natural range <>)
605 of pthreadLongUint_t
;
607 type pthread_t
is mod 2 ** Long_Integer'Size;
609 type pthread_cond_t
is record
612 name
: pthreadLongString_t
;
615 block
: pthreadLongAddr_t_ptr
;
617 for pthread_cond_t
'Size use 8*32;
618 pragma Convention
(C
, pthread_cond_t
);
620 type pthread_attr_t
is record
622 name
: pthreadLongString_t
;
623 arg
: pthreadLongUint_t
;
624 reserved
: pthreadLongUint_array
(0 .. 18);
626 for pthread_attr_t
'Size use 8*176;
627 pragma Convention
(C
, pthread_attr_t
);
629 type pthread_mutex_t
is record
632 name
: pthreadLongString_t
;
635 block
: pthreadLongAddr_p
;
639 for pthread_mutex_t
'Size use 8*40;
640 pragma Convention
(C
, pthread_mutex_t
);
642 type pthread_mutexattr_t
is record
644 reserved
: pthreadLongUint_array
(0 .. 14);
646 for pthread_mutexattr_t
'Size use 8*128;
647 pragma Convention
(C
, pthread_mutexattr_t
);
649 type pthread_condattr_t
is record
651 reserved
: pthreadLongUint_array
(0 .. 12);
653 for pthread_condattr_t
'Size use 8*112;
654 pragma Convention
(C
, pthread_condattr_t
);
656 type pthread_key_t
is new unsigned
;
658 pragma Inline
(pthread_self
);
660 end System
.OS_Interface
;