6#if defined(DART_HOST_OS_WINDOWS)
16#if !defined(PLATFORM_DISABLE_SOCKET)
26const char* Platform::executable_name_ =
nullptr;
27int Platform::script_index_ = 1;
28char** Platform::argv_ =
nullptr;
36 _set_invalid_parameter_handler(InvalidParameterHandler);
40 _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE);
41 _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
42 _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE);
43 _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
44 _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE);
45 _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
49 _set_error_mode(_OUT_TO_STDERR);
60 UINT new_mode = SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX;
61 if (
getenv(
"DART_SUPPRESS_WER") !=
nullptr) {
62 new_mode |= SEM_NOGPFAULTERRORBOX;
64 UINT existing_mode = SetErrorMode(new_mode);
65 SetErrorMode(new_mode | existing_mode);
67 SetExceptionHandler();
74 DartExceptionHandler(
struct _EXCEPTION_POINTERS* ExceptionInfo) {
75 if ((ExceptionInfo->ExceptionRecord->ExceptionCode ==
76 EXCEPTION_ACCESS_VIOLATION) ||
77 (ExceptionInfo->ExceptionRecord->ExceptionCode ==
78 EXCEPTION_ILLEGAL_INSTRUCTION)) {
80 "\n===== CRASH =====\n"
81 "ExceptionCode=%d, ExceptionFlags=%d, ExceptionAddress=%p\n",
82 ExceptionInfo->ExceptionRecord->ExceptionCode,
83 ExceptionInfo->ExceptionRecord->ExceptionFlags,
84 ExceptionInfo->ExceptionRecord->ExceptionAddress);
86 Console::RestoreConfig();
92 return EXCEPTION_CONTINUE_SEARCH;
95 static void SetExceptionHandler() {
96 SetUnhandledExceptionFilter(DartExceptionHandler);
100 static void InvalidParameterHandler(
const wchar_t* expression,
104 uintptr_t reserved) {
114 PlatformWin::InitOnce();
120 GetSystemInfo(&
info);
121 return info.dwNumberOfProcessors;
128static constexpr const wchar_t* kCurrentVersion =
129 L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion";
131static bool GetCurrentVersionDWord(
const wchar_t* field,
DWORD* value) {
132 DWORD value_size =
sizeof(*value);
134 RRF_RT_REG_DWORD,
nullptr, value, &value_size);
138static bool GetCurrentVersionString(
const wchar_t* field,
const char** value) {
139 wchar_t wversion[256];
140 DWORD wversion_size =
sizeof(wversion);
142 RRF_RT_REG_SZ,
nullptr, wversion, &wversion_size);
150static const char* VersionNumber() {
154 if (!GetCurrentVersionDWord(
L"CurrentMajorVersionNumber", &major)) {
156 if (!GetCurrentVersionString(
L"CurrentVersion", &version)) {
163 if (!GetCurrentVersionDWord(
L"CurrentMinorVersionNumber", &minor)) {
172 if (!GetCurrentVersionString(
L"ProductName", &
name)) {
177 const char* version_number = VersionNumber();
178 if (version_number ==
nullptr) {
184 if (!GetCurrentVersionString(
L"CurrentBuild", &
build)) {
189 const char*
kFormat =
"\"%s\" %s (Build %s)";
190 int len = snprintf(
nullptr, 0, kFormat,
name, version_number,
build);
205 wchar_t locale_name[LOCALE_NAME_MAX_LENGTH];
206 int result = GetUserDefaultLocaleName(locale_name, LOCALE_NAME_MAX_LENGTH);
214#if defined(PLATFORM_DISABLE_SOCKET)
221 const int HOSTNAME_MAXLENGTH = 256;
222 wchar_t hostname_w[HOSTNAME_MAXLENGTH];
223 if (GetHostNameW(hostname_w, HOSTNAME_MAXLENGTH) != 0) {
226 return WideCharToMultiByte(CP_UTF8, 0, hostname_w, -1,
buffer, buffer_length,
227 nullptr,
nullptr) != 0;
232 wchar_t* strings = GetEnvironmentStringsW();
233 if (strings ==
nullptr) {
236 wchar_t* tmp = strings;
238 while (*tmp !=
'\0') {
246 tmp += (wcslen(tmp) + 1);
252 for (intptr_t current = 0; current < i;) {
257 tmp += (wcslen(tmp) + 1);
259 FreeEnvironmentStringsW(strings);
264 return executable_name_;
271 const int kTmpBufferSize = 32768;
272 wchar_t* tmp_buffer =
277 GetModuleFileNameW(
nullptr, tmp_buffer, kTmpBufferSize);
290 const int kTmpBufferSize = 32768;
291 wchar_t tmp_buffer[kTmpBufferSize];
293 GetModuleFileNameW(
nullptr, tmp_buffer, kTmpBufferSize);
297 WideToUtf8Scope wide_to_utf8_scope(tmp_buffer);
298 if (wide_to_utf8_scope.length() <= result_size) {
299 strncpy(
result, wide_to_utf8_scope.utf8(), result_size);
300 return wide_to_utf8_scope.length();
313 ::ExitProcess(exit_code);
322 ::ExitProcess(exit_code);
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
static void RestoreConfig()
static char * ScopedCStringFormatted(const char *format,...) PRINTF_ATTRIBUTE(1
static char * ScopedCString(intptr_t length)
static const char * GetCanonicalPath(Namespace *namespc, const char *path, char *dest=nullptr, int dest_size=0)
static char * WideToUtf8(wchar_t *wide, intptr_t len=-1, intptr_t *result_len=nullptr)
DART_EXPORT void Dart_PrepareToAbort(void)
DART_EXPORT void Dart_DumpNativeStackTrace(void *context)
static const uint8_t buffer[]
Dart_NativeFunction function
bool InitOnce(char **error)
DART_EXPORT void Dart_PrepareToAbort()
DART_EXPORT uint8_t * Dart_ScopeAllocate(intptr_t size)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
#define HKEY_LOCAL_MACHINE
WINBASEAPI VOID WINAPI SetLastError(_In_ DWORD dwErrCode)
WINBASEAPI _Check_return_ _Post_equals_last_error_ DWORD WINAPI GetLastError(VOID)