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_WINDOWS) | 6 #if defined(TARGET_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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 // See: https://msdn.microsoft.com/en-us/library/windows/desktop/ms680621(v=
vs.85).aspx | 58 // See: https://msdn.microsoft.com/en-us/library/windows/desktop/ms680621(v=
vs.85).aspx |
59 SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX); | 59 SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX); |
60 } | 60 } |
61 | 61 |
62 static void SaveAndConfigureConsole() { | 62 static void SaveAndConfigureConsole() { |
63 MutexLocker ml(platform_win_mutex_); | 63 MutexLocker ml(platform_win_mutex_); |
64 ASSERT(saved_output_cp_ == -1); | 64 ASSERT(saved_output_cp_ == -1); |
65 saved_output_cp_ = GetConsoleOutputCP(); | 65 saved_output_cp_ = GetConsoleOutputCP(); |
66 SetConsoleOutputCP(CP_UTF8); | 66 SetConsoleOutputCP(CP_UTF8); |
67 | 67 |
| 68 ansi_supported_ = true; |
68 HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE); | 69 HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE); |
69 if ((out != INVALID_HANDLE_VALUE) && | 70 if ((out != INVALID_HANDLE_VALUE) && |
70 GetConsoleMode(out, &saved_console_out_mode_)) { | 71 GetConsoleMode(out, &saved_console_out_mode_)) { |
71 const DWORD request = | 72 const DWORD request = |
72 saved_console_out_mode_ | ENABLE_VIRTUAL_TERMINAL_PROCESSING; | 73 saved_console_out_mode_ | ENABLE_VIRTUAL_TERMINAL_PROCESSING; |
73 SetConsoleMode(out, request); | 74 ansi_supported_ = ansi_supported_ && SetConsoleMode(out, request); |
| 75 } else { |
| 76 ansi_supported_ = false; |
74 } | 77 } |
75 | 78 |
76 HANDLE in = GetStdHandle(STD_INPUT_HANDLE); | 79 HANDLE in = GetStdHandle(STD_INPUT_HANDLE); |
77 if ((in != INVALID_HANDLE_VALUE) && | 80 if ((in != INVALID_HANDLE_VALUE) && |
78 GetConsoleMode(in, &saved_console_in_mode_)) { | 81 GetConsoleMode(in, &saved_console_in_mode_)) { |
79 const DWORD request = | 82 const DWORD request = |
80 saved_console_in_mode_ | ENABLE_VIRTUAL_TERMINAL_INPUT; | 83 saved_console_in_mode_ | ENABLE_VIRTUAL_TERMINAL_INPUT; |
81 SetConsoleMode(in, request); | 84 ansi_supported_ = ansi_supported_ && SetConsoleMode(in, request); |
| 85 } else { |
| 86 ansi_supported_ = false; |
82 } | 87 } |
83 } | 88 } |
84 | 89 |
85 static void RestoreConsole() { | 90 static void RestoreConsole() { |
86 MutexLocker ml(platform_win_mutex_); | 91 MutexLocker ml(platform_win_mutex_); |
87 if (saved_output_cp_ != -1) { | 92 if (saved_output_cp_ != -1) { |
88 SetConsoleOutputCP(saved_output_cp_); | 93 SetConsoleOutputCP(saved_output_cp_); |
89 saved_output_cp_ = -1; | 94 saved_output_cp_ = -1; |
90 } | 95 } |
91 HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE); | 96 HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE); |
92 if (out != INVALID_HANDLE_VALUE) { | 97 if (out != INVALID_HANDLE_VALUE) { |
93 SetConsoleMode(out, saved_console_out_mode_); | 98 SetConsoleMode(out, saved_console_out_mode_); |
94 saved_console_out_mode_ = 0; | 99 saved_console_out_mode_ = 0; |
95 } | 100 } |
96 HANDLE in = GetStdHandle(STD_INPUT_HANDLE); | 101 HANDLE in = GetStdHandle(STD_INPUT_HANDLE); |
97 if (in != INVALID_HANDLE_VALUE) { | 102 if (in != INVALID_HANDLE_VALUE) { |
98 SetConsoleMode(in, saved_console_in_mode_); | 103 SetConsoleMode(in, saved_console_in_mode_); |
99 saved_console_in_mode_ = 0; | 104 saved_console_in_mode_ = 0; |
100 } | 105 } |
101 } | 106 } |
102 | 107 |
| 108 static bool ansi_supported() { return ansi_supported_; } |
| 109 |
103 private: | 110 private: |
104 static Mutex* platform_win_mutex_; | 111 static Mutex* platform_win_mutex_; |
105 static int saved_output_cp_; | 112 static int saved_output_cp_; |
106 static DWORD saved_console_out_mode_; | 113 static DWORD saved_console_out_mode_; |
107 static DWORD saved_console_in_mode_; | 114 static DWORD saved_console_in_mode_; |
| 115 static bool ansi_supported_; |
108 | 116 |
109 static void InvalidParameterHandler(const wchar_t* expression, | 117 static void InvalidParameterHandler(const wchar_t* expression, |
110 const wchar_t* function, | 118 const wchar_t* function, |
111 const wchar_t* file, | 119 const wchar_t* file, |
112 unsigned int line, | 120 unsigned int line, |
113 uintptr_t reserved) { | 121 uintptr_t reserved) { |
114 // Doing nothing here means that the CRT call that invoked it will | 122 // Doing nothing here means that the CRT call that invoked it will |
115 // return an error code and/or set errno. | 123 // return an error code and/or set errno. |
116 } | 124 } |
117 | 125 |
118 DISALLOW_ALLOCATION(); | 126 DISALLOW_ALLOCATION(); |
119 DISALLOW_IMPLICIT_CONSTRUCTORS(PlatformWin); | 127 DISALLOW_IMPLICIT_CONSTRUCTORS(PlatformWin); |
120 }; | 128 }; |
121 | 129 |
122 int PlatformWin::saved_output_cp_ = -1; | 130 int PlatformWin::saved_output_cp_ = -1; |
123 DWORD PlatformWin::saved_console_out_mode_ = 0; | 131 DWORD PlatformWin::saved_console_out_mode_ = 0; |
124 DWORD PlatformWin::saved_console_in_mode_ = 0; | 132 DWORD PlatformWin::saved_console_in_mode_ = 0; |
125 Mutex* PlatformWin::platform_win_mutex_ = NULL; | 133 Mutex* PlatformWin::platform_win_mutex_ = NULL; |
| 134 bool PlatformWin::ansi_supported_ = false; |
126 | 135 |
127 bool Platform::Initialize() { | 136 bool Platform::Initialize() { |
128 PlatformWin::InitOnce(); | 137 PlatformWin::InitOnce(); |
129 PlatformWin::SaveAndConfigureConsole(); | 138 PlatformWin::SaveAndConfigureConsole(); |
130 return true; | 139 return true; |
131 } | 140 } |
132 | 141 |
133 | 142 |
134 int Platform::NumberOfProcessors() { | 143 int Platform::NumberOfProcessors() { |
135 SYSTEM_INFO info; | 144 SYSTEM_INFO info; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 if (GetLastError() != ERROR_SUCCESS) { | 221 if (GetLastError() != ERROR_SUCCESS) { |
213 return NULL; | 222 return NULL; |
214 } | 223 } |
215 char* path = StringUtilsWin::WideToUtf8(tmp_buffer); | 224 char* path = StringUtilsWin::WideToUtf8(tmp_buffer); |
216 // Return the canonical path as the returned path might contain symlinks. | 225 // Return the canonical path as the returned path might contain symlinks. |
217 const char* canon_path = File::GetCanonicalPath(path); | 226 const char* canon_path = File::GetCanonicalPath(path); |
218 return canon_path; | 227 return canon_path; |
219 } | 228 } |
220 | 229 |
221 | 230 |
| 231 bool Platform::AnsiSupported() { |
| 232 return PlatformWin::ansi_supported(); |
| 233 } |
| 234 |
| 235 |
222 void Platform::Exit(int exit_code) { | 236 void Platform::Exit(int exit_code) { |
223 // TODO(zra): Remove once VM shuts down cleanly. | 237 // TODO(zra): Remove once VM shuts down cleanly. |
224 ::dart::private_flag_windows_run_tls_destructors = false; | 238 ::dart::private_flag_windows_run_tls_destructors = false; |
225 // Restore the console's output code page | 239 // Restore the console's output code page |
226 PlatformWin::RestoreConsole(); | 240 PlatformWin::RestoreConsole(); |
227 // On Windows we use ExitProcess so that threads can't clobber the exit_code. | 241 // On Windows we use ExitProcess so that threads can't clobber the exit_code. |
228 // See: https://code.google.com/p/nativeclient/issues/detail?id=2870 | 242 // See: https://code.google.com/p/nativeclient/issues/detail?id=2870 |
229 ::ExitProcess(exit_code); | 243 ::ExitProcess(exit_code); |
230 } | 244 } |
231 | 245 |
232 } // namespace bin | 246 } // namespace bin |
233 } // namespace dart | 247 } // namespace dart |
234 | 248 |
235 #endif // defined(TARGET_OS_WINDOWS) | 249 #endif // defined(TARGET_OS_WINDOWS) |
OLD | NEW |