hppa: Fix LO_SUM DLTIND14R address support in PRINT_OPERAND_ADDRESS
[official-gcc.git] / gcc / ada / ctrl_c.c
blob8c0a5962067c2b1bd669573ea76b61f7dcb66221
1 /****************************************************************************
2 * *
3 * GNAT COMPILER COMPONENTS *
4 * *
5 * C T R L _ C *
6 * *
7 * C Implementation File *
8 * *
9 * Copyright (C) 2002-2024, 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 #ifndef IN_RTS
33 #include "config.h"
34 #include "system.h"
35 #endif
37 /* Services to intercept Ctrl-C */
39 /* __gnat_install_int_handler will install the specified handler.
40 If called for the first time, it will also save the original handler */
41 void __gnat_install_int_handler (void (*) (void));
43 /* __gnat_uninstall_int_handler will reinstall the original handler */
44 void __gnat_uninstall_int_handler (void);
46 /* POSIX implementation */
48 #if (defined (__unix__) || defined (_AIX) || defined (__APPLE__)) \
49 || defined (VMS) && !defined (__vxworks)
51 #ifdef VMS
52 /* On VMS _gnat_handle_vms_condition gets control first, and it has to
53 resignal the Ctrl/C in order for sigaction to gain control and execute
54 the user handler routine, but in doing so propagates the condition
55 causing the program to terminate. So instead we install a dummy handler
56 routine and put the real user handler in a special global variable so
57 that __gnat_handle_vms_condition can declare an AST to asynchronously
58 execute the Ctrl/C user handler at some future time and allow
59 __gnat_handle_vms_condition to return and not be held up waiting for
60 the potentially unbounded time required to execute the Crtl/C handler. */
61 void
62 dummy_handler () {}
64 /* Lives in init.c. */
65 extern void (*__gnat_ctrl_c_handler) (void);
66 #endif
68 #include <signal.h>
70 void (*sigint_intercepted) (void) = 0;
72 struct sigaction original_act;
74 static void
75 __gnat_int_handler (int sig __attribute__ ((unused)))
77 if (sigint_intercepted != 0)
78 sigint_intercepted ();
81 /* Install handler and save original handler. */
83 void
84 __gnat_install_int_handler (void (*proc) (void))
86 struct sigaction act;
88 if (sigint_intercepted == 0)
90 act.sa_handler = __gnat_int_handler;
91 #if defined (__Lynx__) || defined (VMS) || defined(__DJGPP__)
92 /* LynxOS, VMS and DJGPP do not support SA_RESTART. */
93 act.sa_flags = 0;
94 #else
95 act.sa_flags = SA_RESTART;
96 #endif
97 sigemptyset (&act.sa_mask);
98 sigaction (SIGINT, &act, &original_act);
101 #ifdef VMS
102 sigint_intercepted = &dummy_handler;
103 __gnat_ctrl_c_handler = proc;
104 #else
105 sigint_intercepted = proc;
106 #endif
109 /* Restore original handler */
111 void
112 __gnat_uninstall_int_handler (void)
114 if (sigint_intercepted != 0)
116 sigaction (SIGINT, &original_act, 0);
117 sigint_intercepted = 0;
119 #ifdef VMS
120 if (__gnat_ctrl_c_handler)
121 __gnat_ctrl_c_handler = 0;
122 #endif
125 /* Windows implementation */
127 #elif defined (__MINGW32__)
129 #define WIN32_LEAN_AND_MEAN
130 #include "mingw32.h"
131 #include <windows.h>
133 void (*sigint_intercepted) (void) = NULL;
135 static BOOL WINAPI
136 __gnat_int_handler (DWORD dwCtrlType)
138 switch (dwCtrlType)
140 case CTRL_C_EVENT:
141 case CTRL_BREAK_EVENT:
142 if (sigint_intercepted != 0)
144 sigint_intercepted ();
145 return TRUE;
147 break;
149 case CTRL_CLOSE_EVENT:
150 case CTRL_LOGOFF_EVENT:
151 case CTRL_SHUTDOWN_EVENT:
152 break;
155 return FALSE;
158 void
159 __gnat_install_int_handler (void (*proc) (void))
161 if (sigint_intercepted == NULL)
162 SetConsoleCtrlHandler (__gnat_int_handler, TRUE);
164 sigint_intercepted = proc;
167 void
168 __gnat_uninstall_int_handler (void)
170 if (sigint_intercepted != NULL)
171 SetConsoleCtrlHandler (__gnat_int_handler, FALSE);
173 sigint_intercepted = NULL;
176 /* Default implementation: do nothing */
178 #else
180 void
181 __gnat_install_int_handler (void (*proc) (void) __attribute__ ((unused)))
185 void
186 __gnat_uninstall_int_handler (void)
189 #endif