Add first chance exception handler API

This change adds the option for Breakpad hosts to register a callback
that gets the first chance to handle an exception. The handler will 
return true if it handled the exception and false otherwise.

The primary use case is V8's trap-based bounds checking support for
WebAssembly.

Bug:
Change-Id: I5aa5b87d1229f1cef905a00404fa2027ee86be56
Reviewed-on: https://chromium-review.googlesource.com/509994
Reviewed-by: Mark Mentovai <mark@chromium.org>
This commit is contained in:
Eric Holk 2017-06-19 10:06:28 -07:00 committed by Mark Mentovai
parent c142362a6c
commit 1628d99f7b
3 changed files with 44 additions and 0 deletions

View file

@ -1177,3 +1177,26 @@ TEST(ExceptionHandlerTest, WriteMinidumpForChild) {
close(fds[1]);
unlink(minidump_filename.c_str());
}
namespace {
const int kSimpleFirstChanceReturnStatus = 42;
bool SimpleFirstChanceHandler(int, void*, void*) {
exit(kSimpleFirstChanceReturnStatus);
}
}
TEST(ExceptionHandlerTest, FirstChanceHandlerRuns) {
AutoTempDir temp_dir;
const pid_t child = fork();
if (child == 0) {
ExceptionHandler handler(
MinidumpDescriptor(temp_dir.path()), NULL, NULL, NULL, true, -1);
google_breakpad::SetFirstChanceExceptionHandler(SimpleFirstChanceHandler);
DoNullPointerDereference();
}
int status;
ASSERT_NE(HANDLE_EINTR(waitpid(child, &status, 0)), -1);
ASSERT_TRUE(WIFEXITED(status));
ASSERT_EQ(kSimpleFirstChanceReturnStatus, WEXITSTATUS(status));
}