Chromium Code Reviews| 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_WINDOWS) | 6 #if defined(HOST_OS_WINDOWS) |
| 7 | 7 |
| 8 #include "bin/platform.h" | 8 #include "bin/platform.h" |
| 9 | 9 |
| 10 #include <crtdbg.h> | 10 #include <crtdbg.h> |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 #define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004 | 29 #define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004 |
| 30 #endif | 30 #endif |
| 31 | 31 |
| 32 namespace dart { | 32 namespace dart { |
| 33 | 33 |
| 34 // Defined in vm/os_thread_win.cc | 34 // Defined in vm/os_thread_win.cc |
| 35 extern bool private_flag_windows_run_tls_destructors; | 35 extern bool private_flag_windows_run_tls_destructors; |
| 36 | 36 |
| 37 namespace bin { | 37 namespace bin { |
| 38 | 38 |
| 39 | |
| 40 static LONG WINAPI | |
|
zra
2017/07/12 22:14:59
Could you add a comment here with a link to the do
alexmarkov
2017/07/12 22:39:49
Done.
| |
| 41 DartExceptionHandler(struct _EXCEPTION_POINTERS* ExceptionInfo) { | |
| 42 if (ExceptionInfo->ExceptionRecord->ExceptionCode == | |
| 43 EXCEPTION_ACCESS_VIOLATION) { | |
| 44 Dart_DumpNativeStackTrace(ExceptionInfo->ContextRecord); | |
| 45 abort(); | |
|
zra
2017/07/12 22:14:59
It would be polite of us to call PlatformWin::Rest
alexmarkov
2017/07/12 22:39:49
Done.
| |
| 46 } | |
| 47 return EXCEPTION_CONTINUE_SEARCH; | |
| 48 } | |
| 49 | |
| 50 | |
| 39 const char* Platform::executable_name_ = NULL; | 51 const char* Platform::executable_name_ = NULL; |
| 40 char* Platform::resolved_executable_name_ = NULL; | 52 char* Platform::resolved_executable_name_ = NULL; |
| 41 int Platform::script_index_ = 1; | 53 int Platform::script_index_ = 1; |
| 42 char** Platform::argv_ = NULL; | 54 char** Platform::argv_ = NULL; |
| 43 | 55 |
| 44 class PlatformWin { | 56 class PlatformWin { |
| 45 public: | 57 public: |
| 46 static void InitOnce() { | 58 static void InitOnce() { |
| 47 platform_win_mutex_ = new Mutex(); | 59 platform_win_mutex_ = new Mutex(); |
| 48 saved_output_cp_ = -1; | 60 saved_output_cp_ = -1; |
| 49 saved_input_cp_ = -1; | 61 saved_input_cp_ = -1; |
| 50 // Set up a no-op handler so that CRT functions return an error instead of | 62 // Set up a no-op handler so that CRT functions return an error instead of |
| 51 // hitting an assertion failure. | 63 // hitting an assertion failure. |
| 52 // See: https://msdn.microsoft.com/en-us/library/a9yf33zb.aspx | 64 // See: https://msdn.microsoft.com/en-us/library/a9yf33zb.aspx |
| 53 _set_invalid_parameter_handler(InvalidParameterHandler); | 65 _set_invalid_parameter_handler(InvalidParameterHandler); |
| 54 // Disable the message box for assertions in the CRT in Debug builds. | 66 // Disable the message box for assertions in the CRT in Debug builds. |
| 55 // See: https://msdn.microsoft.com/en-us/library/1y71x448.aspx | 67 // See: https://msdn.microsoft.com/en-us/library/1y71x448.aspx |
| 56 _CrtSetReportMode(_CRT_ASSERT, 0); | 68 _CrtSetReportMode(_CRT_ASSERT, 0); |
| 57 // Disable dialog boxes for "critical" errors or when OpenFile cannot find | 69 // Disable dialog boxes for "critical" errors or when OpenFile cannot find |
| 58 // the requested file. See: | 70 // the requested file. See: |
| 59 // See: https://msdn.microsoft.com/en-us/library/windows/desktop/ms680621(v= vs.85).aspx | 71 // See: https://msdn.microsoft.com/en-us/library/windows/desktop/ms680621(v= vs.85).aspx |
| 60 SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX); | 72 SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX); |
| 61 // Set up a signal handler that restores the console state on a | 73 // Set up a signal handler that restores the console state on a |
| 62 // CTRL_C_EVENT signal. This will only run when there is no signal handler | 74 // CTRL_C_EVENT signal. This will only run when there is no signal handler |
| 63 // registered for the CTRL_C_EVENT from Dart code. | 75 // registered for the CTRL_C_EVENT from Dart code. |
| 64 SetConsoleCtrlHandler(SignalHandler, TRUE); | 76 SetConsoleCtrlHandler(SignalHandler, TRUE); |
| 77 #ifndef PRODUCT | |
| 78 // Set up global exception handler to be able to dump stack trace on crash. | |
| 79 SetExceptionHandler(); | |
| 80 #endif | |
| 65 } | 81 } |
| 66 | 82 |
| 67 static BOOL WINAPI SignalHandler(DWORD signal) { | 83 static BOOL WINAPI SignalHandler(DWORD signal) { |
| 68 if (signal == CTRL_C_EVENT) { | 84 if (signal == CTRL_C_EVENT) { |
| 69 // We call this without taking the lock because this is a signal | 85 // We call this without taking the lock because this is a signal |
| 70 // handler, and because the process is about to go down. | 86 // handler, and because the process is about to go down. |
| 71 RestoreConsoleLocked(); | 87 RestoreConsoleLocked(); |
| 72 } | 88 } |
| 73 return FALSE; | 89 return FALSE; |
| 74 } | 90 } |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 99 // TODO(28984): Due to issue #29104, we cannot set | 115 // TODO(28984): Due to issue #29104, we cannot set |
| 100 // ENABLE_VIRTUAL_TERMINAL_INPUT here, as it causes ENABLE_PROCESSED_INPUT | 116 // ENABLE_VIRTUAL_TERMINAL_INPUT here, as it causes ENABLE_PROCESSED_INPUT |
| 101 // to be ignored. | 117 // to be ignored. |
| 102 } | 118 } |
| 103 | 119 |
| 104 static void RestoreConsole() { | 120 static void RestoreConsole() { |
| 105 MutexLocker ml(platform_win_mutex_); | 121 MutexLocker ml(platform_win_mutex_); |
| 106 RestoreConsoleLocked(); | 122 RestoreConsoleLocked(); |
| 107 } | 123 } |
| 108 | 124 |
| 125 static void SetExceptionHandler() { | |
| 126 SetUnhandledExceptionFilter(DartExceptionHandler); | |
| 127 } | |
| 128 | |
| 109 private: | 129 private: |
| 110 static Mutex* platform_win_mutex_; | 130 static Mutex* platform_win_mutex_; |
| 111 static int saved_output_cp_; | 131 static int saved_output_cp_; |
| 112 static int saved_input_cp_; | 132 static int saved_input_cp_; |
| 113 | 133 |
| 114 static void RestoreConsoleLocked() { | 134 static void RestoreConsoleLocked() { |
| 115 // STD_OUTPUT_HANDLE and STD_INPUT_HANDLE may have been closed or | 135 // STD_OUTPUT_HANDLE and STD_INPUT_HANDLE may have been closed or |
| 116 // redirected. Therefore, we explicitly open the CONOUT$ and CONIN$ | 136 // redirected. Therefore, we explicitly open the CONOUT$ and CONIN$ |
| 117 // devices, so that we can be sure that we are really unsetting | 137 // devices, so that we can be sure that we are really unsetting |
| 118 // ENABLE_VIRTUAL_TERMINAL_PROCESSING and ENABLE_VIRTUAL_TERMINAL_INPUT | 138 // ENABLE_VIRTUAL_TERMINAL_PROCESSING and ENABLE_VIRTUAL_TERMINAL_INPUT |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 292 PlatformWin::RestoreConsole(); | 312 PlatformWin::RestoreConsole(); |
| 293 // On Windows we use ExitProcess so that threads can't clobber the exit_code. | 313 // On Windows we use ExitProcess so that threads can't clobber the exit_code. |
| 294 // See: https://code.google.com/p/nativeclient/issues/detail?id=2870 | 314 // See: https://code.google.com/p/nativeclient/issues/detail?id=2870 |
| 295 ::ExitProcess(exit_code); | 315 ::ExitProcess(exit_code); |
| 296 } | 316 } |
| 297 | 317 |
| 298 } // namespace bin | 318 } // namespace bin |
| 299 } // namespace dart | 319 } // namespace dart |
| 300 | 320 |
| 301 #endif // defined(HOST_OS_WINDOWS) | 321 #endif // defined(HOST_OS_WINDOWS) |
| OLD | NEW |