blob: 762f061ce2fb42883afd8dd8d6a2315429857200 [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"
Dave Allisonf4b80bc2014-05-14 15:41:25 -070026#include "sigchain.h"
Ian Rogers22d5e732014-07-15 22:23:51 -070027#include "thread-inl.h"
Dave Allisonb373e092014-02-20 16:06:36 -080028#include "verify_object-inl.h"
29
Dave Allison8ce6b902014-08-26 11:07:58 -070030// Note on nested signal support
31// -----------------------------
32//
33// Typically a signal handler should not need to deal with signals that occur within it.
34// However, when a SIGSEGV occurs that is in generated code and is not one of the
35// handled signals (implicit checks), we call a function to try to dump the stack
36// to the log. This enhances the debugging experience but may have the side effect
37// that it may not work. If the cause of the original SIGSEGV is a corrupted stack or other
38// memory region, the stack backtrace code may run into trouble and may either crash
39// or fail with an abort (SIGABRT). In either case we don't want that (new) signal to
40// mask the original signal and thus prevent useful debug output from being presented.
41//
42// In order to handle this situation, before we call the stack tracer we do the following:
43//
44// 1. shutdown the fault manager so that we are talking to the real signal management
45// functions rather than those in sigchain.
46// 2. use pthread_sigmask to allow SIGSEGV and SIGABRT signals to be delivered to the
47// thread running the signal handler.
48// 3. set the handler for SIGSEGV and SIGABRT to a secondary signal handler.
49// 4. save the thread's state to the TLS of the current thread using 'setjmp'
50//
51// We then call the stack tracer and one of two things may happen:
52// a. it completes successfully
53// b. it crashes and a signal is raised.
54//
55// In the former case, we fall through and everything is fine. In the latter case
56// our secondary signal handler gets called in a signal context. This results in
57// a call to FaultManager::HandledNestedSignal(), an archirecture specific function
58// whose purpose is to call 'longjmp' on the jmp_buf saved in the TLS of the current
59// thread. This results in a return with a non-zero value from 'setjmp'. We detect this
60// and write something to the log to tell the user that it happened.
61//
62// Regardless of how we got there, we reach the code after the stack tracer and we
63// restore the signal states to their original values, reinstate the fault manager (thus
64// reestablishing the signal chain) and continue.
65
66// This is difficult to test with a runtime test. To invoke the nested signal code
67// on any signal, uncomment the following line and run something that throws a
68// NullPointerException.
69// #define TEST_NESTED_SIGNAL
70
Dave Allisonb373e092014-02-20 16:06:36 -080071namespace art {
72// Static fault manger object accessed by signal handler.
73FaultManager fault_manager;
74
Narayan Kamathc37769b2015-06-17 09:49:40 +010075extern "C" __attribute__((visibility("default"))) void art_sigsegv_fault() {
Dave Allisonf4b80bc2014-05-14 15:41:25 -070076 // Set a breakpoint here to be informed when a SIGSEGV is unhandled by ART.
77 VLOG(signals)<< "Caught unknown SIGSEGV in ART fault handler - chaining to next handler.";
78}
Dave Allisonf4b80bc2014-05-14 15:41:25 -070079
Dave Allisonb373e092014-02-20 16:06:36 -080080// Signal handler called on SIGSEGV.
81static void art_fault_handler(int sig, siginfo_t* info, void* context) {
82 fault_manager.HandleFault(sig, info, context);
83}
84
Dave Allison8ce6b902014-08-26 11:07:58 -070085// Signal handler for dealing with a nested signal.
86static void art_nested_signal_handler(int sig, siginfo_t* info, void* context) {
87 fault_manager.HandleNestedSignal(sig, info, context);
88}
89
Dave Allison1f8ef6f2014-08-20 17:38:41 -070090FaultManager::FaultManager() : initialized_(false) {
Dave Allisonb373e092014-02-20 16:06:36 -080091 sigaction(SIGSEGV, nullptr, &oldaction_);
92}
93
94FaultManager::~FaultManager() {
Dave Allisonb373e092014-02-20 16:06:36 -080095}
96
Mathieu Chartierd0004802014-10-15 16:59:47 -070097static void SetUpArtAction(struct sigaction* action) {
98 action->sa_sigaction = art_fault_handler;
99 sigemptyset(&action->sa_mask);
100 action->sa_flags = SA_SIGINFO | SA_ONSTACK;
101#if !defined(__APPLE__) && !defined(__mips__)
102 action->sa_restorer = nullptr;
103#endif
104}
105
106void FaultManager::EnsureArtActionInFrontOfSignalChain() {
107 if (initialized_) {
108 struct sigaction action;
109 SetUpArtAction(&action);
110 EnsureFrontOfChain(SIGSEGV, &action);
111 } else {
112 LOG(WARNING) << "Can't call " << __FUNCTION__ << " due to unitialized fault manager";
113 }
114}
Dave Allisonf4b80bc2014-05-14 15:41:25 -0700115
Dave Allisonb373e092014-02-20 16:06:36 -0800116void FaultManager::Init() {
Dave Allison1f8ef6f2014-08-20 17:38:41 -0700117 CHECK(!initialized_);
Dave Allisonb373e092014-02-20 16:06:36 -0800118 struct sigaction action;
Mathieu Chartierd0004802014-10-15 16:59:47 -0700119 SetUpArtAction(&action);
Dave Allisonf4b80bc2014-05-14 15:41:25 -0700120
121 // Set our signal handler now.
Dave Allison69dfe512014-07-11 17:11:58 +0000122 int e = sigaction(SIGSEGV, &action, &oldaction_);
123 if (e != 0) {
124 VLOG(signals) << "Failed to claim SEGV: " << strerror(errno);
125 }
Dave Allisonf4b80bc2014-05-14 15:41:25 -0700126 // Make sure our signal handler is called before any user handlers.
127 ClaimSignalChain(SIGSEGV, &oldaction_);
Dave Allison1f8ef6f2014-08-20 17:38:41 -0700128 initialized_ = true;
129}
130
Andreas Gampe928f72b2014-09-09 19:53:48 -0700131void FaultManager::Release() {
Dave Allison1f8ef6f2014-08-20 17:38:41 -0700132 if (initialized_) {
133 UnclaimSignalChain(SIGSEGV);
134 initialized_ = false;
135 }
Dave Allisonb373e092014-02-20 16:06:36 -0800136}
137
Andreas Gampe928f72b2014-09-09 19:53:48 -0700138void FaultManager::Shutdown() {
139 if (initialized_) {
140 Release();
141
142 // Free all handlers.
143 STLDeleteElements(&generated_code_handlers_);
144 STLDeleteElements(&other_handlers_);
145 }
146}
147
Dave Allisonb373e092014-02-20 16:06:36 -0800148void FaultManager::HandleFault(int sig, siginfo_t* info, void* context) {
Brian Carlstrom4d466a82014-05-08 19:05:29 -0700149 // BE CAREFUL ALLOCATING HERE INCLUDING USING LOG(...)
150 //
151 // If malloc calls abort, it will be holding its lock.
152 // If the handler tries to call malloc, it will deadlock.
153 VLOG(signals) << "Handling fault";
Dave Allison69dfe512014-07-11 17:11:58 +0000154 if (IsInGeneratedCode(info, context, true)) {
Brian Carlstrom4d466a82014-05-08 19:05:29 -0700155 VLOG(signals) << "in generated code, looking for handler";
Mathieu Chartierc751fdc2014-03-30 15:25:44 -0700156 for (const auto& handler : generated_code_handlers_) {
Brian Carlstrom4d466a82014-05-08 19:05:29 -0700157 VLOG(signals) << "invoking Action on handler " << handler;
Mathieu Chartierc751fdc2014-03-30 15:25:44 -0700158 if (handler->Action(sig, info, context)) {
Dave Allison8ce6b902014-08-26 11:07:58 -0700159#ifdef TEST_NESTED_SIGNAL
160 // In test mode we want to fall through to stack trace handler
161 // on every signal (in reality this will cause a crash on the first
162 // signal).
163 break;
164#else
165 // We have handled a signal so it's time to return from the
166 // signal handler to the appropriate place.
Dave Allisonb373e092014-02-20 16:06:36 -0800167 return;
Dave Allison8ce6b902014-08-26 11:07:58 -0700168#endif
Dave Allisonb373e092014-02-20 16:06:36 -0800169 }
170 }
171 }
Dave Allison8ce6b902014-08-26 11:07:58 -0700172
173 // We hit a signal we didn't handle. This might be something for which
174 // we can give more information about so call all registered handlers to see
175 // if it is.
Dave Allison0c2894b2014-08-29 12:06:16 -0700176
177 Thread* self = Thread::Current();
178
Christopher Ferris5e2b8742014-11-18 15:50:47 -0800179 // If ART is not running, or the thread is not attached to ART pass the
180 // signal on to the next handler in the chain.
181 if (self == nullptr || Runtime::Current() == nullptr || !Runtime::Current()->IsStarted()) {
182 InvokeUserSignalHandler(sig, info, context);
183 return;
184 }
Dave Allison0c2894b2014-08-29 12:06:16 -0700185 // Now set up the nested signal handler.
186
Ian Rogersad11e7a2014-11-11 16:55:11 -0800187 // TODO: add SIGSEGV back to the nested signals when we can handle running out stack gracefully.
188 static const int handled_nested_signals[] = {SIGABRT};
189 constexpr size_t num_handled_nested_signals = arraysize(handled_nested_signals);
190
Andreas Gampe928f72b2014-09-09 19:53:48 -0700191 // Release the fault manager so that it will remove the signal chain for
Dave Allison0c2894b2014-08-29 12:06:16 -0700192 // SIGSEGV and we call the real sigaction.
Andreas Gampe928f72b2014-09-09 19:53:48 -0700193 fault_manager.Release();
Dave Allison0c2894b2014-08-29 12:06:16 -0700194
195 // The action for SIGSEGV should be the default handler now.
196
197 // Unblock the signals we allow so that they can be delivered in the signal handler.
198 sigset_t sigset;
199 sigemptyset(&sigset);
Ian Rogersad11e7a2014-11-11 16:55:11 -0800200 for (int signal : handled_nested_signals) {
201 sigaddset(&sigset, signal);
202 }
Dave Allison0c2894b2014-08-29 12:06:16 -0700203 pthread_sigmask(SIG_UNBLOCK, &sigset, nullptr);
204
205 // If we get a signal in this code we want to invoke our nested signal
206 // handler.
Ian Rogersad11e7a2014-11-11 16:55:11 -0800207 struct sigaction action;
208 struct sigaction oldactions[num_handled_nested_signals];
Dave Allison0c2894b2014-08-29 12:06:16 -0700209 action.sa_sigaction = art_nested_signal_handler;
210
211 // Explicitly mask out SIGSEGV and SIGABRT from the nested signal handler. This
212 // should be the default but we definitely don't want these happening in our
213 // nested signal handler.
214 sigemptyset(&action.sa_mask);
Ian Rogersad11e7a2014-11-11 16:55:11 -0800215 for (int signal : handled_nested_signals) {
216 sigaddset(&action.sa_mask, signal);
217 }
Dave Allison0c2894b2014-08-29 12:06:16 -0700218
219 action.sa_flags = SA_SIGINFO | SA_ONSTACK;
220#if !defined(__APPLE__) && !defined(__mips__)
221 action.sa_restorer = nullptr;
222#endif
223
Ian Rogersad11e7a2014-11-11 16:55:11 -0800224 // Catch handled signals to invoke our nested handler.
225 bool success = true;
226 for (size_t i = 0; i < num_handled_nested_signals; ++i) {
227 success = sigaction(handled_nested_signals[i], &action, &oldactions[i]) == 0;
228 if (!success) {
229 PLOG(ERROR) << "Unable to set up nested signal handler";
230 break;
231 }
232 }
233 if (success) {
Dave Allison0c2894b2014-08-29 12:06:16 -0700234 // Save the current state and call the handlers. If anything causes a signal
235 // our nested signal handler will be invoked and this will longjmp to the saved
236 // state.
237 if (setjmp(*self->GetNestedSignalState()) == 0) {
238 for (const auto& handler : other_handlers_) {
239 if (handler->Action(sig, info, context)) {
Dave Allison8be44cf2014-09-04 14:33:42 -0700240 // Restore the signal handlers, reinit the fault manager and return. Signal was
241 // handled.
Ian Rogersad11e7a2014-11-11 16:55:11 -0800242 for (size_t i = 0; i < num_handled_nested_signals; ++i) {
243 success = sigaction(handled_nested_signals[i], &oldactions[i], nullptr) == 0;
244 if (!success) {
245 PLOG(ERROR) << "Unable to restore signal handler";
246 }
247 }
Dave Allison8be44cf2014-09-04 14:33:42 -0700248 fault_manager.Init();
249 return;
Dave Allison0c2894b2014-08-29 12:06:16 -0700250 }
251 }
252 } else {
253 LOG(ERROR) << "Nested signal detected - original signal being reported";
Dave Allisonb373e092014-02-20 16:06:36 -0800254 }
Dave Allison0c2894b2014-08-29 12:06:16 -0700255
256 // Restore the signal handlers.
Ian Rogersad11e7a2014-11-11 16:55:11 -0800257 for (size_t i = 0; i < num_handled_nested_signals; ++i) {
258 success = sigaction(handled_nested_signals[i], &oldactions[i], nullptr) == 0;
259 if (!success) {
260 PLOG(ERROR) << "Unable to restore signal handler";
261 }
262 }
Dave Allisonb373e092014-02-20 16:06:36 -0800263 }
Dave Allisondfd3b472014-07-16 16:04:32 -0700264
Dave Allison0c2894b2014-08-29 12:06:16 -0700265 // Now put the fault manager back in place.
266 fault_manager.Init();
Dave Allisonf4b80bc2014-05-14 15:41:25 -0700267
Dave Allison8be44cf2014-09-04 14:33:42 -0700268 // Set a breakpoint in this function to catch unhandled signals.
269 art_sigsegv_fault();
Dave Allison0c2894b2014-08-29 12:06:16 -0700270
Dave Allison8be44cf2014-09-04 14:33:42 -0700271 // Pass this on to the next handler in the chain, or the default if none.
272 InvokeUserSignalHandler(sig, info, context);
Dave Allisonb373e092014-02-20 16:06:36 -0800273}
274
Mathieu Chartierc751fdc2014-03-30 15:25:44 -0700275void FaultManager::AddHandler(FaultHandler* handler, bool generated_code) {
Andreas Gampe928f72b2014-09-09 19:53:48 -0700276 DCHECK(initialized_);
Mathieu Chartierc751fdc2014-03-30 15:25:44 -0700277 if (generated_code) {
278 generated_code_handlers_.push_back(handler);
279 } else {
280 other_handlers_.push_back(handler);
281 }
282}
283
284void FaultManager::RemoveHandler(FaultHandler* handler) {
285 auto it = std::find(generated_code_handlers_.begin(), generated_code_handlers_.end(), handler);
286 if (it != generated_code_handlers_.end()) {
287 generated_code_handlers_.erase(it);
288 return;
289 }
290 auto it2 = std::find(other_handlers_.begin(), other_handlers_.end(), handler);
291 if (it2 != other_handlers_.end()) {
292 other_handlers_.erase(it);
293 return;
294 }
295 LOG(FATAL) << "Attempted to remove non existent handler " << handler;
296}
Dave Allisonb373e092014-02-20 16:06:36 -0800297
298// This function is called within the signal handler. It checks that
299// the mutator_lock is held (shared). No annotalysis is done.
Dave Allison69dfe512014-07-11 17:11:58 +0000300bool FaultManager::IsInGeneratedCode(siginfo_t* siginfo, void* context, bool check_dex_pc) {
Dave Allisonb373e092014-02-20 16:06:36 -0800301 // We can only be running Java code in the current thread if it
302 // is in Runnable state.
Dave Allison5cd33752014-04-15 15:57:58 -0700303 VLOG(signals) << "Checking for generated code";
Dave Allisonb373e092014-02-20 16:06:36 -0800304 Thread* thread = Thread::Current();
305 if (thread == nullptr) {
Dave Allison5cd33752014-04-15 15:57:58 -0700306 VLOG(signals) << "no current thread";
Dave Allisonb373e092014-02-20 16:06:36 -0800307 return false;
308 }
309
310 ThreadState state = thread->GetState();
311 if (state != kRunnable) {
Dave Allison5cd33752014-04-15 15:57:58 -0700312 VLOG(signals) << "not runnable";
Dave Allisonb373e092014-02-20 16:06:36 -0800313 return false;
314 }
315
316 // Current thread is runnable.
317 // Make sure it has the mutator lock.
318 if (!Locks::mutator_lock_->IsSharedHeld(thread)) {
Dave Allison5cd33752014-04-15 15:57:58 -0700319 VLOG(signals) << "no lock";
Dave Allisonb373e092014-02-20 16:06:36 -0800320 return false;
321 }
322
Mathieu Chartiere401d142015-04-22 13:56:20 -0700323 ArtMethod* method_obj = 0;
Dave Allisonb373e092014-02-20 16:06:36 -0800324 uintptr_t return_pc = 0;
Mathieu Chartierc751fdc2014-03-30 15:25:44 -0700325 uintptr_t sp = 0;
Dave Allisonb373e092014-02-20 16:06:36 -0800326
327 // Get the architecture specific method address and return address. These
Mathieu Chartierc751fdc2014-03-30 15:25:44 -0700328 // are in architecture specific files in arch/<arch>/fault_handler_<arch>.
Dave Allisondfd3b472014-07-16 16:04:32 -0700329 GetMethodAndReturnPcAndSp(siginfo, context, &method_obj, &return_pc, &sp);
Dave Allisonb373e092014-02-20 16:06:36 -0800330
331 // If we don't have a potential method, we're outta here.
Dave Allison5cd33752014-04-15 15:57:58 -0700332 VLOG(signals) << "potential method: " << method_obj;
Mathieu Chartiere401d142015-04-22 13:56:20 -0700333 // TODO: Check linear alloc and image.
Mathieu Chartierc751fdc2014-03-30 15:25:44 -0700334 if (method_obj == 0 || !IsAligned<kObjectAlignment>(method_obj)) {
Dave Allison5cd33752014-04-15 15:57:58 -0700335 VLOG(signals) << "no method";
Dave Allisonb373e092014-02-20 16:06:36 -0800336 return false;
337 }
338
339 // Verify that the potential method is indeed a method.
340 // TODO: check the GC maps to make sure it's an object.
Dave Allisonb373e092014-02-20 16:06:36 -0800341 // Check that the class pointer inside the object is not null and is aligned.
Mathieu Chartierc751fdc2014-03-30 15:25:44 -0700342 // TODO: Method might be not a heap address, and GetClass could fault.
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800343 // No read barrier because method_obj may not be a real object.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700344 mirror::Class* cls = method_obj->GetDeclaringClassNoBarrier();
Dave Allisonb373e092014-02-20 16:06:36 -0800345 if (cls == nullptr) {
Dave Allison5cd33752014-04-15 15:57:58 -0700346 VLOG(signals) << "not a class";
Dave Allisonb373e092014-02-20 16:06:36 -0800347 return false;
348 }
349 if (!IsAligned<kObjectAlignment>(cls)) {
Dave Allison5cd33752014-04-15 15:57:58 -0700350 VLOG(signals) << "not aligned";
Dave Allisonb373e092014-02-20 16:06:36 -0800351 return false;
352 }
353
354
355 if (!VerifyClassClass(cls)) {
Dave Allison5cd33752014-04-15 15:57:58 -0700356 VLOG(signals) << "not a class class";
Dave Allisonb373e092014-02-20 16:06:36 -0800357 return false;
358 }
359
Dave Allisonb373e092014-02-20 16:06:36 -0800360 // We can be certain that this is a method now. Check if we have a GC map
361 // at the return PC address.
Dave Allisonf9439142014-03-27 15:10:22 -0700362 if (true || kIsDebugBuild) {
Dave Allison5cd33752014-04-15 15:57:58 -0700363 VLOG(signals) << "looking for dex pc for return pc " << std::hex << return_pc;
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800364 const void* code = Runtime::Current()->GetInstrumentation()->GetQuickCodeFor(method_obj,
365 sizeof(void*));
Dave Allisonf9439142014-03-27 15:10:22 -0700366 uint32_t sought_offset = return_pc - reinterpret_cast<uintptr_t>(code);
Dave Allison5cd33752014-04-15 15:57:58 -0700367 VLOG(signals) << "pc offset: " << std::hex << sought_offset;
Dave Allisonf9439142014-03-27 15:10:22 -0700368 }
Mathieu Chartierc751fdc2014-03-30 15:25:44 -0700369 uint32_t dexpc = method_obj->ToDexPc(return_pc, false);
Dave Allison5cd33752014-04-15 15:57:58 -0700370 VLOG(signals) << "dexpc: " << dexpc;
Mathieu Chartierc751fdc2014-03-30 15:25:44 -0700371 return !check_dex_pc || dexpc != DexFile::kDexNoIndex;
372}
373
374FaultHandler::FaultHandler(FaultManager* manager) : manager_(manager) {
Dave Allisonb373e092014-02-20 16:06:36 -0800375}
376
377//
378// Null pointer fault handler
379//
Mathieu Chartierc751fdc2014-03-30 15:25:44 -0700380NullPointerHandler::NullPointerHandler(FaultManager* manager) : FaultHandler(manager) {
381 manager_->AddHandler(this, true);
Dave Allisonb373e092014-02-20 16:06:36 -0800382}
383
384//
385// Suspension fault handler
386//
Mathieu Chartierc751fdc2014-03-30 15:25:44 -0700387SuspensionHandler::SuspensionHandler(FaultManager* manager) : FaultHandler(manager) {
388 manager_->AddHandler(this, true);
Dave Allisonb373e092014-02-20 16:06:36 -0800389}
390
391//
392// Stack overflow fault handler
393//
Mathieu Chartierc751fdc2014-03-30 15:25:44 -0700394StackOverflowHandler::StackOverflowHandler(FaultManager* manager) : FaultHandler(manager) {
395 manager_->AddHandler(this, true);
Dave Allisonb373e092014-02-20 16:06:36 -0800396}
Mathieu Chartierc751fdc2014-03-30 15:25:44 -0700397
398//
399// Stack trace handler, used to help get a stack trace from SIGSEGV inside of compiled code.
400//
401JavaStackTraceHandler::JavaStackTraceHandler(FaultManager* manager) : FaultHandler(manager) {
402 manager_->AddHandler(this, false);
403}
404
405bool JavaStackTraceHandler::Action(int sig, siginfo_t* siginfo, void* context) {
406 // Make sure that we are in the generated code, but we may not have a dex pc.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700407 UNUSED(sig);
Dave Allison8ce6b902014-08-26 11:07:58 -0700408#ifdef TEST_NESTED_SIGNAL
409 bool in_generated_code = true;
410#else
411 bool in_generated_code = manager_->IsInGeneratedCode(siginfo, context, false);
412#endif
413 if (in_generated_code) {
Mathieu Chartierc751fdc2014-03-30 15:25:44 -0700414 LOG(ERROR) << "Dumping java stack trace for crash in generated code";
Mathieu Chartiere401d142015-04-22 13:56:20 -0700415 ArtMethod* method = nullptr;
Mathieu Chartierc751fdc2014-03-30 15:25:44 -0700416 uintptr_t return_pc = 0;
417 uintptr_t sp = 0;
Mathieu Chartierc751fdc2014-03-30 15:25:44 -0700418 Thread* self = Thread::Current();
Dave Allison8ce6b902014-08-26 11:07:58 -0700419
Dave Allison0c2894b2014-08-29 12:06:16 -0700420 manager_->GetMethodAndReturnPcAndSp(siginfo, context, &method, &return_pc, &sp);
421 // Inside of generated code, sp[0] is the method, so sp is the frame.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700422 self->SetTopOfStack(reinterpret_cast<ArtMethod**>(sp));
Dave Allison8ce6b902014-08-26 11:07:58 -0700423#ifdef TEST_NESTED_SIGNAL
Dave Allison0c2894b2014-08-29 12:06:16 -0700424 // To test the nested signal handler we raise a signal here. This will cause the
425 // nested signal handler to be called and perform a longjmp back to the setjmp
426 // above.
427 abort();
Dave Allison8ce6b902014-08-26 11:07:58 -0700428#endif
Dave Allison0c2894b2014-08-29 12:06:16 -0700429 self->DumpJavaStack(LOG(ERROR));
Mathieu Chartierc751fdc2014-03-30 15:25:44 -0700430 }
Dave Allison8ce6b902014-08-26 11:07:58 -0700431
Mathieu Chartierc751fdc2014-03-30 15:25:44 -0700432 return false; // Return false since we want to propagate the fault to the main signal handler.
433}
434
Dave Allisonb373e092014-02-20 16:06:36 -0800435} // namespace art