diff --git a/runtime/bin/extensions_win.cc b/runtime/bin/extensions_win.cc index 52edf59d59d..1fb7004a84e 100644 --- a/runtime/bin/extensions_win.cc +++ b/runtime/bin/extensions_win.cc @@ -3,12 +3,15 @@ // BSD-style license that can be found in the LICENSE file. #include "bin/extensions.h" +#include "bin/utils.h" void* Extensions::LoadExtensionLibrary(const char* library_path, const char* extension_name) { const char* strings[] = { library_path, "/", extension_name, ".dll", NULL }; char* library_file = Concatenate(strings); - void* lib_handle = LoadLibrary(library_file); + wchar_t* unicode_library_file = StringUtils::Utf8ToWide(library_file); + void* lib_handle = LoadLibraryW(unicode_library_file); + delete(unicode_library_file); free(library_file); return lib_handle; } diff --git a/runtime/bin/process_win.cc b/runtime/bin/process_win.cc index a09692bb11c..fa64639716b 100644 --- a/runtime/bin/process_win.cc +++ b/runtime/bin/process_win.cc @@ -202,7 +202,7 @@ enum NamedPipeType { // NOTE: If this function returns false the handles might have been allocated // and the caller should make sure to close them in case of an error. static bool CreateProcessPipe(HANDLE handles[2], - char* pipe_name, + wchar_t* pipe_name, NamedPipeType type) { // Security attributes describing an inheritable handle. SECURITY_ATTRIBUTES inherit_handle; @@ -212,14 +212,14 @@ static bool CreateProcessPipe(HANDLE handles[2], if (type == kInheritRead) { handles[kWriteHandle] = - CreateNamedPipe(pipe_name, - PIPE_ACCESS_OUTBOUND | FILE_FLAG_OVERLAPPED, - PIPE_TYPE_BYTE | PIPE_WAIT, - 1, // Number of pipes - 1024, // Out buffer size - 1024, // In buffer size - 0, // Timeout in ms - NULL); + CreateNamedPipeW(pipe_name, + PIPE_ACCESS_OUTBOUND | FILE_FLAG_OVERLAPPED, + PIPE_TYPE_BYTE | PIPE_WAIT, + 1, // Number of pipes + 1024, // Out buffer size + 1024, // In buffer size + 0, // Timeout in ms + NULL); if (handles[kWriteHandle] == INVALID_HANDLE_VALUE) { Log::PrintErr("CreateNamedPipe failed %d\n", GetLastError()); @@ -227,13 +227,13 @@ static bool CreateProcessPipe(HANDLE handles[2], } handles[kReadHandle] = - CreateFile(pipe_name, - GENERIC_READ, - 0, - &inherit_handle, - OPEN_EXISTING, - FILE_READ_ATTRIBUTES | FILE_FLAG_OVERLAPPED, - NULL); + CreateFileW(pipe_name, + GENERIC_READ, + 0, + &inherit_handle, + OPEN_EXISTING, + FILE_READ_ATTRIBUTES | FILE_FLAG_OVERLAPPED, + NULL); if (handles[kReadHandle] == INVALID_HANDLE_VALUE) { Log::PrintErr("CreateFile failed %d\n", GetLastError()); return false; @@ -241,14 +241,14 @@ static bool CreateProcessPipe(HANDLE handles[2], } else { ASSERT(type == kInheritWrite || type == kInheritNone); handles[kReadHandle] = - CreateNamedPipe(pipe_name, - PIPE_ACCESS_INBOUND | FILE_FLAG_OVERLAPPED, - PIPE_TYPE_BYTE | PIPE_WAIT, - 1, // Number of pipes - 1024, // Out buffer size - 1024, // In buffer size - 0, // Timeout in ms - NULL); + CreateNamedPipeW(pipe_name, + PIPE_ACCESS_INBOUND | FILE_FLAG_OVERLAPPED, + PIPE_TYPE_BYTE | PIPE_WAIT, + 1, // Number of pipes + 1024, // Out buffer size + 1024, // In buffer size + 0, // Timeout in ms + NULL); if (handles[kReadHandle] == INVALID_HANDLE_VALUE) { Log::PrintErr("CreateNamedPipe failed %d\n", GetLastError()); @@ -256,13 +256,13 @@ static bool CreateProcessPipe(HANDLE handles[2], } handles[kWriteHandle] = - CreateFile(pipe_name, - GENERIC_WRITE, - 0, - (type == kInheritWrite) ? &inherit_handle : NULL, - OPEN_EXISTING, - FILE_WRITE_ATTRIBUTES | FILE_FLAG_OVERLAPPED, - NULL); + CreateFileW(pipe_name, + GENERIC_WRITE, + 0, + (type == kInheritWrite) ? &inherit_handle : NULL, + OPEN_EXISTING, + FILE_WRITE_ATTRIBUTES | FILE_FLAG_OVERLAPPED, + NULL); if (handles[kWriteHandle] == INVALID_HANDLE_VALUE) { Log::PrintErr("CreateFile failed %d\n", GetLastError()); return false; @@ -337,7 +337,8 @@ int Process::Start(const char* path, HANDLE exit_handles[2] = { INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE }; // Generate unique pipe names for the four named pipes needed. - char pipe_names[4][80]; + static const int kMaxPipeNameSize = 80; + wchar_t pipe_names[4][kMaxPipeNameSize]; UUID uuid; RPC_STATUS status = UuidCreateSequential(&uuid); if (status != RPC_S_OK && status != RPC_S_UUID_LOCAL_ONLY) { @@ -345,20 +346,20 @@ int Process::Start(const char* path, Log::PrintErr("UuidCreateSequential failed %d\n", status); return status; } - RPC_CSTR uuid_string; - status = UuidToString(&uuid, &uuid_string); + RPC_WSTR uuid_string; + status = UuidToStringW(&uuid, &uuid_string); if (status != RPC_S_OK) { SetOsErrorMessage(os_error_message); Log::PrintErr("UuidToString failed %d\n", status); return status; } for (int i = 0; i < 4; i++) { - static const char* prefix = "\\\\.\\Pipe\\dart"; - snprintf(pipe_names[i], - sizeof(pipe_names[i]), - "%s_%s_%d", prefix, uuid_string, i + 1); + static const wchar_t* prefix = L"\\\\.\\Pipe\\dart"; + _snwprintf(pipe_names[i], + kMaxPipeNameSize, + L"%s_%s_%d", prefix, uuid_string, i + 1); } - status = RpcStringFree(&uuid_string); + status = RpcStringFreeW(&uuid_string); if (status != RPC_S_OK) { SetOsErrorMessage(os_error_message); Log::PrintErr("RpcStringFree failed %d\n", status); diff --git a/runtime/bin/socket_win.cc b/runtime/bin/socket_win.cc index adc6aef87ae..fdefef2abbd 100644 --- a/runtime/bin/socket_win.cc +++ b/runtime/bin/socket_win.cc @@ -66,12 +66,14 @@ bool Socket::GetRemotePeer(intptr_t fd, char *host, intptr_t *port) { // Clear the port before calling WSAAddressToString as WSAAddressToString // includes the port in the formatted string. socket_address.sin_port = 0; + wchar_t* unicode_host = StringUtils::Utf8ToWide(host); DWORD len = INET_ADDRSTRLEN; - int err = WSAAddressToString(reinterpret_cast(&socket_address), - sizeof(socket_address), - NULL, - host, - &len); + int err = WSAAddressToStringW(reinterpret_cast(&socket_address), + sizeof(socket_address), + NULL, + unicode_host, + &len); + free(unicode_host); if (err != 0) { Log::PrintErr("Error WSAAddressToString: %d\n", WSAGetLastError()); return false; @@ -195,12 +197,14 @@ const char* Socket::LookupIPv4Address(char* host, OSError** os_error) { // Clear the port before calling WSAAddressToString as WSAAddressToString // includes the port in the formatted string. + wchar_t* unicode_buffer = StringUtils::Utf8ToWide(buffer); DWORD len = INET_ADDRSTRLEN; - int err = WSAAddressToString(reinterpret_cast(sockaddr), - sizeof(sockaddr_in), - NULL, - buffer, - &len); + int err = WSAAddressToStringW(reinterpret_cast(sockaddr), + sizeof(sockaddr_in), + NULL, + unicode_buffer, + &len); + free(unicode_buffer); if (err != 0) { free(buffer); return NULL; diff --git a/runtime/platform/globals.h b/runtime/platform/globals.h index 3e179be95ce..0742a4ad98f 100644 --- a/runtime/platform/globals.h +++ b/runtime/platform/globals.h @@ -20,7 +20,8 @@ #define NOSERVICE #define NOSOUND #define NOMCX - +#define _UNICODE +#define UNICODE #include #include #include