| OLD | NEW |
| 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/thread.h" | 10 #include "bin/thread.h" |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 } | 462 } |
| 463 os_error_message[os_error_message_len - 1] = '\0'; | 463 os_error_message[os_error_message_len - 1] = '\0'; |
| 464 return error_code; | 464 return error_code; |
| 465 } | 465 } |
| 466 | 466 |
| 467 | 467 |
| 468 int Process::Start(const char* path, | 468 int Process::Start(const char* path, |
| 469 char* arguments[], | 469 char* arguments[], |
| 470 intptr_t arguments_length, | 470 intptr_t arguments_length, |
| 471 const char* working_directory, | 471 const char* working_directory, |
| 472 char* environment[], | |
| 473 intptr_t environment_length, | |
| 474 intptr_t* in, | 472 intptr_t* in, |
| 475 intptr_t* out, | 473 intptr_t* out, |
| 476 intptr_t* err, | 474 intptr_t* err, |
| 477 intptr_t* id, | 475 intptr_t* id, |
| 478 intptr_t* exit_handler, | 476 intptr_t* exit_handler, |
| 479 char* os_error_message, | 477 char* os_error_message, |
| 480 int os_error_message_len) { | 478 int os_error_message_len) { |
| 481 // Ensure that the process exit handler thread has been started. | 479 // Ensure that the process exit handler thread has been started. |
| 482 bool initialized = ExitCodeHandler::EnsureInitialized(); | 480 bool initialized = ExitCodeHandler::EnsureInitialized(); |
| 483 if (!initialized) { | 481 if (!initialized) { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 len += written; | 578 len += written; |
| 581 remaining -= written; | 579 remaining -= written; |
| 582 ASSERT(remaining >= 0); | 580 ASSERT(remaining >= 0); |
| 583 for (int i = 0; i < arguments_length; i++) { | 581 for (int i = 0; i < arguments_length; i++) { |
| 584 written = snprintf(command_line + len, remaining, " %s", arguments[i]); | 582 written = snprintf(command_line + len, remaining, " %s", arguments[i]); |
| 585 len += written; | 583 len += written; |
| 586 remaining -= written; | 584 remaining -= written; |
| 587 ASSERT(remaining >= 0); | 585 ASSERT(remaining >= 0); |
| 588 } | 586 } |
| 589 | 587 |
| 590 // Create environment block if an environment is supplied. | |
| 591 char* environment_block = NULL; | |
| 592 if (environment != NULL) { | |
| 593 // An environment block is a sequence of zero-terminated strings | |
| 594 // followed by a block-terminating zero char. | |
| 595 intptr_t block_size = 1; | |
| 596 for (intptr_t i = 0; i < environment_length; i++) { | |
| 597 block_size += strlen(environment[i]) + 1; | |
| 598 } | |
| 599 environment_block = new char[block_size]; | |
| 600 intptr_t block_index = 0; | |
| 601 for (intptr_t i = 0; i < environment_length; i++) { | |
| 602 intptr_t len = strlen(environment[i]); | |
| 603 intptr_t result = snprintf(environment_block + block_index, | |
| 604 len, | |
| 605 "%s", | |
| 606 environment[i]); | |
| 607 ASSERT(result == len); | |
| 608 block_index += len; | |
| 609 environment_block[block_index++] = '\0'; | |
| 610 } | |
| 611 // Block-terminating zero char. | |
| 612 environment_block[block_index++] = '\0'; | |
| 613 ASSERT(block_index == block_size); | |
| 614 } | |
| 615 | |
| 616 // Create process. | 588 // Create process. |
| 617 BOOL result = CreateProcess(NULL, // ApplicationName | 589 BOOL result = CreateProcess(NULL, // ApplicationName |
| 618 command_line, | 590 command_line, |
| 619 NULL, // ProcessAttributes | 591 NULL, // ProcessAttributes |
| 620 NULL, // ThreadAttributes | 592 NULL, // ThreadAttributes |
| 621 TRUE, // InheritHandles | 593 TRUE, // InheritHandles |
| 622 0, // CreationFlags | 594 0, // CreationFlags |
| 623 environment_block, | 595 NULL, // Environment |
| 624 working_directory, | 596 working_directory, |
| 625 &startup_info, | 597 &startup_info, |
| 626 &process_info); | 598 &process_info); |
| 627 | 599 |
| 628 // Deallocate command-line and environment block strings. | 600 // Deallocate command-line string. |
| 629 delete[] command_line; | 601 delete[] command_line; |
| 630 delete[] environment_block; | |
| 631 | 602 |
| 632 if (result == 0) { | 603 if (result == 0) { |
| 633 int error_code = SetOsErrorMessage(os_error_message, os_error_message_len); | 604 int error_code = SetOsErrorMessage(os_error_message, os_error_message_len); |
| 634 CloseProcessPipes( | 605 CloseProcessPipes( |
| 635 stdin_handles, stdout_handles, stderr_handles, exit_handles); | 606 stdin_handles, stdout_handles, stderr_handles, exit_handles); |
| 636 return error_code; | 607 return error_code; |
| 637 } | 608 } |
| 638 | 609 |
| 639 ProcessInfoList::AddProcess(process_info.dwProcessId, | 610 ProcessInfoList::AddProcess(process_info.dwProcessId, |
| 640 process_info.hProcess, | 611 process_info.hProcess, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 671 if (!result) { | 642 if (!result) { |
| 672 return false; | 643 return false; |
| 673 } | 644 } |
| 674 return true; | 645 return true; |
| 675 } | 646 } |
| 676 | 647 |
| 677 | 648 |
| 678 void Process::TerminateExitCodeHandler() { | 649 void Process::TerminateExitCodeHandler() { |
| 679 ExitCodeHandler::TerminateExitCodeThread(); | 650 ExitCodeHandler::TerminateExitCodeThread(); |
| 680 } | 651 } |
| OLD | NEW |