blob: 5c5abeb0a6e07dd9c9ac4e4cd5f5efe05bc915ad [file] [log] [blame]
Dave Allisonb373e092014-02-20 16:06:36 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "fault_handler.h"
Ian Rogers22d5e732014-07-15 22:23:51 -070018
Dave Allison8ce6b902014-08-26 11:07:58 -070019#include <setjmp.h>
Dave Allisonb373e092014-02-20 16:06:36 -080020#include <sys/mman.h>
21#include <sys/ucontext.h>
Mathieu Chartiere401d142015-04-22 13:56:20 -070022
23#include "art_method-inl.h"
Andreas Gampe928f72b2014-09-09 19:53:48 -070024#include "base/stl_util.h"
Ian Rogers22d5e732014-07-15 22:23:51 -070025#include "mirror/class.h"
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010026#include "oat_quick_method_header.h"
Dave Allisonf4b80bc2014-05-14 15:41:25 -070027#include "sigchain.h"
Ian Rogers22d5e732014-07-15 22:23:51 -070028#include "thread-inl.h"
Dave Allisonb373e092014-02-20 16:06:36 -080029#include "verify_object-inl.h"
30
Dave Allison8ce6b902014-08-26 11:07:58 -070031// Note on nested signal support
32// -----------------------------
33//
34// Typically a signal handler should not need to deal with signals that occur within it.
35// However, when a SIGSEGV occurs that is in generated code and is not one of the
36// handled signals (implicit checks), we call a function to try to dump the stack
37// to the log. This enhances the debugging experience but may have the side effect
38// that it may not work. If the cause of the original SIGSEGV is a corrupted stack or other
39// memory region, the stack backtrace code may run into trouble and may either crash
40// or fail with an abort (SIGABRT). In either case we don't want that (new) signal to
41// mask the original signal and thus prevent useful debug output from being presented.
42//
43// In order to handle this situation, before we call the stack tracer we do the following:
44//
45// 1. shutdown the fault manager so that we are talking to the real signal management
46// functions rather than those in sigchain.
47// 2. use pthread_sigmask to allow SIGSEGV and SIGABRT signals to be delivered to the
48// thread running the signal handler.
49// 3. set the handler for SIGSEGV and SIGABRT to a secondary signal handler.
50// 4. save the thread's state to the TLS of the current thread using 'setjmp'
51//
52// We then call the stack tracer and one of two things may happen:
53// a. it completes successfully
54// b. it crashes and a signal is raised.
55//
56// In the former case, we fall through and everything is fine. In the latter case
57// our secondary signal handler gets called in a signal context. This results in
58// a call to FaultManager::HandledNestedSignal(), an archirecture specific function
59// whose purpose is to call 'longjmp' on the jmp_buf saved in the TLS of the current
60// thread. This results in a return with a non-zero value from 'setjmp'. We detect this
61// and write something to the log to tell the user that it happened.
62//
63// Regardless of how we got there, we reach the code after the stack tracer and we
64// restore the signal states to their original values, reinstate the fault manager (thus
65// reestablishing the signal chain) and continue.
66
67// This is difficult to test with a runtime test. To invoke the nested signal code
68// on any signal, uncomment the following line and run something that throws a
69// NullPointerException.
70// #define TEST_NESTED_SIGNAL
71
Dave Allisonb373e092014-02-20 16:06:36 -080072namespace art {
73// Static fault manger object accessed by signal handler.
74FaultManager fault_manager;
75
Narayan Kamathc37769b2015-06-17 09:49:40 +010076extern "C" __attribute__((visibility("default"))) void art_sigsegv_fault() {
Dave Allisonf4b80bc2014-05-14 15:41:25 -070077 // Set a breakpoint here to be informed when a SIGSEGV is unhandled by ART.
78 VLOG(signals)<< "Caught unknown SIGSEGV in ART fault handler - chaining to next handler.";
79}
Dave Allisonf4b80bc2014-05-14 15:41:25 -070080
Dave Allisonb373e092014-02-20 16:06:36 -080081// Signal handler called on SIGSEGV.
82static void art_fault_handler(int sig, siginfo_t* info, void* context) {
83 fault_manager.HandleFault(sig, info, context);
84}
85
Dave Allison8ce6b902014-08-26 11:07:58 -070086// Signal handler for dealing with a nested signal.
87static void art_nested_signal_handler(int sig, siginfo_t* info, void* context) {
88 fault_manager.HandleNestedSignal(sig, info, context);
89}
90
Dave Allison1f8ef6f2014-08-20 17:38:41 -070091FaultManager::FaultManager() : initialized_(false) {
Dave Allisonb373e092014-02-20 16:06:36 -080092 sigaction(SIGSEGV, nullptr, &oldaction_);
93}
94
95FaultManager::~FaultManager() {
Dave Allisonb373e092014-02-20 16:06:36 -080096}
97
Mathieu Chartierd0004802014-10-15 16:59:47 -070098static void SetUpArtAction(struct sigaction* action) {
99 action->sa_sigaction = art_fault_handler;
100 sigemptyset(&action->sa_mask);
101 action->sa_flags = SA_SIGINFO | SA_ONSTACK;
102#if !defined(__APPLE__) && !defined(__mips__)
103 action->sa_restorer = nullptr;
104#endif
105}
106
107void FaultManager::EnsureArtActionInFrontOfSignalChain() {
108 if (initialized_) {
109 struct sigaction action;
110 SetUpArtAction(&action);
111 EnsureFrontOfChain(SIGSEGV, &action);
112 } else {
113 LOG(WARNING) << "Can't call " << __FUNCTION__ << " due to unitialized fault manager";
114 }
115}
Dave Allisonf4b80bc2014-05-14 15:41:25 -0700116
Dave Allisonb373e092014-02-20 16:06:36 -0800117void FaultManager::Init() {
Dave Allison1f8ef6f2014-08-20 17:38:41 -0700118 CHECK(!initialized_);
Dave Allisonb373e092014-02-20 16:06:36 -0800119 struct sigaction action;
Mathieu Chartierd0004802014-10-15 16:59:47 -0700120 SetUpArtAction(&action);
Dave Allisonf4b80bc2014-05-14 15:41:25 -0700121
122 // Set our signal handler now.
Dave Allison69dfe512014-07-11 17:11:58 +0000123 int e = sigaction(SIGSEGV, &action, &oldaction_);
124 if (e != 0) {
125 VLOG(signals) << "Failed to claim SEGV: " << strerror(errno);
126 }
Dave Allisonf4b80bc2014-05-14 15:41:25 -0700127 // Make sure our signal handler is called before any user handlers.
128 ClaimSignalChain(SIGSEGV, &oldaction_);
Dave Allison1f8ef6f2014-08-20 17:38:41 -0700129 initialized_ = true;
130}
131
Andreas Gampe928f72b2014-09-09 19:53:48 -0700132void FaultManager::Release() {
Dave Allison1f8ef6f2014-08-20 17:38:41 -0700133 if (initialized_) {
134 UnclaimSignalChain(SIGSEGV);
135 initialized_ = false;
136 }
Dave Allisonb373e092014-02-20 16:06:36 -0800137}
138
Andreas Gampe928f72b2014-09-09 19:53:48 -0700139void FaultManager::Shutdown() {
140 if (initialized_) {
141 Release();
142
143 // Free all handlers.
144 STLDeleteElements(&generated_code_handlers_);
145 STLDeleteElements(&other_handlers_);
146 }
147}
148
jgu211376bdf2016-01-18 09:12:33 -0500149bool FaultManager::HandleFaultByOtherHandlers(int sig, siginfo_t* info, void* context) {
Dave Allison0c2894b2014-08-29 12:06:16 -0700150 Thread* self = Thread::Current();
151
jgu211376bdf2016-01-18 09:12:33 -0500152 DCHECK(self != nullptr);
153 DCHECK(Runtime::Current() != nullptr);
154 DCHECK(Runtime::Current()->IsStarted());
155
Dave Allison0c2894b2014-08-29 12:06:16 -0700156 // Now set up the nested signal handler.
157
Ian Rogersad11e7a2014-11-11 16:55:11 -0800158 // TODO: add SIGSEGV back to the nested signals when we can handle running out stack gracefully.
159 static const int handled_nested_signals[] = {SIGABRT};
160 constexpr size_t num_handled_nested_signals = arraysize(handled_nested_signals);
161
Andreas Gampe928f72b2014-09-09 19:53:48 -0700162 // Release the fault manager so that it will remove the signal chain for
Dave Allison0c2894b2014-08-29 12:06:16 -0700163 // SIGSEGV and we call the real sigaction.
Andreas Gampe928f72b2014-09-09 19:53:48 -0700164 fault_manager.Release();
Dave Allison0c2894b2014-08-29 12:06:16 -0700165
166 // The action for SIGSEGV should be the default handler now.
167
168 // Unblock the signals we allow so that they can be delivered in the signal handler.
169 sigset_t sigset;
170 sigemptyset(&sigset);
Ian Rogersad11e7a2014-11-11 16:55:11 -0800171 for (int signal : handled_nested_signals) {
172 sigaddset(&sigset, signal);
173 }
Dave Allison0c2894b2014-08-29 12:06:16 -0700174 pthread_sigmask(SIG_UNBLOCK, &sigset, nullptr);
175
176 // If we get a signal in this code we want to invoke our nested signal
177 // handler.
Ian Rogersad11e7a2014-11-11 16:55:11 -0800178 struct sigaction action;
179 struct sigaction oldactions[num_handled_nested_signals];
Dave Allison0c2894b2014-08-29 12:06:16 -0700180 action.sa_sigaction = art_nested_signal_handler;
181
182 // Explicitly mask out SIGSEGV and SIGABRT from the nested signal handler. This
183 // should be the default but we definitely don't want these happening in our
184 // nested signal handler.
185 sigemptyset(&action.sa_mask);
Ian Rogersad11e7a2014-11-11 16:55:11 -0800186 for (int signal : handled_nested_signals) {
187 sigaddset(&action.sa_mask, signal);
188 }
Dave Allison0c2894b2014-08-29 12:06:16 -0700189
190 action.sa_flags = SA_SIGINFO | SA_ONSTACK;
191#if !defined(__APPLE__) && !defined(__mips__)
192 action.sa_restorer = nullptr;
193#endif
194
Ian Rogersad11e7a2014-11-11 16:55:11 -0800195 // Catch handled signals to invoke our nested handler.
196 bool success = true;
197 for (size_t i = 0; i < num_handled_nested_signals; ++i) {
198 success = sigaction(handled_nested_signals[i], &action, &oldactions[i]) == 0;
199 if (!success) {
200 PLOG(ERROR) << "Unable to set up nested signal handler";
201 break;
202 }
203 }
jgu211376bdf2016-01-18 09:12:33 -0500204
Ian Rogersad11e7a2014-11-11 16:55:11 -0800205 if (success) {
Dave Allison0c2894b2014-08-29 12:06:16 -0700206 // Save the current state and call the handlers. If anything causes a signal
207 // our nested signal handler will be invoked and this will longjmp to the saved
208 // state.
209 if (setjmp(*self->GetNestedSignalState()) == 0) {
210 for (const auto& handler : other_handlers_) {
211 if (handler->Action(sig, info, context)) {
Dave Allison8be44cf2014-09-04 14:33:42 -0700212 // Restore the signal handlers, reinit the fault manager and return. Signal was
213 // handled.
Ian Rogersad11e7a2014-11-11 16:55:11 -0800214 for (size_t i = 0; i < num_handled_nested_signals; ++i) {
215 success = sigaction(handled_nested_signals[i], &oldactions[i], nullptr) == 0;
216 if (!success) {
217 PLOG(ERROR) << "Unable to restore signal handler";
218 }
219 }
Dave Allison8be44cf2014-09-04 14:33:42 -0700220 fault_manager.Init();
jgu211376bdf2016-01-18 09:12:33 -0500221 return true;
Dave Allison0c2894b2014-08-29 12:06:16 -0700222 }
223 }
224 } else {
225 LOG(ERROR) << "Nested signal detected - original signal being reported";
Dave Allisonb373e092014-02-20 16:06:36 -0800226 }
Dave Allison0c2894b2014-08-29 12:06:16 -0700227
228 // Restore the signal handlers.
Ian Rogersad11e7a2014-11-11 16:55:11 -0800229 for (size_t i = 0; i < num_handled_nested_signals; ++i) {
230 success = sigaction(handled_nested_signals[i], &oldactions[i], nullptr) == 0;
231 if (!success) {
232 PLOG(ERROR) << "Unable to restore signal handler";
233 }
234 }
Dave Allisonb373e092014-02-20 16:06:36 -0800235 }
Dave Allisondfd3b472014-07-16 16:04:32 -0700236
Dave Allison0c2894b2014-08-29 12:06:16 -0700237 // Now put the fault manager back in place.
238 fault_manager.Init();
jgu211376bdf2016-01-18 09:12:33 -0500239 return false;
240}
241
242void FaultManager::HandleFault(int sig, siginfo_t* info, void* context) {
243 // BE CAREFUL ALLOCATING HERE INCLUDING USING LOG(...)
244 //
245 // If malloc calls abort, it will be holding its lock.
246 // If the handler tries to call malloc, it will deadlock.
247 VLOG(signals) << "Handling fault";
248 if (IsInGeneratedCode(info, context, true)) {
249 VLOG(signals) << "in generated code, looking for handler";
250 for (const auto& handler : generated_code_handlers_) {
251 VLOG(signals) << "invoking Action on handler " << handler;
252 if (handler->Action(sig, info, context)) {
253#ifdef TEST_NESTED_SIGNAL
254 // In test mode we want to fall through to stack trace handler
255 // on every signal (in reality this will cause a crash on the first
256 // signal).
257 break;
258#else
259 // We have handled a signal so it's time to return from the
260 // signal handler to the appropriate place.
261 return;
262#endif
263 }
264 }
265
266 // We hit a signal we didn't handle. This might be something for which
267 // we can give more information about so call all registered handlers to see
268 // if it is.
269 if (HandleFaultByOtherHandlers(sig, info, context)) {
270 return;
271 }
272 }
Dave Allisonf4b80bc2014-05-14 15:41:25 -0700273
Dave Allison8be44cf2014-09-04 14:33:42 -0700274 // Set a breakpoint in this function to catch unhandled signals.
275 art_sigsegv_fault();
Dave Allison0c2894b2014-08-29 12:06:16 -0700276
Dave Allison8be44cf2014-09-04 14:33:42 -0700277 // Pass this on to the next handler in the chain, or the default if none.
278 InvokeUserSignalHandler(sig, info, context);
Dave Allisonb373e092014-02-20 16:06:36 -0800279}
280
Mathieu Chartierc751fdc2014-03-30 15:25:44 -0700281void FaultManager::AddHandler(FaultHandler* handler, bool generated_code) {
Andreas Gampe928f72b2014-09-09 19:53:48 -0700282 DCHECK(initialized_);
Mathieu Chartierc751fdc2014-03-30 15:25:44 -0700283 if (generated_code) {
284 generated_code_handlers_.push_back(handler);
285 } else {
286 other_handlers_.push_back(handler);
287 }
288}
289
290void FaultManager::RemoveHandler(FaultHandler* handler) {
291 auto it = std::find(generated_code_handlers_.begin(), generated_code_handlers_.end(), handler);
292 if (it != generated_code_handlers_.end()) {
293 generated_code_handlers_.erase(it);
294 return;
295 }
296 auto it2 = std::find(other_handlers_.begin(), other_handlers_.end(), handler);
297 if (it2 != other_handlers_.end()) {
298 other_handlers_.erase(it);
299 return;
300 }
301 LOG(FATAL) << "Attempted to remove non existent handler " << handler;
302}
Dave Allisonb373e092014-02-20 16:06:36 -0800303
304// This function is called within the signal handler. It checks that
305// the mutator_lock is held (shared). No annotalysis is done.
Dave Allison69dfe512014-07-11 17:11:58 +0000306bool FaultManager::IsInGeneratedCode(siginfo_t* siginfo, void* context, bool check_dex_pc) {
Dave Allisonb373e092014-02-20 16:06:36 -0800307 // We can only be running Java code in the current thread if it
308 // is in Runnable state.
Dave Allison5cd33752014-04-15 15:57:58 -0700309 VLOG(signals) << "Checking for generated code";
Dave Allisonb373e092014-02-20 16:06:36 -0800310 Thread* thread = Thread::Current();
311 if (thread == nullptr) {
Dave Allison5cd33752014-04-15 15:57:58 -0700312 VLOG(signals) << "no current thread";
Dave Allisonb373e092014-02-20 16:06:36 -0800313 return false;
314 }
315
316 ThreadState state = thread->GetState();
317 if (state != kRunnable) {
Dave Allison5cd33752014-04-15 15:57:58 -0700318 VLOG(signals) << "not runnable";
Dave Allisonb373e092014-02-20 16:06:36 -0800319 return false;
320 }
321
322 // Current thread is runnable.
323 // Make sure it has the mutator lock.
324 if (!Locks::mutator_lock_->IsSharedHeld(thread)) {
Dave Allison5cd33752014-04-15 15:57:58 -0700325 VLOG(signals) << "no lock";
Dave Allisonb373e092014-02-20 16:06:36 -0800326 return false;
327 }
328
Nicolas Geoffray7bf2b4f2015-07-08 10:11:59 +0000329 ArtMethod* method_obj = nullptr;
Dave Allisonb373e092014-02-20 16:06:36 -0800330 uintptr_t return_pc = 0;
Mathieu Chartierc751fdc2014-03-30 15:25:44 -0700331 uintptr_t sp = 0;
Dave Allisonb373e092014-02-20 16:06:36 -0800332
333 // Get the architecture specific method address and return address. These
Mathieu Chartierc751fdc2014-03-30 15:25:44 -0700334 // are in architecture specific files in arch/<arch>/fault_handler_<arch>.
Dave Allisondfd3b472014-07-16 16:04:32 -0700335 GetMethodAndReturnPcAndSp(siginfo, context, &method_obj, &return_pc, &sp);
Dave Allisonb373e092014-02-20 16:06:36 -0800336
337 // If we don't have a potential method, we're outta here.
Dave Allison5cd33752014-04-15 15:57:58 -0700338 VLOG(signals) << "potential method: " << method_obj;
Mathieu Chartiere401d142015-04-22 13:56:20 -0700339 // TODO: Check linear alloc and image.
Vladimir Marko14632852015-08-17 12:07:23 +0100340 DCHECK_ALIGNED(ArtMethod::Size(sizeof(void*)), sizeof(void*))
Nicolas Geoffray7bf2b4f2015-07-08 10:11:59 +0000341 << "ArtMethod is not pointer aligned";
342 if (method_obj == nullptr || !IsAligned<sizeof(void*)>(method_obj)) {
Dave Allison5cd33752014-04-15 15:57:58 -0700343 VLOG(signals) << "no method";
Dave Allisonb373e092014-02-20 16:06:36 -0800344 return false;
345 }
346
347 // Verify that the potential method is indeed a method.
348 // TODO: check the GC maps to make sure it's an object.
Dave Allisonb373e092014-02-20 16:06:36 -0800349 // Check that the class pointer inside the object is not null and is aligned.
Mathieu Chartierc751fdc2014-03-30 15:25:44 -0700350 // TODO: Method might be not a heap address, and GetClass could fault.
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800351 // No read barrier because method_obj may not be a real object.
Mathieu Chartiere7f75f32016-02-01 16:08:15 -0800352 mirror::Class* cls = method_obj->GetDeclaringClassUnchecked<kWithoutReadBarrier>();
Dave Allisonb373e092014-02-20 16:06:36 -0800353 if (cls == nullptr) {
Dave Allison5cd33752014-04-15 15:57:58 -0700354 VLOG(signals) << "not a class";
Dave Allisonb373e092014-02-20 16:06:36 -0800355 return false;
356 }
357 if (!IsAligned<kObjectAlignment>(cls)) {
Dave Allison5cd33752014-04-15 15:57:58 -0700358 VLOG(signals) << "not aligned";
Dave Allisonb373e092014-02-20 16:06:36 -0800359 return false;
360 }
361
362
363 if (!VerifyClassClass(cls)) {
Dave Allison5cd33752014-04-15 15:57:58 -0700364 VLOG(signals) << "not a class class";
Dave Allisonb373e092014-02-20 16:06:36 -0800365 return false;
366 }
367
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +0100368 const OatQuickMethodHeader* method_header = method_obj->GetOatQuickMethodHeader(return_pc);
Nicolas Geoffray6bc43742015-10-12 18:11:10 +0100369
Dave Allisonb373e092014-02-20 16:06:36 -0800370 // We can be certain that this is a method now. Check if we have a GC map
371 // at the return PC address.
Dave Allisonf9439142014-03-27 15:10:22 -0700372 if (true || kIsDebugBuild) {
Dave Allison5cd33752014-04-15 15:57:58 -0700373 VLOG(signals) << "looking for dex pc for return pc " << std::hex << return_pc;
Nicolas Geoffray6bc43742015-10-12 18:11:10 +0100374 uint32_t sought_offset = return_pc -
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +0100375 reinterpret_cast<uintptr_t>(method_header->GetEntryPoint());
Dave Allison5cd33752014-04-15 15:57:58 -0700376 VLOG(signals) << "pc offset: " << std::hex << sought_offset;
Dave Allisonf9439142014-03-27 15:10:22 -0700377 }
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +0100378 uint32_t dexpc = method_header->ToDexPc(method_obj, return_pc, false);
Dave Allison5cd33752014-04-15 15:57:58 -0700379 VLOG(signals) << "dexpc: " << dexpc;
Mathieu Chartierc751fdc2014-03-30 15:25:44 -0700380 return !check_dex_pc || dexpc != DexFile::kDexNoIndex;
381}
382
383FaultHandler::FaultHandler(FaultManager* manager) : manager_(manager) {
Dave Allisonb373e092014-02-20 16:06:36 -0800384}
385
386//
387// Null pointer fault handler
388//
Mathieu Chartierc751fdc2014-03-30 15:25:44 -0700389NullPointerHandler::NullPointerHandler(FaultManager* manager) : FaultHandler(manager) {
390 manager_->AddHandler(this, true);
Dave Allisonb373e092014-02-20 16:06:36 -0800391}
392
393//
394// Suspension fault handler
395//
Mathieu Chartierc751fdc2014-03-30 15:25:44 -0700396SuspensionHandler::SuspensionHandler(FaultManager* manager) : FaultHandler(manager) {
397 manager_->AddHandler(this, true);
Dave Allisonb373e092014-02-20 16:06:36 -0800398}
399
400//
401// Stack overflow fault handler
402//
Mathieu Chartierc751fdc2014-03-30 15:25:44 -0700403StackOverflowHandler::StackOverflowHandler(FaultManager* manager) : FaultHandler(manager) {
404 manager_->AddHandler(this, true);
Dave Allisonb373e092014-02-20 16:06:36 -0800405}
Mathieu Chartierc751fdc2014-03-30 15:25:44 -0700406
407//
408// Stack trace handler, used to help get a stack trace from SIGSEGV inside of compiled code.
409//
410JavaStackTraceHandler::JavaStackTraceHandler(FaultManager* manager) : FaultHandler(manager) {
411 manager_->AddHandler(this, false);
412}
413
Roland Levillain4b8f1ec2015-08-26 18:34:03 +0100414bool JavaStackTraceHandler::Action(int sig ATTRIBUTE_UNUSED, siginfo_t* siginfo, void* context) {
Mathieu Chartierc751fdc2014-03-30 15:25:44 -0700415 // Make sure that we are in the generated code, but we may not have a dex pc.
Dave Allison8ce6b902014-08-26 11:07:58 -0700416#ifdef TEST_NESTED_SIGNAL
417 bool in_generated_code = true;
418#else
419 bool in_generated_code = manager_->IsInGeneratedCode(siginfo, context, false);
420#endif
421 if (in_generated_code) {
Mathieu Chartierc751fdc2014-03-30 15:25:44 -0700422 LOG(ERROR) << "Dumping java stack trace for crash in generated code";
Mathieu Chartiere401d142015-04-22 13:56:20 -0700423 ArtMethod* method = nullptr;
Mathieu Chartierc751fdc2014-03-30 15:25:44 -0700424 uintptr_t return_pc = 0;
425 uintptr_t sp = 0;
Mathieu Chartierc751fdc2014-03-30 15:25:44 -0700426 Thread* self = Thread::Current();
Dave Allison8ce6b902014-08-26 11:07:58 -0700427
Dave Allison0c2894b2014-08-29 12:06:16 -0700428 manager_->GetMethodAndReturnPcAndSp(siginfo, context, &method, &return_pc, &sp);
429 // Inside of generated code, sp[0] is the method, so sp is the frame.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700430 self->SetTopOfStack(reinterpret_cast<ArtMethod**>(sp));
Dave Allison8ce6b902014-08-26 11:07:58 -0700431#ifdef TEST_NESTED_SIGNAL
Dave Allison0c2894b2014-08-29 12:06:16 -0700432 // To test the nested signal handler we raise a signal here. This will cause the
433 // nested signal handler to be called and perform a longjmp back to the setjmp
434 // above.
435 abort();
Dave Allison8ce6b902014-08-26 11:07:58 -0700436#endif
Dave Allison0c2894b2014-08-29 12:06:16 -0700437 self->DumpJavaStack(LOG(ERROR));
Mathieu Chartierc751fdc2014-03-30 15:25:44 -0700438 }
Dave Allison8ce6b902014-08-26 11:07:58 -0700439
Mathieu Chartierc751fdc2014-03-30 15:25:44 -0700440 return false; // Return false since we want to propagate the fault to the main signal handler.
441}
442
Dave Allisonb373e092014-02-20 16:06:36 -0800443} // namespace art