2015-09-28 Paul Thomas <pault@gcc.gnu.org>
[official-gcc.git] / gcc / ada / sysdep.c
blob01dae2bf1fc24a8181c29ce516d46c4f5d2843f8
1 /****************************************************************************
2 * *
3 * GNAT COMPILER COMPONENTS *
4 * *
5 * S Y S D E P *
6 * *
7 * C Implementation File *
8 * *
9 * Copyright (C) 1992-2015, Free Software Foundation, Inc. *
10 * *
11 * GNAT 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 * GNAT was originally developed by the GNAT team at New York University. *
28 * Extensive contributions were provided by Ada Core Technologies Inc. *
29 * *
30 ****************************************************************************/
32 /* This file contains system dependent symbols that are referenced in the
33 GNAT Run Time Library */
35 #ifdef __vxworks
36 #include "ioLib.h"
37 #if ! defined (VTHREADS)
38 #include "dosFsLib.h"
39 #endif
40 #if ! defined (__RTP__) && (! defined (VTHREADS) || defined (__VXWORKSMILS__))
41 # include "nfsLib.h"
42 #endif
43 #include "selectLib.h"
44 #include "vxWorks.h"
45 #include "version.h"
46 #if defined (__RTP__)
47 # include "vwModNum.h"
48 #endif /* __RTP__ */
49 #endif
51 #ifdef __ANDROID__
52 #undef __linux__
53 #endif
55 #ifdef IN_RTS
56 #define POSIX
57 #include "tconfig.h"
58 #include "tsystem.h"
59 #include <fcntl.h>
60 #include <sys/stat.h>
61 #else
62 #include "config.h"
63 #include "system.h"
64 #endif
66 #include <time.h>
67 #include <errno.h>
69 #if defined (__sun__) && !defined (__vxworks)
70 /* The declaration is present in <time.h> but conditionalized
71 on a couple of macros we don't define. */
72 extern struct tm *localtime_r(const time_t *, struct tm *);
73 #endif
75 #include "adaint.h"
77 /* Don't use macros versions of this functions on VxWorks since they cause
78 imcompatible changes in some VxWorks versions */
79 #ifdef __vxworks
80 #undef getchar
81 #undef putchar
82 #undef feof
83 #undef ferror
84 #undef fileno
85 #endif
88 Notes:
90 (1) Opening a file with read mode fails if the file does not exist or
91 cannot be read.
93 (2) Opening a file with append mode causes all subsequent writes to the
94 file to be forced to the then current end-of-file, regardless of
95 intervening calls to the fseek function.
97 (3) When a file is opened with update mode, both input and output may be
98 performed on the associated stream. However, output may not be directly
99 followed by input without an intervening call to the fflush function or
100 to a file positioning function (fseek, fsetpos, or rewind), and input
101 may not be directly followed by output without an intervening call to a
102 file positioning function, unless the input operation encounters
103 end-of-file.
105 The other target dependent declarations here are for the three functions
106 __gnat_set_binary_mode, __gnat_set_text_mode and __gnat_set_mode:
108 void __gnat_set_binary_mode (int handle);
109 void __gnat_set_text_mode (int handle);
110 void __gnat_set_mode (int handle, int mode);
112 These functions have no effect in Unix (or similar systems where there is
113 no distinction between binary and text files), but in DOS (and similar
114 systems where text mode does CR/LF translation), these functions allow
115 the mode of the stream with the given handle (fileno can be used to get
116 the handle of a stream) to be changed dynamically. The returned result
117 is 0 if no error occurs and -1 if an error occurs.
119 Finally there is a boolean (character) variable
121 char __gnat_text_translation_required;
123 which is zero (false) in Unix mode, and one (true) in DOS mode, with a
124 true value indicating that text translation is required on text files
125 and that fopen supports the trailing t and b modifiers.
129 #if defined (WINNT) || defined (__CYGWIN__)
131 const char __gnat_text_translation_required = 1;
133 #ifdef __CYGWIN__
134 #define WIN_SETMODE setmode
135 #include <io.h>
136 #else
137 #define WIN_SETMODE _setmode
138 #endif
140 void
141 __gnat_set_binary_mode (int handle)
143 WIN_SETMODE (handle, O_BINARY);
146 void
147 __gnat_set_text_mode (int handle)
149 WIN_SETMODE (handle, O_TEXT);
152 void
153 __gnat_set_mode (int handle, int mode)
155 /* the values here must be synchronized with
156 System.File_Control_Block.Content_Encodding:
158 None = 0
159 Default_Text = 1
160 Text = 2
161 U8text = 3
162 Wtext = 4
163 U16text = 5 */
165 switch (mode) {
166 case 0 : WIN_SETMODE (handle, _O_BINARY); break;
167 case 1 : WIN_SETMODE (handle, CurrentCCSEncoding); break;
168 case 2 : WIN_SETMODE (handle, _O_TEXT); break;
169 case 3 : WIN_SETMODE (handle, _O_U8TEXT); break;
170 case 4 : WIN_SETMODE (handle, _O_WTEXT); break;
171 case 5 : WIN_SETMODE (handle, _O_U16TEXT); break;
175 #ifdef __CYGWIN__
177 char *
178 __gnat_ttyname (int filedes)
180 extern char *ttyname (int);
182 return ttyname (filedes);
185 #endif /* __CYGWIN__ */
187 #if defined (__CYGWIN__) || defined (__MINGW32__)
188 #include <windows.h>
190 int __gnat_is_windows_xp (void);
193 __gnat_is_windows_xp (void)
195 static int is_win_xp=0, is_win_xp_checked=0;
197 if (!is_win_xp_checked)
199 OSVERSIONINFO version;
201 is_win_xp_checked = 1;
203 memset (&version, 0, sizeof (version));
204 version.dwOSVersionInfoSize = sizeof (version);
206 is_win_xp = GetVersionEx (&version)
207 && version.dwPlatformId == VER_PLATFORM_WIN32_NT
208 && (version.dwMajorVersion > 5
209 || (version.dwMajorVersion == 5 && version.dwMinorVersion >= 1));
211 return is_win_xp;
214 /* Get the bounds of the stack. The stack pointer is supposed to be
215 initialized to BASE when a thread is created and the stack can be extended
216 to LIMIT before reaching a guard page.
217 Note: for the main thread, the system automatically extend the stack, so
218 LIMIT is only the current limit. */
220 void
221 __gnat_get_stack_bounds (void **base, void **limit)
223 NT_TIB *tib;
225 /* We know that the first field of the TEB is the TIB. */
226 tib = (NT_TIB *)NtCurrentTeb ();
228 *base = tib->StackBase;
229 *limit = tib->StackLimit;
232 #endif /* __CYGWIN__ || __MINGW32__ */
234 #ifdef __MINGW32__
236 /* Return the name of the tty. Under windows there is no name for
237 the tty, so this function, if connected to a tty, returns the generic name
238 "console". */
240 char *
241 __gnat_ttyname (int filedes)
243 if (isatty (filedes))
244 return "console";
245 else
246 return NULL;
249 #endif /* __MINGW32__ */
251 #else
253 const char __gnat_text_translation_required = 0;
255 /* These functions do nothing in non-DOS systems. */
257 void
258 __gnat_set_binary_mode (int handle ATTRIBUTE_UNUSED)
262 void
263 __gnat_set_text_mode (int handle ATTRIBUTE_UNUSED)
267 void
268 __gnat_set_mode (int handle ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
272 char *
273 __gnat_ttyname (int filedes)
275 #if defined (__vxworks)
276 return "";
277 #else
278 extern char *ttyname (int);
280 return ttyname (filedes);
281 #endif /* defined (__vxworks) */
283 #endif
285 #if defined (__linux__) || defined (__sun__) \
286 || defined (WINNT) \
287 || defined (__MACHTEN__) || defined (__hpux__) || defined (_AIX) \
288 || (defined (__svr4__) && defined (__i386__)) || defined (__Lynx__) \
289 || defined (__CYGWIN__) || defined (__FreeBSD__) || defined (__OpenBSD__) \
290 || defined (__GLIBC__) || defined (__APPLE__) || defined (__DragonFly__)
292 # ifdef __MINGW32__
293 # if OLD_MINGW
294 # include <termios.h>
295 # else
296 # include <conio.h> /* for getch(), kbhit() */
297 # endif
298 # else
299 # include <termios.h>
300 # endif
302 #endif
304 /* Implements the common processing for getc_immediate and
305 getc_immediate_nowait. */
307 extern void getc_immediate (FILE *, int *, int *);
308 extern void getc_immediate_nowait (FILE *, int *, int *, int *);
309 extern void getc_immediate_common (FILE *, int *, int *, int *, int);
311 /* Called by Get_Immediate (Foo); */
313 void
314 getc_immediate (FILE *stream, int *ch, int *end_of_file)
316 int avail;
318 getc_immediate_common (stream, ch, end_of_file, &avail, 1);
321 /* Called by Get_Immediate (Foo, Available); */
323 void
324 getc_immediate_nowait (FILE *stream, int *ch, int *end_of_file, int *avail)
326 getc_immediate_common (stream, ch, end_of_file, avail, 0);
329 /* Called by getc_immediate () and getc_immediate_nowait () */
331 void
332 getc_immediate_common (FILE *stream,
333 int *ch,
334 int *end_of_file,
335 int *avail,
336 int waiting ATTRIBUTE_UNUSED)
338 #if defined (__linux__) || defined (__sun__) \
339 || defined (__CYGWIN32__) || defined (__MACHTEN__) || defined (__hpux__) \
340 || defined (_AIX) || (defined (__svr4__) && defined (__i386__)) \
341 || defined (__Lynx__) || defined (__FreeBSD__) || defined (__OpenBSD__) \
342 || defined (__GLIBC__) || defined (__APPLE__) || defined (__DragonFly__)
343 char c;
344 int nread;
345 int good_one = 0;
346 int eof_ch = 4; /* Ctrl-D */
347 int fd = fileno (stream);
348 struct termios otermios_rec, termios_rec;
350 if (isatty (fd))
352 tcgetattr (fd, &termios_rec);
353 memcpy (&otermios_rec, &termios_rec, sizeof (struct termios));
355 /* Set RAW mode, with no echo */
356 termios_rec.c_lflag = termios_rec.c_lflag & ~ICANON & ~ECHO;
358 #if defined (__linux__) || defined (__sun__) \
359 || defined (__MACHTEN__) || defined (__hpux__) \
360 || defined (_AIX) || (defined (__svr4__) && defined (__i386__)) \
361 || defined (__Lynx__) || defined (__FreeBSD__) || defined (__OpenBSD__) \
362 || defined (__GLIBC__) || defined (__APPLE__) || defined (__DragonFly__)
363 eof_ch = termios_rec.c_cc[VEOF];
365 /* If waiting (i.e. Get_Immediate (Char)), set MIN = 1 and wait for
366 a character forever. This doesn't seem to effect Ctrl-Z or
367 Ctrl-C processing.
368 If not waiting (i.e. Get_Immediate (Char, Available)),
369 don't wait for anything but timeout immediately. */
370 termios_rec.c_cc[VMIN] = waiting;
371 termios_rec.c_cc[VTIME] = 0;
372 #endif
373 tcsetattr (fd, TCSANOW, &termios_rec);
375 while (! good_one)
377 /* Read is used here instead of fread, because fread doesn't
378 work on Solaris5 and Sunos4 in this situation. Maybe because we
379 are mixing calls that use file descriptors and streams. */
380 nread = read (fd, &c, 1);
381 if (nread > 0)
383 /* On Unix terminals, Ctrl-D (EOT) is an End of File. */
384 if (c == eof_ch)
386 *avail = 0;
387 *end_of_file = 1;
388 good_one = 1;
391 /* Everything else is ok */
392 else if (c != eof_ch)
394 *avail = 1;
395 *end_of_file = 0;
396 good_one = 1;
400 else if (! waiting)
402 *avail = 0;
403 *end_of_file = 0;
404 good_one = 1;
406 else
407 good_one = 0;
410 tcsetattr (fd, TCSANOW, &otermios_rec);
411 *ch = c;
414 else
415 #elif defined (__MINGW32__)
416 int fd = fileno (stream);
417 int char_waiting;
418 int eot_ch = 4; /* Ctrl-D */
420 if (isatty (fd))
422 if (waiting)
424 *ch = getch ();
426 if (*ch == eot_ch)
427 *end_of_file = 1;
428 else
429 *end_of_file = 0;
431 *avail = 1;
433 else /* ! waiting */
435 char_waiting = kbhit();
437 if (char_waiting == 1)
439 *avail = 1;
440 *ch = getch ();
442 if (*ch == eot_ch)
443 *end_of_file = 1;
444 else
445 *end_of_file = 0;
447 else
449 *avail = 0;
450 *end_of_file = 0;
454 else
455 #elif defined (__vxworks)
456 /* Bit masks of file descriptors to read from. */
457 struct fd_set readFds;
458 /* Timeout before select returns if nothing can be read. */
459 struct timeval timeOut;
460 char c;
461 int fd = fileno (stream);
462 int nread;
463 int option;
464 int readable;
465 int status;
466 int width;
468 if (isatty (fd))
470 /* If we do not want to wait, we have to set up fd in RAW mode. This
471 should be done outside this function as setting fd in RAW mode under
472 vxWorks flushes the buffer of fd. If the RAW mode was set here, the
473 buffer would be empty and we would always return that no character
474 is available */
475 if (! waiting)
477 /* Initialization of timeOut for its use with select. */
478 timeOut.tv_sec = 0;
479 timeOut.tv_usec = 0;
481 /* Initialization of readFds for its use with select;
482 FD is the only file descriptor to be monitored */
483 FD_ZERO (&readFds);
484 FD_SET (fd, &readFds);
485 width = 2;
487 /* We do all this processing to emulate a non blocking read. */
488 readable = select (width, &readFds, NULL, NULL, &timeOut);
489 if (readable == ERROR)
490 *avail = -1, *end_of_file = -1;
491 /* No character available in input. */
492 else if (readable == 0)
493 *avail = 0, *end_of_file = 0;
494 else
496 nread = read (fd, &c, 1);
497 if (nread > 0)
498 *avail = 1, *end_of_file = 0;
499 /* End Of File. */
500 else if (nread == 0)
501 *avail = 0, *end_of_file = 1;
502 /* Error. */
503 else
504 *avail = -1, *end_of_file = -1;
508 /* We have to wait until we get a character */
509 else
511 *avail = -1;
512 *end_of_file = -1;
514 /* Save the current mode of FD. */
515 option = ioctl (fd, FIOGETOPTIONS, 0);
517 /* Set FD in RAW mode. */
518 status = ioctl (fd, FIOSETOPTIONS, OPT_RAW);
519 if (status != -1)
521 nread = read (fd, &c, 1);
522 if (nread > 0)
523 *avail = 1, *end_of_file = 0;
524 /* End of file. */
525 else if (nread == 0)
526 *avail = 0, *end_of_file = 1;
527 /* Else there is an ERROR. */
530 /* Revert FD to its previous mode. */
531 status = ioctl (fd, FIOSETOPTIONS, option);
534 *ch = c;
536 else
537 #endif
539 /* If we're not on a terminal, then we don't need any fancy processing.
540 Also this is the only thing that's left if we're not on one of the
541 supported systems; which means that for non supported systems,
542 get_immediate may wait for a carriage return on terminals. */
543 *ch = fgetc (stream);
544 if (feof (stream))
546 *end_of_file = 1;
547 *avail = 0;
549 else
551 *end_of_file = 0;
552 *avail = 1;
557 /* The following definitions are provided in NT to support Windows based
558 Ada programs. */
560 #ifdef WINNT
561 #include <windows.h>
563 /* Provide functions to echo the values passed to WinMain (windows bindings
564 will want to import these). We use the same names as the routines used
565 by AdaMagic for compatibility. */
567 char *rts_get_hInstance (void);
568 char *rts_get_hPrevInstance (void);
569 char *rts_get_lpCommandLine (void);
570 int rts_get_nShowCmd (void);
572 char *
573 rts_get_hInstance (void)
575 return (char *)GetModuleHandleA (0);
578 char *
579 rts_get_hPrevInstance (void)
581 return 0;
584 char *
585 rts_get_lpCommandLine (void)
587 return GetCommandLineA ();
591 rts_get_nShowCmd (void)
593 return 1;
596 #endif /* WINNT */
598 /* This value is returned as the time zone offset when a valid value
599 cannot be determined. It is simply a bizarre value that will never
600 occur. It is 3 days plus 73 seconds (offset is in seconds). */
602 long __gnat_invalid_tzoff = 259273;
604 /* Definition of __gnat_localtime_r used by a-calend.adb */
606 #if defined (__MINGW32__)
608 #ifdef CERT
610 /* For the Cert run times on native Windows we use dummy functions
611 for locking and unlocking tasks since we do not support multiple
612 threads on this configuration (Cert run time on native Windows). */
614 void dummy (void) {}
616 void (*Lock_Task) () = &dummy;
617 void (*Unlock_Task) () = &dummy;
619 #else
621 #define Lock_Task system__soft_links__lock_task
622 extern void (*Lock_Task) (void);
624 #define Unlock_Task system__soft_links__unlock_task
625 extern void (*Unlock_Task) (void);
627 #endif
629 /* Reentrant localtime for Windows. */
631 extern void
632 __gnat_localtime_tzoff (const time_t *, const int *, long *);
634 static const unsigned long long w32_epoch_offset = 11644473600ULL;
635 void
636 __gnat_localtime_tzoff (const time_t *timer, const int *is_historic, long *off)
638 TIME_ZONE_INFORMATION tzi;
640 DWORD tzi_status;
642 (*Lock_Task) ();
644 tzi_status = GetTimeZoneInformation (&tzi);
646 /* Cases where we simply want to extract the offset of the current time
647 zone, regardless of the date. A value of "0" for flag "is_historic"
648 signifies that the date is NOT historic, see the
649 body of Ada.Calendar.UTC_Time_Offset. */
651 if (*is_historic == 0) {
652 *off = tzi.Bias;
654 /* The system is operating in the range covered by the StandardDate
655 member. */
656 if (tzi_status == TIME_ZONE_ID_STANDARD) {
657 *off = *off + tzi.StandardBias;
660 /* The system is operating in the range covered by the DaylightDate
661 member. */
662 else if (tzi_status == TIME_ZONE_ID_DAYLIGHT) {
663 *off = *off + tzi.DaylightBias;
666 *off = *off * -60;
669 /* Time zone offset calculations for a historic or future date */
671 else {
672 union
674 FILETIME ft_time;
675 unsigned long long ull_time;
676 } utc_time, local_time;
678 SYSTEMTIME utc_sys_time, local_sys_time;
679 BOOL status;
681 /* First convert unix time_t structure to windows FILETIME format. */
682 utc_time.ull_time = ((unsigned long long) *timer + w32_epoch_offset)
683 * 10000000ULL;
685 /* If GetTimeZoneInformation does not return a value between 0 and 2 then
686 it means that we were not able to retrieve timezone information. Note
687 that we cannot use here FileTimeToLocalFileTime as Windows will use in
688 always in this case the current timezone setting. As suggested on MSDN
689 we use the following three system calls to get the right information.
690 Note also that starting with Windows Vista new functions are provided
691 to get timezone settings that depend on the year. We cannot use them as
692 we still support Windows XP and Windows 2003. */
694 status = (tzi_status >= 0 && tzi_status <= 2)
695 && FileTimeToSystemTime (&utc_time.ft_time, &utc_sys_time)
696 && SystemTimeToTzSpecificLocalTime (&tzi, &utc_sys_time, &local_sys_time)
697 && SystemTimeToFileTime (&local_sys_time, &local_time.ft_time);
699 /* An error has occurred, return invalid_tzoff */
701 if (!status) {
702 *off = __gnat_invalid_tzoff;
704 else {
705 if (local_time.ull_time > utc_time.ull_time) {
706 *off = (long) ((local_time.ull_time - utc_time.ull_time)
707 / 10000000ULL);
709 else {
710 *off = - (long) ((utc_time.ull_time - local_time.ull_time)
711 / 10000000ULL);
716 (*Unlock_Task) ();
719 #elif defined (__Lynx__)
721 /* On Lynx, all time values are treated in GMT */
723 /* As of LynxOS 3.1.0a patch level 040, LynuxWorks changes the
724 prototype to the C library function localtime_r from the POSIX.4
725 Draft 9 to the POSIX 1.c version. Before this change the following
726 spec is required. Only use when ___THREADS_POSIX4ad4__ is defined,
727 the Lynx convention when building against the legacy API. */
729 extern void
730 __gnat_localtime_tzoff (const time_t *, const int *, long *);
732 void
733 __gnat_localtime_tzoff (const time_t *timer, const int *is_historic, long *off)
735 *off = 0;
738 #else
740 /* Other targets except Lynx and Windows provide a standard localtime_r */
742 #define Lock_Task system__soft_links__lock_task
743 extern void (*Lock_Task) (void);
745 #define Unlock_Task system__soft_links__unlock_task
746 extern void (*Unlock_Task) (void);
748 extern void
749 __gnat_localtime_tzoff (const time_t *, const int *, long *);
751 void
752 __gnat_localtime_tzoff (const time_t *timer ATTRIBUTE_UNUSED,
753 const int *is_historic ATTRIBUTE_UNUSED,
754 long *off ATTRIBUTE_UNUSED)
756 struct tm tp ATTRIBUTE_UNUSED;
758 /* AIX, HPUX, Sun Solaris */
759 #if defined (_AIX) || defined (__hpux__) || defined (__sun__)
761 (*Lock_Task) ();
763 localtime_r (timer, &tp);
764 *off = (long) -timezone;
766 (*Unlock_Task) ();
768 /* Correct the offset if Daylight Saving Time is in effect */
770 if (tp.tm_isdst > 0)
771 *off = *off + 3600;
774 /* VxWorks */
775 #elif defined (__vxworks)
776 #include <stdlib.h>
778 (*Lock_Task) ();
780 localtime_r (timer, &tp);
782 /* Try to read the environment variable TIMEZONE. The variable may not have
783 been initialize, in that case return an offset of zero (0) for UTC. */
785 char *tz_str = getenv ("TIMEZONE");
787 if ((tz_str == NULL) || (*tz_str == '\0'))
788 *off = 0;
789 else
791 char *tz_start, *tz_end;
793 /* The format of the data contained in TIMEZONE is N::U:S:E where N is the
794 name of the time zone, U are the minutes difference from UTC, S is the
795 start of DST in mmddhh and E is the end of DST in mmddhh. Extracting
796 the value of U involves setting two pointers, one at the beginning and
797 one at the end of the value. The end pointer is then set to null in
798 order to delimit a string slice for atol to process. */
800 tz_start = index (tz_str, ':') + 2;
801 tz_end = index (tz_start, ':');
802 *tz_end = '\0';
804 /* The Ada layer expects an offset in seconds. Note that we must reverse
805 the sign of the result since west is positive and east is negative on
806 VxWorks targets. */
808 *off = -atol (tz_start) * 60;
810 /* Correct the offset if Daylight Saving Time is in effect */
812 if (tp.tm_isdst > 0)
813 *off = *off + 3600;
816 (*Unlock_Task) ();
819 /* Darwin, Free BSD, Linux, where component tm_gmtoff is present in
820 struct tm */
822 #elif defined (__APPLE__) || defined (__FreeBSD__) || defined (__linux__) \
823 || defined (__GLIBC__) || defined (__DragonFly__) || defined (__OpenBSD__)
825 localtime_r (timer, &tp);
826 *off = tp.tm_gmtoff;
829 /* Default: treat all time values in GMT */
831 #else
832 *off = 0;
834 #endif /* defined(_AIX) ... */
837 #endif
839 #ifdef __vxworks
841 #include <taskLib.h>
843 /* __gnat_get_task_options is used by s-taprop.adb only for VxWorks. This
844 function returns the options to be set when creating a new task. It fetches
845 the options assigned to the current task (parent), so offering some user
846 level control over the options for a task hierarchy. It forces VX_FP_TASK
847 because it is almost always required. On processors with the SPE
848 category, VX_SPE_TASK should be used instead to enable the SPE. */
849 extern int __gnat_get_task_options (void);
852 __gnat_get_task_options (void)
854 int options;
856 /* Get the options for the task creator */
857 taskOptionsGet (taskIdSelf (), &options);
859 /* Force VX_FP_TASK or VX_SPE_TASK as needed */
860 #if defined (__SPE__)
861 options |= VX_SPE_TASK;
862 #else
863 options |= VX_FP_TASK;
864 #endif
866 /* Mask those bits that are not under user control */
867 #ifdef VX_USR_TASK_OPTIONS
868 return options & VX_USR_TASK_OPTIONS;
869 #else
870 return options;
871 #endif
874 #endif
877 __gnat_is_file_not_found_error (int errno_val) {
878 switch (errno_val) {
879 case ENOENT:
880 #ifdef __vxworks
881 /* In the case of VxWorks, we also have to take into account various
882 * filesystem-specific variants of this error.
884 #if ! defined (VTHREADS) && (_WRS_VXWORKS_MAJOR < 7)
885 case S_dosFsLib_FILE_NOT_FOUND:
886 #endif
887 #if ! defined (__RTP__) && (! defined (VTHREADS) || defined (__VXWORKSMILS__))
888 case S_nfsLib_NFSERR_NOENT:
889 #endif
890 #if defined (__RTP__)
891 /* An RTP can return an NFS file not found, and the NFS bits must
892 first be masked on to check the errno. */
893 case M_nfsStat | ENOENT:
894 #endif
895 #endif
896 return 1;
898 default:
899 return 0;
903 #ifdef __ANDROID__
905 /* Provide extern symbols for sig* as needed by the tasking run-time, instead
906 of static inline functions. */
908 #include <signal.h>
911 _sigismember (sigset_t *set, int signum)
913 return sigismember (set, signum);
917 _sigaddset (sigset_t *set, int signum)
919 return sigaddset (set, signum);
923 _sigdelset (sigset_t *set, int signum)
925 return sigdelset (set, signum);
929 _sigemptyset (sigset_t *set)
931 return sigemptyset (set);
935 _sigfillset (sigset_t *set)
937 return sigfillset (set);
940 #include <unistd.h>
942 _getpagesize (void)
944 return getpagesize ();
946 #endif