diff --git a/src/node.cc b/src/node.cc index 652e30a7ab..d7c26ffcd1 100644 --- a/src/node.cc +++ b/src/node.cc @@ -2361,13 +2361,14 @@ DWORD WINAPI EnableDebugThreadProc(void* arg) { } -static int GetDebugSignalHandlerMappingName(DWORD pid, char* buf, size_t buf_len) { - return snprintf(buf, buf_len, "node-debug-handler-%u", pid); +static int GetDebugSignalHandlerMappingName(DWORD pid, wchar_t* buf, + size_t buf_len) { + return _snwprintf(buf, buf_len, L"node-debug-handler-%u", pid); } static int RegisterDebugSignalHandler() { - char mapping_name[32]; + wchar_t mapping_name[32]; HANDLE mapping_handle; DWORD pid; LPTHREAD_START_ROUTINE* handler; @@ -2376,11 +2377,11 @@ static int RegisterDebugSignalHandler() { if (GetDebugSignalHandlerMappingName(pid, mapping_name, - sizeof mapping_name) < 0) { + ARRAY_SIZE(mapping_name)) < 0) { return -1; } - mapping_handle = CreateFileMappingA(INVALID_HANDLE_VALUE, + mapping_handle = CreateFileMappingW(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, @@ -2390,11 +2391,12 @@ static int RegisterDebugSignalHandler() { return -1; } - handler = (LPTHREAD_START_ROUTINE*) MapViewOfFile(mapping_handle, - FILE_MAP_ALL_ACCESS, - 0, - 0, - sizeof *handler); + handler = reinterpret_cast( + MapViewOfFile(mapping_handle, + FILE_MAP_ALL_ACCESS, + 0, + 0, + sizeof *handler)); if (handler == NULL) { CloseHandle(mapping_handle); return -1; @@ -2415,7 +2417,7 @@ static Handle DebugProcess(const Arguments& args) { HANDLE process = NULL; HANDLE thread = NULL; HANDLE mapping = NULL; - char mapping_name[32]; + wchar_t mapping_name[32]; LPTHREAD_START_ROUTINE* handler = NULL; if (args.Length() != 1) { @@ -2437,22 +2439,24 @@ static Handle DebugProcess(const Arguments& args) { if (GetDebugSignalHandlerMappingName(pid, mapping_name, - sizeof mapping_name) < 0) { + ARRAY_SIZE(mapping_name)) < 0) { rv = ThrowException(ErrnoException(errno, "sprintf")); goto out; } - mapping = OpenFileMapping(FILE_MAP_READ, FALSE, mapping_name); + mapping = OpenFileMappingW(FILE_MAP_READ, FALSE, mapping_name); if (mapping == NULL) { - rv = ThrowException(WinapiErrnoException(GetLastError(), "sprintf")); + rv = ThrowException(WinapiErrnoException(GetLastError(), + "OpenFileMappingW")); goto out; } - handler = (LPTHREAD_START_ROUTINE*) MapViewOfFile(mapping, - FILE_MAP_READ, - 0, - 0, - sizeof *handler); + handler = reinterpret_cast( + MapViewOfFile(mapping, + FILE_MAP_READ, + 0, + 0, + sizeof *handler)); if (handler == NULL || *handler == NULL) { rv = ThrowException(WinapiErrnoException(GetLastError(), "MapViewOfFile")); goto out; diff --git a/src/platform_win32.cc b/src/platform_win32.cc index 65add1124a..c84131a701 100644 --- a/src/platform_win32.cc +++ b/src/platform_win32.cc @@ -48,9 +48,10 @@ double Platform::prog_start_time = Platform::GetUptime(); const char *winapi_strerror(const int errorno) { char *errmsg = NULL; - FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | + FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errorno, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&errmsg, 0, NULL); + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + reinterpret_cast(&errmsg), 0, NULL); if (errmsg) { // Remove trailing newlines @@ -72,9 +73,10 @@ void winapi_perror(const char* prefix = NULL) { DWORD errorno = GetLastError(); const char *errmsg = NULL; - FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | + FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errorno, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&errmsg, 0, NULL); + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + reinterpret_cast(&errmsg), 0, NULL); if (!errmsg) { errmsg = "Unknown error\n"; @@ -203,8 +205,7 @@ int Platform::GetMemory(size_t *rss) { HANDLE current_process = GetCurrentProcess(); PROCESS_MEMORY_COUNTERS pmc; - if ( !GetProcessMemoryInfo( current_process, &pmc, sizeof(pmc)) ) - { + if (!GetProcessMemoryInfo(current_process, &pmc, sizeof(pmc))) { winapi_perror("GetProcessMemoryInfo"); } @@ -220,40 +221,49 @@ int Platform::GetCPUInfo(Local *cpus) { for (int i = 0; i < 32; i++) { - char key[128] = "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\"; - char processor_number[32]; - itoa(i, processor_number, 10); - strncat(key, processor_number, 2); + wchar_t key[128] = L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\"; + wchar_t processor_number[32]; + _itow(i, processor_number, 10); + wcsncat(key, processor_number, 2); HKEY processor_key = NULL; DWORD cpu_speed = 0; DWORD cpu_speed_length = sizeof(cpu_speed); - char cpu_brand[256]; + wchar_t cpu_brand[256]; DWORD cpu_brand_length = sizeof(cpu_brand); - if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, key, 0, KEY_QUERY_VALUE, - &processor_key) != ERROR_SUCCESS) { + if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, + key, + 0, + KEY_QUERY_VALUE, + &processor_key) != ERROR_SUCCESS) { if (i == 0) { - winapi_perror("RegOpenKeyEx"); + winapi_perror("RegOpenKeyExW"); return -1; } continue; } - if (RegQueryValueEx(processor_key, "~MHz", NULL, NULL, - (LPBYTE)&cpu_speed, &cpu_speed_length) - != ERROR_SUCCESS) { - winapi_perror("RegQueryValueEx"); + if (RegQueryValueExW(processor_key, + L"~MHz", + NULL, + NULL, + reinterpret_cast(&cpu_speed), + &cpu_speed_length) != ERROR_SUCCESS) { + winapi_perror("RegQueryValueExW"); return -1; } - if (RegQueryValueEx(processor_key, "ProcessorNameString", NULL, NULL, - (LPBYTE)&cpu_brand, &cpu_brand_length) - != ERROR_SUCCESS) { - winapi_perror("RegQueryValueEx"); + if (RegQueryValueExW(processor_key, + L"ProcessorNameString", + NULL, + NULL, + reinterpret_cast(&cpu_brand), + &cpu_brand_length) != ERROR_SUCCESS) { + winapi_perror("RegQueryValueExW"); return -1; } @@ -267,7 +277,8 @@ int Platform::GetCPUInfo(Local *cpus) { times_info->Set(String::New("irq"), Integer::New(0)); Local cpu_info = Object::New(); - cpu_info->Set(String::New("model"), String::New(cpu_brand)); + cpu_info->Set(String::New("model"), + String::New(reinterpret_cast(cpu_brand))); cpu_info->Set(String::New("speed"), Integer::New(cpu_speed)); cpu_info->Set(String::New("times"), times_info); (*cpus)->Set(i,cpu_info);