| 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 "platform/globals.h" | 5 #include "platform/globals.h" |
| 6 #if defined(TARGET_OS_WINDOWS) | 6 #if defined(TARGET_OS_WINDOWS) |
| 7 | 7 |
| 8 #include <process.h> // NOLINT | 8 #include <process.h> // NOLINT |
| 9 | 9 |
| 10 #include "bin/builtin.h" | 10 #include "bin/builtin.h" |
| 11 #include "bin/dartutils.h" |
| 11 #include "bin/process.h" | 12 #include "bin/process.h" |
| 12 #include "bin/eventhandler.h" | 13 #include "bin/eventhandler.h" |
| 13 #include "bin/lockers.h" | 14 #include "bin/lockers.h" |
| 14 #include "bin/log.h" | 15 #include "bin/log.h" |
| 15 #include "bin/socket.h" | 16 #include "bin/socket.h" |
| 16 #include "bin/thread.h" | 17 #include "bin/thread.h" |
| 17 #include "bin/utils.h" | 18 #include "bin/utils.h" |
| 18 #include "bin/utils_win.h" | 19 #include "bin/utils_win.h" |
| 19 | 20 |
| 20 | 21 |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 stdin_handles_[kWriteHandle] = INVALID_HANDLE_VALUE; | 428 stdin_handles_[kWriteHandle] = INVALID_HANDLE_VALUE; |
| 428 stdout_handles_[kReadHandle] = INVALID_HANDLE_VALUE; | 429 stdout_handles_[kReadHandle] = INVALID_HANDLE_VALUE; |
| 429 stdout_handles_[kWriteHandle] = INVALID_HANDLE_VALUE; | 430 stdout_handles_[kWriteHandle] = INVALID_HANDLE_VALUE; |
| 430 stderr_handles_[kReadHandle] = INVALID_HANDLE_VALUE; | 431 stderr_handles_[kReadHandle] = INVALID_HANDLE_VALUE; |
| 431 stderr_handles_[kWriteHandle] = INVALID_HANDLE_VALUE; | 432 stderr_handles_[kWriteHandle] = INVALID_HANDLE_VALUE; |
| 432 exit_handles_[kReadHandle] = INVALID_HANDLE_VALUE; | 433 exit_handles_[kReadHandle] = INVALID_HANDLE_VALUE; |
| 433 exit_handles_[kWriteHandle] = INVALID_HANDLE_VALUE; | 434 exit_handles_[kWriteHandle] = INVALID_HANDLE_VALUE; |
| 434 | 435 |
| 435 // Transform input strings to system format. | 436 // Transform input strings to system format. |
| 436 const wchar_t* system_path = StringUtilsWin::Utf8ToWide(path_); | 437 const wchar_t* system_path = StringUtilsWin::Utf8ToWide(path_); |
| 437 wchar_t** system_arguments = new wchar_t*[arguments_length]; | 438 wchar_t** system_arguments; |
| 439 system_arguments = reinterpret_cast<wchar_t**>( |
| 440 Dart_ScopeAllocate(arguments_length * sizeof(*system_arguments))); |
| 438 for (int i = 0; i < arguments_length; i++) { | 441 for (int i = 0; i < arguments_length; i++) { |
| 439 system_arguments[i] = StringUtilsWin::Utf8ToWide(arguments[i]); | 442 system_arguments[i] = StringUtilsWin::Utf8ToWide(arguments[i]); |
| 440 } | 443 } |
| 441 | 444 |
| 442 // Compute command-line length. | 445 // Compute command-line length. |
| 443 int command_line_length = wcslen(system_path); | 446 int command_line_length = wcslen(system_path); |
| 444 for (int i = 0; i < arguments_length; i++) { | 447 for (int i = 0; i < arguments_length; i++) { |
| 445 command_line_length += wcslen(system_arguments[i]); | 448 command_line_length += wcslen(system_arguments[i]); |
| 446 } | 449 } |
| 447 // Account for null termination and one space per argument. | 450 // Account for null termination and one space per argument. |
| 448 command_line_length += arguments_length + 1; | 451 command_line_length += arguments_length + 1; |
| 449 | 452 |
| 450 // Put together command-line string. | 453 // Put together command-line string. |
| 451 command_line_ = new wchar_t[command_line_length]; | 454 command_line_ = new wchar_t[command_line_length]; |
| 452 int len = 0; | 455 int len = 0; |
| 453 int remaining = command_line_length; | 456 int remaining = command_line_length; |
| 454 int written = | 457 int written = |
| 455 _snwprintf(command_line_ + len, remaining, L"%s", system_path); | 458 _snwprintf(command_line_ + len, remaining, L"%s", system_path); |
| 456 len += written; | 459 len += written; |
| 457 remaining -= written; | 460 remaining -= written; |
| 458 ASSERT(remaining >= 0); | 461 ASSERT(remaining >= 0); |
| 459 for (int i = 0; i < arguments_length; i++) { | 462 for (int i = 0; i < arguments_length; i++) { |
| 460 written = | 463 written = |
| 461 _snwprintf( | 464 _snwprintf( |
| 462 command_line_ + len, remaining, L" %s", system_arguments[i]); | 465 command_line_ + len, remaining, L" %s", system_arguments[i]); |
| 463 len += written; | 466 len += written; |
| 464 remaining -= written; | 467 remaining -= written; |
| 465 ASSERT(remaining >= 0); | 468 ASSERT(remaining >= 0); |
| 466 } | 469 } |
| 467 free(const_cast<wchar_t*>(system_path)); | |
| 468 for (int i = 0; i < arguments_length; i++) free(system_arguments[i]); | |
| 469 delete[] system_arguments; | |
| 470 | 470 |
| 471 // Create environment block if an environment is supplied. | 471 // Create environment block if an environment is supplied. |
| 472 environment_block_ = NULL; | 472 environment_block_ = NULL; |
| 473 if (environment != NULL) { | 473 if (environment != NULL) { |
| 474 wchar_t** system_environment = new wchar_t*[environment_length]; | 474 wchar_t** system_environment; |
| 475 system_environment = reinterpret_cast<wchar_t**>( |
| 476 Dart_ScopeAllocate(environment_length * sizeof(*system_environment))); |
| 475 // Convert environment strings to system strings. | 477 // Convert environment strings to system strings. |
| 476 for (intptr_t i = 0; i < environment_length; i++) { | 478 for (intptr_t i = 0; i < environment_length; i++) { |
| 477 system_environment[i] = StringUtilsWin::Utf8ToWide(environment[i]); | 479 system_environment[i] = StringUtilsWin::Utf8ToWide(environment[i]); |
| 478 } | 480 } |
| 479 | 481 |
| 480 // An environment block is a sequence of zero-terminated strings | 482 // An environment block is a sequence of zero-terminated strings |
| 481 // followed by a block-terminating zero char. | 483 // followed by a block-terminating zero char. |
| 482 intptr_t block_size = 1; | 484 intptr_t block_size = 1; |
| 483 for (intptr_t i = 0; i < environment_length; i++) { | 485 for (intptr_t i = 0; i < environment_length; i++) { |
| 484 block_size += wcslen(system_environment[i]) + 1; | 486 block_size += wcslen(system_environment[i]) + 1; |
| 485 } | 487 } |
| 486 environment_block_ = new wchar_t[block_size]; | 488 environment_block_ = new wchar_t[block_size]; |
| 487 intptr_t block_index = 0; | 489 intptr_t block_index = 0; |
| 488 for (intptr_t i = 0; i < environment_length; i++) { | 490 for (intptr_t i = 0; i < environment_length; i++) { |
| 489 intptr_t len = wcslen(system_environment[i]); | 491 intptr_t len = wcslen(system_environment[i]); |
| 490 intptr_t result = _snwprintf(environment_block_ + block_index, | 492 intptr_t result = _snwprintf(environment_block_ + block_index, |
| 491 len, | 493 len, |
| 492 L"%s", | 494 L"%s", |
| 493 system_environment[i]); | 495 system_environment[i]); |
| 494 ASSERT(result == len); | 496 ASSERT(result == len); |
| 495 block_index += len; | 497 block_index += len; |
| 496 environment_block_[block_index++] = '\0'; | 498 environment_block_[block_index++] = '\0'; |
| 497 } | 499 } |
| 498 // Block-terminating zero char. | 500 // Block-terminating zero char. |
| 499 environment_block_[block_index++] = '\0'; | 501 environment_block_[block_index++] = '\0'; |
| 500 ASSERT(block_index == block_size); | 502 ASSERT(block_index == block_size); |
| 501 for (intptr_t i = 0; i < environment_length; i++) { | |
| 502 free(system_environment[i]); | |
| 503 } | |
| 504 delete[] system_environment; | |
| 505 } | 503 } |
| 506 | 504 |
| 507 system_working_directory_ = NULL; | 505 system_working_directory_ = NULL; |
| 508 if (working_directory_ != NULL) { | 506 if (working_directory_ != NULL) { |
| 509 system_working_directory_ = | 507 system_working_directory_ = |
| 510 StringUtilsWin::Utf8ToWide(working_directory_); | 508 StringUtilsWin::Utf8ToWide(working_directory_); |
| 511 } | 509 } |
| 512 | 510 |
| 513 attribute_list_ = NULL; | 511 attribute_list_ = NULL; |
| 514 } | 512 } |
| 515 | 513 |
| 516 | 514 |
| 517 ~ProcessStarter() { | 515 ~ProcessStarter() { |
| 518 // Deallocate command-line and environment block strings. | 516 // Deallocate command-line and environment block strings. |
| 519 delete[] command_line_; | 517 delete[] command_line_; |
| 520 delete[] environment_block_; | 518 delete[] environment_block_; |
| 521 if (system_working_directory_ != NULL) { | |
| 522 free(const_cast<wchar_t*>(system_working_directory_)); | |
| 523 } | |
| 524 if (attribute_list_ != NULL) { | 519 if (attribute_list_ != NULL) { |
| 525 delete_proc_thread_attr_list(attribute_list_); | 520 delete_proc_thread_attr_list(attribute_list_); |
| 526 free(attribute_list_); | 521 free(attribute_list_); |
| 527 } | 522 } |
| 528 } | 523 } |
| 529 | 524 |
| 530 | 525 |
| 531 int Start() { | 526 int Start() { |
| 532 // Create pipes required. | 527 // Create pipes required. |
| 533 int err = CreatePipes(); | 528 int err = CreatePipes(); |
| (...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1043 USE(SetConsoleCtrlHandler(SignalHandler, false)); | 1038 USE(SetConsoleCtrlHandler(SignalHandler, false)); |
| 1044 } | 1039 } |
| 1045 } | 1040 } |
| 1046 delete handler; | 1041 delete handler; |
| 1047 } | 1042 } |
| 1048 | 1043 |
| 1049 } // namespace bin | 1044 } // namespace bin |
| 1050 } // namespace dart | 1045 } // namespace dart |
| 1051 | 1046 |
| 1052 #endif // defined(TARGET_OS_WINDOWS) | 1047 #endif // defined(TARGET_OS_WINDOWS) |
| OLD | NEW |