OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "platform/globals.h" | 5 #include "platform/globals.h" |
6 #if defined(HOST_OS_ANDROID) | 6 #if defined(HOST_OS_ANDROID) |
7 | 7 |
8 #include "bin/platform.h" | 8 #include "bin/platform.h" |
9 | 9 |
10 #include <signal.h> // NOLINT | 10 #include <signal.h> // NOLINT |
11 #include <string.h> // NOLINT | 11 #include <string.h> // NOLINT |
12 #include <unistd.h> // NOLINT | 12 #include <unistd.h> // NOLINT |
13 | 13 |
14 #include "bin/fdutils.h" | 14 #include "bin/fdutils.h" |
15 #include "bin/file.h" | 15 #include "bin/file.h" |
16 | 16 |
17 namespace dart { | 17 namespace dart { |
18 namespace bin { | 18 namespace bin { |
19 | 19 |
20 const char* Platform::executable_name_ = NULL; | 20 const char* Platform::executable_name_ = NULL; |
21 char* Platform::resolved_executable_name_ = NULL; | 21 char* Platform::resolved_executable_name_ = NULL; |
22 int Platform::script_index_ = 1; | 22 int Platform::script_index_ = 1; |
23 char** Platform::argv_ = NULL; | 23 char** Platform::argv_ = NULL; |
24 | 24 |
| 25 static void segv_handler(int signal, siginfo_t* siginfo, void* context) { |
| 26 Dart_DumpNativeStackTrace(context); |
| 27 abort(); |
| 28 } |
| 29 |
25 bool Platform::Initialize() { | 30 bool Platform::Initialize() { |
26 // Turn off the signal handler for SIGPIPE as it causes the process | 31 // Turn off the signal handler for SIGPIPE as it causes the process |
27 // to terminate on writing to a closed pipe. Without the signal | 32 // to terminate on writing to a closed pipe. Without the signal |
28 // handler error EPIPE is set instead. | 33 // handler error EPIPE is set instead. |
29 struct sigaction act; | 34 struct sigaction act; |
30 bzero(&act, sizeof(act)); | 35 bzero(&act, sizeof(act)); |
31 act.sa_handler = SIG_IGN; | 36 act.sa_handler = SIG_IGN; |
32 if (sigaction(SIGPIPE, &act, 0) != 0) { | 37 if (sigaction(SIGPIPE, &act, 0) != 0) { |
33 perror("Setting signal handler failed"); | 38 perror("Setting signal handler failed"); |
34 return false; | 39 return false; |
35 } | 40 } |
| 41 |
| 42 act.sa_flags = SA_SIGINFO; |
| 43 act.sa_sigaction = &segv_handler; |
| 44 if (sigemptyset(&act.sa_mask) != 0) { |
| 45 perror("sigemptyset() failed."); |
| 46 return false; |
| 47 } |
| 48 if (sigaddset(&act.sa_mask, SIGPROF) != 0) { |
| 49 perror("sigaddset() failed"); |
| 50 return false; |
| 51 } |
| 52 if (sigaction(SIGSEGV, &act, NULL) != 0) { |
| 53 perror("sigaction() failed."); |
| 54 return false; |
| 55 } |
| 56 if (sigaction(SIGBUS, &act, NULL) != 0) { |
| 57 perror("sigaction() failed."); |
| 58 return false; |
| 59 } |
| 60 if (sigaction(SIGTRAP, &act, NULL) != 0) { |
| 61 perror("sigaction() failed."); |
| 62 return false; |
| 63 } |
| 64 |
36 return true; | 65 return true; |
37 } | 66 } |
38 | 67 |
39 int Platform::NumberOfProcessors() { | 68 int Platform::NumberOfProcessors() { |
40 return sysconf(_SC_NPROCESSORS_ONLN); | 69 return sysconf(_SC_NPROCESSORS_ONLN); |
41 } | 70 } |
42 | 71 |
43 const char* Platform::OperatingSystem() { | 72 const char* Platform::OperatingSystem() { |
44 return "android"; | 73 return "android"; |
45 } | 74 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 } | 119 } |
91 | 120 |
92 void Platform::Exit(int exit_code) { | 121 void Platform::Exit(int exit_code) { |
93 exit(exit_code); | 122 exit(exit_code); |
94 } | 123 } |
95 | 124 |
96 } // namespace bin | 125 } // namespace bin |
97 } // namespace dart | 126 } // namespace dart |
98 | 127 |
99 #endif // defined(HOST_OS_ANDROID) | 128 #endif // defined(HOST_OS_ANDROID) |
OLD | NEW |