Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(414)

Unified Diff: components/nacl/loader/nonsfi/irt_exception_handling.cc

Issue 230413002: NonSFI NaCl: Plumb Exception IRT enough for breakpad. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/nacl/loader/nonsfi/irt_exception_handling.cc
diff --git a/components/nacl/loader/nonsfi/irt_exception_handling.cc b/components/nacl/loader/nonsfi/irt_exception_handling.cc
new file mode 100644
index 0000000000000000000000000000000000000000..143a2874b9aa25fc5d3efb27265e4172ae145191
--- /dev/null
+++ b/components/nacl/loader/nonsfi/irt_exception_handling.cc
@@ -0,0 +1,105 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <errno.h>
+#include <signal.h>
+
+#include "base/atomicops.h"
+#include "components/nacl/loader/nonsfi/irt_interfaces.h"
+#include "native_client/src/include/nacl_macros.h"
+#include "native_client/src/trusted/service_runtime/nacl_exception.h"
+#include "native_client/src/trusted/service_runtime/nacl_signal.h"
+
+namespace nacl {
+namespace nonsfi {
+namespace {
+
+// This is NonSFI version of exception handling codebase, NaCl side of
+// things resides in:
+// native_client/src/trusted/service_runtime/linux/nacl_signal.c
+// native_client/src/trusted/service_runtime/sys_exception.c
+
+// Crash signals to handle. The differences from SFI NaCl are that
+// NonSFI NaCl does not use NACL_THREAD_SUSPEND_SIGNAL (==SIGUSR1),
+// and SIGSYS is reserved for seccomp-bpf.
+static const int kSignals[] = {
+ SIGSTKFLT,
+ SIGINT, SIGQUIT, SIGILL, SIGTRAP, SIGBUS, SIGFPE, SIGSEGV,
+ // Handle SIGABRT in case someone sends it asynchronously using kill().
+ SIGABRT
+};
+
+volatile NaClExceptionHandler signal_handler_function_pointer = NULL;
Mark Seaborn 2014/04/24 23:39:28 Doesn't need to be volatile
Junichi Uekawa 2014/04/25 01:06:10 Done.
+
+// Signal handler, responsible for calling the registered handlers.
Mark Seaborn 2014/04/24 23:39:28 Nit: "handler" singular
Junichi Uekawa 2014/04/25 01:06:10 Done.
+static void SignalCatch(int sig, siginfo_t* info, void* uc) {
+ if (signal_handler_function_pointer) {
+ NaClSignalContext signal_context;
+ NaClSignalContextFromHandler(&signal_context, uc);
+ NaClExceptionFrame exception_frame;
+ NaClSignalSetUpExceptionFrame(&exception_frame,
+ &signal_context,
+ 0 /* context_user_addr,
+ not useful for NonSFI NaCl. */);
+ signal_handler_function_pointer(&exception_frame.context);
+ }
+ _exit(-1);
+}
+
+static int IrtExceptionHandler(NaClExceptionHandler handler,
+ NaClExceptionHandler* old_handler) {
+ if (old_handler)
+ *old_handler = signal_handler_function_pointer;
+ signal_handler_function_pointer = handler;
+ return 0;
+}
+
+static int IrtExceptionStack(void* stack, size_t size) {
+ // TODO(uekawa): I think we shouldn't implement this until we really
+ // need it. IrtThreadCreate allocates sigaltstack already, and
+ // there is no legitimate reason I can think of that you would want
+ // to reallocate an altstack. Note that
+ // native_client/src/tests/exception_test/exception_crash_test.c
+ // wants to use this but we are not running that test yet. Instead
+ // of returning an error, ignore and succeed.
+ return 0;
+}
+
+static int IrtExceptionClearFlag(void) {
+ // TODO(uekawa): I think we shouldn't implement this until we really
+ // need it.
+ return -ENOSYS;
+}
+
+} // namespace
+
+const struct nacl_irt_exception_handling kIrtExceptionHandling = {
+ IrtExceptionHandler,
+ IrtExceptionStack,
+ IrtExceptionClearFlag,
+};
+
+void InitializeSignalHandler() {
+ struct sigaction sa;
+ unsigned int a;
+
+ memset(&sa, 0, sizeof(sa));
+ sigemptyset(&sa.sa_mask);
+ sa.sa_sigaction = SignalCatch;
+ sa.sa_flags = SA_ONSTACK | SA_SIGINFO;
+
+ // Mask all signals we catch to prevent re-entry.
+ for (a = 0; a < NACL_ARRAY_SIZE(kSignals); a++) {
+ sigaddset(&sa.sa_mask, kSignals[a]);
+ }
+
+ // Install all handlers.
+ for (a = 0; a < NACL_ARRAY_SIZE(kSignals); a++) {
+ if (sigaction(kSignals[a], &sa, NULL) != 0)
+ NaClLog(LOG_FATAL, "sigaction to register signals failed.");
Mark Seaborn 2014/04/24 23:39:28 Nit: needs a "\n" at the end (NaClLog doesn't add
Junichi Uekawa 2014/04/25 01:06:10 Done.
+ }
+}
+
+} // namespace nonsfi
+} // namespace nacl

Powered by Google App Engine
This is Rietveld 408576698