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

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

Issue 11567010: Complete the transition to unicode APIs on Windows. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years 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 | Annotate | Revision Log
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 <process.h> 5 #include <process.h>
6 6
7 #include "bin/builtin.h" 7 #include "bin/builtin.h"
8 #include "bin/process.h" 8 #include "bin/process.h"
9 #include "bin/eventhandler.h" 9 #include "bin/eventhandler.h"
10 #include "bin/log.h" 10 #include "bin/log.h"
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 kInheritNone 195 kInheritNone
196 }; 196 };
197 197
198 198
199 // Create a pipe for communicating with a new process. The handles array 199 // Create a pipe for communicating with a new process. The handles array
200 // will contain the read and write ends of the pipe. Based on the type 200 // will contain the read and write ends of the pipe. Based on the type
201 // one of the handles will be inheritable. 201 // one of the handles will be inheritable.
202 // NOTE: If this function returns false the handles might have been allocated 202 // NOTE: If this function returns false the handles might have been allocated
203 // and the caller should make sure to close them in case of an error. 203 // and the caller should make sure to close them in case of an error.
204 static bool CreateProcessPipe(HANDLE handles[2], 204 static bool CreateProcessPipe(HANDLE handles[2],
205 char* pipe_name, 205 wchar_t* pipe_name,
206 NamedPipeType type) { 206 NamedPipeType type) {
207 // Security attributes describing an inheritable handle. 207 // Security attributes describing an inheritable handle.
208 SECURITY_ATTRIBUTES inherit_handle; 208 SECURITY_ATTRIBUTES inherit_handle;
209 inherit_handle.nLength = sizeof(SECURITY_ATTRIBUTES); 209 inherit_handle.nLength = sizeof(SECURITY_ATTRIBUTES);
210 inherit_handle.bInheritHandle = TRUE; 210 inherit_handle.bInheritHandle = TRUE;
211 inherit_handle.lpSecurityDescriptor = NULL; 211 inherit_handle.lpSecurityDescriptor = NULL;
212 212
213 if (type == kInheritRead) { 213 if (type == kInheritRead) {
214 handles[kWriteHandle] = 214 handles[kWriteHandle] =
215 CreateNamedPipe(pipe_name, 215 CreateNamedPipeW(pipe_name,
216 PIPE_ACCESS_OUTBOUND | FILE_FLAG_OVERLAPPED, 216 PIPE_ACCESS_OUTBOUND | FILE_FLAG_OVERLAPPED,
217 PIPE_TYPE_BYTE | PIPE_WAIT, 217 PIPE_TYPE_BYTE | PIPE_WAIT,
218 1, // Number of pipes 218 1, // Number of pipes
219 1024, // Out buffer size 219 1024, // Out buffer size
220 1024, // In buffer size 220 1024, // In buffer size
221 0, // Timeout in ms 221 0, // Timeout in ms
222 NULL); 222 NULL);
223 223
224 if (handles[kWriteHandle] == INVALID_HANDLE_VALUE) { 224 if (handles[kWriteHandle] == INVALID_HANDLE_VALUE) {
225 Log::PrintErr("CreateNamedPipe failed %d\n", GetLastError()); 225 Log::PrintErr("CreateNamedPipe failed %d\n", GetLastError());
226 return false; 226 return false;
227 } 227 }
228 228
229 handles[kReadHandle] = 229 handles[kReadHandle] =
230 CreateFile(pipe_name, 230 CreateFileW(pipe_name,
231 GENERIC_READ, 231 GENERIC_READ,
232 0, 232 0,
233 &inherit_handle, 233 &inherit_handle,
234 OPEN_EXISTING, 234 OPEN_EXISTING,
235 FILE_READ_ATTRIBUTES | FILE_FLAG_OVERLAPPED, 235 FILE_READ_ATTRIBUTES | FILE_FLAG_OVERLAPPED,
236 NULL); 236 NULL);
237 if (handles[kReadHandle] == INVALID_HANDLE_VALUE) { 237 if (handles[kReadHandle] == INVALID_HANDLE_VALUE) {
238 Log::PrintErr("CreateFile failed %d\n", GetLastError()); 238 Log::PrintErr("CreateFile failed %d\n", GetLastError());
239 return false; 239 return false;
240 } 240 }
241 } else { 241 } else {
242 ASSERT(type == kInheritWrite || type == kInheritNone); 242 ASSERT(type == kInheritWrite || type == kInheritNone);
243 handles[kReadHandle] = 243 handles[kReadHandle] =
244 CreateNamedPipe(pipe_name, 244 CreateNamedPipeW(pipe_name,
245 PIPE_ACCESS_INBOUND | FILE_FLAG_OVERLAPPED, 245 PIPE_ACCESS_INBOUND | FILE_FLAG_OVERLAPPED,
246 PIPE_TYPE_BYTE | PIPE_WAIT, 246 PIPE_TYPE_BYTE | PIPE_WAIT,
247 1, // Number of pipes 247 1, // Number of pipes
248 1024, // Out buffer size 248 1024, // Out buffer size
249 1024, // In buffer size 249 1024, // In buffer size
250 0, // Timeout in ms 250 0, // Timeout in ms
251 NULL); 251 NULL);
252 252
253 if (handles[kReadHandle] == INVALID_HANDLE_VALUE) { 253 if (handles[kReadHandle] == INVALID_HANDLE_VALUE) {
254 Log::PrintErr("CreateNamedPipe failed %d\n", GetLastError()); 254 Log::PrintErr("CreateNamedPipe failed %d\n", GetLastError());
255 return false; 255 return false;
256 } 256 }
257 257
258 handles[kWriteHandle] = 258 handles[kWriteHandle] =
259 CreateFile(pipe_name, 259 CreateFileW(pipe_name,
260 GENERIC_WRITE, 260 GENERIC_WRITE,
261 0, 261 0,
262 (type == kInheritWrite) ? &inherit_handle : NULL, 262 (type == kInheritWrite) ? &inherit_handle : NULL,
263 OPEN_EXISTING, 263 OPEN_EXISTING,
264 FILE_WRITE_ATTRIBUTES | FILE_FLAG_OVERLAPPED, 264 FILE_WRITE_ATTRIBUTES | FILE_FLAG_OVERLAPPED,
265 NULL); 265 NULL);
266 if (handles[kWriteHandle] == INVALID_HANDLE_VALUE) { 266 if (handles[kWriteHandle] == INVALID_HANDLE_VALUE) {
267 Log::PrintErr("CreateFile failed %d\n", GetLastError()); 267 Log::PrintErr("CreateFile failed %d\n", GetLastError());
268 return false; 268 return false;
269 } 269 }
270 } 270 }
271 return true; 271 return true;
272 } 272 }
273 273
274 274
275 static void CloseProcessPipe(HANDLE handles[2]) { 275 static void CloseProcessPipe(HANDLE handles[2]) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 intptr_t* err, 330 intptr_t* err,
331 intptr_t* id, 331 intptr_t* id,
332 intptr_t* exit_handler, 332 intptr_t* exit_handler,
333 char** os_error_message) { 333 char** os_error_message) {
334 HANDLE stdin_handles[2] = { INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE }; 334 HANDLE stdin_handles[2] = { INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE };
335 HANDLE stdout_handles[2] = { INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE }; 335 HANDLE stdout_handles[2] = { INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE };
336 HANDLE stderr_handles[2] = { INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE }; 336 HANDLE stderr_handles[2] = { INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE };
337 HANDLE exit_handles[2] = { INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE }; 337 HANDLE exit_handles[2] = { INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE };
338 338
339 // Generate unique pipe names for the four named pipes needed. 339 // Generate unique pipe names for the four named pipes needed.
340 char pipe_names[4][80]; 340 static const int kMaxPipeNameSize = 80;
341 wchar_t pipe_names[4][kMaxPipeNameSize];
341 UUID uuid; 342 UUID uuid;
342 RPC_STATUS status = UuidCreateSequential(&uuid); 343 RPC_STATUS status = UuidCreateSequential(&uuid);
343 if (status != RPC_S_OK && status != RPC_S_UUID_LOCAL_ONLY) { 344 if (status != RPC_S_OK && status != RPC_S_UUID_LOCAL_ONLY) {
344 SetOsErrorMessage(os_error_message); 345 SetOsErrorMessage(os_error_message);
345 Log::PrintErr("UuidCreateSequential failed %d\n", status); 346 Log::PrintErr("UuidCreateSequential failed %d\n", status);
346 return status; 347 return status;
347 } 348 }
348 RPC_CSTR uuid_string; 349 RPC_WSTR uuid_string;
349 status = UuidToString(&uuid, &uuid_string); 350 status = UuidToStringW(&uuid, &uuid_string);
350 if (status != RPC_S_OK) { 351 if (status != RPC_S_OK) {
351 SetOsErrorMessage(os_error_message); 352 SetOsErrorMessage(os_error_message);
352 Log::PrintErr("UuidToString failed %d\n", status); 353 Log::PrintErr("UuidToString failed %d\n", status);
353 return status; 354 return status;
354 } 355 }
355 for (int i = 0; i < 4; i++) { 356 for (int i = 0; i < 4; i++) {
356 static const char* prefix = "\\\\.\\Pipe\\dart"; 357 static const wchar_t* prefix = L"\\\\.\\Pipe\\dart";
357 snprintf(pipe_names[i], 358 _snwprintf(pipe_names[i],
358 sizeof(pipe_names[i]), 359 kMaxPipeNameSize,
359 "%s_%s_%d", prefix, uuid_string, i + 1); 360 L"%s_%s_%d", prefix, uuid_string, i + 1);
360 } 361 }
361 status = RpcStringFree(&uuid_string); 362 status = RpcStringFreeW(&uuid_string);
362 if (status != RPC_S_OK) { 363 if (status != RPC_S_OK) {
363 SetOsErrorMessage(os_error_message); 364 SetOsErrorMessage(os_error_message);
364 Log::PrintErr("RpcStringFree failed %d\n", status); 365 Log::PrintErr("RpcStringFree failed %d\n", status);
365 return status; 366 return status;
366 } 367 }
367 368
368 if (!CreateProcessPipe(stdin_handles, pipe_names[0], kInheritRead)) { 369 if (!CreateProcessPipe(stdin_handles, pipe_names[0], kInheritRead)) {
369 int error_code = SetOsErrorMessage(os_error_message); 370 int error_code = SetOsErrorMessage(os_error_message);
370 CloseProcessPipes( 371 CloseProcessPipes(
371 stdin_handles, stdout_handles, stderr_handles, exit_handles); 372 stdin_handles, stdout_handles, stderr_handles, exit_handles);
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 606
606 607
607 void Process::TerminateExitCodeHandler() { 608 void Process::TerminateExitCodeHandler() {
608 // Nothing needs to be done on Windows. 609 // Nothing needs to be done on Windows.
609 } 610 }
610 611
611 612
612 intptr_t Process::CurrentProcessId() { 613 intptr_t Process::CurrentProcessId() {
613 return static_cast<intptr_t>(GetCurrentProcessId()); 614 return static_cast<intptr_t>(GetCurrentProcessId());
614 } 615 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698