1------------------------------------------------------------------------------ 2-- -- 3-- GNU ADA RUN-TIME LIBRARY (GNARL) COMPONENTS -- 4-- -- 5-- S Y S T E M . O S _ I N T E R F A C E -- 6-- -- 7-- S p e c -- 8-- -- 9-- Copyright (C) 1999-2003 Free Software Foundation, Inc. -- 10-- -- 11-- GNARL 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 2, or (at your option) any later ver- -- 14-- sion. GNARL 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. See the GNU General Public License -- 17-- for more details. You should have received a copy of the GNU General -- 18-- Public License distributed with GNARL; see file COPYING. If not, write -- 19-- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, -- 20-- MA 02111-1307, USA. -- 21-- -- 22-- As a special exception, if other files instantiate generics from this -- 23-- unit, or you link this unit with other files to produce an executable, -- 24-- this unit does not by itself cause the resulting executable to be -- 25-- covered by the GNU General Public License. This exception does not -- 26-- however invalidate any other reasons why the executable file might be -- 27-- covered by the GNU Public License. -- 28-- -- 29-- GNARL was developed by the GNARL team at Florida State University. -- 30-- Extensive contributions were provided by Ada Core Technologies, Inc. -- 31-- -- 32------------------------------------------------------------------------------ 33 34-- This is a HPUX 11.0 (Native THREADS) version of this package. 35 36-- This package encapsulates all direct interfaces to OS services 37-- that are needed by children of System. 38 39-- PLEASE DO NOT add any with-clauses to this package 40-- or remove the pragma Elaborate_Body. 41-- It is designed to be a bottom-level (leaf) package. 42 43with Interfaces.C; 44package System.OS_Interface is 45 pragma Preelaborate; 46 47 pragma Linker_Options ("-lpthread"); 48 49 subtype int is Interfaces.C.int; 50 subtype short is Interfaces.C.short; 51 subtype long is Interfaces.C.long; 52 subtype unsigned is Interfaces.C.unsigned; 53 subtype unsigned_short is Interfaces.C.unsigned_short; 54 subtype unsigned_long is Interfaces.C.unsigned_long; 55 subtype unsigned_char is Interfaces.C.unsigned_char; 56 subtype plain_char is Interfaces.C.plain_char; 57 subtype size_t is Interfaces.C.size_t; 58 59 ----------- 60 -- Errno -- 61 ----------- 62 63 function errno return int; 64 pragma Import (C, errno, "__get_errno"); 65 66 EAGAIN : constant := 11; 67 EINTR : constant := 4; 68 EINVAL : constant := 22; 69 ENOMEM : constant := 12; 70 ETIMEDOUT : constant := 238; 71 72 ------------- 73 -- Signals -- 74 ------------- 75 76 Max_Interrupt : constant := 44; 77 type Signal is new int range 0 .. Max_Interrupt; 78 for Signal'Size use int'Size; 79 80 SIGHUP : constant := 1; -- hangup 81 SIGINT : constant := 2; -- interrupt (rubout) 82 SIGQUIT : constant := 3; -- quit (ASCD FS) 83 SIGILL : constant := 4; -- illegal instruction (not reset) 84 SIGTRAP : constant := 5; -- trace trap (not reset) 85 SIGIOT : constant := 6; -- IOT instruction 86 SIGABRT : constant := 6; -- used by abort, replace SIGIOT in the future 87 SIGEMT : constant := 7; -- EMT instruction 88 SIGFPE : constant := 8; -- floating point exception 89 SIGKILL : constant := 9; -- kill (cannot be caught or ignored) 90 SIGBUS : constant := 10; -- bus error 91 SIGSEGV : constant := 11; -- segmentation violation 92 SIGSYS : constant := 12; -- bad argument to system call 93 SIGPIPE : constant := 13; -- write on a pipe with no one to read it 94 SIGALRM : constant := 14; -- alarm clock 95 SIGTERM : constant := 15; -- software termination signal from kill 96 SIGUSR1 : constant := 16; -- user defined signal 1 97 SIGUSR2 : constant := 17; -- user defined signal 2 98 SIGCLD : constant := 18; -- alias for SIGCHLD 99 SIGCHLD : constant := 18; -- child status change 100 SIGPWR : constant := 19; -- power-fail restart 101 SIGVTALRM : constant := 20; -- virtual timer alarm 102 SIGPROF : constant := 21; -- profiling timer alarm 103 SIGIO : constant := 22; -- asynchronous I/O 104 SIGPOLL : constant := 22; -- pollable event occurred 105 SIGWINCH : constant := 23; -- window size change 106 SIGSTOP : constant := 24; -- stop (cannot be caught or ignored) 107 SIGTSTP : constant := 25; -- user stop requested from tty 108 SIGCONT : constant := 26; -- stopped process has been continued 109 SIGTTIN : constant := 27; -- background tty read attempted 110 SIGTTOU : constant := 28; -- background tty write attempted 111 SIGURG : constant := 29; -- urgent condition on IO channel 112 SIGLOST : constant := 30; -- remote lock lost (NFS) 113 SIGDIL : constant := 32; -- DIL signal 114 SIGXCPU : constant := 33; -- CPU time limit exceeded (setrlimit) 115 SIGXFSZ : constant := 34; -- file size limit exceeded (setrlimit) 116 SIGCANCEL : constant := 35; -- used for pthread cancellation. 117 SIGGFAULT : constant := 36; -- Graphics framebuffer fault 118 119 SIGADAABORT : constant := SIGABRT; 120 -- Note: on other targets, we usually use SIGABRT, but on HPUX, it 121 -- appears that SIGABRT can't be used in sigwait(), so we use SIGTERM. 122 123 type Signal_Set is array (Natural range <>) of Signal; 124 125 Unmasked : constant Signal_Set := 126 (SIGABRT, SIGPIPE, SIGBUS, SIGTRAP, SIGTTIN, SIGTTOU, SIGTSTP, SIGPROF, 127 SIGALRM, SIGVTALRM, SIGIO, SIGCHLD); 128 129 Reserved : constant Signal_Set := (SIGKILL, SIGSTOP); 130 131 type sigset_t is private; 132 133 function sigaddset (set : access sigset_t; sig : Signal) return int; 134 pragma Import (C, sigaddset, "sigaddset"); 135 136 function sigdelset (set : access sigset_t; sig : Signal) return int; 137 pragma Import (C, sigdelset, "sigdelset"); 138 139 function sigfillset (set : access sigset_t) return int; 140 pragma Import (C, sigfillset, "sigfillset"); 141 142 function sigismember (set : access sigset_t; sig : Signal) return int; 143 pragma Import (C, sigismember, "sigismember"); 144 145 function sigemptyset (set : access sigset_t) return int; 146 pragma Import (C, sigemptyset, "sigemptyset"); 147 148 type struct_sigaction is record 149 sa_handler : System.Address; 150 sa_mask : sigset_t; 151 sa_flags : int; 152 end record; 153 pragma Convention (C, struct_sigaction); 154 type struct_sigaction_ptr is access all struct_sigaction; 155 156 SA_SIGINFO : constant := 16#10#; 157 158 SIG_BLOCK : constant := 0; 159 SIG_UNBLOCK : constant := 1; 160 SIG_SETMASK : constant := 2; 161 162 SIG_DFL : constant := 0; 163 SIG_IGN : constant := 1; 164 165 function sigaction 166 (sig : Signal; 167 act : struct_sigaction_ptr; 168 oact : struct_sigaction_ptr) return int; 169 pragma Import (C, sigaction, "sigaction"); 170 171 ---------- 172 -- Time -- 173 ---------- 174 175 Time_Slice_Supported : constant Boolean := True; 176 -- Indicates wether time slicing is supported 177 178 type timespec is private; 179 180 type clockid_t is private; 181 182 CLOCK_REALTIME : constant clockid_t; 183 184 function clock_gettime 185 (clock_id : clockid_t; 186 tp : access timespec) return int; 187 pragma Import (C, clock_gettime, "clock_gettime"); 188 189 function clock_getres 190 (clock_id : clockid_t; 191 res : access timespec) return int; 192 pragma Import (C, clock_getres, "clock_getres"); 193 194 function To_Duration (TS : timespec) return Duration; 195 pragma Inline (To_Duration); 196 197 function To_Timespec (D : Duration) return timespec; 198 pragma Inline (To_Timespec); 199 200 type struct_timezone is record 201 tz_minuteswest : int; 202 tz_dsttime : int; 203 end record; 204 pragma Convention (C, struct_timezone); 205 type struct_timezone_ptr is access all struct_timezone; 206 207 type struct_timeval is private; 208 -- This is needed on systems that do not have clock_gettime() 209 -- but do have gettimeofday(). 210 211 function To_Duration (TV : struct_timeval) return Duration; 212 pragma Inline (To_Duration); 213 214 function To_Timeval (D : Duration) return struct_timeval; 215 pragma Inline (To_Timeval); 216 217 ------------------------- 218 -- Priority Scheduling -- 219 ------------------------- 220 221 SCHED_FIFO : constant := 0; 222 SCHED_RR : constant := 1; 223 SCHED_OTHER : constant := 2; 224 225 ------------- 226 -- Process -- 227 ------------- 228 229 type pid_t is private; 230 231 function kill (pid : pid_t; sig : Signal) return int; 232 pragma Import (C, kill, "kill"); 233 234 function getpid return pid_t; 235 pragma Import (C, getpid, "getpid"); 236 237 --------- 238 -- LWP -- 239 --------- 240 241 function lwp_self return System.Address; 242 pragma Import (C, lwp_self, "_lwp_self"); 243 244 ------------- 245 -- Threads -- 246 ------------- 247 248 type Thread_Body is access 249 function (arg : System.Address) return System.Address; 250 type pthread_t is private; 251 subtype Thread_Id is pthread_t; 252 253 type pthread_mutex_t is limited private; 254 type pthread_cond_t is limited private; 255 type pthread_attr_t is limited private; 256 type pthread_mutexattr_t is limited private; 257 type pthread_condattr_t is limited private; 258 type pthread_key_t is private; 259 260 PTHREAD_CREATE_DETACHED : constant := 16#de#; 261 262 ----------- 263 -- Stack -- 264 ----------- 265 266 Stack_Base_Available : constant Boolean := False; 267 -- Indicates wether the stack base is available on this target. 268 269 function Get_Stack_Base (thread : pthread_t) return Address; 270 pragma Inline (Get_Stack_Base); 271 -- returns the stack base of the specified thread. 272 -- Only call this function when Stack_Base_Available is True. 273 274 function Get_Page_Size return size_t; 275 function Get_Page_Size return Address; 276 pragma Import (C, Get_Page_Size, "getpagesize"); 277 -- returns the size of a page, or 0 if this is not relevant on this 278 -- target 279 280 PROT_NONE : constant := 0; 281 PROT_READ : constant := 1; 282 PROT_WRITE : constant := 2; 283 PROT_EXEC : constant := 4; 284 PROT_ALL : constant := PROT_READ + PROT_WRITE + PROT_EXEC; 285 286 PROT_ON : constant := PROT_READ; 287 PROT_OFF : constant := PROT_ALL; 288 289 function mprotect (addr : Address; len : size_t; prot : int) return int; 290 pragma Import (C, mprotect); 291 292 --------------------------------------- 293 -- Nonstandard Thread Initialization -- 294 --------------------------------------- 295 296 procedure pthread_init; 297 pragma Inline (pthread_init); 298 -- This is a dummy procedure to share some GNULLI files 299 300 ------------------------- 301 -- POSIX.1c Section 3 -- 302 ------------------------- 303 304 function sigwait 305 (set : access sigset_t; 306 sig : access Signal) return int; 307 pragma Import (C, sigwait, "sigwait"); 308 309 function pthread_kill 310 (thread : pthread_t; 311 sig : Signal) return int; 312 pragma Import (C, pthread_kill, "pthread_kill"); 313 314 type sigset_t_ptr is access all sigset_t; 315 316 function pthread_sigmask 317 (how : int; 318 set : sigset_t_ptr; 319 oset : sigset_t_ptr) return int; 320 pragma Import (C, pthread_sigmask, "pthread_sigmask"); 321 322 -------------------------- 323 -- POSIX.1c Section 11 -- 324 -------------------------- 325 326 function pthread_mutexattr_init 327 (attr : access pthread_mutexattr_t) return int; 328 pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init"); 329 330 function pthread_mutexattr_destroy 331 (attr : access pthread_mutexattr_t) return int; 332 pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy"); 333 334 function pthread_mutex_init 335 (mutex : access pthread_mutex_t; 336 attr : access pthread_mutexattr_t) return int; 337 pragma Import (C, pthread_mutex_init, "pthread_mutex_init"); 338 339 function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int; 340 pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy"); 341 342 function pthread_mutex_lock (mutex : access pthread_mutex_t) return int; 343 pragma Import (C, pthread_mutex_lock, "pthread_mutex_lock"); 344 345 function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int; 346 pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock"); 347 348 function pthread_condattr_init 349 (attr : access pthread_condattr_t) return int; 350 pragma Import (C, pthread_condattr_init, "pthread_condattr_init"); 351 352 function pthread_condattr_destroy 353 (attr : access pthread_condattr_t) return int; 354 pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy"); 355 356 function pthread_cond_init 357 (cond : access pthread_cond_t; 358 attr : access pthread_condattr_t) return int; 359 pragma Import (C, pthread_cond_init, "pthread_cond_init"); 360 361 function pthread_cond_destroy (cond : access pthread_cond_t) return int; 362 pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy"); 363 364 function pthread_cond_signal (cond : access pthread_cond_t) return int; 365 pragma Import (C, pthread_cond_signal, "pthread_cond_signal"); 366 367 function pthread_cond_wait 368 (cond : access pthread_cond_t; 369 mutex : access pthread_mutex_t) return int; 370 pragma Import (C, pthread_cond_wait, "pthread_cond_wait"); 371 372 function pthread_cond_timedwait 373 (cond : access pthread_cond_t; 374 mutex : access pthread_mutex_t; 375 abstime : access timespec) return int; 376 pragma Import (C, pthread_cond_timedwait, "pthread_cond_timedwait"); 377 378 Relative_Timed_Wait : constant Boolean := False; 379 -- pthread_cond_timedwait requires an absolute delay time 380 381 ---------------------------- 382 -- POSIX.1c Section 13 -- 383 ---------------------------- 384 385 PTHREAD_PRIO_NONE : constant := 16#100#; 386 PTHREAD_PRIO_PROTECT : constant := 16#200#; 387 PTHREAD_PRIO_INHERIT : constant := 16#400#; 388 389 function pthread_mutexattr_setprotocol 390 (attr : access pthread_mutexattr_t; 391 protocol : int) return int; 392 pragma Import (C, pthread_mutexattr_setprotocol); 393 394 function pthread_mutexattr_setprioceiling 395 (attr : access pthread_mutexattr_t; 396 prioceiling : int) return int; 397 pragma Import (C, pthread_mutexattr_setprioceiling); 398 399 type Array_7_Int is array (0 .. 6) of int; 400 type struct_sched_param is record 401 sched_priority : int; 402 sched_reserved : Array_7_Int; 403 end record; 404 405 function pthread_setschedparam 406 (thread : pthread_t; 407 policy : int; 408 param : access struct_sched_param) 409 return int; 410 pragma Import (C, pthread_setschedparam, "pthread_setschedparam"); 411 412 function pthread_attr_setscope 413 (attr : access pthread_attr_t; 414 contentionscope : int) return int; 415 pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope"); 416 417 function pthread_attr_setinheritsched 418 (attr : access pthread_attr_t; 419 inheritsched : int) return int; 420 pragma Import (C, pthread_attr_setinheritsched); 421 422 function pthread_attr_setschedpolicy 423 (attr : access pthread_attr_t; 424 policy : int) return int; 425 pragma Import (C, pthread_attr_setschedpolicy); 426 427 function sched_yield return int; 428 pragma Import (C, sched_yield, "sched_yield"); 429 430 --------------------------- 431 -- P1003.1c - Section 16 -- 432 --------------------------- 433 434 function pthread_attr_init 435 (attributes : access pthread_attr_t) return int; 436 pragma Import (C, pthread_attr_init, "__pthread_attr_init_system"); 437 438 function pthread_attr_destroy 439 (attributes : access pthread_attr_t) return int; 440 pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy"); 441 442 function pthread_attr_setdetachstate 443 (attr : access pthread_attr_t; 444 detachstate : int) return int; 445 pragma Import (C, pthread_attr_setdetachstate); 446 447 function pthread_attr_setstacksize 448 (attr : access pthread_attr_t; 449 stacksize : size_t) return int; 450 pragma Import (C, pthread_attr_setstacksize, "pthread_attr_setstacksize"); 451 452 function pthread_create 453 (thread : access pthread_t; 454 attributes : access pthread_attr_t; 455 start_routine : Thread_Body; 456 arg : System.Address) return int; 457 pragma Import (C, pthread_create, "__pthread_create_system"); 458 459 procedure pthread_exit (status : System.Address); 460 pragma Import (C, pthread_exit, "pthread_exit"); 461 462 function pthread_self return pthread_t; 463 pragma Import (C, pthread_self, "pthread_self"); 464 465 -------------------------- 466 -- POSIX.1c Section 17 -- 467 -------------------------- 468 469 function pthread_setspecific 470 (key : pthread_key_t; 471 value : System.Address) return int; 472 pragma Import (C, pthread_setspecific, "pthread_setspecific"); 473 474 function pthread_getspecific (key : pthread_key_t) return System.Address; 475 pragma Import (C, pthread_getspecific, "pthread_getspecific"); 476 477 type destructor_pointer is access procedure (arg : System.Address); 478 479 function pthread_key_create 480 (key : access pthread_key_t; 481 destructor : destructor_pointer) return int; 482 pragma Import (C, pthread_key_create, "pthread_key_create"); 483 484private 485 486 type unsigned_int_array_8 is array (0 .. 7) of unsigned; 487 type sigset_t is record 488 sigset : unsigned_int_array_8; 489 end record; 490 pragma Convention (C_Pass_By_Copy, sigset_t); 491 492 type pid_t is new int; 493 494 type time_t is new long; 495 496 type timespec is record 497 tv_sec : time_t; 498 tv_nsec : long; 499 end record; 500 pragma Convention (C, timespec); 501 502 type clockid_t is new int; 503 CLOCK_REALTIME : constant clockid_t := 1; 504 505 type struct_timeval is record 506 tv_sec : time_t; 507 tv_usec : time_t; 508 end record; 509 pragma Convention (C, struct_timeval); 510 511 type pthread_attr_t is new int; 512 type pthread_condattr_t is new int; 513 type pthread_mutexattr_t is new int; 514 type pthread_t is new int; 515 516 type short_array is array (Natural range <>) of short; 517 type int_array is array (Natural range <>) of int; 518 519 type pthread_mutex_t is record 520 m_short : short_array (0 .. 1); 521 m_int : int; 522 m_int1 : int_array (0 .. 3); 523 m_pad : int; -- needed for 32 bit ABI, but *not* for 64 bit 524 m_ptr : System.Address; 525 m_int2 : int_array (0 .. 1); 526 m_int3 : int_array (0 .. 3); 527 m_short2 : short_array (0 .. 1); 528 m_int4 : int_array (0 .. 4); 529 m_int5 : int_array (0 .. 1); 530 end record; 531 pragma Convention (C, pthread_mutex_t); 532 533 type pthread_cond_t is record 534 c_short : short_array (0 .. 1); 535 c_int : int; 536 c_int1 : int_array (0 .. 3); 537 m_pad : int; -- needed for 32 bit ABI, but *not* for 64 bit 538 m_ptr : System.Address; 539 c_int2 : int_array (0 .. 1); 540 c_int3 : int_array (0 .. 1); 541 c_int4 : int_array (0 .. 1); 542 end record; 543 pragma Convention (C, pthread_cond_t); 544 545 type pthread_key_t is new int; 546 547end System.OS_Interface; 548