1 /****************************************************************************
3 * GNAT COMPILER COMPONENTS *
7 * C Implementation File *
9 * Copyright (C) 1992-2011, Free Software Foundation, Inc. *
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. *
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. *
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/>. *
27 * GNAT was originally developed by the GNAT team at New York University. *
28 * Extensive contributions were provided by Ada Core Technologies Inc. *
30 ****************************************************************************/
32 /* This unit contains initialization circuits that are system dependent.
33 A major part of the functionality involves stack overflow checking.
34 The GCC backend generates probe instructions to test for stack overflow.
35 For details on the exact approach used to generate these probes, see the
36 "Using and Porting GCC" manual, in particular the "Stack Checking" section
37 and the subsection "Specifying How Stack Checking is Done". The handlers
38 installed by this file are used to catch the resulting signals that come
39 from these probes failing (i.e. touching protected pages). */
45 /* This file should be kept synchronized with 2sinit.ads, 2sinit.adb,
46 s-init-ae653-cert.adb and s-init-xi-sparc.adb. All these files implement
47 the required functionality for different targets. */
49 /* The following include is here to meet the published VxWorks requirement
50 that the __vxworks header appear before any other include. */
60 /* We don't have libiberty, so use malloc. */
61 #define xmalloc(S) malloc (S)
70 extern void __gnat_raise_program_error (const char *, int);
72 /* Addresses of exception data blocks for predefined exceptions. Tasking_Error
73 is not used in this unit, and the abort signal is only used on IRIX. */
74 extern struct Exception_Data constraint_error
;
75 extern struct Exception_Data numeric_error
;
76 extern struct Exception_Data program_error
;
77 extern struct Exception_Data storage_error
;
79 /* For the Cert run time we use the regular raise exception routine because
80 Raise_From_Signal_Handler is not available. */
82 #define Raise_From_Signal_Handler \
83 __gnat_raise_exception
84 extern void Raise_From_Signal_Handler (struct Exception_Data
*, const char *);
86 #define Raise_From_Signal_Handler \
87 ada__exceptions__raise_from_signal_handler
88 extern void Raise_From_Signal_Handler (struct Exception_Data
*, const char *);
91 /* Global values computed by the binder. */
92 int __gl_main_priority
= -1;
93 int __gl_main_cpu
= -1;
94 int __gl_time_slice_val
= -1;
95 char __gl_wc_encoding
= 'n';
96 char __gl_locking_policy
= ' ';
97 char __gl_queuing_policy
= ' ';
98 char __gl_task_dispatching_policy
= ' ';
99 char *__gl_priority_specific_dispatching
= 0;
100 int __gl_num_specific_dispatching
= 0;
101 char *__gl_interrupt_states
= 0;
102 int __gl_num_interrupt_states
= 0;
103 int __gl_unreserve_all_interrupts
= 0;
104 int __gl_exception_tracebacks
= 0;
105 int __gl_zero_cost_exceptions
= 0;
106 int __gl_detect_blocking
= 0;
107 int __gl_default_stack_size
= -1;
108 int __gl_leap_seconds_support
= 0;
109 int __gl_canonical_streams
= 0;
111 /* Indication of whether synchronous signal handler has already been
112 installed by a previous call to adainit. */
113 int __gnat_handler_installed
= 0;
116 int __gnat_inside_elab_final_code
= 0;
117 /* ??? This variable is obsolete since 2001-08-29 but is kept to allow
118 bootstrap from old GNAT versions (< 3.15). */
121 /* HAVE_GNAT_INIT_FLOAT must be set on every targets where a __gnat_init_float
122 is defined. If this is not set then a void implementation will be defined
123 at the end of this unit. */
124 #undef HAVE_GNAT_INIT_FLOAT
126 /******************************/
127 /* __gnat_get_interrupt_state */
128 /******************************/
130 char __gnat_get_interrupt_state (int);
132 /* This routine is called from the runtime as needed to determine the state
133 of an interrupt, as set by an Interrupt_State pragma appearing anywhere
134 in the current partition. The input argument is the interrupt number,
135 and the result is one of the following:
137 'n' this interrupt not set by any Interrupt_State pragma
138 'u' Interrupt_State pragma set state to User
139 'r' Interrupt_State pragma set state to Runtime
140 's' Interrupt_State pragma set state to System */
143 __gnat_get_interrupt_state (int intrup
)
145 if (intrup
>= __gl_num_interrupt_states
)
148 return __gl_interrupt_states
[intrup
];
151 /***********************************/
152 /* __gnat_get_specific_dispatching */
153 /***********************************/
155 char __gnat_get_specific_dispatching (int);
157 /* This routine is called from the runtime as needed to determine the
158 priority specific dispatching policy, as set by a
159 Priority_Specific_Dispatching pragma appearing anywhere in the current
160 partition. The input argument is the priority number, and the result
161 is the upper case first character of the policy name, e.g. 'F' for
162 FIFO_Within_Priorities. A space ' ' is returned if no
163 Priority_Specific_Dispatching pragma is used in the partition. */
166 __gnat_get_specific_dispatching (int priority
)
168 if (__gl_num_specific_dispatching
== 0)
170 else if (priority
>= __gl_num_specific_dispatching
)
173 return __gl_priority_specific_dispatching
[priority
];
178 /**********************/
179 /* __gnat_set_globals */
180 /**********************/
182 /* This routine is kept for bootstrapping purposes, since the binder generated
183 file now sets the __gl_* variables directly. */
186 __gnat_set_globals (void)
199 #include <sys/time.h>
201 /* Some versions of AIX don't define SA_NODEFER. */
205 #endif /* SA_NODEFER */
207 /* Versions of AIX before 4.3 don't have nanosleep but provide
210 #ifndef _AIXVERSION_430
212 extern int nanosleep (struct timestruc_t
*, struct timestruc_t
*);
215 nanosleep (struct timestruc_t
*Rqtp
, struct timestruc_t
*Rmtp
)
217 return nsleep (Rqtp
, Rmtp
);
220 #endif /* _AIXVERSION_430 */
223 __gnat_error_handler (int sig
,
224 siginfo_t
*si ATTRIBUTE_UNUSED
,
225 void *ucontext ATTRIBUTE_UNUSED
)
227 struct Exception_Data
*exception
;
233 /* FIXME: we need to detect the case of a *real* SIGSEGV. */
234 exception
= &storage_error
;
235 msg
= "stack overflow or erroneous memory access";
239 exception
= &constraint_error
;
244 exception
= &constraint_error
;
249 exception
= &program_error
;
250 msg
= "unhandled signal";
253 Raise_From_Signal_Handler (exception
, msg
);
257 __gnat_install_handler (void)
259 struct sigaction act
;
261 /* Set up signal handler to map synchronous signals to appropriate
262 exceptions. Make sure that the handler isn't interrupted by another
263 signal that might cause a scheduling event! */
265 act
.sa_flags
= SA_NODEFER
| SA_RESTART
| SA_SIGINFO
;
266 act
.sa_sigaction
= __gnat_error_handler
;
267 sigemptyset (&act
.sa_mask
);
269 /* Do not install handlers if interrupt state is "System". */
270 if (__gnat_get_interrupt_state (SIGABRT
) != 's')
271 sigaction (SIGABRT
, &act
, NULL
);
272 if (__gnat_get_interrupt_state (SIGFPE
) != 's')
273 sigaction (SIGFPE
, &act
, NULL
);
274 if (__gnat_get_interrupt_state (SIGILL
) != 's')
275 sigaction (SIGILL
, &act
, NULL
);
276 if (__gnat_get_interrupt_state (SIGSEGV
) != 's')
277 sigaction (SIGSEGV
, &act
, NULL
);
278 if (__gnat_get_interrupt_state (SIGBUS
) != 's')
279 sigaction (SIGBUS
, &act
, NULL
);
281 __gnat_handler_installed
= 1;
288 #elif defined(__alpha__) && defined(__osf__)
291 #include <sys/siginfo.h>
293 extern char *__gnat_get_code_loc (struct sigcontext
*);
294 extern void __gnat_set_code_loc (struct sigcontext
*, char *);
295 extern size_t __gnat_machine_state_length (void);
297 #define HAVE_GNAT_ADJUST_CONTEXT_FOR_RAISE
300 __gnat_adjust_context_for_raise (int signo
, void *ucontext
)
302 struct sigcontext
*sigcontext
= (struct sigcontext
*) ucontext
;
304 /* The unwinder expects the signal context to contain the address of the
305 faulting instruction. For SIGFPE, this depends on the trap shadow
306 situation (see man ieee). We nonetheless always compensate for it,
307 considering that PC designates the instruction following the one that
308 trapped. This is not necessarily true but corresponds to what we have
315 __gnat_error_handler (int sig
, siginfo_t
*si
, void *ucontext
)
317 struct Exception_Data
*exception
;
318 static int recurse
= 0;
321 /* Adjusting is required for every fault context, so adjust for this one
322 now, before we possibly trigger a recursive fault below. */
323 __gnat_adjust_context_for_raise (sig
, ucontext
);
325 /* If this was an explicit signal from a "kill", just resignal it. */
326 if (SI_FROMUSER (si
))
328 signal (sig
, SIG_DFL
);
329 kill (getpid(), sig
);
332 /* Otherwise, treat it as something we handle. */
336 /* If the problem was permissions, this is a constraint error.
337 Likewise if the failing address isn't maximally aligned or if
340 ??? Using a static variable here isn't task-safe, but it's
341 much too hard to do anything else and we're just determining
342 which exception to raise. */
343 if (si
->si_code
== SEGV_ACCERR
344 || (long) si
->si_addr
== 0
345 || (((long) si
->si_addr
) & 3) != 0
348 exception
= &constraint_error
;
353 /* See if the page before the faulting page is accessible. Do that
354 by trying to access it. We'd like to simply try to access
355 4096 + the faulting address, but it's not guaranteed to be
356 the actual address, just to be on the same page. */
359 ((long) si
->si_addr
& - getpagesize ()))[getpagesize ()];
360 exception
= &storage_error
;
361 msg
= "stack overflow or erroneous memory access";
366 exception
= &program_error
;
371 exception
= &constraint_error
;
376 exception
= &program_error
;
377 msg
= "unhandled signal";
381 Raise_From_Signal_Handler (exception
, CONST_CAST (char *, msg
));
385 __gnat_install_handler (void)
387 struct sigaction act
;
389 /* Setup signal handler to map synchronous signals to appropriate
390 exceptions. Make sure that the handler isn't interrupted by another
391 signal that might cause a scheduling event! */
393 act
.sa_handler
= (void (*) (int)) __gnat_error_handler
;
394 act
.sa_flags
= SA_RESTART
| SA_NODEFER
| SA_SIGINFO
;
395 sigemptyset (&act
.sa_mask
);
397 /* Do not install handlers if interrupt state is "System". */
398 if (__gnat_get_interrupt_state (SIGABRT
) != 's')
399 sigaction (SIGABRT
, &act
, NULL
);
400 if (__gnat_get_interrupt_state (SIGFPE
) != 's')
401 sigaction (SIGFPE
, &act
, NULL
);
402 if (__gnat_get_interrupt_state (SIGILL
) != 's')
403 sigaction (SIGILL
, &act
, NULL
);
404 if (__gnat_get_interrupt_state (SIGSEGV
) != 's')
405 sigaction (SIGSEGV
, &act
, NULL
);
406 if (__gnat_get_interrupt_state (SIGBUS
) != 's')
407 sigaction (SIGBUS
, &act
, NULL
);
409 __gnat_handler_installed
= 1;
412 /* Routines called by s-mastop-tru64.adb. */
417 __gnat_get_code_loc (struct sigcontext
*context
)
419 return (char *) context
->sc_pc
;
423 __gnat_set_code_loc (struct sigcontext
*context
, char *pc
)
425 context
->sc_pc
= (long) pc
;
429 __gnat_machine_state_length (void)
431 return sizeof (struct sigcontext
);
438 #elif defined (__hpux__)
441 #include <sys/ucontext.h>
444 __gnat_error_handler (int sig
,
445 siginfo_t
*si ATTRIBUTE_UNUSED
,
446 void *ucontext ATTRIBUTE_UNUSED
)
448 struct Exception_Data
*exception
;
454 /* FIXME: we need to detect the case of a *real* SIGSEGV. */
455 exception
= &storage_error
;
456 msg
= "stack overflow or erroneous memory access";
460 exception
= &constraint_error
;
465 exception
= &constraint_error
;
470 exception
= &program_error
;
471 msg
= "unhandled signal";
474 Raise_From_Signal_Handler (exception
, msg
);
477 /* This must be in keeping with System.OS_Interface.Alternate_Stack_Size. */
478 #if defined (__hppa__)
479 char __gnat_alternate_stack
[16 * 1024]; /* 2 * SIGSTKSZ */
481 char __gnat_alternate_stack
[128 * 1024]; /* MINSIGSTKSZ */
485 __gnat_install_handler (void)
487 struct sigaction act
;
489 /* Set up signal handler to map synchronous signals to appropriate
490 exceptions. Make sure that the handler isn't interrupted by another
491 signal that might cause a scheduling event! Also setup an alternate
492 stack region for the handler execution so that stack overflows can be
493 handled properly, avoiding a SEGV generation from stack usage by the
497 stack
.ss_sp
= __gnat_alternate_stack
;
498 stack
.ss_size
= sizeof (__gnat_alternate_stack
);
500 sigaltstack (&stack
, NULL
);
502 act
.sa_sigaction
= __gnat_error_handler
;
503 act
.sa_flags
= SA_NODEFER
| SA_RESTART
| SA_SIGINFO
;
504 sigemptyset (&act
.sa_mask
);
506 /* Do not install handlers if interrupt state is "System". */
507 if (__gnat_get_interrupt_state (SIGABRT
) != 's')
508 sigaction (SIGABRT
, &act
, NULL
);
509 if (__gnat_get_interrupt_state (SIGFPE
) != 's')
510 sigaction (SIGFPE
, &act
, NULL
);
511 if (__gnat_get_interrupt_state (SIGILL
) != 's')
512 sigaction (SIGILL
, &act
, NULL
);
513 if (__gnat_get_interrupt_state (SIGBUS
) != 's')
514 sigaction (SIGBUS
, &act
, NULL
);
515 act
.sa_flags
|= SA_ONSTACK
;
516 if (__gnat_get_interrupt_state (SIGSEGV
) != 's')
517 sigaction (SIGSEGV
, &act
, NULL
);
519 __gnat_handler_installed
= 1;
522 /*********************/
523 /* GNU/Linux Section */
524 /*********************/
526 #elif defined (linux)
530 #define __USE_GNU 1 /* required to get REG_EIP/RIP from glibc's ucontext.h */
531 #include <sys/ucontext.h>
533 /* GNU/Linux, which uses glibc, does not define NULL in included
537 #define NULL ((void *) 0)
542 /* MaRTE OS provides its own version of sigaction, sigfillset, and
543 sigemptyset (overriding these symbol names). We want to make sure that
544 the versions provided by the underlying C library are used here (these
545 versions are renamed by MaRTE to linux_sigaction, fake_linux_sigfillset,
546 and fake_linux_sigemptyset, respectively). The MaRTE library will not
547 always be present (it will not be linked if no tasking constructs are
548 used), so we use the weak symbol mechanism to point always to the symbols
549 defined within the C library. */
551 #pragma weak linux_sigaction
552 int linux_sigaction (int signum
, const struct sigaction
*act
,
553 struct sigaction
*oldact
) {
554 return sigaction (signum
, act
, oldact
);
556 #define sigaction(signum, act, oldact) linux_sigaction (signum, act, oldact)
558 #pragma weak fake_linux_sigfillset
559 void fake_linux_sigfillset (sigset_t
*set
) {
562 #define sigfillset(set) fake_linux_sigfillset (set)
564 #pragma weak fake_linux_sigemptyset
565 void fake_linux_sigemptyset (sigset_t
*set
) {
568 #define sigemptyset(set) fake_linux_sigemptyset (set)
572 #if defined (i386) || defined (__x86_64__) || defined (__ia64__)
574 #define HAVE_GNAT_ADJUST_CONTEXT_FOR_RAISE
577 __gnat_adjust_context_for_raise (int signo ATTRIBUTE_UNUSED
, void *ucontext
)
579 mcontext_t
*mcontext
= &((ucontext_t
*) ucontext
)->uc_mcontext
;
581 /* On the i386 and x86-64 architectures, stack checking is performed by
582 means of probes with moving stack pointer, that is to say the probed
583 address is always the value of the stack pointer. Upon hitting the
584 guard page, the stack pointer therefore points to an inaccessible
585 address and an alternate signal stack is needed to run the handler.
586 But there is an additional twist: on these architectures, the EH
587 return code writes the address of the handler at the target CFA's
588 value on the stack before doing the jump. As a consequence, if
589 there is an active handler in the frame whose stack has overflowed,
590 the stack pointer must nevertheless point to an accessible address
591 by the time the EH return is executed.
593 We therefore adjust the saved value of the stack pointer by the size
594 of one page + a small dope of 4 words, in order to make sure that it
595 points to an accessible address in case it's used as the target CFA.
596 The stack checking code guarantees that this address is unused by the
597 time this happens. */
600 unsigned long *pc
= (unsigned long *)mcontext
->gregs
[REG_EIP
];
601 /* The pattern is "orl $0x0,(%esp)" for a probe in 32-bit mode. */
602 if (signo
== SIGSEGV
&& pc
&& *pc
== 0x00240c83)
603 mcontext
->gregs
[REG_ESP
] += 4096 + 4 * sizeof (unsigned long);
604 #elif defined (__x86_64__)
605 unsigned long *pc
= (unsigned long *)mcontext
->gregs
[REG_RIP
];
606 /* The pattern is "orq $0x0,(%rsp)" for a probe in 64-bit mode. */
607 if (signo
== SIGSEGV
&& pc
&& (*pc
& 0xffffffffff) == 0x00240c8348)
608 mcontext
->gregs
[REG_RSP
] += 4096 + 4 * sizeof (unsigned long);
609 #elif defined (__ia64__)
610 /* ??? The IA-64 unwinder doesn't compensate for signals. */
618 __gnat_error_handler (int sig
, siginfo_t
*si ATTRIBUTE_UNUSED
, void *ucontext
)
620 struct Exception_Data
*exception
;
623 /* Adjusting is required for every fault context, so adjust for this one
624 now, before we possibly trigger a recursive fault below. */
625 __gnat_adjust_context_for_raise (sig
, ucontext
);
630 /* Here we would like a discrimination test to see whether the page
631 before the faulting address is accessible. Unfortunately, Linux
632 seems to have no way of giving us the faulting address.
634 In old versions of init.c, we had a test of the page before the
638 ((long) si->esp_at_signal & - getpagesize ()))[getpagesize ()];
640 but that's wrong since it tests the stack pointer location and the
641 stack probing code may not move it until all probes succeed.
643 For now we simply do not attempt any discrimination at all. Note
644 that this is quite acceptable, since a "real" SIGSEGV can only
645 occur as the result of an erroneous program. */
646 exception
= &storage_error
;
647 msg
= "stack overflow or erroneous memory access";
651 exception
= &constraint_error
;
656 exception
= &constraint_error
;
661 exception
= &program_error
;
662 msg
= "unhandled signal";
665 Raise_From_Signal_Handler (exception
, msg
);
668 #if defined (i386) || defined (__x86_64__) || defined (__powerpc__)
669 /* This must be in keeping with System.OS_Interface.Alternate_Stack_Size. */
670 char __gnat_alternate_stack
[16 * 1024]; /* 2 * SIGSTKSZ */
674 #include <sys/mman.h>
675 #include <native/task.h>
681 __gnat_install_handler (void)
683 struct sigaction act
;
688 if (__gl_main_priority
== -1)
691 prio
= __gl_main_priority
;
693 /* Avoid memory swapping for this program */
695 mlockall (MCL_CURRENT
|MCL_FUTURE
);
697 /* Turn the current Linux task into a native Xenomai task */
699 rt_task_shadow(&main_task
, "environment_task", prio
, T_FPU
);
702 /* Set up signal handler to map synchronous signals to appropriate
703 exceptions. Make sure that the handler isn't interrupted by another
704 signal that might cause a scheduling event! Also setup an alternate
705 stack region for the handler execution so that stack overflows can be
706 handled properly, avoiding a SEGV generation from stack usage by the
709 #if defined (i386) || defined (__x86_64__) || defined (__powerpc__)
711 stack
.ss_sp
= __gnat_alternate_stack
;
712 stack
.ss_size
= sizeof (__gnat_alternate_stack
);
714 sigaltstack (&stack
, NULL
);
717 act
.sa_sigaction
= __gnat_error_handler
;
718 act
.sa_flags
= SA_NODEFER
| SA_RESTART
| SA_SIGINFO
;
719 sigemptyset (&act
.sa_mask
);
721 /* Do not install handlers if interrupt state is "System". */
722 if (__gnat_get_interrupt_state (SIGABRT
) != 's')
723 sigaction (SIGABRT
, &act
, NULL
);
724 if (__gnat_get_interrupt_state (SIGFPE
) != 's')
725 sigaction (SIGFPE
, &act
, NULL
);
726 if (__gnat_get_interrupt_state (SIGILL
) != 's')
727 sigaction (SIGILL
, &act
, NULL
);
728 if (__gnat_get_interrupt_state (SIGBUS
) != 's')
729 sigaction (SIGBUS
, &act
, NULL
);
730 #if defined (i386) || defined (__x86_64__) || defined (__powerpc__)
731 act
.sa_flags
|= SA_ONSTACK
;
733 if (__gnat_get_interrupt_state (SIGSEGV
) != 's')
734 sigaction (SIGSEGV
, &act
, NULL
);
736 __gnat_handler_installed
= 1;
752 #define SIGADAABORT 48
753 #define SIGNAL_STACK_SIZE 4096
754 #define SIGNAL_STACK_ALIGNMENT 64
756 #define Check_Abort_Status \
757 system__soft_links__check_abort_status
758 extern int (*Check_Abort_Status
) (void);
760 extern struct Exception_Data _abort_signal
;
762 /* We are not setting the SA_SIGINFO bit in the sigaction flags when
763 connecting that handler, with the effects described in the sigaction
766 SA_SIGINFO If set and the signal is caught, sig is passed as the
767 first argument to the signal-catching function. If the
768 second argument is not equal to NULL, it points to a
769 siginfo_t structure containing the reason why the
770 signal was generated [see siginfo(5)]; the third
771 argument points to a ucontext_t structure containing
772 the receiving process's context when the signal was
773 delivered [see ucontext(5)]. If cleared and the signal
774 is caught, the first argument is also the signal number
775 but the second argument is the signal code identifying
776 the cause of the signal. The third argument points to a
777 sigcontext_t structure containing the receiving
778 process's context when the signal was delivered. This
779 is the default behavior (see signal(5) for more
780 details). Additionally, when SA_SIGINFO is set for a
781 signal, multiple occurrences of that signal will be
782 queued for delivery in FIFO order (see sigqueue(3) for
783 a more detailed explanation of this concept), if those
784 occurrences of that signal were generated using
788 __gnat_error_handler (int sig
, siginfo_t
*reason
, void *uc ATTRIBUTE_UNUSED
)
790 /* This handler is installed with SA_SIGINFO cleared, but there's no
791 prototype for the resulting alternative three-argument form, so we
792 have to hack around this by casting reason to the int actually
794 int code
= (int) reason
;
795 struct Exception_Data
*exception
;
803 exception
= &program_error
;
804 msg
= "SIGSEGV: (Invalid virtual address)";
806 else if (code
== ENXIO
)
808 exception
= &program_error
;
809 msg
= "SIGSEGV: (Read beyond mapped object)";
811 else if (code
== ENOSPC
)
813 exception
= &program_error
; /* ??? storage_error ??? */
814 msg
= "SIGSEGV: (Autogrow for file failed)";
816 else if (code
== EACCES
|| code
== EEXIST
)
818 /* ??? We handle stack overflows here, some of which do trigger
819 SIGSEGV + EEXIST on Irix 6.5 although EEXIST is not part of
820 the documented valid codes for SEGV in the signal(5) man
823 /* ??? Re-add smarts to further verify that we launched
824 the stack into a guard page, not an attempt to
825 write to .text or something. */
826 exception
= &storage_error
;
827 msg
= "SIGSEGV: stack overflow or erroneous memory access";
831 /* Just in case the OS guys did it to us again. Sometimes
832 they fail to document all of the valid codes that are
833 passed to signal handlers, just in case someone depends
834 on knowing all the codes. */
835 exception
= &program_error
;
836 msg
= "SIGSEGV: (Undocumented reason)";
841 /* Map all bus errors to Program_Error. */
842 exception
= &program_error
;
847 /* Map all fpe errors to Constraint_Error. */
848 exception
= &constraint_error
;
853 if ((*Check_Abort_Status
) ())
855 exception
= &_abort_signal
;
864 /* Everything else is a Program_Error. */
865 exception
= &program_error
;
866 msg
= "unhandled signal";
869 Raise_From_Signal_Handler (exception
, msg
);
873 __gnat_install_handler (void)
875 struct sigaction act
;
877 /* Setup signal handler to map synchronous signals to appropriate
878 exceptions. Make sure that the handler isn't interrupted by another
879 signal that might cause a scheduling event!
881 The handler is installed with SA_SIGINFO cleared, but there's no
882 C++ prototype for the three-argument form, so fake it by using
883 sa_sigaction and casting the arguments instead. */
885 act
.sa_sigaction
= __gnat_error_handler
;
886 act
.sa_flags
= SA_NODEFER
+ SA_RESTART
;
887 sigfillset (&act
.sa_mask
);
888 sigemptyset (&act
.sa_mask
);
890 /* Do not install handlers if interrupt state is "System". */
891 if (__gnat_get_interrupt_state (SIGABRT
) != 's')
892 sigaction (SIGABRT
, &act
, NULL
);
893 if (__gnat_get_interrupt_state (SIGFPE
) != 's')
894 sigaction (SIGFPE
, &act
, NULL
);
895 if (__gnat_get_interrupt_state (SIGILL
) != 's')
896 sigaction (SIGILL
, &act
, NULL
);
897 if (__gnat_get_interrupt_state (SIGSEGV
) != 's')
898 sigaction (SIGSEGV
, &act
, NULL
);
899 if (__gnat_get_interrupt_state (SIGBUS
) != 's')
900 sigaction (SIGBUS
, &act
, NULL
);
901 if (__gnat_get_interrupt_state (SIGADAABORT
) != 's')
902 sigaction (SIGADAABORT
, &act
, NULL
);
904 __gnat_handler_installed
= 1;
907 /*******************/
909 /*******************/
911 #elif defined (__Lynx__)
917 __gnat_error_handler (int sig
)
919 struct Exception_Data
*exception
;
925 exception
= &constraint_error
;
929 exception
= &constraint_error
;
933 exception
= &storage_error
;
934 msg
= "stack overflow or erroneous memory access";
937 exception
= &constraint_error
;
941 exception
= &program_error
;
942 msg
= "unhandled signal";
945 Raise_From_Signal_Handler(exception
, msg
);
949 __gnat_install_handler(void)
951 struct sigaction act
;
953 act
.sa_handler
= __gnat_error_handler
;
955 sigemptyset (&act
.sa_mask
);
957 /* Do not install handlers if interrupt state is "System". */
958 if (__gnat_get_interrupt_state (SIGFPE
) != 's')
959 sigaction (SIGFPE
, &act
, NULL
);
960 if (__gnat_get_interrupt_state (SIGILL
) != 's')
961 sigaction (SIGILL
, &act
, NULL
);
962 if (__gnat_get_interrupt_state (SIGSEGV
) != 's')
963 sigaction (SIGSEGV
, &act
, NULL
);
964 if (__gnat_get_interrupt_state (SIGBUS
) != 's')
965 sigaction (SIGBUS
, &act
, NULL
);
967 __gnat_handler_installed
= 1;
970 /*******************/
971 /* Solaris Section */
972 /*******************/
974 #elif defined (sun) && defined (__SVR4) && !defined (__vxworks)
978 #include <sys/ucontext.h>
979 #include <sys/regset.h>
981 /* The code below is common to SPARC and x86. Beware of the delay slot
982 differences for signal context adjustments. */
984 #if defined (__sparc)
985 #define RETURN_ADDR_OFFSET 8
987 #define RETURN_ADDR_OFFSET 0
991 __gnat_error_handler (int sig
, siginfo_t
*si
, void *ucontext ATTRIBUTE_UNUSED
)
993 struct Exception_Data
*exception
;
994 static int recurse
= 0;
1000 /* If the problem was permissions, this is a constraint error.
1001 Likewise if the failing address isn't maximally aligned or if
1004 ??? Using a static variable here isn't task-safe, but it's
1005 much too hard to do anything else and we're just determining
1006 which exception to raise. */
1007 if (si
->si_code
== SEGV_ACCERR
1008 || (long) si
->si_addr
== 0
1009 || (((long) si
->si_addr
) & 3) != 0
1012 exception
= &constraint_error
;
1017 /* See if the page before the faulting page is accessible. Do that
1018 by trying to access it. We'd like to simply try to access
1019 4096 + the faulting address, but it's not guaranteed to be
1020 the actual address, just to be on the same page. */
1023 ((long) si
->si_addr
& - getpagesize ()))[getpagesize ()];
1024 exception
= &storage_error
;
1025 msg
= "stack overflow or erroneous memory access";
1030 exception
= &program_error
;
1035 exception
= &constraint_error
;
1040 exception
= &program_error
;
1041 msg
= "unhandled signal";
1045 Raise_From_Signal_Handler (exception
, msg
);
1049 __gnat_install_handler (void)
1051 struct sigaction act
;
1053 /* Set up signal handler to map synchronous signals to appropriate
1054 exceptions. Make sure that the handler isn't interrupted by another
1055 signal that might cause a scheduling event! */
1057 act
.sa_sigaction
= __gnat_error_handler
;
1058 act
.sa_flags
= SA_NODEFER
| SA_RESTART
| SA_SIGINFO
;
1059 sigemptyset (&act
.sa_mask
);
1061 /* Do not install handlers if interrupt state is "System". */
1062 if (__gnat_get_interrupt_state (SIGABRT
) != 's')
1063 sigaction (SIGABRT
, &act
, NULL
);
1064 if (__gnat_get_interrupt_state (SIGFPE
) != 's')
1065 sigaction (SIGFPE
, &act
, NULL
);
1066 if (__gnat_get_interrupt_state (SIGSEGV
) != 's')
1067 sigaction (SIGSEGV
, &act
, NULL
);
1068 if (__gnat_get_interrupt_state (SIGBUS
) != 's')
1069 sigaction (SIGBUS
, &act
, NULL
);
1071 __gnat_handler_installed
= 1;
1080 /* Routine called from binder to override default feature values. */
1081 void __gnat_set_features (void);
1082 int __gnat_features_set
= 0;
1085 #define lib_get_curr_invo_context LIB$I64_GET_CURR_INVO_CONTEXT
1086 #define lib_get_prev_invo_context LIB$I64_GET_PREV_INVO_CONTEXT
1087 #define lib_get_invo_handle LIB$I64_GET_INVO_HANDLE
1089 #define lib_get_curr_invo_context LIB$GET_CURR_INVO_CONTEXT
1090 #define lib_get_prev_invo_context LIB$GET_PREV_INVO_CONTEXT
1091 #define lib_get_invo_handle LIB$GET_INVO_HANDLE
1094 /* Define macro symbols for the VMS conditions that become Ada exceptions.
1095 Most of these are also defined in the header file ssdef.h which has not
1096 yet been converted to be recognized by GNU C. */
1098 /* Defining these as macros, as opposed to external addresses, allows
1099 them to be used in a case statement below. */
1100 #define SS$_ACCVIO 12
1101 #define SS$_HPARITH 1284
1102 #define SS$_STKOVF 1364
1103 #define SS$_RESIGNAL 2328
1105 /* These codes are in standard message libraries. */
1106 extern int C$_SIGKILL
;
1107 extern int CMA$_EXIT_THREAD
;
1108 extern int SS$_DEBUG
;
1109 extern int SS$_INTDIV
;
1110 extern int LIB$_KEYNOTFOU
;
1111 extern int LIB$_ACTIMAGE
;
1112 extern int MTH$_FLOOVEMAT
; /* Some ACVC_21 CXA tests */
1114 /* These codes are non standard, which is to say the author is
1115 not sure if they are defined in the standard message libraries
1116 so keep them as macros for now. */
1117 #define RDB$_STREAM_EOF 20480426
1118 #define FDL$_UNPRIKW 11829410
1120 struct cond_except
{
1122 const struct Exception_Data
*except
;
1125 struct descriptor_s
{
1126 unsigned short len
, mbz
;
1130 /* Conditions that don't have an Ada exception counterpart must raise
1131 Non_Ada_Error. Since this is defined in s-auxdec, it should only be
1132 referenced by user programs, not the compiler or tools. Hence the
1137 #define Status_Error ada__io_exceptions__status_error
1138 extern struct Exception_Data Status_Error
;
1140 #define Mode_Error ada__io_exceptions__mode_error
1141 extern struct Exception_Data Mode_Error
;
1143 #define Name_Error ada__io_exceptions__name_error
1144 extern struct Exception_Data Name_Error
;
1146 #define Use_Error ada__io_exceptions__use_error
1147 extern struct Exception_Data Use_Error
;
1149 #define Device_Error ada__io_exceptions__device_error
1150 extern struct Exception_Data Device_Error
;
1152 #define End_Error ada__io_exceptions__end_error
1153 extern struct Exception_Data End_Error
;
1155 #define Data_Error ada__io_exceptions__data_error
1156 extern struct Exception_Data Data_Error
;
1158 #define Layout_Error ada__io_exceptions__layout_error
1159 extern struct Exception_Data Layout_Error
;
1161 #define Non_Ada_Error system__aux_dec__non_ada_error
1162 extern struct Exception_Data Non_Ada_Error
;
1164 #define Coded_Exception system__vms_exception_table__coded_exception
1165 extern struct Exception_Data
*Coded_Exception (Exception_Code
);
1167 #define Base_Code_In system__vms_exception_table__base_code_in
1168 extern Exception_Code
Base_Code_In (Exception_Code
);
1170 /* DEC Ada exceptions are not defined in a header file, so they
1171 must be declared as external addresses. */
1173 extern int ADA$_PROGRAM_ERROR
;
1174 extern int ADA$_LOCK_ERROR
;
1175 extern int ADA$_EXISTENCE_ERROR
;
1176 extern int ADA$_KEY_ERROR
;
1177 extern int ADA$_KEYSIZERR
;
1178 extern int ADA$_STAOVF
;
1179 extern int ADA$_CONSTRAINT_ERRO
;
1180 extern int ADA$_IOSYSFAILED
;
1181 extern int ADA$_LAYOUT_ERROR
;
1182 extern int ADA$_STORAGE_ERROR
;
1183 extern int ADA$_DATA_ERROR
;
1184 extern int ADA$_DEVICE_ERROR
;
1185 extern int ADA$_END_ERROR
;
1186 extern int ADA$_MODE_ERROR
;
1187 extern int ADA$_NAME_ERROR
;
1188 extern int ADA$_STATUS_ERROR
;
1189 extern int ADA$_NOT_OPEN
;
1190 extern int ADA$_ALREADY_OPEN
;
1191 extern int ADA$_USE_ERROR
;
1192 extern int ADA$_UNSUPPORTED
;
1193 extern int ADA$_FAC_MODE_MISMAT
;
1194 extern int ADA$_ORG_MISMATCH
;
1195 extern int ADA$_RFM_MISMATCH
;
1196 extern int ADA$_RAT_MISMATCH
;
1197 extern int ADA$_MRS_MISMATCH
;
1198 extern int ADA$_MRN_MISMATCH
;
1199 extern int ADA$_KEY_MISMATCH
;
1200 extern int ADA$_MAXLINEXC
;
1201 extern int ADA$_LINEXCMRS
;
1203 /* DEC Ada specific conditions. */
1204 static const struct cond_except dec_ada_cond_except_table
[] = {
1205 {&ADA$_PROGRAM_ERROR
, &program_error
},
1206 {&ADA$_USE_ERROR
, &Use_Error
},
1207 {&ADA$_KEYSIZERR
, &program_error
},
1208 {&ADA$_STAOVF
, &storage_error
},
1209 {&ADA$_CONSTRAINT_ERRO
, &constraint_error
},
1210 {&ADA$_IOSYSFAILED
, &Device_Error
},
1211 {&ADA$_LAYOUT_ERROR
, &Layout_Error
},
1212 {&ADA$_STORAGE_ERROR
, &storage_error
},
1213 {&ADA$_DATA_ERROR
, &Data_Error
},
1214 {&ADA$_DEVICE_ERROR
, &Device_Error
},
1215 {&ADA$_END_ERROR
, &End_Error
},
1216 {&ADA$_MODE_ERROR
, &Mode_Error
},
1217 {&ADA$_NAME_ERROR
, &Name_Error
},
1218 {&ADA$_STATUS_ERROR
, &Status_Error
},
1219 {&ADA$_NOT_OPEN
, &Use_Error
},
1220 {&ADA$_ALREADY_OPEN
, &Use_Error
},
1221 {&ADA$_USE_ERROR
, &Use_Error
},
1222 {&ADA$_UNSUPPORTED
, &Use_Error
},
1223 {&ADA$_FAC_MODE_MISMAT
, &Use_Error
},
1224 {&ADA$_ORG_MISMATCH
, &Use_Error
},
1225 {&ADA$_RFM_MISMATCH
, &Use_Error
},
1226 {&ADA$_RAT_MISMATCH
, &Use_Error
},
1227 {&ADA$_MRS_MISMATCH
, &Use_Error
},
1228 {&ADA$_MRN_MISMATCH
, &Use_Error
},
1229 {&ADA$_KEY_MISMATCH
, &Use_Error
},
1230 {&ADA$_MAXLINEXC
, &constraint_error
},
1231 {&ADA$_LINEXCMRS
, &constraint_error
},
1236 /* Already handled by a pragma Import_Exception
1237 in Aux_IO_Exceptions */
1238 {&ADA$_LOCK_ERROR
, &Lock_Error
},
1239 {&ADA$_EXISTENCE_ERROR
, &Existence_Error
},
1240 {&ADA$_KEY_ERROR
, &Key_Error
},
1245 /* Non-DEC Ada specific conditions. We could probably also put
1246 SS$_HPARITH here and possibly SS$_ACCVIO, SS$_STKOVF. */
1247 static const struct cond_except cond_except_table
[] = {
1248 {&MTH$_FLOOVEMAT
, &constraint_error
},
1249 {&SS$_INTDIV
, &constraint_error
},
1253 /* To deal with VMS conditions and their mapping to Ada exceptions,
1254 the __gnat_error_handler routine below is installed as an exception
1255 vector having precedence over DEC frame handlers. Some conditions
1256 still need to be handled by such handlers, however, in which case
1257 __gnat_error_handler needs to return SS$_RESIGNAL. Consider for
1258 instance the use of a third party library compiled with DECAda and
1259 performing its own exception handling internally.
1261 To allow some user-level flexibility, which conditions should be
1262 resignaled is controlled by a predicate function, provided with the
1263 condition value and returning a boolean indication stating whether
1264 this condition should be resignaled or not.
1266 That predicate function is called indirectly, via a function pointer,
1267 by __gnat_error_handler, and changing that pointer is allowed to the
1268 user code by way of the __gnat_set_resignal_predicate interface.
1270 The user level function may then implement what it likes, including
1271 for instance the maintenance of a dynamic data structure if the set
1272 of to be resignalled conditions has to change over the program's
1275 ??? This is not a perfect solution to deal with the possible
1276 interactions between the GNAT and the DECAda exception handling
1277 models and better (more general) schemes are studied. This is so
1278 just provided as a convenient workaround in the meantime, and
1279 should be use with caution since the implementation has been kept
1283 resignal_predicate (int code
);
1285 static const int * const cond_resignal_table
[] = {
1291 (int *) RDB$_STREAM_EOF
,
1292 (int *) FDL$_UNPRIKW
,
1296 static const int facility_resignal_table
[] = {
1297 0x1380000, /* RDB */
1298 0x2220000, /* SQL */
1302 /* Default GNAT predicate for resignaling conditions. */
1305 __gnat_default_resignal_p (int code
)
1309 for (i
= 0; facility_resignal_table
[i
]; i
++)
1310 if ((code
& 0xfff0000) == facility_resignal_table
[i
])
1313 for (i
= 0, iexcept
= 0;
1314 cond_resignal_table
[i
] &&
1315 !(iexcept
= LIB$
MATCH_COND (&code
, &cond_resignal_table
[i
]));
1321 /* Static pointer to predicate that the __gnat_error_handler exception
1322 vector invokes to determine if it should resignal a condition. */
1324 static resignal_predicate
*__gnat_resignal_p
= __gnat_default_resignal_p
;
1326 /* User interface to change the predicate pointer to PREDICATE. Reset to
1327 the default if PREDICATE is null. */
1330 __gnat_set_resignal_predicate (resignal_predicate
*predicate
)
1332 if (predicate
== NULL
)
1333 __gnat_resignal_p
= __gnat_default_resignal_p
;
1335 __gnat_resignal_p
= predicate
;
1338 /* Should match System.Parameters.Default_Exception_Msg_Max_Length. */
1339 #define Default_Exception_Msg_Max_Length 512
1341 /* Action routine for SYS$PUTMSG. There may be multiple
1342 conditions, each with text to be appended to MESSAGE
1343 and separated by line termination. */
1346 copy_msg (struct descriptor_s
*msgdesc
, char *message
)
1348 int len
= strlen (message
);
1351 /* Check for buffer overflow and skip. */
1352 if (len
> 0 && len
<= Default_Exception_Msg_Max_Length
- 3)
1354 strcat (message
, "\r\n");
1358 /* Check for buffer overflow and truncate if necessary. */
1359 copy_len
= (len
+ msgdesc
->len
<= Default_Exception_Msg_Max_Length
- 1 ?
1361 Default_Exception_Msg_Max_Length
- 1 - len
);
1362 strncpy (&message
[len
], msgdesc
->adr
, copy_len
);
1363 message
[len
+ copy_len
] = 0;
1369 __gnat_handle_vms_condition (int *sigargs
, void *mechargs
)
1371 struct Exception_Data
*exception
= 0;
1372 Exception_Code base_code
;
1373 struct descriptor_s gnat_facility
= {4, 0, "GNAT"};
1374 char message
[Default_Exception_Msg_Max_Length
];
1376 const char *msg
= "";
1378 /* Check for conditions to resignal which aren't effected by pragma
1379 Import_Exception. */
1380 if (__gnat_resignal_p (sigargs
[1]))
1381 return SS$_RESIGNAL
;
1384 /* See if it's an imported exception. Beware that registered exceptions
1385 are bound to their base code, with the severity bits masked off. */
1386 base_code
= Base_Code_In ((Exception_Code
) sigargs
[1]);
1387 exception
= Coded_Exception (base_code
);
1393 /* Subtract PC & PSL fields which messes with PUTMSG. */
1395 SYS$
PUTMSG (sigargs
, copy_msg
, &gnat_facility
, message
);
1399 exception
->Name_Length
= 19;
1400 /* ??? The full name really should be get sys$getmsg returns. */
1401 exception
->Full_Name
= "IMPORTED_EXCEPTION";
1402 exception
->Import_Code
= base_code
;
1405 /* Do not adjust the program counter as already points to the next
1406 instruction (just after the call to LIB$STOP). */
1407 Raise_From_Signal_Handler (exception
, msg
);
1416 if (sigargs
[3] == 0)
1418 exception
= &constraint_error
;
1419 msg
= "access zero";
1423 exception
= &storage_error
;
1424 msg
= "stack overflow or erroneous memory access";
1426 __gnat_adjust_context_for_raise (SS$_ACCVIO
, (void *)mechargs
);
1430 exception
= &storage_error
;
1431 msg
= "stack overflow";
1432 __gnat_adjust_context_for_raise (SS$_STKOVF
, (void *)mechargs
);
1437 return SS$_RESIGNAL
; /* toplev.c handles for compiler */
1439 exception
= &constraint_error
;
1440 msg
= "arithmetic error";
1441 __gnat_adjust_context_for_raise (SS$_HPARITH
, (void *)mechargs
);
1450 /* Scan the DEC Ada exception condition table for a match and fetch
1451 the associated GNAT exception pointer. */
1453 dec_ada_cond_except_table
[i
].cond
&&
1454 !LIB$
MATCH_COND (&sigargs
[1],
1455 &dec_ada_cond_except_table
[i
].cond
);
1457 exception
= (struct Exception_Data
*)
1458 dec_ada_cond_except_table
[i
].except
;
1462 /* Scan the VMS standard condition table for a match and fetch
1463 the associated GNAT exception pointer. */
1465 cond_except_table
[i
].cond
&&
1466 !LIB$
MATCH_COND (&sigargs
[1], &cond_except_table
[i
].cond
);
1468 exception
= (struct Exception_Data
*)
1469 cond_except_table
[i
].except
;
1472 /* User programs expect Non_Ada_Error to be raised, reference
1473 DEC Ada test CXCONDHAN. */
1474 exception
= &Non_Ada_Error
;
1478 exception
= &program_error
;
1481 /* Subtract PC & PSL fields which messes with PUTMSG. */
1483 SYS$
PUTMSG (sigargs
, copy_msg
, &gnat_facility
, message
);
1489 Raise_From_Signal_Handler (exception
, msg
);
1493 __gnat_install_handler (void)
1495 long prvhnd ATTRIBUTE_UNUSED
;
1497 #if !defined (IN_RTS)
1498 SYS$
SETEXV (1, __gnat_handle_vms_condition
, 3, &prvhnd
);
1501 __gnat_handler_installed
= 1;
1504 /* __gnat_adjust_context_for_raise for Alpha - see comments along with the
1505 default version later in this file. */
1507 #if defined (IN_RTS) && defined (__alpha__)
1509 #include <vms/chfctxdef.h>
1510 #include <vms/chfdef.h>
1512 #define HAVE_GNAT_ADJUST_CONTEXT_FOR_RAISE
1515 __gnat_adjust_context_for_raise (int signo ATTRIBUTE_UNUSED
, void *ucontext
)
1517 if (signo
== SS$_HPARITH
)
1519 /* Sub one to the address of the instruction signaling the condition,
1520 located in the sigargs array. */
1522 CHF$MECH_ARRAY
* mechargs
= (CHF$MECH_ARRAY
*) ucontext
;
1523 CHF$SIGNAL_ARRAY
* sigargs
1524 = (CHF$SIGNAL_ARRAY
*) mechargs
->chf$q_mch_sig_addr
;
1526 int vcount
= sigargs
->chf$is_sig_args
;
1527 int * pc_slot
= & (&sigargs
->chf$l_sig_name
)[vcount
-2];
1535 /* __gnat_adjust_context_for_raise for ia64. */
1537 #if defined (IN_RTS) && defined (__IA64)
1539 #include <vms/chfctxdef.h>
1540 #include <vms/chfdef.h>
1542 #define HAVE_GNAT_ADJUST_CONTEXT_FOR_RAISE
1544 typedef unsigned long long u64
;
1547 __gnat_adjust_context_for_raise (int signo ATTRIBUTE_UNUSED
, void *ucontext
)
1549 /* Add one to the address of the instruction signaling the condition,
1550 located in the 64bits sigargs array. */
1552 CHF$MECH_ARRAY
* mechargs
= (CHF$MECH_ARRAY
*) ucontext
;
1554 CHF64$SIGNAL_ARRAY
*chfsig64
1555 = (CHF64$SIGNAL_ARRAY
*) mechargs
->chf$ph_mch_sig64_addr
;
1558 = (u64
*)chfsig64
+ 1 + chfsig64
->chf64$l_sig_args
;
1560 u64
* ih_pc_loc
= post_sigarray
- 2;
1567 /* Easier interface for LIB$GET_LOGICAL: put the equivalence of NAME into BUF,
1568 always NUL terminated. In case of error or if the result is longer than
1569 LEN (length of BUF) an empty string is written info BUF. */
1572 __gnat_vms_get_logical (const char *name
, char *buf
, int len
)
1574 struct descriptor_s name_desc
, result_desc
;
1576 unsigned short rlen
;
1578 /* Build the descriptor for NAME. */
1579 name_desc
.len
= strlen (name
);
1581 name_desc
.adr
= (char *)name
;
1583 /* Build the descriptor for the result. */
1584 result_desc
.len
= len
;
1585 result_desc
.mbz
= 0;
1586 result_desc
.adr
= buf
;
1588 status
= LIB$
GET_LOGICAL (&name_desc
, &result_desc
, &rlen
);
1590 if ((status
& 1) == 1 && rlen
< len
)
1596 /* Size of a page on ia64 and alpha VMS. */
1597 #define VMS_PAGESIZE 8192
1600 #define PSL__C_USER 3
1605 /* Descending region. */
1606 #define VA__M_DESCEND 1
1608 /* Get by virtual address. */
1609 #define VA___REGSUM_BY_VA 1
1611 /* Memory region summary. */
1614 unsigned long long q_region_id
;
1615 unsigned int l_flags
;
1616 unsigned int l_region_protection
;
1618 unsigned long long q_region_size
;
1619 void *pq_first_free_va
;
1622 extern int SYS$
GET_REGION_INFO (unsigned int, unsigned long long *,
1623 void *, void *, unsigned int,
1624 void *, unsigned int *);
1625 extern int SYS$
EXPREG_64 (unsigned long long *, unsigned long long,
1626 unsigned int, unsigned int, void **,
1627 unsigned long long *);
1628 extern int SYS$
SETPRT_64 (void *, unsigned long long, unsigned int,
1629 unsigned int, void **, unsigned long long *,
1631 extern int SYS$
PUTMSG (void *, int (*)(), void *, unsigned long long);
1633 /* Add a guard page in the memory region containing ADDR at ADDR +/- SIZE.
1634 (The sign depends on the kind of the memory region). */
1637 __gnat_set_stack_guard_page (void *addr
, unsigned long size
)
1641 unsigned long long ret_len
;
1642 unsigned int ret_prot
;
1644 unsigned long long length
;
1645 unsigned int retlen
;
1646 struct regsum buffer
;
1648 /* Get the region for ADDR. */
1649 status
= SYS$GET_REGION_INFO
1650 (VA___REGSUM_BY_VA
, NULL
, addr
, NULL
, sizeof (buffer
), &buffer
, &retlen
);
1652 if ((status
& 1) != 1)
1655 /* Extend the region. */
1656 status
= SYS$
EXPREG_64 (&buffer
.q_region_id
,
1657 size
, 0, 0, &start_va
, &length
);
1659 if ((status
& 1) != 1)
1662 /* Create a guard page. */
1663 if (!(buffer
.l_flags
& VA__M_DESCEND
))
1664 start_va
= (void *)((unsigned long long)start_va
+ length
- VMS_PAGESIZE
);
1666 status
= SYS$
SETPRT_64 (start_va
, VMS_PAGESIZE
, PSL__C_USER
, PRT__C_NA
,
1667 &ret_va
, &ret_len
, &ret_prot
);
1669 if ((status
& 1) != 1)
1674 /* Read logicals to limit the stack(s) size. */
1677 __gnat_set_stack_limit (void)
1685 /* The main stack. */
1686 __gnat_vms_get_logical ("GNAT_STACK_SIZE", value
, sizeof (value
));
1687 size
= strtoul (value
, &e
, 0);
1688 if (e
> value
&& *e
== 0)
1690 asm ("mov %0=sp" : "=r" (sp
));
1691 __gnat_set_stack_guard_page (sp
, size
* 1024);
1694 /* The register stack. */
1695 __gnat_vms_get_logical ("GNAT_RBS_SIZE", value
, sizeof (value
));
1696 size
= strtoul (value
, &e
, 0);
1697 if (e
> value
&& *e
== 0)
1699 asm ("mov %0=ar.bsp" : "=r" (sp
));
1700 __gnat_set_stack_guard_page (sp
, size
* 1024);
1705 /* Feature logical name and global variable address pair.
1706 If we ever add another feature logical to this list, the
1707 feature struct will need to be enhanced to take into account
1708 possible values for *gl_addr. */
1714 /* Default values for GNAT features set by environment. */
1715 int __gl_heap_size
= 64;
1717 /* Array feature logical names and global variable addresses. */
1718 static const struct feature features
[] = {
1719 {"GNAT$NO_MALLOC_64", &__gl_heap_size
},
1724 __gnat_set_features (void)
1729 /* Loop through features array and test name for enable/disable. */
1730 for (i
= 0; features
[i
].name
; i
++)
1732 __gnat_vms_get_logical (features
[i
].name
, buff
, sizeof (buff
));
1734 if (strcmp (buff
, "ENABLE") == 0
1735 || strcmp (buff
, "TRUE") == 0
1736 || strcmp (buff
, "1") == 0)
1737 *features
[i
].gl_addr
= 32;
1738 else if (strcmp (buff
, "DISABLE") == 0
1739 || strcmp (buff
, "FALSE") == 0
1740 || strcmp (buff
, "0") == 0)
1741 *features
[i
].gl_addr
= 64;
1744 /* Features to artificially limit the stack size. */
1745 __gnat_set_stack_limit ();
1747 __gnat_features_set
= 1;
1750 /* Return true if the VMS version is 7.x. */
1752 extern unsigned int LIB$
GETSYI (int *, ...);
1754 #define SYI$_VERSION 0x1000
1757 __gnat_is_vms_v7 (void)
1759 struct descriptor_s desc
;
1762 int code
= SYI$_VERSION
;
1764 desc
.len
= sizeof (version
);
1768 status
= LIB$
GETSYI (&code
, 0, &desc
);
1769 if ((status
& 1) == 1 && version
[1] == '7' && version
[2] == '.')
1775 /*******************/
1776 /* FreeBSD Section */
1777 /*******************/
1779 #elif defined (__FreeBSD__)
1782 #include <sys/ucontext.h>
1786 __gnat_error_handler (int sig
,
1787 siginfo_t
*si ATTRIBUTE_UNUSED
,
1788 void *ucontext ATTRIBUTE_UNUSED
)
1790 struct Exception_Data
*exception
;
1796 exception
= &constraint_error
;
1801 exception
= &constraint_error
;
1806 exception
= &storage_error
;
1807 msg
= "stack overflow or erroneous memory access";
1811 exception
= &constraint_error
;
1816 exception
= &program_error
;
1817 msg
= "unhandled signal";
1820 Raise_From_Signal_Handler (exception
, msg
);
1824 __gnat_install_handler ()
1826 struct sigaction act
;
1828 /* Set up signal handler to map synchronous signals to appropriate
1829 exceptions. Make sure that the handler isn't interrupted by another
1830 signal that might cause a scheduling event! */
1833 = (void (*)(int, struct __siginfo
*, void*)) __gnat_error_handler
;
1834 act
.sa_flags
= SA_NODEFER
| SA_RESTART
| SA_SIGINFO
;
1835 (void) sigemptyset (&act
.sa_mask
);
1837 (void) sigaction (SIGILL
, &act
, NULL
);
1838 (void) sigaction (SIGFPE
, &act
, NULL
);
1839 (void) sigaction (SIGSEGV
, &act
, NULL
);
1840 (void) sigaction (SIGBUS
, &act
, NULL
);
1842 __gnat_handler_installed
= 1;
1845 /*******************/
1846 /* VxWorks Section */
1847 /*******************/
1849 #elif defined(__vxworks)
1852 #include <taskLib.h>
1860 #include "private/vThreadsP.h"
1863 void __gnat_error_handler (int, void *, struct sigcontext
*);
1867 /* Directly vectored Interrupt routines are not supported when using RTPs. */
1869 extern int __gnat_inum_to_ivec (int);
1871 /* This is needed by the GNAT run time to handle Vxworks interrupts. */
1873 __gnat_inum_to_ivec (int num
)
1875 return INUM_TO_IVEC (num
);
1879 #if !defined(__alpha_vxworks) && (_WRS_VXWORKS_MAJOR != 6) && !defined(__RTP__)
1881 /* getpid is used by s-parint.adb, but is not defined by VxWorks, except
1882 on Alpha VxWorks and VxWorks 6.x (including RTPs). */
1884 extern long getpid (void);
1889 return taskIdSelf ();
1893 /* VxWorks 653 vThreads expects the field excCnt to be zeroed when a signal is.
1894 handled. The VxWorks version of longjmp does this; GCC's builtin_longjmp
1897 __gnat_clear_exception_count (void)
1900 WIND_TCB
*currentTask
= (WIND_TCB
*) taskIdSelf();
1902 currentTask
->vThreads
.excCnt
= 0;
1906 /* Handle different SIGnal to exception mappings in different VxWorks
1909 __gnat_map_signal (int sig
, void *si ATTRIBUTE_UNUSED
,
1910 struct sigcontext
*sc ATTRIBUTE_UNUSED
)
1912 struct Exception_Data
*exception
;
1918 exception
= &constraint_error
;
1922 #ifdef __VXWORKSMILS__
1924 exception
= &storage_error
;
1925 msg
= "SIGILL: possible stack overflow";
1928 exception
= &storage_error
;
1932 exception
= &program_error
;
1937 exception
= &constraint_error
;
1938 msg
= "Floating point exception or SIGILL";
1941 exception
= &storage_error
;
1945 exception
= &storage_error
;
1946 msg
= "SIGBUS: possible stack overflow";
1949 #elif (_WRS_VXWORKS_MAJOR == 6)
1951 exception
= &constraint_error
;
1955 /* In RTP mode a SIGSEGV is most likely due to a stack overflow,
1956 since stack checking uses the probing mechanism. */
1958 exception
= &storage_error
;
1959 msg
= "SIGSEGV: possible stack overflow";
1962 exception
= &program_error
;
1966 /* VxWorks 6 kernel mode with probing. SIGBUS for guard page hit */
1968 exception
= &storage_error
;
1972 exception
= &storage_error
;
1973 msg
= "SIGBUS: possible stack overflow";
1977 /* VxWorks 5: a SIGILL is most likely due to a stack overflow,
1978 since stack checking uses the stack limit mechanism. */
1980 exception
= &storage_error
;
1981 msg
= "SIGILL: possible stack overflow";
1984 exception
= &storage_error
;
1988 exception
= &program_error
;
1993 exception
= &program_error
;
1994 msg
= "unhandled signal";
1997 __gnat_clear_exception_count ();
1998 Raise_From_Signal_Handler (exception
, msg
);
2001 /* Tasking and Non-tasking signal handler. Map SIGnal to Ada exception
2002 propagation after the required low level adjustments. */
2005 __gnat_error_handler (int sig
, void *si
, struct sigcontext
*sc
)
2009 /* VxWorks will always mask out the signal during the signal handler and
2010 will reenable it on a longjmp. GNAT does not generate a longjmp to
2011 return from a signal handler so the signal will still be masked unless
2013 sigprocmask (SIG_SETMASK
, NULL
, &mask
);
2014 sigdelset (&mask
, sig
);
2015 sigprocmask (SIG_SETMASK
, &mask
, NULL
);
2017 #if defined (__PPC__) && defined(_WRS_KERNEL)
2018 /* On PowerPC, kernel mode, we process signals through a Call Frame Info
2019 trampoline, voiding the need for myriads of fallback_frame_state
2020 variants in the ZCX runtime. We have no simple way to distinguish ZCX
2021 from SJLJ here, so we do this for SJLJ as well even though this is not
2022 necessary. This only incurs a few extra instructions and a tiny
2023 amount of extra stack usage. */
2025 #include "sigtramp.h"
2027 __gnat_sigtramp (sig
, (void *)si
, (void *)sc
,
2028 (sighandler_t
*)&__gnat_map_signal
);
2031 __gnat_map_signal (sig
, si
, sc
);
2036 __gnat_install_handler (void)
2038 struct sigaction act
;
2040 /* Setup signal handler to map synchronous signals to appropriate
2041 exceptions. Make sure that the handler isn't interrupted by another
2042 signal that might cause a scheduling event! */
2044 act
.sa_handler
= __gnat_error_handler
;
2045 act
.sa_flags
= SA_SIGINFO
| SA_ONSTACK
;
2046 sigemptyset (&act
.sa_mask
);
2048 /* For VxWorks, install all signal handlers, since pragma Interrupt_State
2049 applies to vectored hardware interrupts, not signals. */
2050 sigaction (SIGFPE
, &act
, NULL
);
2051 sigaction (SIGILL
, &act
, NULL
);
2052 sigaction (SIGSEGV
, &act
, NULL
);
2053 sigaction (SIGBUS
, &act
, NULL
);
2055 __gnat_handler_installed
= 1;
2058 #define HAVE_GNAT_INIT_FLOAT
2061 __gnat_init_float (void)
2063 /* Disable overflow/underflow exceptions on the PPC processor, needed
2064 to get correct Ada semantics. Note that for AE653 vThreads, the HW
2065 overflow settings are an OS configuration issue. The instructions
2066 below have no effect. */
2067 #if defined (_ARCH_PPC) && !defined (_SOFT_FLOAT) && (!defined (VTHREADS) || defined (__VXWORKSMILS__))
2068 #if defined (__SPE__)
2070 const unsigned long spefscr_mask
= 0xfffffff3;
2071 unsigned long spefscr
;
2072 asm ("mfspr %0, 512" : "=r" (spefscr
));
2073 spefscr
= spefscr
& spefscr_mask
;
2074 asm ("mtspr 512, %0\n\tisync" : : "r" (spefscr
));
2082 #if (defined (__i386__) || defined (i386)) && !defined (VTHREADS)
2083 /* This is used to properly initialize the FPU on an x86 for each
2088 /* Similarly for SPARC64. Achieved by masking bits in the Trap Enable Mask
2089 field of the Floating-point Status Register (see the SPARC Architecture
2090 Manual Version 9, p 48). */
2091 #if defined (sparc64)
2093 #define FSR_TEM_NVM (1 << 27) /* Invalid operand */
2094 #define FSR_TEM_OFM (1 << 26) /* Overflow */
2095 #define FSR_TEM_UFM (1 << 25) /* Underflow */
2096 #define FSR_TEM_DZM (1 << 24) /* Division by Zero */
2097 #define FSR_TEM_NXM (1 << 23) /* Inexact result */
2101 __asm__("st %%fsr, %0" : "=m" (fsr
));
2102 fsr
&= ~(FSR_TEM_OFM
| FSR_TEM_UFM
);
2103 __asm__("ld %0, %%fsr" : : "m" (fsr
));
2108 /* This subprogram is called by System.Task_Primitives.Operations.Enter_Task
2109 (if not null) when a new task is created. It is initialized by
2110 System.Stack_Checking.Operations.Initialize_Stack_Limit.
2111 The use of a hook avoids to drag stack checking subprograms if stack
2112 checking is not used. */
2113 void (*__gnat_set_stack_limit_hook
)(void) = (void (*)(void))0;
2115 /******************/
2116 /* NetBSD Section */
2117 /******************/
2119 #elif defined(__NetBSD__)
2125 __gnat_error_handler (int sig
)
2127 struct Exception_Data
*exception
;
2133 exception
= &constraint_error
;
2137 exception
= &constraint_error
;
2141 exception
= &storage_error
;
2142 msg
= "stack overflow or erroneous memory access";
2145 exception
= &constraint_error
;
2149 exception
= &program_error
;
2150 msg
= "unhandled signal";
2153 Raise_From_Signal_Handler(exception
, msg
);
2157 __gnat_install_handler(void)
2159 struct sigaction act
;
2161 act
.sa_handler
= __gnat_error_handler
;
2162 act
.sa_flags
= SA_NODEFER
| SA_RESTART
;
2163 sigemptyset (&act
.sa_mask
);
2165 /* Do not install handlers if interrupt state is "System". */
2166 if (__gnat_get_interrupt_state (SIGFPE
) != 's')
2167 sigaction (SIGFPE
, &act
, NULL
);
2168 if (__gnat_get_interrupt_state (SIGILL
) != 's')
2169 sigaction (SIGILL
, &act
, NULL
);
2170 if (__gnat_get_interrupt_state (SIGSEGV
) != 's')
2171 sigaction (SIGSEGV
, &act
, NULL
);
2172 if (__gnat_get_interrupt_state (SIGBUS
) != 's')
2173 sigaction (SIGBUS
, &act
, NULL
);
2175 __gnat_handler_installed
= 1;
2178 /*******************/
2179 /* OpenBSD Section */
2180 /*******************/
2182 #elif defined(__OpenBSD__)
2188 __gnat_error_handler (int sig
)
2190 struct Exception_Data
*exception
;
2196 exception
= &constraint_error
;
2200 exception
= &constraint_error
;
2204 exception
= &storage_error
;
2205 msg
= "stack overflow or erroneous memory access";
2208 exception
= &constraint_error
;
2212 exception
= &program_error
;
2213 msg
= "unhandled signal";
2216 Raise_From_Signal_Handler(exception
, msg
);
2220 __gnat_install_handler(void)
2222 struct sigaction act
;
2224 act
.sa_handler
= __gnat_error_handler
;
2225 act
.sa_flags
= SA_NODEFER
| SA_RESTART
;
2226 sigemptyset (&act
.sa_mask
);
2228 /* Do not install handlers if interrupt state is "System" */
2229 if (__gnat_get_interrupt_state (SIGFPE
) != 's')
2230 sigaction (SIGFPE
, &act
, NULL
);
2231 if (__gnat_get_interrupt_state (SIGILL
) != 's')
2232 sigaction (SIGILL
, &act
, NULL
);
2233 if (__gnat_get_interrupt_state (SIGSEGV
) != 's')
2234 sigaction (SIGSEGV
, &act
, NULL
);
2235 if (__gnat_get_interrupt_state (SIGBUS
) != 's')
2236 sigaction (SIGBUS
, &act
, NULL
);
2238 __gnat_handler_installed
= 1;
2241 /******************/
2242 /* Darwin Section */
2243 /******************/
2245 #elif defined(__APPLE__)
2248 #include <sys/syscall.h>
2249 #include <mach/mach_vm.h>
2250 #include <mach/mach_init.h>
2251 #include <mach/vm_statistics.h>
2253 /* This must be in keeping with System.OS_Interface.Alternate_Stack_Size. */
2254 char __gnat_alternate_stack
[32 * 1024]; /* 1 * MINSIGSTKSZ */
2256 /* Defined in xnu unix_signal.c.
2257 Tell the kernel to re-use alt stack when delivering a signal. */
2258 #define UC_RESET_ALT_STACK 0x80000000
2260 /* Return true if ADDR is within a stack guard area. */
2262 __gnat_is_stack_guard (mach_vm_address_t addr
)
2265 vm_region_submap_info_data_64_t info
;
2266 mach_vm_address_t start
;
2267 mach_vm_size_t size
;
2269 mach_msg_type_number_t count
;
2271 count
= VM_REGION_SUBMAP_INFO_COUNT_64
;
2275 kret
= mach_vm_region_recurse (mach_task_self (), &start
, &size
, &depth
,
2276 (vm_region_recurse_info_t
) &info
, &count
);
2277 if (kret
== KERN_SUCCESS
2278 && addr
>= start
&& addr
< (start
+ size
)
2279 && info
.protection
== VM_PROT_NONE
2280 && info
.user_tag
== VM_MEMORY_STACK
)
2286 __gnat_error_handler (int sig
, siginfo_t
*si
, void *ucontext ATTRIBUTE_UNUSED
)
2288 struct Exception_Data
*exception
;
2290 #if defined (__x86_64__)
2291 /* Work around radar #10302855/pr50678, where the unwinders (libunwind or
2292 libgcc_s depending on the system revision) and the DWARF unwind data for
2293 the sigtramp have different ideas about register numbering (causing rbx
2294 and rdx to be transposed).. */
2295 ucontext_t
*uc
= (ucontext_t
*)ucontext
;
2296 unsigned long t
= uc
->uc_mcontext
->__ss
.__rbx
;
2297 uc
->uc_mcontext
->__ss
.__rbx
= uc
->uc_mcontext
->__ss
.__rdx
;
2298 uc
->uc_mcontext
->__ss
.__rdx
= t
;
2305 if (__gnat_is_stack_guard ((unsigned long)si
->si_addr
))
2307 exception
= &storage_error
;
2308 msg
= "stack overflow";
2312 exception
= &constraint_error
;
2313 msg
= "erroneous memory access";
2315 /* Reset the use of alt stack, so that the alt stack will be used
2316 for the next signal delivery.
2317 The stack can't be used in case of stack checking. */
2318 syscall (SYS_sigreturn
, NULL
, UC_RESET_ALT_STACK
);
2322 exception
= &constraint_error
;
2327 exception
= &program_error
;
2328 msg
= "unhandled signal";
2331 Raise_From_Signal_Handler (exception
, msg
);
2335 __gnat_install_handler (void)
2337 struct sigaction act
;
2339 /* Set up signal handler to map synchronous signals to appropriate
2340 exceptions. Make sure that the handler isn't interrupted by another
2341 signal that might cause a scheduling event! Also setup an alternate
2342 stack region for the handler execution so that stack overflows can be
2343 handled properly, avoiding a SEGV generation from stack usage by the
2344 handler itself (and it is required by Darwin). */
2347 stack
.ss_sp
= __gnat_alternate_stack
;
2348 stack
.ss_size
= sizeof (__gnat_alternate_stack
);
2350 sigaltstack (&stack
, NULL
);
2352 act
.sa_flags
= SA_NODEFER
| SA_RESTART
| SA_SIGINFO
;
2353 act
.sa_sigaction
= __gnat_error_handler
;
2354 sigemptyset (&act
.sa_mask
);
2356 /* Do not install handlers if interrupt state is "System". */
2357 if (__gnat_get_interrupt_state (SIGABRT
) != 's')
2358 sigaction (SIGABRT
, &act
, NULL
);
2359 if (__gnat_get_interrupt_state (SIGFPE
) != 's')
2360 sigaction (SIGFPE
, &act
, NULL
);
2361 if (__gnat_get_interrupt_state (SIGILL
) != 's')
2362 sigaction (SIGILL
, &act
, NULL
);
2364 act
.sa_flags
|= SA_ONSTACK
;
2365 if (__gnat_get_interrupt_state (SIGSEGV
) != 's')
2366 sigaction (SIGSEGV
, &act
, NULL
);
2367 if (__gnat_get_interrupt_state (SIGBUS
) != 's')
2368 sigaction (SIGBUS
, &act
, NULL
);
2370 __gnat_handler_installed
= 1;
2375 /* For all other versions of GNAT, the handler does nothing. */
2377 /*******************/
2378 /* Default Section */
2379 /*******************/
2382 __gnat_install_handler (void)
2384 __gnat_handler_installed
= 1;
2389 /*********************/
2390 /* __gnat_init_float */
2391 /*********************/
2393 /* This routine is called as each process thread is created, for possible
2394 initialization of the FP processor. This version is used under INTERIX
2397 #if defined (_WIN32) || defined (__INTERIX) \
2398 || defined (__Lynx__) || defined(__NetBSD__) || defined(__FreeBSD__) \
2399 || defined (__OpenBSD__)
2401 #define HAVE_GNAT_INIT_FLOAT
2404 __gnat_init_float (void)
2406 #if defined (__i386__) || defined (i386) || defined (__x86_64)
2408 /* This is used to properly initialize the FPU on an x86 for each
2413 #endif /* Defined __i386__ */
2417 #ifndef HAVE_GNAT_INIT_FLOAT
2419 /* All targets without a specific __gnat_init_float will use an empty one. */
2421 __gnat_init_float (void)
2426 /***********************************/
2427 /* __gnat_adjust_context_for_raise */
2428 /***********************************/
2430 #ifndef HAVE_GNAT_ADJUST_CONTEXT_FOR_RAISE
2432 /* All targets without a specific version will use an empty one. */
2434 /* Given UCONTEXT a pointer to a context structure received by a signal
2435 handler for SIGNO, perform the necessary adjustments to let the handler
2436 raise an exception. Calls to this routine are not conditioned by the
2437 propagation scheme in use. */
2440 __gnat_adjust_context_for_raise (int signo ATTRIBUTE_UNUSED
,
2441 void *ucontext ATTRIBUTE_UNUSED
)
2443 /* We used to compensate here for the raised from call vs raised from signal
2444 exception discrepancy with the GCC ZCX scheme, but this now can be dealt
2445 with generically in the unwinder (see GCC PR other/26208). This however
2446 requires the use of the _Unwind_GetIPInfo routine in raise-gcc.c, which
2447 is predicated on the definition of HAVE_GETIPINFO at compile time. Only
2448 the VMS ports still do the compensation described in the few lines below.
2450 *** Call vs signal exception discrepancy with GCC ZCX scheme ***
2452 The GCC unwinder expects to be dealing with call return addresses, since
2453 this is the "nominal" case of what we retrieve while unwinding a regular
2456 To evaluate if a handler applies at some point identified by a return
2457 address, the propagation engine needs to determine what region the
2458 corresponding call instruction pertains to. Because the return address
2459 may not be attached to the same region as the call, the unwinder always
2460 subtracts "some" amount from a return address to search the region
2461 tables, amount chosen to ensure that the resulting address is inside the
2464 When we raise an exception from a signal handler, e.g. to transform a
2465 SIGSEGV into Storage_Error, things need to appear as if the signal
2466 handler had been "called" by the instruction which triggered the signal,
2467 so that exception handlers that apply there are considered. What the
2468 unwinder will retrieve as the return address from the signal handler is
2469 what it will find as the faulting instruction address in the signal
2470 context pushed by the kernel. Leaving this address untouched looses, if
2471 the triggering instruction happens to be the very first of a region, as
2472 the later adjustments performed by the unwinder would yield an address
2473 outside that region. We need to compensate for the unwinder adjustments
2474 at some point, and this is what this routine is expected to do.
2476 signo is passed because on some targets for some signals the PC in
2477 context points to the instruction after the faulting one, in which case
2478 the unwinder adjustment is still desired. */