init_signals.cc (11080:31ab5ca6836d) | init_signals.cc (11235:4162427127e9) |
---|---|
1/* | 1/* |
2 * Copyright (c) 2012 ARM Limited | 2 * Copyright (c) 2012, 2015 ARM Limited |
3 * All rights reserved 4 * 5 * The license below extends only to copyright in the software and shall 6 * not be construed as granting a license to any other intellectual 7 * property including but not limited to intellectual property relating 8 * to a hardware implementation of the functionality of the software 9 * licensed hereunder. You may use the software subject to the license 10 * terms below provided that you ensure that this notice is replicated --- 25 unchanged lines hidden (view full) --- 36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 40 * 41 * Authors: Nathan Binkert 42 */ 43 | 3 * All rights reserved 4 * 5 * The license below extends only to copyright in the software and shall 6 * not be construed as granting a license to any other intellectual 7 * property including but not limited to intellectual property relating 8 * to a hardware implementation of the functionality of the software 9 * licensed hereunder. You may use the software subject to the license 10 * terms below provided that you ensure that this notice is replicated --- 25 unchanged lines hidden (view full) --- 36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 40 * 41 * Authors: Nathan Binkert 42 */ 43 |
44#include "sim/init_signals.hh" 45 46#include <sys/types.h> 47#include <unistd.h> 48 |
|
44#include <csignal> 45#include <iostream> 46#include <string> 47 | 49#include <csignal> 50#include <iostream> 51#include <string> 52 |
53#include "base/atomicio.hh" |
|
48#include "base/cprintf.hh" 49#include "sim/async.hh" | 54#include "base/cprintf.hh" 55#include "sim/async.hh" |
56#include "sim/backtrace.hh" |
|
50#include "sim/core.hh" 51#include "sim/eventq.hh" | 57#include "sim/core.hh" 58#include "sim/eventq.hh" |
52#include "sim/init_signals.hh" | |
53 54using namespace std; 55 | 59 60using namespace std; 61 |
62// Use an separate stack for fatal signal handlers 63static uint8_t fatalSigStack[2 * SIGSTKSZ]; 64 65static bool 66setupAltStack() 67{ 68 stack_t stack; 69 stack.ss_sp = fatalSigStack; 70 stack.ss_size = sizeof(fatalSigStack); 71 stack.ss_flags = 0; 72 73 return sigaltstack(&stack, NULL) == 0; 74} 75 76static void 77installSignalHandler(int signal, void (*handler)(int sigtype), 78 int flags = SA_RESTART) 79{ 80 struct sigaction sa; 81 82 memset(&sa, 0, sizeof(sa)); 83 sigemptyset(&sa.sa_mask); 84 sa.sa_handler = handler; 85 sa.sa_flags = flags; 86 87 if (sigaction(signal, &sa, NULL) == -1) 88 panic("Failed to setup handler for signal %i\n", signal); 89} 90 91static void 92raiseFatalSignal(int signo) 93{ 94 // The signal handler should have been reset and unmasked (it was 95 // registered with SA_RESETHAND | SA_NODEFER), just raise the 96 // signal again to invoke the default handler. 97 pthread_kill(pthread_self(), signo); 98 99 // Something is really wrong if the process is alive at this 100 // point, manually try to exit it. 101 STATIC_ERR("Failed to execute default signal handler!\n"); 102 _exit(127); 103} 104 |
|
56/// Stats signal handler. 57void 58dumpStatsHandler(int sigtype) 59{ 60 async_event = true; 61 async_statdump = true; 62 /* Wake up some event queue to handle event */ 63 getEventQueue(0)->wakeup(); --- 18 unchanged lines hidden (view full) --- 82 /* Wake up some event queue to handle event */ 83 getEventQueue(0)->wakeup(); 84} 85 86/// Abort signal handler. 87void 88abortHandler(int sigtype) 89{ | 105/// Stats signal handler. 106void 107dumpStatsHandler(int sigtype) 108{ 109 async_event = true; 110 async_statdump = true; 111 /* Wake up some event queue to handle event */ 112 getEventQueue(0)->wakeup(); --- 18 unchanged lines hidden (view full) --- 131 /* Wake up some event queue to handle event */ 132 getEventQueue(0)->wakeup(); 133} 134 135/// Abort signal handler. 136void 137abortHandler(int sigtype) 138{ |
90 ccprintf(cerr, "Program aborted at tick %llu\n", curTick()); | 139 const EventQueue *const eq(curEventQueue()); 140 if (eq) { 141 ccprintf(cerr, "Program aborted at tick %llu\n", eq->getCurTick()); 142 } else { 143 STATIC_ERR("Program aborted\n\n"); 144 } 145 146 print_backtrace(); 147 raiseFatalSignal(sigtype); |
91} 92 | 148} 149 |
150/// Segmentation fault signal handler. 151static void 152segvHandler(int sigtype) 153{ 154 STATIC_ERR("gem5 has encountered a segmentation fault!\n\n"); 155 156 print_backtrace(); 157 raiseFatalSignal(SIGSEGV); 158} 159 |
|
93// Handle SIGIO 94static void 95ioHandler(int sigtype) 96{ 97 async_event = true; 98 async_io = true; 99 /* Wake up some event queue to handle event */ 100 getEventQueue(0)->wakeup(); 101} 102 | 160// Handle SIGIO 161static void 162ioHandler(int sigtype) 163{ 164 async_event = true; 165 async_io = true; 166 /* Wake up some event queue to handle event */ 167 getEventQueue(0)->wakeup(); 168} 169 |
103static void 104installSignalHandler(int signal, void (*handler)(int sigtype)) 105{ 106 struct sigaction sa; 107 108 memset(&sa, 0, sizeof(sa)); 109 sigemptyset(&sa.sa_mask); 110 sa.sa_handler = handler; 111 sa.sa_flags = SA_RESTART; 112 113 if (sigaction(signal, &sa, NULL) == -1) 114 panic("Failed to setup handler for signal %i\n", signal); 115} 116 | |
117/* 118 * M5 can do several special things when various signals are sent. 119 * None are mandatory. 120 */ 121void 122initSignals() 123{ 124 // Floating point exceptions may happen on misspeculated paths, so --- 7 unchanged lines hidden (view full) --- 132 installSignalHandler(SIGUSR1, dumpStatsHandler); 133 134 // Dump intermediate stats and reset them 135 installSignalHandler(SIGUSR2, dumprstStatsHandler); 136 137 // Exit cleanly on Interrupt (Ctrl-C) 138 installSignalHandler(SIGINT, exitNowHandler); 139 | 170/* 171 * M5 can do several special things when various signals are sent. 172 * None are mandatory. 173 */ 174void 175initSignals() 176{ 177 // Floating point exceptions may happen on misspeculated paths, so --- 7 unchanged lines hidden (view full) --- 185 installSignalHandler(SIGUSR1, dumpStatsHandler); 186 187 // Dump intermediate stats and reset them 188 installSignalHandler(SIGUSR2, dumprstStatsHandler); 189 190 // Exit cleanly on Interrupt (Ctrl-C) 191 installSignalHandler(SIGINT, exitNowHandler); 192 |
140 // Print out cycle number on abort 141 installSignalHandler(SIGABRT, abortHandler); | 193 // Print the current cycle number and a backtrace on abort. Make 194 // sure the signal is unmasked and the handler reset when a signal 195 // is delivered to be able to invoke the default handler. 196 installSignalHandler(SIGABRT, abortHandler, SA_RESETHAND | SA_NODEFER); |
142 | 197 |
198 // Setup a SIGSEGV handler with a private stack 199 if (setupAltStack()) { 200 installSignalHandler(SIGSEGV, segvHandler, 201 SA_RESETHAND | SA_NODEFER | SA_ONSTACK); 202 } else { 203 warn("Failed to setup stack for SIGSEGV handler, " 204 "using default signal handler.\n"); 205 } 206 |
|
143 // Install a SIGIO handler to handle asynchronous file IO. See the 144 // PollQueue class. 145 installSignalHandler(SIGIO, ioHandler); 146} 147 | 207 // Install a SIGIO handler to handle asynchronous file IO. See the 208 // PollQueue class. 209 installSignalHandler(SIGIO, ioHandler); 210} 211 |