| 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 "bin/file.h" | 10 #include "bin/file.h" |
| 11 #include "bin/lockers.h" |
| 11 #include "bin/log.h" | 12 #include "bin/log.h" |
| 12 #if !defined(DART_IO_DISABLED) && !defined(PLATFORM_DISABLE_SOCKET) | 13 #if !defined(DART_IO_DISABLED) && !defined(PLATFORM_DISABLE_SOCKET) |
| 13 #include "bin/socket.h" | 14 #include "bin/socket.h" |
| 14 #endif | 15 #endif |
| 16 #include "bin/thread.h" |
| 15 #include "bin/utils.h" | 17 #include "bin/utils.h" |
| 16 #include "bin/utils_win.h" | 18 #include "bin/utils_win.h" |
| 17 | 19 |
| 18 namespace dart { | 20 namespace dart { |
| 19 | 21 |
| 20 // Defined in vm/os_thread_win.cc | 22 // Defined in vm/os_thread_win.cc |
| 21 extern bool private_flag_windows_run_tls_destructors; | 23 extern bool private_flag_windows_run_tls_destructors; |
| 22 | 24 |
| 23 namespace bin { | 25 namespace bin { |
| 24 | 26 |
| 25 const char* Platform::executable_name_ = NULL; | 27 const char* Platform::executable_name_ = NULL; |
| 26 char* Platform::resolved_executable_name_ = NULL; | 28 char* Platform::resolved_executable_name_ = NULL; |
| 27 int Platform::script_index_ = 1; | 29 int Platform::script_index_ = 1; |
| 28 char** Platform::argv_ = NULL; | 30 char** Platform::argv_ = NULL; |
| 29 | 31 |
| 32 class PlatformWin { |
| 33 public: |
| 34 static void InitOnce() { |
| 35 platform_win_mutex_ = new Mutex(); |
| 36 saved_output_cp_ = -1; |
| 37 } |
| 38 |
| 39 static void SaveAndSetOutputCP() { |
| 40 MutexLocker ml(platform_win_mutex_); |
| 41 ASSERT(saved_output_cp_ == -1); |
| 42 saved_output_cp_ = GetConsoleOutputCP(); |
| 43 SetConsoleOutputCP(CP_UTF8); |
| 44 } |
| 45 |
| 46 static void RestoreOutputCP() { |
| 47 MutexLocker ml(platform_win_mutex_); |
| 48 if (saved_output_cp_ != -1) { |
| 49 SetConsoleOutputCP(saved_output_cp_); |
| 50 saved_output_cp_ = -1; |
| 51 } |
| 52 } |
| 53 |
| 54 private: |
| 55 static Mutex* platform_win_mutex_; |
| 56 static int saved_output_cp_; |
| 57 |
| 58 DISALLOW_ALLOCATION(); |
| 59 DISALLOW_IMPLICIT_CONSTRUCTORS(PlatformWin); |
| 60 }; |
| 61 |
| 62 int PlatformWin::saved_output_cp_ = -1; |
| 63 Mutex* PlatformWin::platform_win_mutex_ = NULL; |
| 64 |
| 30 bool Platform::Initialize() { | 65 bool Platform::Initialize() { |
| 66 PlatformWin::InitOnce(); |
| 67 PlatformWin::SaveAndSetOutputCP(); |
| 31 SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX); | 68 SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX); |
| 32 return true; | 69 return true; |
| 33 } | 70 } |
| 34 | 71 |
| 35 | 72 |
| 36 int Platform::NumberOfProcessors() { | 73 int Platform::NumberOfProcessors() { |
| 37 SYSTEM_INFO info; | 74 SYSTEM_INFO info; |
| 38 GetSystemInfo(&info); | 75 GetSystemInfo(&info); |
| 39 return info.dwNumberOfProcessors; | 76 return info.dwNumberOfProcessors; |
| 40 } | 77 } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 char* path = StringUtilsWin::WideToUtf8(tmp_buffer); | 154 char* path = StringUtilsWin::WideToUtf8(tmp_buffer); |
| 118 // Return the canonical path as the returned path might contain symlinks. | 155 // Return the canonical path as the returned path might contain symlinks. |
| 119 const char* canon_path = File::GetCanonicalPath(path); | 156 const char* canon_path = File::GetCanonicalPath(path); |
| 120 return canon_path; | 157 return canon_path; |
| 121 } | 158 } |
| 122 | 159 |
| 123 | 160 |
| 124 void Platform::Exit(int exit_code) { | 161 void Platform::Exit(int exit_code) { |
| 125 // TODO(zra): Remove once VM shuts down cleanly. | 162 // TODO(zra): Remove once VM shuts down cleanly. |
| 126 ::dart::private_flag_windows_run_tls_destructors = false; | 163 ::dart::private_flag_windows_run_tls_destructors = false; |
| 164 // Restore the console's output code page |
| 165 PlatformWin::RestoreOutputCP(); |
| 127 // On Windows we use ExitProcess so that threads can't clobber the exit_code. | 166 // On Windows we use ExitProcess so that threads can't clobber the exit_code. |
| 128 // See: https://code.google.com/p/nativeclient/issues/detail?id=2870 | 167 // See: https://code.google.com/p/nativeclient/issues/detail?id=2870 |
| 129 ::ExitProcess(exit_code); | 168 ::ExitProcess(exit_code); |
| 130 } | 169 } |
| 131 | 170 |
| 132 } // namespace bin | 171 } // namespace bin |
| 133 } // namespace dart | 172 } // namespace dart |
| 134 | 173 |
| 135 #endif // defined(TARGET_OS_WINDOWS) | 174 #endif // defined(TARGET_OS_WINDOWS) |
| OLD | NEW |