Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(295)

Side by Side Diff: runtime/bin/platform_win.cc

Issue 2710103002: [dart:io][windows] Set up CRT error handling behavior (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tests/standalone/io/file_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
11
10 #include "bin/file.h" 12 #include "bin/file.h"
11 #include "bin/lockers.h" 13 #include "bin/lockers.h"
12 #include "bin/log.h" 14 #include "bin/log.h"
13 #if !defined(DART_IO_DISABLED) && !defined(PLATFORM_DISABLE_SOCKET) 15 #if !defined(DART_IO_DISABLED) && !defined(PLATFORM_DISABLE_SOCKET)
14 #include "bin/socket.h" 16 #include "bin/socket.h"
15 #endif 17 #endif
16 #include "bin/thread.h" 18 #include "bin/thread.h"
17 #include "bin/utils.h" 19 #include "bin/utils.h"
18 #include "bin/utils_win.h" 20 #include "bin/utils_win.h"
19 21
20 namespace dart { 22 namespace dart {
21 23
22 // Defined in vm/os_thread_win.cc 24 // Defined in vm/os_thread_win.cc
23 extern bool private_flag_windows_run_tls_destructors; 25 extern bool private_flag_windows_run_tls_destructors;
24 26
25 namespace bin { 27 namespace bin {
26 28
27 const char* Platform::executable_name_ = NULL; 29 const char* Platform::executable_name_ = NULL;
28 char* Platform::resolved_executable_name_ = NULL; 30 char* Platform::resolved_executable_name_ = NULL;
29 int Platform::script_index_ = 1; 31 int Platform::script_index_ = 1;
30 char** Platform::argv_ = NULL; 32 char** Platform::argv_ = NULL;
31 33
32 class PlatformWin { 34 class PlatformWin {
33 public: 35 public:
34 static void InitOnce() { 36 static void InitOnce() {
35 platform_win_mutex_ = new Mutex(); 37 platform_win_mutex_ = new Mutex();
36 saved_output_cp_ = -1; 38 saved_output_cp_ = -1;
39 // Set up a no-op handler so that CRT functions return an error instead of
40 // hitting an assertion failure.
41 // See: https://msdn.microsoft.com/en-us/library/a9yf33zb.aspx
42 _set_invalid_parameter_handler(InvalidParameterHandler);
43 // Disable the message box for assertions in the CRT in Debug builds.
44 // See: https://msdn.microsoft.com/en-us/library/1y71x448.aspx
45 _CrtSetReportMode(_CRT_ASSERT, 0);
46 // Disable dialog boxes for "critical" errors or when OpenFile cannot find
47 // the requested file. See:
48 // See: https://msdn.microsoft.com/en-us/library/windows/desktop/ms680621(v= vs.85).aspx
49 SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
37 } 50 }
38 51
39 static void SaveAndSetOutputCP() { 52 static void SaveAndSetOutputCP() {
40 MutexLocker ml(platform_win_mutex_); 53 MutexLocker ml(platform_win_mutex_);
41 ASSERT(saved_output_cp_ == -1); 54 ASSERT(saved_output_cp_ == -1);
42 saved_output_cp_ = GetConsoleOutputCP(); 55 saved_output_cp_ = GetConsoleOutputCP();
43 SetConsoleOutputCP(CP_UTF8); 56 SetConsoleOutputCP(CP_UTF8);
44 } 57 }
45 58
46 static void RestoreOutputCP() { 59 static void RestoreOutputCP() {
47 MutexLocker ml(platform_win_mutex_); 60 MutexLocker ml(platform_win_mutex_);
48 if (saved_output_cp_ != -1) { 61 if (saved_output_cp_ != -1) {
49 SetConsoleOutputCP(saved_output_cp_); 62 SetConsoleOutputCP(saved_output_cp_);
50 saved_output_cp_ = -1; 63 saved_output_cp_ = -1;
51 } 64 }
52 } 65 }
53 66
54 private: 67 private:
55 static Mutex* platform_win_mutex_; 68 static Mutex* platform_win_mutex_;
56 static int saved_output_cp_; 69 static int saved_output_cp_;
57 70
71 static void InvalidParameterHandler(const wchar_t* expression,
72 const wchar_t* function,
73 const wchar_t* file,
74 unsigned int line,
75 uintptr_t reserved) {
76 // Doing nothing here means that the CRT call that invoked it will
77 // return an error code and/or set errno.
78 }
79
58 DISALLOW_ALLOCATION(); 80 DISALLOW_ALLOCATION();
59 DISALLOW_IMPLICIT_CONSTRUCTORS(PlatformWin); 81 DISALLOW_IMPLICIT_CONSTRUCTORS(PlatformWin);
60 }; 82 };
61 83
62 int PlatformWin::saved_output_cp_ = -1; 84 int PlatformWin::saved_output_cp_ = -1;
63 Mutex* PlatformWin::platform_win_mutex_ = NULL; 85 Mutex* PlatformWin::platform_win_mutex_ = NULL;
64 86
65 bool Platform::Initialize() { 87 bool Platform::Initialize() {
66 PlatformWin::InitOnce(); 88 PlatformWin::InitOnce();
67 PlatformWin::SaveAndSetOutputCP(); 89 PlatformWin::SaveAndSetOutputCP();
68 SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
69 return true; 90 return true;
70 } 91 }
71 92
72 93
73 int Platform::NumberOfProcessors() { 94 int Platform::NumberOfProcessors() {
74 SYSTEM_INFO info; 95 SYSTEM_INFO info;
75 GetSystemInfo(&info); 96 GetSystemInfo(&info);
76 return info.dwNumberOfProcessors; 97 return info.dwNumberOfProcessors;
77 } 98 }
78 99
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 PlatformWin::RestoreOutputCP(); 186 PlatformWin::RestoreOutputCP();
166 // On Windows we use ExitProcess so that threads can't clobber the exit_code. 187 // On Windows we use ExitProcess so that threads can't clobber the exit_code.
167 // See: https://code.google.com/p/nativeclient/issues/detail?id=2870 188 // See: https://code.google.com/p/nativeclient/issues/detail?id=2870
168 ::ExitProcess(exit_code); 189 ::ExitProcess(exit_code);
169 } 190 }
170 191
171 } // namespace bin 192 } // namespace bin
172 } // namespace dart 193 } // namespace dart
173 194
174 #endif // defined(TARGET_OS_WINDOWS) 195 #endif // defined(TARGET_OS_WINDOWS)
OLDNEW
« no previous file with comments | « no previous file | tests/standalone/io/file_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698