| 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(TARGET_OS_LINUX) | 6 #if defined(TARGET_OS_LINUX) |
| 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 |
| 26 static void segv_handler(int signal, siginfo_t* siginfo, void* context) { |
| 27 Dart_DumpNativeStackTrace(context); |
| 28 abort(); |
| 29 } |
| 30 |
| 25 bool Platform::Initialize() { | 31 bool Platform::Initialize() { |
| 26 // Turn off the signal handler for SIGPIPE as it causes the process | 32 // Turn off the signal handler for SIGPIPE as it causes the process |
| 27 // to terminate on writing to a closed pipe. Without the signal | 33 // to terminate on writing to a closed pipe. Without the signal |
| 28 // handler error EPIPE is set instead. | 34 // handler error EPIPE is set instead. |
| 29 struct sigaction act; | 35 struct sigaction act; |
| 30 bzero(&act, sizeof(act)); | 36 bzero(&act, sizeof(act)); |
| 31 act.sa_handler = SIG_IGN; | 37 act.sa_handler = SIG_IGN; |
| 32 if (sigaction(SIGPIPE, &act, 0) != 0) { | 38 if (sigaction(SIGPIPE, &act, 0) != 0) { |
| 33 perror("Setting signal handler failed"); | 39 perror("Setting signal handler failed"); |
| 34 return false; | 40 return false; |
| 35 } | 41 } |
| 42 |
| 43 act.sa_flags = SA_SIGINFO; |
| 44 act.sa_sigaction = &segv_handler; |
| 45 if (sigemptyset(&act.sa_mask) != 0) { |
| 46 perror("sigemptyset() failed."); |
| 47 return false; |
| 48 } |
| 49 if (sigaddset(&act.sa_mask, SIGPROF) != 0) { |
| 50 perror("sigaddset() failed"); |
| 51 return false; |
| 52 } |
| 53 if (sigaction(SIGSEGV, &act, NULL) != 0) { |
| 54 perror("sigaction() failed."); |
| 55 return false; |
| 56 } |
| 36 return true; | 57 return true; |
| 37 } | 58 } |
| 38 | 59 |
| 39 | 60 |
| 40 int Platform::NumberOfProcessors() { | 61 int Platform::NumberOfProcessors() { |
| 41 return sysconf(_SC_NPROCESSORS_ONLN); | 62 return sysconf(_SC_NPROCESSORS_ONLN); |
| 42 } | 63 } |
| 43 | 64 |
| 44 | 65 |
| 45 const char* Platform::OperatingSystem() { | 66 const char* Platform::OperatingSystem() { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 | 107 |
| 87 | 108 |
| 88 void Platform::Exit(int exit_code) { | 109 void Platform::Exit(int exit_code) { |
| 89 exit(exit_code); | 110 exit(exit_code); |
| 90 } | 111 } |
| 91 | 112 |
| 92 } // namespace bin | 113 } // namespace bin |
| 93 } // namespace dart | 114 } // namespace dart |
| 94 | 115 |
| 95 #endif // defined(TARGET_OS_LINUX) | 116 #endif // defined(TARGET_OS_LINUX) |
| OLD | NEW |