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

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: review comments 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 #include <errno.h>
Mark Seaborn 2014/04/23 03:49:50 Nit: add empty line between boilerplate and first
Junichi Uekawa 2014/04/23 07:56:15 Done.
5 #include <signal.h>
6
7 #include <map>
Mark Seaborn 2014/04/23 03:49:50 Not used?
Junichi Uekawa 2014/04/23 07:56:15 Done.
8
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 // TODO(uekawa): The list of signals to be handled might need updating.
Mark Seaborn 2014/04/23 03:49:50 It should be OK (so you can remove this TODO). An
Junichi Uekawa 2014/04/23 07:56:15 Done.
24 // NonSFI NaCl does not use NACL_THREAD_SUSPEND_SIGNAL (==SIGUSR1) (??check??)
Mark Seaborn 2014/04/23 03:49:50 Correct. That's used for thread suspension, curre
Junichi Uekawa 2014/04/23 07:56:15 I've re-wrote the comment with the context.
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 NaClExceptionHandler signal_handler_function_pointer = NULL;
34
35 // Signal handler, responsible for calling the registered handlers.
36 static void SignalCatch(int sig, siginfo_t *info, void *uc) {
Mark Seaborn 2014/04/23 03:49:50 Nit: use Chromium-style "* " spacing
Junichi Uekawa 2014/04/23 07:56:15 Done.
37 if (signal_handler_function_pointer) {
38 // TODO(uekawa): Whether to add dependency or copy the implementation?
Mark Seaborn 2014/04/23 03:49:50 Adding the dependency isn't ideal but it's OK for
Junichi Uekawa 2014/04/23 07:56:15 I've pondered of not adding a dependency; it intro
39 NaClSignalContext signal_context;
40 NaClSignalContextFromHandler(&signal_context, uc);
41 // Is this safe to allocate this on stack ?
Mark Seaborn 2014/04/23 03:49:50 Yes
Junichi Uekawa 2014/04/23 07:56:15 thanks
42 NaClExceptionFrame exception_frame;
43 NaClSignalSetUpExceptionFrame(&exception_frame,
44 &signal_context,
45 0 /* context_user_addr, what is this? */);
Mark Seaborn 2014/04/23 03:49:50 This parameter doesn't apply if we're calling user
Junichi Uekawa 2014/04/23 07:56:15 I think we don't need this for nonsfi NaCl, but pr
46
47 signal_handler_function_pointer(&exception_frame.context);
48 }
49 // TODO(uekawa): Only exit on crash signals?
Mark Seaborn 2014/04/23 03:49:50 All the signals you're handling are crash signals
Junichi Uekawa 2014/04/23 07:56:15 Removed the comment.
50 _exit(-1);
51 }
52
53 static int IrtExceptionHandler(NaClExceptionHandler handler,
54 NaClExceptionHandler *old_handler) {
55 // TODO(uekawa): Do I need to have a mutex lock?
Mark Seaborn 2014/04/23 03:49:50 You could use AtomicExchange from base/atomicops.h
Junichi Uekawa 2014/04/23 07:56:15 after staring at AtomicExchange, I don't think thi
Mark Seaborn 2014/04/24 23:39:27 But setting the new handler and getting the old on
Junichi Uekawa 2014/04/25 01:06:09 Done.
56 if (old_handler)
57 *old_handler = signal_handler_function_pointer;
58 signal_handler_function_pointer = handler;
59 return 0;
60 }
61
62 static int IrtExceptionStack(void *stack, size_t size) {
63 // TODO(uekawa): I think we shouldn't implement this until we really
64 // need it. IrtThreadCreate allocates sigaltstack already, and
65 // there is no legitimate reason I can think of that you would want
66 // to reallocate an altstack. Note that
67 // native_client/src/tests/exception_test/exception_crash_test.c
68 // wants to use this but we are not running that test yet.
69 return -EINVAL;
Mark Seaborn 2014/04/23 03:49:50 This could return 0, since it's mostly-OK as a no-
Junichi Uekawa 2014/04/23 07:56:15 Done.
70 }
71
72 static int IrtExceptionClearFlag(void) {
73 // TODO(uekawa): I think we shouldn't implement this until we really
74 // need it.
75 return -EINVAL;
Mark Seaborn 2014/04/23 03:49:50 ENOSYS would be more appropriate
Junichi Uekawa 2014/04/23 07:56:15 Done.
76 }
77
78 } // namespace
79
80 const struct nacl_irt_exception_handling kIrtExceptionHandling = {
81 IrtExceptionHandler,
82 IrtExceptionStack,
83 IrtExceptionClearFlag,
84 };
85
86 void InitializeSignalHandler(void) {
Mark Seaborn 2014/04/23 03:49:50 Nit: Should be "()" rather than "(void)" in C++.
Junichi Uekawa 2014/04/23 07:56:15 Done.
87 struct sigaction sa;
88 unsigned int a;
89
90 memset(&sa, 0, sizeof(sa));
91 sigemptyset(&sa.sa_mask);
92 sa.sa_sigaction = SignalCatch;
93 sa.sa_flags = SA_ONSTACK | SA_SIGINFO;
94
95 // Mask all signals we catch to prevent re-entry.
96 for (a = 0; a < NACL_ARRAY_SIZE(kSignals); a++) {
97 sigaddset(&sa.sa_mask, kSignals[a]);
98 }
99
100 // Install all handlers.
101 for (a = 0; a < NACL_ARRAY_SIZE(kSignals); a++) {
102 if (sigaction(kSignals[a], &sa, NULL) != 0)
103 perror("sigaction");
Mark Seaborn 2014/04/23 03:49:50 This should be a fatal error, otherwise this would
Junichi Uekawa 2014/04/23 07:56:15 Done.
104 }
105 }
106
107 } // namespace nonsfi
108 } // namespace nacl
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698