2010-07-27 Paolo Carlini <paolo.carlini@oracle.com>
[official-gcc/alias-decl.git] / gcc / ada / s-osinte-tru64.adb
blobad391bcb473f00fe1d0723033203639987725aa1
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 -- B o d y --
8 -- --
9 -- Copyright (C) 1998-2009, 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 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 ------------------------------------------------------------------------------
32 -- This is the DEC Unix version of this package
34 -- This package encapsulates all direct interfaces to OS services
35 -- that are needed by children of System.
37 pragma Polling (Off);
38 -- Turn off polling, we do not want ATC polling to take place during
39 -- tasking operations. It causes infinite loops and other problems.
41 with Interfaces.C; use Interfaces.C;
42 with System.Machine_Code; use System.Machine_Code;
44 package body System.OS_Interface is
46 --------------------
47 -- Get_Stack_Base --
48 --------------------
50 function Get_Stack_Base (thread : pthread_t) return Address is
51 pragma Unreferenced (thread);
52 begin
53 return Null_Address;
54 end Get_Stack_Base;
56 ------------------
57 -- pthread_init --
58 ------------------
60 procedure pthread_init is
61 begin
62 null;
63 end pthread_init;
65 ------------------
66 -- pthread_self --
67 ------------------
69 function pthread_self return pthread_t is
70 Self : pthread_t;
71 begin
72 Asm ("call_pal 0x9e" & ASCII.LF & ASCII.HT &
73 "bis $31, $0, %0",
74 Outputs => pthread_t'Asm_Output ("=r", Self),
75 Clobber => "$0",
76 Volatile => True);
77 return Self;
78 end pthread_self;
80 ----------------------
81 -- Hide_Yellow_Zone --
82 ----------------------
84 procedure Hide_Unhide_Yellow_Zone (Hide : Boolean) is
85 type Teb_Ptr is access all pthread_teb_t;
86 Teb : Teb_Ptr;
87 Res : Interfaces.C.int;
88 pragma Unreferenced (Res);
90 begin
91 -- Get the Thread Environment Block address
93 Asm ("call_pal 0x9e" & ASCII.LF & ASCII.HT &
94 "bis $31, $0, %0",
95 Outputs => Teb_Ptr'Asm_Output ("=r", Teb),
96 Clobber => "$0",
97 Volatile => True);
99 -- Stick a guard page right above the Yellow Zone if it exists
101 if Teb.all.stack_yellow /= Teb.all.stack_guard then
102 Res :=
103 mprotect
104 (Teb.all.stack_yellow, Get_Page_Size,
105 prot => (if Hide then PROT_ON else PROT_OFF));
106 end if;
107 end Hide_Unhide_Yellow_Zone;
109 -----------------
110 -- To_Duration --
111 -----------------
113 function To_Duration (TS : timespec) return Duration is
114 begin
115 return Duration (TS.tv_sec) + Duration (TS.tv_nsec) / 10#1#E9;
116 end To_Duration;
118 -----------------
119 -- To_Timespec --
120 -----------------
122 function To_Timespec (D : Duration) return timespec is
123 S : time_t;
124 F : Duration;
126 begin
127 S := time_t (Long_Long_Integer (D));
128 F := D - Duration (S);
130 -- If F has negative value due to a round-up, adjust for positive F
131 -- value.
133 if F < 0.0 then
134 S := S - 1;
135 F := F + 1.0;
136 end if;
138 return timespec'(tv_sec => S,
139 tv_nsec => long (Long_Long_Integer (F * 10#1#E9)));
140 end To_Timespec;
142 end System.OS_Interface;