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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <errno.h>
6 #include <signal.h>
7
8 #include "base/atomicops.h"
9 #include "components/nacl/loader/nonsfi/irt_interfaces.h"
10 #include "native_client/src/include/nacl_macros.h"
11 #include "native_client/src/trusted/service_runtime/nacl_exception.h"
12 #include "native_client/src/trusted/service_runtime/nacl_signal.h"
13
14 namespace nacl {
15 namespace nonsfi {
16 namespace {
17
18 // This is NonSFI version of exception handling codebase, NaCl side of
19 // things resides in:
20 // native_client/src/trusted/service_runtime/linux/nacl_signal.c
21 // native_client/src/trusted/service_runtime/sys_exception.c
22
23 // Crash signals to handle. The differences from SFI NaCl are that
24 // NonSFI NaCl does not use NACL_THREAD_SUSPEND_SIGNAL (==SIGUSR1),
25 // and SIGSYS is reserved for seccomp-bpf.
26 static const int kSignals[] = {
27 SIGSTKFLT,
28 SIGINT, SIGQUIT, SIGILL, SIGTRAP, SIGBUS, SIGFPE, SIGSEGV,
29 // Handle SIGABRT in case someone sends it asynchronously using kill().
30 SIGABRT
31 };
32
33 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.
34
35 // 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.
36 static void SignalCatch(int sig, siginfo_t* info, void* uc) {
37 if (signal_handler_function_pointer) {
38 NaClSignalContext signal_context;
39 NaClSignalContextFromHandler(&signal_context, uc);
40 NaClExceptionFrame exception_frame;
41 NaClSignalSetUpExceptionFrame(&exception_frame,
42 &signal_context,
43 0 /* context_user_addr,
44 not useful for NonSFI NaCl. */);
45 signal_handler_function_pointer(&exception_frame.context);
46 }
47 _exit(-1);
48 }
49
50 static int IrtExceptionHandler(NaClExceptionHandler handler,
51 NaClExceptionHandler* old_handler) {
52 if (old_handler)
53 *old_handler = signal_handler_function_pointer;
54 signal_handler_function_pointer = handler;
55 return 0;
56 }
57
58 static int IrtExceptionStack(void* stack, size_t size) {
59 // TODO(uekawa): I think we shouldn't implement this until we really
60 // need it. IrtThreadCreate allocates sigaltstack already, and
61 // there is no legitimate reason I can think of that you would want
62 // to reallocate an altstack. Note that
63 // native_client/src/tests/exception_test/exception_crash_test.c
64 // wants to use this but we are not running that test yet. Instead
65 // of returning an error, ignore and succeed.
66 return 0;
67 }
68
69 static int IrtExceptionClearFlag(void) {
70 // TODO(uekawa): I think we shouldn't implement this until we really
71 // need it.
72 return -ENOSYS;
73 }
74
75 } // namespace
76
77 const struct nacl_irt_exception_handling kIrtExceptionHandling = {
78 IrtExceptionHandler,
79 IrtExceptionStack,
80 IrtExceptionClearFlag,
81 };
82
83 void InitializeSignalHandler() {
84 struct sigaction sa;
85 unsigned int a;
86
87 memset(&sa, 0, sizeof(sa));
88 sigemptyset(&sa.sa_mask);
89 sa.sa_sigaction = SignalCatch;
90 sa.sa_flags = SA_ONSTACK | SA_SIGINFO;
91
92 // Mask all signals we catch to prevent re-entry.
93 for (a = 0; a < NACL_ARRAY_SIZE(kSignals); a++) {
94 sigaddset(&sa.sa_mask, kSignals[a]);
95 }
96
97 // Install all handlers.
98 for (a = 0; a < NACL_ARRAY_SIZE(kSignals); a++) {
99 if (sigaction(kSignals[a], &sa, NULL) != 0)
100 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.
101 }
102 }
103
104 } // namespace nonsfi
105 } // namespace nacl
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698