OLD | NEW |
1 //===- Signals.cpp - Generic Unix Signals Implementation -----*- C++ -*-===// | 1 //===- Signals.cpp - Generic Unix Signals Implementation -----*- C++ -*-===// |
2 // | 2 // |
3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 // | 9 // |
10 // This file defines some helpful functions for dealing with the possibility of | 10 // This file defines some helpful functions for dealing with the possibility of |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 }; | 86 }; |
87 | 87 |
88 static unsigned NumRegisteredSignals = 0; | 88 static unsigned NumRegisteredSignals = 0; |
89 static struct { | 89 static struct { |
90 struct sigaction SA; | 90 struct sigaction SA; |
91 int SigNo; | 91 int SigNo; |
92 } RegisteredSignalInfo[(sizeof(IntSigs)+sizeof(KillSigs))/sizeof(KillSigs[0])]; | 92 } RegisteredSignalInfo[(sizeof(IntSigs)+sizeof(KillSigs))/sizeof(KillSigs[0])]; |
93 | 93 |
94 | 94 |
95 static void RegisterHandler(int Signal) { | 95 static void RegisterHandler(int Signal) { |
| 96 #if !defined(__native_client__) |
96 assert(NumRegisteredSignals < | 97 assert(NumRegisteredSignals < |
97 sizeof(RegisteredSignalInfo)/sizeof(RegisteredSignalInfo[0]) && | 98 sizeof(RegisteredSignalInfo)/sizeof(RegisteredSignalInfo[0]) && |
98 "Out of space for signal handlers!"); | 99 "Out of space for signal handlers!"); |
99 | 100 |
100 struct sigaction NewHandler; | 101 struct sigaction NewHandler; |
101 | 102 |
102 NewHandler.sa_handler = SignalHandler; | 103 NewHandler.sa_handler = SignalHandler; |
103 NewHandler.sa_flags = SA_NODEFER|SA_RESETHAND; | 104 NewHandler.sa_flags = SA_NODEFER|SA_RESETHAND; |
104 sigemptyset(&NewHandler.sa_mask); | 105 sigemptyset(&NewHandler.sa_mask); |
105 | 106 |
106 // Install the new handler, save the old one in RegisteredSignalInfo. | 107 // Install the new handler, save the old one in RegisteredSignalInfo. |
107 sigaction(Signal, &NewHandler, | 108 sigaction(Signal, &NewHandler, |
108 &RegisteredSignalInfo[NumRegisteredSignals].SA); | 109 &RegisteredSignalInfo[NumRegisteredSignals].SA); |
109 RegisteredSignalInfo[NumRegisteredSignals].SigNo = Signal; | 110 RegisteredSignalInfo[NumRegisteredSignals].SigNo = Signal; |
110 ++NumRegisteredSignals; | 111 ++NumRegisteredSignals; |
| 112 #endif // (__native_client__) |
111 } | 113 } |
112 | 114 |
113 static void RegisterHandlers() { | 115 static void RegisterHandlers() { |
114 // If the handlers are already registered, we're done. | 116 // If the handlers are already registered, we're done. |
115 if (NumRegisteredSignals != 0) return; | 117 if (NumRegisteredSignals != 0) return; |
116 | 118 |
117 for (auto S : IntSigs) RegisterHandler(S); | 119 for (auto S : IntSigs) RegisterHandler(S); |
118 for (auto S : KillSigs) RegisterHandler(S); | 120 for (auto S : KillSigs) RegisterHandler(S); |
119 } | 121 } |
120 | 122 |
121 static void UnregisterHandlers() { | 123 static void UnregisterHandlers() { |
| 124 #if !defined(__native_client__) |
122 // Restore all of the signal handlers to how they were before we showed up. | 125 // Restore all of the signal handlers to how they were before we showed up. |
123 for (unsigned i = 0, e = NumRegisteredSignals; i != e; ++i) | 126 for (unsigned i = 0, e = NumRegisteredSignals; i != e; ++i) |
124 sigaction(RegisteredSignalInfo[i].SigNo, | 127 sigaction(RegisteredSignalInfo[i].SigNo, |
125 &RegisteredSignalInfo[i].SA, nullptr); | 128 &RegisteredSignalInfo[i].SA, nullptr); |
126 NumRegisteredSignals = 0; | 129 NumRegisteredSignals = 0; |
| 130 #endif // (__native_client__) |
127 } | 131 } |
128 | 132 |
129 | 133 |
130 /// RemoveFilesToRemove - Process the FilesToRemove list. This function | 134 /// RemoveFilesToRemove - Process the FilesToRemove list. This function |
131 /// should be called with the SignalsMutex lock held. | 135 /// should be called with the SignalsMutex lock held. |
132 /// NB: This must be an async signal safe function. It cannot allocate or free | 136 /// NB: This must be an async signal safe function. It cannot allocate or free |
133 /// memory, even in debug builds. | 137 /// memory, even in debug builds. |
134 static void RemoveFilesToRemove() { | 138 static void RemoveFilesToRemove() { |
135 // We avoid iterators in case of debug iterators that allocate or release | 139 // We avoid iterators in case of debug iterators that allocate or release |
136 // memory. | 140 // memory. |
(...skipping 23 matching lines...) Expand all Loading... |
160 } | 164 } |
161 | 165 |
162 // SignalHandler - The signal handler that runs. | 166 // SignalHandler - The signal handler that runs. |
163 static RETSIGTYPE SignalHandler(int Sig) { | 167 static RETSIGTYPE SignalHandler(int Sig) { |
164 // Restore the signal behavior to default, so that the program actually | 168 // Restore the signal behavior to default, so that the program actually |
165 // crashes when we return and the signal reissues. This also ensures that if | 169 // crashes when we return and the signal reissues. This also ensures that if |
166 // we crash in our signal handler that the program will terminate immediately | 170 // we crash in our signal handler that the program will terminate immediately |
167 // instead of recursing in the signal handler. | 171 // instead of recursing in the signal handler. |
168 UnregisterHandlers(); | 172 UnregisterHandlers(); |
169 | 173 |
| 174 #if !defined(__native_client__) |
170 // Unmask all potentially blocked kill signals. | 175 // Unmask all potentially blocked kill signals. |
171 sigset_t SigMask; | 176 sigset_t SigMask; |
172 sigfillset(&SigMask); | 177 sigfillset(&SigMask); |
173 sigprocmask(SIG_UNBLOCK, &SigMask, nullptr); | 178 sigprocmask(SIG_UNBLOCK, &SigMask, nullptr); |
| 179 #endif |
174 | 180 |
175 { | 181 { |
176 unique_lock<SmartMutex<true>> Guard(*SignalsMutex); | 182 unique_lock<SmartMutex<true>> Guard(*SignalsMutex); |
177 RemoveFilesToRemove(); | 183 RemoveFilesToRemove(); |
178 | 184 |
179 if (std::find(std::begin(IntSigs), std::end(IntSigs), Sig) | 185 if (std::find(std::begin(IntSigs), std::end(IntSigs), Sig) |
180 != std::end(IntSigs)) { | 186 != std::end(IntSigs)) { |
181 if (InterruptFunction) { | 187 if (InterruptFunction) { |
182 void (*IF)() = InterruptFunction; | 188 void (*IF)() = InterruptFunction; |
183 Guard.unlock(); | 189 Guard.unlock(); |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 abort(); | 539 abort(); |
534 } | 540 } |
535 | 541 |
536 void abort() { | 542 void abort() { |
537 raise(SIGABRT); | 543 raise(SIGABRT); |
538 usleep(1000); | 544 usleep(1000); |
539 __builtin_trap(); | 545 __builtin_trap(); |
540 } | 546 } |
541 | 547 |
542 #endif | 548 #endif |
OLD | NEW |