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

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

Issue 11497007: Fix Windows process implementation to only inherit the three handles needed for stdin, stdout and s… (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
« no previous file with comments | « no previous file | no next file » | 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 <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 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 return error_code; 382 return error_code;
383 } 383 }
384 if (!CreateProcessPipe(exit_handles, pipe_names[3], kInheritNone)) { 384 if (!CreateProcessPipe(exit_handles, pipe_names[3], kInheritNone)) {
385 int error_code = SetOsErrorMessage(os_error_message, os_error_message_len); 385 int error_code = SetOsErrorMessage(os_error_message, os_error_message_len);
386 CloseProcessPipes( 386 CloseProcessPipes(
387 stdin_handles, stdout_handles, stderr_handles, exit_handles); 387 stdin_handles, stdout_handles, stderr_handles, exit_handles);
388 return error_code; 388 return error_code;
389 } 389 }
390 390
391 // Setup info structures. 391 // Setup info structures.
392 STARTUPINFO startup_info; 392 STARTUPINFOEX startup_info;
393 ZeroMemory(&startup_info, sizeof(startup_info)); 393 ZeroMemory(&startup_info, sizeof(startup_info));
394 startup_info.cb = sizeof(startup_info); 394 startup_info.StartupInfo.cb = sizeof(startup_info);
395 startup_info.hStdInput = stdin_handles[kReadHandle]; 395 startup_info.StartupInfo.hStdInput = stdin_handles[kReadHandle];
396 startup_info.hStdOutput = stdout_handles[kWriteHandle]; 396 startup_info.StartupInfo.hStdOutput = stdout_handles[kWriteHandle];
397 startup_info.hStdError = stderr_handles[kWriteHandle]; 397 startup_info.StartupInfo.hStdError = stderr_handles[kWriteHandle];
398 startup_info.dwFlags = STARTF_USESTDHANDLES; 398 startup_info.StartupInfo.dwFlags = STARTF_USESTDHANDLES;
399
400 // Setup the handles to inherit. We only want to inherit the three handles
401 // for stdin, stdout and stderr.
402 SIZE_T size = 0;
403 // The call to determine the size of an attribute list always fails with
404 // ERROR_INSUFFICIENT_BUFFER and that error should be ignored.
405 if (!InitializeProcThreadAttributeList(NULL, 1, 0, &size) &&
406 GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
407 int error_code = SetOsErrorMessage(os_error_message, os_error_message_len);
408 CloseProcessPipes(
409 stdin_handles, stdout_handles, stderr_handles, exit_handles);
410 return error_code;
411 }
412 LPPROC_THREAD_ATTRIBUTE_LIST attribute_list =
413 reinterpret_cast<LPPROC_THREAD_ATTRIBUTE_LIST>(malloc(size));
414 ZeroMemory(attribute_list, size);
415 if (!InitializeProcThreadAttributeList(attribute_list, 1, 0, &size)) {
416 int error_code = SetOsErrorMessage(os_error_message, os_error_message_len);
417 CloseProcessPipes(
418 stdin_handles, stdout_handles, stderr_handles, exit_handles);
419 free(attribute_list);
420 return error_code;
421 }
422 static const int kNumInheritedHandles = 3;
423 HANDLE inherited_handles[kNumInheritedHandles] =
424 { stdin_handles[kReadHandle],
425 stdout_handles[kWriteHandle],
426 stderr_handles[kWriteHandle] };
427 if (!UpdateProcThreadAttribute(attribute_list,
428 0,
429 PROC_THREAD_ATTRIBUTE_HANDLE_LIST,
430 inherited_handles,
431 kNumInheritedHandles * sizeof(HANDLE),
432 NULL,
433 NULL)) {
434 DeleteProcThreadAttributeList(attribute_list);
435 int error_code = SetOsErrorMessage(os_error_message, os_error_message_len);
436 CloseProcessPipes(
437 stdin_handles, stdout_handles, stderr_handles, exit_handles);
438 free(attribute_list);
439 return error_code;
440 }
441 startup_info.lpAttributeList = attribute_list;
399 442
400 PROCESS_INFORMATION process_info; 443 PROCESS_INFORMATION process_info;
401 ZeroMemory(&process_info, sizeof(process_info)); 444 ZeroMemory(&process_info, sizeof(process_info));
402 445
403 // Transform input strings to system format. 446 // Transform input strings to system format.
404 path = StringUtils::Utf8ToSystemString(path); 447 path = StringUtils::Utf8ToSystemString(path);
405 for (int i = 0; i < arguments_length; i++) { 448 for (int i = 0; i < arguments_length; i++) {
406 arguments[i] = StringUtils::Utf8ToSystemString(arguments[i]); 449 arguments[i] = StringUtils::Utf8ToSystemString(arguments[i]);
407 } 450 }
408 451
409 // Compute command-line length. 452 // Compute command-line length.
410 int command_line_length = strlen(path); 453 int command_line_length = strlen(path);
411 for (int i = 0; i < arguments_length; i++) { 454 for (int i = 0; i < arguments_length; i++) {
412 command_line_length += strlen(arguments[i]); 455 command_line_length += strlen(arguments[i]);
413 } 456 }
414 // Account for null termination and one space per argument. 457 // Account for null termination and one space per argument.
415 command_line_length += arguments_length + 1; 458 command_line_length += arguments_length + 1;
416 static const int kMaxCommandLineLength = 32768; 459 static const int kMaxCommandLineLength = 32768;
417 if (command_line_length > kMaxCommandLineLength) { 460 if (command_line_length > kMaxCommandLineLength) {
418 int error_code = SetOsErrorMessage(os_error_message, os_error_message_len); 461 int error_code = SetOsErrorMessage(os_error_message, os_error_message_len);
419 CloseProcessPipes( 462 CloseProcessPipes(
420 stdin_handles, stdout_handles, stderr_handles, exit_handles); 463 stdin_handles, stdout_handles, stderr_handles, exit_handles);
421 free(const_cast<char*>(path)); 464 free(const_cast<char*>(path));
422 for (int i = 0; i < arguments_length; i++) free(arguments[i]); 465 for (int i = 0; i < arguments_length; i++) free(arguments[i]);
466 DeleteProcThreadAttributeList(attribute_list);
467 free(attribute_list);
423 return error_code; 468 return error_code;
424 } 469 }
425 470
426 // Put together command-line string. 471 // Put together command-line string.
427 char* command_line = new char[command_line_length]; 472 char* command_line = new char[command_line_length];
428 int len = 0; 473 int len = 0;
429 int remaining = command_line_length; 474 int remaining = command_line_length;
430 int written = snprintf(command_line + len, remaining, "%s", path); 475 int written = snprintf(command_line + len, remaining, "%s", path);
431 len += written; 476 len += written;
432 remaining -= written; 477 remaining -= written;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 if (working_directory != NULL) { 520 if (working_directory != NULL) {
476 working_directory = StringUtils::Utf8ToSystemString(working_directory); 521 working_directory = StringUtils::Utf8ToSystemString(working_directory);
477 } 522 }
478 523
479 // Create process. 524 // Create process.
480 BOOL result = CreateProcess(NULL, // ApplicationName 525 BOOL result = CreateProcess(NULL, // ApplicationName
481 command_line, 526 command_line,
482 NULL, // ProcessAttributes 527 NULL, // ProcessAttributes
483 NULL, // ThreadAttributes 528 NULL, // ThreadAttributes
484 TRUE, // InheritHandles 529 TRUE, // InheritHandles
485 0, // CreationFlags 530 EXTENDED_STARTUPINFO_PRESENT,
486 environment_block, 531 environment_block,
487 working_directory, 532 working_directory,
488 &startup_info, 533 reinterpret_cast<STARTUPINFO*>(&startup_info),
489 &process_info); 534 &process_info);
490 535
491 // Deallocate command-line and environment block strings. 536 // Deallocate command-line and environment block strings.
492 delete[] command_line; 537 delete[] command_line;
493 delete[] environment_block; 538 delete[] environment_block;
494 if (working_directory != NULL) { 539 if (working_directory != NULL) {
495 free(const_cast<char*>(working_directory)); 540 free(const_cast<char*>(working_directory));
496 } 541 }
497 542
543 DeleteProcThreadAttributeList(attribute_list);
544 free(attribute_list);
545
498 if (result == 0) { 546 if (result == 0) {
499 int error_code = SetOsErrorMessage(os_error_message, os_error_message_len); 547 int error_code = SetOsErrorMessage(os_error_message, os_error_message_len);
500 CloseProcessPipes( 548 CloseProcessPipes(
501 stdin_handles, stdout_handles, stderr_handles, exit_handles); 549 stdin_handles, stdout_handles, stderr_handles, exit_handles);
502 return error_code; 550 return error_code;
503 } 551 }
504 552
505 ProcessInfoList::AddProcess(process_info.dwProcessId, 553 ProcessInfoList::AddProcess(process_info.dwProcessId,
506 process_info.hProcess, 554 process_info.hProcess,
507 exit_handles[kWriteHandle]); 555 exit_handles[kWriteHandle]);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 592
545 593
546 void Process::TerminateExitCodeHandler() { 594 void Process::TerminateExitCodeHandler() {
547 // Nothing needs to be done on Windows. 595 // Nothing needs to be done on Windows.
548 } 596 }
549 597
550 598
551 intptr_t Process::CurrentProcessId() { 599 intptr_t Process::CurrentProcessId() {
552 return static_cast<intptr_t>(GetCurrentProcessId()); 600 return static_cast<intptr_t>(GetCurrentProcessId());
553 } 601 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698