| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 #if !defined(DART_IO_DISABLED) | 5 #if !defined(DART_IO_DISABLED) |
| 6 | 6 |
| 7 #include "platform/globals.h" | 7 #include "platform/globals.h" |
| 8 #if defined(HOST_OS_FUCHSIA) | 8 #if defined(HOST_OS_FUCHSIA) |
| 9 | 9 |
| 10 #include "bin/process.h" | 10 #include "bin/process.h" |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 static void HandleInterruptMsg() { | 331 static void HandleInterruptMsg() { |
| 332 ASSERT(items_[0].handle == interrupt_out_); | 332 ASSERT(items_[0].handle == interrupt_out_); |
| 333 ASSERT(items_[0].waitfor == MX_SOCKET_READABLE); | 333 ASSERT(items_[0].waitfor == MX_SOCKET_READABLE); |
| 334 ASSERT((items_[0].pending & MX_SOCKET_READABLE) != 0); | 334 ASSERT((items_[0].pending & MX_SOCKET_READABLE) != 0); |
| 335 while (true) { | 335 while (true) { |
| 336 Message msg; | 336 Message msg; |
| 337 size_t actual = 0; | 337 size_t actual = 0; |
| 338 LOG_INFO("ExitCodeHandler thread reading interrupt message\n"); | 338 LOG_INFO("ExitCodeHandler thread reading interrupt message\n"); |
| 339 mx_status_t status = | 339 mx_status_t status = |
| 340 mx_socket_read(interrupt_out_, 0, &msg, sizeof(msg), &actual); | 340 mx_socket_read(interrupt_out_, 0, &msg, sizeof(msg), &actual); |
| 341 if (status == ERR_SHOULD_WAIT) { | 341 if (status == MX_ERR_SHOULD_WAIT) { |
| 342 LOG_INFO("ExitCodeHandler thread done reading interrupt messages\n"); | 342 LOG_INFO("ExitCodeHandler thread done reading interrupt messages\n"); |
| 343 return; | 343 return; |
| 344 } | 344 } |
| 345 if (status < 0) { | 345 if (status < 0) { |
| 346 FATAL1("Failed to read exit handler interrupt handle: %s\n", | 346 FATAL1("Failed to read exit handler interrupt handle: %s\n", |
| 347 mx_status_get_string(status)); | 347 mx_status_get_string(status)); |
| 348 } | 348 } |
| 349 if (actual < sizeof(msg)) { | 349 if (actual < sizeof(msg)) { |
| 350 FATAL1("Short read from exit handler interrupt handle: %ld\n", actual); | 350 FATAL1("Short read from exit handler interrupt handle: %ld\n", actual); |
| 351 } | 351 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 intptr_t Process::CurrentProcessId() { | 431 intptr_t Process::CurrentProcessId() { |
| 432 return static_cast<intptr_t>(getpid()); | 432 return static_cast<intptr_t>(getpid()); |
| 433 } | 433 } |
| 434 | 434 |
| 435 | 435 |
| 436 int64_t Process::CurrentRSS() { | 436 int64_t Process::CurrentRSS() { |
| 437 mx_info_task_stats_t task_stats; | 437 mx_info_task_stats_t task_stats; |
| 438 mx_handle_t process = mx_process_self(); | 438 mx_handle_t process = mx_process_self(); |
| 439 mx_status_t status = mx_object_get_info( | 439 mx_status_t status = mx_object_get_info( |
| 440 process, MX_INFO_TASK_STATS, &task_stats, sizeof(task_stats), NULL, NULL); | 440 process, MX_INFO_TASK_STATS, &task_stats, sizeof(task_stats), NULL, NULL); |
| 441 if (status != NO_ERROR) { | 441 if (status != MX_OK) { |
| 442 // TODO(zra): Translate this to a Unix errno. | 442 // TODO(zra): Translate this to a Unix errno. |
| 443 errno = status; | 443 errno = status; |
| 444 return -1; | 444 return -1; |
| 445 } | 445 } |
| 446 return task_stats.mem_private_bytes + task_stats.mem_shared_bytes; | 446 return task_stats.mem_private_bytes + task_stats.mem_shared_bytes; |
| 447 } | 447 } |
| 448 | 448 |
| 449 | 449 |
| 450 int64_t Process::MaxRSS() { | 450 int64_t Process::MaxRSS() { |
| 451 // There is currently no way to get the high watermark value on Fuchsia, so | 451 // There is currently no way to get the high watermark value on Fuchsia, so |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 } | 605 } |
| 606 // We can only use mx_task_kill if we know id is a process handle, and we only | 606 // We can only use mx_task_kill if we know id is a process handle, and we only |
| 607 // know that for sure if it's in our list. | 607 // know that for sure if it's in our list. |
| 608 mx_handle_t process = static_cast<mx_handle_t>(id); | 608 mx_handle_t process = static_cast<mx_handle_t>(id); |
| 609 if (!ProcessInfoList::Exists(process)) { | 609 if (!ProcessInfoList::Exists(process)) { |
| 610 LOG_ERR("Process %ld wasn't in the ProcessInfoList\n", id); | 610 LOG_ERR("Process %ld wasn't in the ProcessInfoList\n", id); |
| 611 errno = ESRCH; // No such process. | 611 errno = ESRCH; // No such process. |
| 612 return false; | 612 return false; |
| 613 } | 613 } |
| 614 mx_status_t status = mx_task_kill(process); | 614 mx_status_t status = mx_task_kill(process); |
| 615 if (status != NO_ERROR) { | 615 if (status != MX_OK) { |
| 616 LOG_ERR("mx_task_kill failed: %s\n", mx_status_get_string(status)); | 616 LOG_ERR("mx_task_kill failed: %s\n", mx_status_get_string(status)); |
| 617 errno = EPERM; // TODO(zra): Figure out what it really should be. | 617 errno = EPERM; // TODO(zra): Figure out what it really should be. |
| 618 return false; | 618 return false; |
| 619 } | 619 } |
| 620 LOG_INFO("Signal %d sent successfully to process %ld\n", signal, id); | 620 LOG_INFO("Signal %d sent successfully to process %ld\n", signal, id); |
| 621 return true; | 621 return true; |
| 622 } | 622 } |
| 623 | 623 |
| 624 | 624 |
| 625 class ProcessStarter { | 625 class ProcessStarter { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 *os_error_message_ = DartUtils::ScopedCopyCString( | 693 *os_error_message_ = DartUtils::ScopedCopyCString( |
| 694 "Failed to create exit code pipe for process start."); | 694 "Failed to create exit code pipe for process start."); |
| 695 return result; | 695 return result; |
| 696 } | 696 } |
| 697 LOG_INFO("ProcessStarter: Start() set up exit_pipe_fds (%d, %d)\n", | 697 LOG_INFO("ProcessStarter: Start() set up exit_pipe_fds (%d, %d)\n", |
| 698 exit_pipe_fds[0], exit_pipe_fds[1]); | 698 exit_pipe_fds[0], exit_pipe_fds[1]); |
| 699 | 699 |
| 700 // Set up a launchpad. | 700 // Set up a launchpad. |
| 701 launchpad_t* lp = NULL; | 701 launchpad_t* lp = NULL; |
| 702 mx_status_t status = SetupLaunchpad(&lp); | 702 mx_status_t status = SetupLaunchpad(&lp); |
| 703 if (status != NO_ERROR) { | 703 if (status != MX_OK) { |
| 704 close(exit_pipe_fds[0]); | 704 close(exit_pipe_fds[0]); |
| 705 close(exit_pipe_fds[1]); | 705 close(exit_pipe_fds[1]); |
| 706 return status; | 706 return status; |
| 707 } | 707 } |
| 708 ASSERT(lp != NULL); | 708 ASSERT(lp != NULL); |
| 709 | 709 |
| 710 // Launch it. | 710 // Launch it. |
| 711 LOG_INFO("ProcessStarter: Start() Calling launchpad_start\n"); | 711 LOG_INFO("ProcessStarter: Start() Calling launchpad_start\n"); |
| 712 mx_handle_t process = MX_HANDLE_INVALID; | 712 mx_handle_t process = MX_HANDLE_INVALID; |
| 713 const char* errormsg = NULL; | 713 const char* errormsg = NULL; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 759 | 759 |
| 760 mx_status_t SetupLaunchpad(launchpad_t** launchpad) { | 760 mx_status_t SetupLaunchpad(launchpad_t** launchpad) { |
| 761 // Set up a vmo for the binary. | 761 // Set up a vmo for the binary. |
| 762 mx_handle_t binary_vmo = launchpad_vmo_from_file(path_); | 762 mx_handle_t binary_vmo = launchpad_vmo_from_file(path_); |
| 763 CHECK_FOR_ERROR(binary_vmo, "launchpad_vmo_from_file"); | 763 CHECK_FOR_ERROR(binary_vmo, "launchpad_vmo_from_file"); |
| 764 | 764 |
| 765 // Run the child process in the same "job". | 765 // Run the child process in the same "job". |
| 766 mx_handle_t job = MX_HANDLE_INVALID; | 766 mx_handle_t job = MX_HANDLE_INVALID; |
| 767 mx_status_t status = | 767 mx_status_t status = |
| 768 mx_handle_duplicate(mx_job_default(), MX_RIGHT_SAME_RIGHTS, &job); | 768 mx_handle_duplicate(mx_job_default(), MX_RIGHT_SAME_RIGHTS, &job); |
| 769 if (status != NO_ERROR) { | 769 if (status != MX_OK) { |
| 770 mx_handle_close(binary_vmo); | 770 mx_handle_close(binary_vmo); |
| 771 } | 771 } |
| 772 CHECK_FOR_ERROR(status, "mx_handle_duplicate"); | 772 CHECK_FOR_ERROR(status, "mx_handle_duplicate"); |
| 773 | 773 |
| 774 // Set up the launchpad. | 774 // Set up the launchpad. |
| 775 launchpad_t* lp = NULL; | 775 launchpad_t* lp = NULL; |
| 776 launchpad_create(job, program_arguments_[0], &lp); | 776 launchpad_create(job, program_arguments_[0], &lp); |
| 777 launchpad_set_args(lp, program_arguments_count_, program_arguments_); | 777 launchpad_set_args(lp, program_arguments_count_, program_arguments_); |
| 778 launchpad_set_environ(lp, program_environment_); | 778 launchpad_set_environ(lp, program_environment_); |
| 779 launchpad_clone(lp, LP_CLONE_MXIO_ROOT); | 779 launchpad_clone(lp, LP_CLONE_MXIO_ROOT); |
| 780 // TODO(zra): Use the supplied working directory when launchpad adds an | 780 // TODO(zra): Use the supplied working directory when launchpad adds an |
| 781 // API to set it. | 781 // API to set it. |
| 782 launchpad_clone(lp, LP_CLONE_MXIO_CWD); | 782 launchpad_clone(lp, LP_CLONE_MXIO_CWD); |
| 783 launchpad_add_pipe(lp, &write_out_, 0); | 783 launchpad_add_pipe(lp, &write_out_, 0); |
| 784 launchpad_add_pipe(lp, &read_in_, 1); | 784 launchpad_add_pipe(lp, &read_in_, 1); |
| 785 launchpad_add_pipe(lp, &read_err_, 2); | 785 launchpad_add_pipe(lp, &read_err_, 2); |
| 786 launchpad_add_vdso_vmo(lp); | 786 launchpad_add_vdso_vmo(lp); |
| 787 launchpad_elf_load(lp, binary_vmo); | 787 launchpad_elf_load(lp, binary_vmo); |
| 788 launchpad_load_vdso(lp, MX_HANDLE_INVALID); | 788 launchpad_load_vdso(lp, MX_HANDLE_INVALID); |
| 789 *launchpad = lp; | 789 *launchpad = lp; |
| 790 return NO_ERROR; | 790 return MX_OK; |
| 791 } | 791 } |
| 792 | 792 |
| 793 #undef CHECK_FOR_ERROR | 793 #undef CHECK_FOR_ERROR |
| 794 | 794 |
| 795 int read_in_; // Pipe for stdout to child process. | 795 int read_in_; // Pipe for stdout to child process. |
| 796 int read_err_; // Pipe for stderr to child process. | 796 int read_err_; // Pipe for stderr to child process. |
| 797 int write_out_; // Pipe for stdin to child process. | 797 int write_out_; // Pipe for stdin to child process. |
| 798 | 798 |
| 799 char** program_arguments_; | 799 char** program_arguments_; |
| 800 intptr_t program_arguments_count_; | 800 intptr_t program_arguments_count_; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 845 } | 845 } |
| 846 | 846 |
| 847 void Process::ClearSignalHandler(intptr_t signal) {} | 847 void Process::ClearSignalHandler(intptr_t signal) {} |
| 848 | 848 |
| 849 } // namespace bin | 849 } // namespace bin |
| 850 } // namespace dart | 850 } // namespace dart |
| 851 | 851 |
| 852 #endif // defined(HOST_OS_FUCHSIA) | 852 #endif // defined(HOST_OS_FUCHSIA) |
| 853 | 853 |
| 854 #endif // !defined(DART_IO_DISABLED) | 854 #endif // !defined(DART_IO_DISABLED) |
| OLD | NEW |