1
# DP: add support for GNU/kFreeBSD.
3
Index: b/src/gcc/ada/terminals.c
4
===================================================================
5
--- a/src/gcc/ada/terminals.c
6
+++ b/src/gcc/ada/terminals.c
7
@@ -987,6 +987,7 @@ __gnat_setup_winsize (void *desc, int ro
8
/* On some system termio is either absent or including it will disable termios
10
#if ! defined (__hpux__) && ! defined (FREEBSD) && \
11
+ ! defined (__FreeBSD_kernel__) && \
12
! defined (__APPLE__) && ! defined(__rtems__)
15
Index: b/src/gcc/ada/s-osinte-kfreebsd-gnu.adb
16
===================================================================
18
+++ b/src/gcc/ada/s-osinte-kfreebsd-gnu.adb
20
+------------------------------------------------------------------------------
22
+-- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
24
+-- S Y S T E M . O S _ I N T E R F A C E --
28
+-- Copyright (C) 1991-1994, Florida State University --
29
+-- Copyright (C) 1995-2006, AdaCore --
31
+-- GNARL is free software; you can redistribute it and/or modify it under --
32
+-- terms of the GNU General Public License as published by the Free Soft- --
33
+-- ware Foundation; either version 2, or (at your option) any later ver- --
34
+-- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
35
+-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
36
+-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
37
+-- for more details. You should have received a copy of the GNU General --
38
+-- Public License distributed with GNARL; see file COPYING. If not, write --
39
+-- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
40
+-- Boston, MA 02110-1301, USA. --
42
+-- As a special exception, if other files instantiate generics from this --
43
+-- unit, or you link this unit with other files to produce an executable, --
44
+-- this unit does not by itself cause the resulting executable to be --
45
+-- covered by the GNU General Public License. This exception does not --
46
+-- however invalidate any other reasons why the executable file might be --
47
+-- covered by the GNU Public License. --
49
+-- GNARL was developed by the GNARL team at Florida State University. --
50
+-- Extensive contributions were provided by Ada Core Technologies, Inc. --
52
+------------------------------------------------------------------------------
54
+-- This is the GNU/kFreeBSD version of this package.
56
+pragma Polling (Off);
57
+-- Turn off polling, we do not want ATC polling to take place during
58
+-- tasking operations. It causes infinite loops and other problems.
60
+-- This package encapsulates all direct interfaces to OS services
61
+-- that are needed by children of System.
63
+package body System.OS_Interface is
65
+ --------------------
66
+ -- Get_Stack_Base --
67
+ --------------------
69
+ function Get_Stack_Base (thread : pthread_t) return Address is
70
+ pragma Warnings (Off, thread);
73
+ return Null_Address;
80
+ procedure pthread_init is
85
+ -----------------------------------
86
+ -- pthread_mutexattr_setprotocol --
87
+ -----------------------------------
89
+ function pthread_mutexattr_setprotocol
90
+ (attr : access pthread_mutexattr_t;
91
+ protocol : int) return int is
92
+ pragma Unreferenced (attr, protocol);
95
+ end pthread_mutexattr_setprotocol;
97
+ -----------------------------------
98
+ -- pthread_mutexattr_getprotocol --
99
+ -----------------------------------
101
+ function pthread_mutexattr_getprotocol
102
+ (attr : access pthread_mutexattr_t;
103
+ protocol : access int) return int is
104
+ pragma Unreferenced (attr, protocol);
107
+ end pthread_mutexattr_getprotocol;
109
+ --------------------------------------
110
+ -- pthread_mutexattr_setprioceiling --
111
+ --------------------------------------
113
+ function pthread_mutexattr_setprioceiling
114
+ (attr : access pthread_mutexattr_t;
115
+ prioceiling : int) return int is
116
+ pragma Unreferenced (attr, prioceiling);
119
+ end pthread_mutexattr_setprioceiling;
121
+ --------------------------------------
122
+ -- pthread_mutexattr_getprioceiling --
123
+ --------------------------------------
125
+ function pthread_mutexattr_getprioceiling
126
+ (attr : access pthread_mutexattr_t;
127
+ prioceiling : access int) return int is
128
+ pragma Unreferenced (attr, prioceiling);
131
+ end pthread_mutexattr_getprioceiling;
137
+ function To_Duration (TS : timespec) return Duration is
139
+ return Duration (TS.tv_sec) + Duration (TS.tv_nsec) / 10#1#E9;
142
+ ------------------------
143
+ -- To_Target_Priority --
144
+ ------------------------
146
+ function To_Target_Priority
147
+ (Prio : System.Any_Priority) return Interfaces.C.int
150
+ return Interfaces.C.int (Prio);
151
+ end To_Target_Priority;
157
+ function To_Timespec (D : Duration) return timespec is
162
+ S := time_t (Long_Long_Integer (D));
163
+ F := D - Duration (S);
165
+ -- If F has negative value due to a round-up, adjust for positive F
173
+ return timespec'(tv_sec => S,
174
+ tv_nsec => long (Long_Long_Integer (F * 10#1#E9)));
177
+end System.OS_Interface;
178
Index: b/src/gcc/ada/gcc-interface/Makefile.in
179
===================================================================
180
--- a/src/gcc/ada/gcc-interface/Makefile.in
181
+++ b/src/gcc/ada/gcc-interface/Makefile.in
182
@@ -1221,7 +1221,7 @@ ifeq ($(strip $(filter-out %86 kfreebsd%
183
a-intnam.ads<a-intnam-freebsd.ads \
184
s-inmaop.adb<s-inmaop-posix.adb \
185
s-intman.adb<s-intman-posix.adb \
186
- s-osinte.adb<s-osinte-posix.adb \
187
+ s-osinte.adb<s-osinte-kfreebsd-gnu.adb \
188
s-osinte.ads<s-osinte-kfreebsd-gnu.ads \
189
s-osprim.adb<s-osprim-posix.adb \
190
s-taprop.adb<s-taprop-posix.adb \
191
@@ -1252,7 +1252,7 @@ ifeq ($(strip $(filter-out x86_64 kfreeb
192
a-numaux.ads<a-numaux-x86.ads \
193
s-inmaop.adb<s-inmaop-posix.adb \
194
s-intman.adb<s-intman-posix.adb \
195
- s-osinte.adb<s-osinte-posix.adb \
196
+ s-osinte.adb<s-osinte-kfreebsd-gnu.adb \
197
s-osinte.ads<s-osinte-kfreebsd-gnu.ads \
198
s-osprim.adb<s-osprim-posix.adb \
199
s-taprop.adb<s-taprop-posix.adb \
200
Index: b/src/gcc/ada/s-osinte-kfreebsd-gnu.ads
201
===================================================================
202
--- a/src/gcc/ada/s-osinte-kfreebsd-gnu.ads
203
+++ b/src/gcc/ada/s-osinte-kfreebsd-gnu.ads
204
@@ -45,6 +45,7 @@ package System.OS_Interface is
207
pragma Linker_Options ("-lpthread");
208
+ pragma Linker_Options ("-lrt");
210
subtype int is Interfaces.C.int;
211
subtype char is Interfaces.C.char;
212
@@ -206,9 +207,7 @@ package System.OS_Interface is
213
function nanosleep (rqtp, rmtp : access timespec) return int;
214
pragma Import (C, nanosleep, "nanosleep");
216
- type clockid_t is private;
218
- CLOCK_REALTIME : constant clockid_t;
219
+ type clockid_t is new int;
221
function clock_gettime
222
(clock_id : clockid_t;
223
@@ -252,6 +251,16 @@ package System.OS_Interface is
224
function getpid return pid_t;
225
pragma Import (C, getpid, "getpid");
231
+ function lwp_self return System.Address;
232
+ -- lwp_self does not exist on this thread library, revert to pthread_self
233
+ -- which is the closest approximation (with getpid). This function is
234
+ -- needed to share 7staprop.adb across POSIX-like targets.
235
+ pragma Import (C, lwp_self, "pthread_self");
240
@@ -282,6 +291,14 @@ package System.OS_Interface is
241
PTHREAD_SCOPE_PROCESS : constant := 0;
242
PTHREAD_SCOPE_SYSTEM : constant := 2;
244
+ -- Read/Write lock not supported on freebsd. To add support both types
245
+ -- pthread_rwlock_t and pthread_rwlockattr_t must properly be defined
246
+ -- with the associated routines pthread_rwlock_[init/destroy] and
247
+ -- pthread_rwlock_[rdlock/wrlock/unlock].
249
+ subtype pthread_rwlock_t is pthread_mutex_t;
250
+ subtype pthread_rwlockattr_t is pthread_mutexattr_t;
255
@@ -419,31 +436,25 @@ package System.OS_Interface is
256
PTHREAD_PRIO_PROTECT : constant := 2;
257
PTHREAD_PRIO_INHERIT : constant := 1;
259
+ -- GNU/kFreeBSD does not support Thread Priority Protection or Thread
260
+ -- Priority Inheritance and lacks some pthread_mutexattr_* functions.
261
+ -- Replace them with dummy versions.
263
function pthread_mutexattr_setprotocol
264
(attr : access pthread_mutexattr_t;
265
protocol : int) return int;
267
- (C, pthread_mutexattr_setprotocol, "pthread_mutexattr_setprotocol");
269
function pthread_mutexattr_getprotocol
270
(attr : access pthread_mutexattr_t;
271
protocol : access int) return int;
273
- (C, pthread_mutexattr_getprotocol, "pthread_mutexattr_getprotocol");
275
function pthread_mutexattr_setprioceiling
276
(attr : access pthread_mutexattr_t;
277
prioceiling : int) return int;
279
- (C, pthread_mutexattr_setprioceiling,
280
- "pthread_mutexattr_setprioceiling");
282
function pthread_mutexattr_getprioceiling
283
(attr : access pthread_mutexattr_t;
284
prioceiling : access int) return int;
286
- (C, pthread_mutexattr_getprioceiling,
287
- "pthread_mutexattr_getprioceiling");
289
type struct_sched_param is record
290
sched_priority : int; -- scheduling priority
291
@@ -570,8 +581,8 @@ private
292
-- #define sa_handler __sigaction_u._handler
293
-- #define sa_sigaction __sigaction_u._sigaction
295
- -- Should we add a signal_context type here ?
296
- -- How could it be done independent of the CPU architecture ?
297
+ -- Should we add a signal_context type here ???
298
+ -- How could it be done independent of the CPU architecture ???
299
-- sigcontext type is opaque, so it is architecturally neutral.
300
-- It is always passed as an access type, so define it as an empty record
301
-- since the contents are not used anywhere.
302
@@ -588,9 +599,6 @@ private
304
pragma Convention (C, timespec);
306
- type clockid_t is new int;
307
- CLOCK_REALTIME : constant clockid_t := 0;
309
type pthread_attr_t is record
312
Index: b/src/gcc/ada/gsocket.h
313
===================================================================
314
--- a/src/gcc/ada/gsocket.h
315
+++ b/src/gcc/ada/gsocket.h
320
-#if defined (__FreeBSD__) || defined (__vxworks) || defined(__rtems__)
321
+#if defined (__FreeBSD__) || defined (__FreeBSD_kernel__) || defined (__vxworks) || defined(__rtems__) || defined(__GNU__)
322
# define Has_Sockaddr_Len 1
324
# define Has_Sockaddr_Len 0
325
Index: b/src/gcc/ada/s-oscons-tmplt.c
326
===================================================================
327
--- a/src/gcc/ada/s-oscons-tmplt.c
328
+++ b/src/gcc/ada/s-oscons-tmplt.c
329
@@ -1414,7 +1414,7 @@ CND(CLOCK_THREAD_CPUTIME_ID, "Thread CPU
330
/* There's no clock_gettime or clock_id's on Darwin, generate a dummy value */
331
# define CLOCK_RT_Ada "-1"
333
-#elif defined(__FreeBSD__) || defined(_AIX)
334
+#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(_AIX)
335
/** On these platforms use system provided monotonic clock instead of
336
** the default CLOCK_REALTIME. We then need to set up cond var attributes
337
** appropriately (see thread.c).