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

Side by Side Diff: trunk/src/components/nacl/loader/nonsfi/irt_exception_handling.cc

Issue 265433002: Revert 266968 "NonSFI NaCl: Plumb Exception IRT enough for break..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 7 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 <pthread.h>
7 #include <signal.h>
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 // 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 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 pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
34 NaClExceptionHandler signal_handler_function_pointer = NULL;
35
36 // Signal handler, responsible for calling the registered handler.
37 void SignalCatch(int sig, siginfo_t* info, void* uc) {
38 if (signal_handler_function_pointer) {
39 NaClSignalContext signal_context;
40 NaClSignalContextFromHandler(&signal_context, uc);
41 NaClExceptionFrame exception_frame;
42 NaClSignalSetUpExceptionFrame(&exception_frame,
43 &signal_context,
44 0 /* context_user_addr,
45 not useful for NonSFI NaCl. */);
46 signal_handler_function_pointer(&exception_frame.context);
47 }
48 _exit(-1);
49 }
50
51 int IrtExceptionHandler(NaClExceptionHandler handler,
52 NaClExceptionHandler* old_handler) {
53 pthread_mutex_lock(&mutex);
54 if (old_handler)
55 *old_handler = signal_handler_function_pointer;
56 signal_handler_function_pointer = handler;
57 pthread_mutex_unlock(&mutex);
58 return 0;
59 }
60
61 int IrtExceptionStack(void* stack, size_t size) {
62 // TODO(uekawa): Implement this function so that the exception stack
63 // actually gets used for running an exception handler. Currently
64 // we don't switch stack, which means we can't handle stack overflow
65 // exceptions.
66 return 0;
67 }
68
69 int IrtExceptionClearFlag(void) {
70 // TODO(uekawa): Implement clear_flag() to behave like SFI NaCl's
71 // implementation, so that a thread can handle a second exception
72 // after handling a first exception
73 return ENOSYS;
74 }
75
76 } // namespace
77
78 const struct nacl_irt_exception_handling kIrtExceptionHandling = {
79 IrtExceptionHandler,
80 IrtExceptionStack,
81 IrtExceptionClearFlag,
82 };
83
84 void InitializeSignalHandler() {
85 struct sigaction sa;
86 unsigned int a;
87
88 memset(&sa, 0, sizeof(sa));
89 sigemptyset(&sa.sa_mask);
90 sa.sa_sigaction = SignalCatch;
91 sa.sa_flags = SA_ONSTACK | SA_SIGINFO;
92
93 // Mask all signals we catch to prevent re-entry.
94 for (a = 0; a < NACL_ARRAY_SIZE(kSignals); a++) {
95 sigaddset(&sa.sa_mask, kSignals[a]);
96 }
97
98 // Install all handlers.
99 for (a = 0; a < NACL_ARRAY_SIZE(kSignals); a++) {
100 if (sigaction(kSignals[a], &sa, NULL) != 0)
101 NaClLog(LOG_FATAL, "sigaction to register signals failed.\n");
102 }
103 }
104
105 } // namespace nonsfi
106 } // namespace nacl
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698