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