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 #include "platform/globals.h" | 5 #include "platform/globals.h" |
6 #if defined(HOST_OS_FUCHSIA) | 6 #if defined(HOST_OS_FUCHSIA) |
7 | 7 |
8 #include "bin/process.h" | 8 #include "bin/process.h" |
9 | 9 |
10 #include <errno.h> | 10 #include <errno.h> |
11 #include <fcntl.h> | 11 #include <fcntl.h> |
12 #include <launchpad/launchpad.h> | 12 #include <launchpad/launchpad.h> |
13 #include <launchpad/vmo.h> | 13 #include <launchpad/vmo.h> |
14 #include <magenta/process.h> | 14 #include <magenta/process.h> |
15 #include <magenta/status.h> | 15 #include <magenta/status.h> |
16 #include <magenta/syscalls.h> | 16 #include <magenta/syscalls.h> |
17 #include <magenta/syscalls/object.h> | 17 #include <magenta/syscalls/object.h> |
18 #include <magenta/types.h> | 18 #include <magenta/types.h> |
19 #include <mxio/io.h> | 19 #include <mxio/io.h> |
| 20 #include <mxio/namespace.h> |
20 #include <mxio/private.h> | 21 #include <mxio/private.h> |
21 #include <mxio/util.h> | 22 #include <mxio/util.h> |
22 #include <poll.h> | 23 #include <poll.h> |
23 #include <pthread.h> | 24 #include <pthread.h> |
24 #include <stdbool.h> | 25 #include <stdbool.h> |
25 #include <stdio.h> | 26 #include <stdio.h> |
26 #include <stdlib.h> | 27 #include <stdlib.h> |
27 #include <string.h> | 28 #include <string.h> |
28 #include <unistd.h> | 29 #include <unistd.h> |
29 | 30 |
30 #include "bin/dartutils.h" | 31 #include "bin/dartutils.h" |
31 #include "bin/eventhandler.h" | 32 #include "bin/eventhandler.h" |
32 #include "bin/fdutils.h" | 33 #include "bin/fdutils.h" |
| 34 #include "bin/file.h" |
33 #include "bin/lockers.h" | 35 #include "bin/lockers.h" |
34 #include "bin/log.h" | 36 #include "bin/log.h" |
| 37 #include "bin/namespace.h" |
35 #include "platform/signal_blocker.h" | 38 #include "platform/signal_blocker.h" |
36 #include "platform/utils.h" | 39 #include "platform/utils.h" |
37 | 40 |
38 // #define PROCESS_LOGGING 1 | 41 // #define PROCESS_LOGGING 1 |
39 #if defined(PROCESS_LOGGING) | 42 #if defined(PROCESS_LOGGING) |
40 #define LOG_ERR(msg, ...) Log::PrintErr("Dart Process: " msg, ##__VA_ARGS__) | 43 #define LOG_ERR(msg, ...) Log::PrintErr("Dart Process: " msg, ##__VA_ARGS__) |
41 #define LOG_INFO(msg, ...) Log::Print("Dart Process: " msg, ##__VA_ARGS__) | 44 #define LOG_INFO(msg, ...) Log::Print("Dart Process: " msg, ##__VA_ARGS__) |
42 #else | 45 #else |
43 #define LOG_ERR(msg, ...) | 46 #define LOG_ERR(msg, ...) |
44 #define LOG_INFO(msg, ...) | 47 #define LOG_INFO(msg, ...) |
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 LOG_ERR("mx_task_kill failed: %s\n", mx_status_get_string(status)); | 505 LOG_ERR("mx_task_kill failed: %s\n", mx_status_get_string(status)); |
503 errno = EPERM; // TODO(zra): Figure out what it really should be. | 506 errno = EPERM; // TODO(zra): Figure out what it really should be. |
504 return false; | 507 return false; |
505 } | 508 } |
506 LOG_INFO("Signal %d sent successfully to process %ld\n", signal, id); | 509 LOG_INFO("Signal %d sent successfully to process %ld\n", signal, id); |
507 return true; | 510 return true; |
508 } | 511 } |
509 | 512 |
510 class ProcessStarter { | 513 class ProcessStarter { |
511 public: | 514 public: |
512 ProcessStarter(const char* path, | 515 ProcessStarter(Namespace* namespc, |
| 516 const char* path, |
513 char* arguments[], | 517 char* arguments[], |
514 intptr_t arguments_length, | 518 intptr_t arguments_length, |
515 const char* working_directory, | 519 const char* working_directory, |
516 char* environment[], | 520 char* environment[], |
517 intptr_t environment_length, | 521 intptr_t environment_length, |
518 ProcessStartMode mode, | 522 ProcessStartMode mode, |
519 intptr_t* in, | 523 intptr_t* in, |
520 intptr_t* out, | 524 intptr_t* out, |
521 intptr_t* err, | 525 intptr_t* err, |
522 intptr_t* id, | 526 intptr_t* id, |
523 intptr_t* exit_event, | 527 intptr_t* exit_event, |
524 char** os_error_message) | 528 char** os_error_message) |
525 : path_(path), | 529 : namespc_(namespc), |
| 530 path_(path), |
526 working_directory_(working_directory), | 531 working_directory_(working_directory), |
527 mode_(mode), | 532 mode_(mode), |
528 in_(in), | 533 in_(in), |
529 out_(out), | 534 out_(out), |
530 err_(err), | 535 err_(err), |
531 id_(id), | 536 id_(id), |
532 exit_event_(exit_event), | 537 exit_event_(exit_event), |
533 os_error_message_(os_error_message) { | 538 os_error_message_(os_error_message) { |
534 LOG_INFO("ProcessStarter: ctor %s with %ld args, mode = %d\n", path, | 539 LOG_INFO("ProcessStarter: ctor %s with %ld args, mode = %d\n", path, |
535 arguments_length, mode); | 540 arguments_length, mode); |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 } | 655 } |
651 | 656 |
652 mx_status_t SetupLaunchpad(launchpad_t** launchpad) { | 657 mx_status_t SetupLaunchpad(launchpad_t** launchpad) { |
653 // TODO(zra): Use the supplied working directory when launchpad adds an | 658 // TODO(zra): Use the supplied working directory when launchpad adds an |
654 // API to set it. | 659 // API to set it. |
655 ASSERT(launchpad != NULL); | 660 ASSERT(launchpad != NULL); |
656 launchpad_t* lp = NULL; | 661 launchpad_t* lp = NULL; |
657 launchpad_create(MX_HANDLE_INVALID, program_arguments_[0], &lp); | 662 launchpad_create(MX_HANDLE_INVALID, program_arguments_[0], &lp); |
658 launchpad_set_args(lp, program_arguments_count_, program_arguments_); | 663 launchpad_set_args(lp, program_arguments_count_, program_arguments_); |
659 launchpad_set_environ(lp, program_environment_); | 664 launchpad_set_environ(lp, program_environment_); |
660 launchpad_clone(lp, LP_CLONE_MXIO_NAMESPACE); | 665 launchpad_clone(lp, LP_CLONE_MXIO_NAMESPACE | LP_CLONE_MXIO_CWD); |
661 launchpad_clone(lp, LP_CLONE_MXIO_CWD); | |
662 launchpad_add_pipe(lp, &write_out_, 0); | 666 launchpad_add_pipe(lp, &write_out_, 0); |
663 launchpad_add_pipe(lp, &read_in_, 1); | 667 launchpad_add_pipe(lp, &read_in_, 1); |
664 launchpad_add_pipe(lp, &read_err_, 2); | 668 launchpad_add_pipe(lp, &read_err_, 2); |
665 launchpad_add_vdso_vmo(lp); | 669 launchpad_add_vdso_vmo(lp); |
666 launchpad_load_from_file(lp, path_); | 670 |
| 671 NamespaceScope ns(namespc_, path_); |
| 672 const int pathfd = TEMP_FAILURE_RETRY(openat64( |
| 673 ns.fd(), ns.path(), O_RDONLY)); |
| 674 launchpad_load_from_fd(lp, pathfd); |
| 675 VOID_TEMP_FAILURE_RETRY(close(pathfd)); |
667 | 676 |
668 // If there were any errors, grab launchpad's error message and put it in | 677 // If there were any errors, grab launchpad's error message and put it in |
669 // the os_error_message_ field. | 678 // the os_error_message_ field. |
670 mx_status_t status = launchpad_get_status(lp); | 679 mx_status_t status = launchpad_get_status(lp); |
671 if (status != MX_OK) { | 680 if (status != MX_OK) { |
672 const intptr_t kMaxMessageSize = 256; | 681 const intptr_t kMaxMessageSize = 256; |
673 char* message = DartUtils::ScopedCString(kMaxMessageSize); | 682 char* message = DartUtils::ScopedCString(kMaxMessageSize); |
674 snprintf(message, kMaxMessageSize, "launchpad failed: %s, %s", | 683 snprintf(message, kMaxMessageSize, "launchpad failed: %s, %s", |
675 mx_status_get_string(status), launchpad_error_message(lp)); | 684 mx_status_get_string(status), launchpad_error_message(lp)); |
676 *os_error_message_ = message; | 685 *os_error_message_ = message; |
677 return status; | 686 return status; |
678 } | 687 } |
679 | 688 |
680 *launchpad = lp; | 689 *launchpad = lp; |
681 return MX_OK; | 690 return MX_OK; |
682 } | 691 } |
683 | 692 |
684 int read_in_; // Pipe for stdout to child process. | 693 int read_in_; // Pipe for stdout to child process. |
685 int read_err_; // Pipe for stderr to child process. | 694 int read_err_; // Pipe for stderr to child process. |
686 int write_out_; // Pipe for stdin to child process. | 695 int write_out_; // Pipe for stdin to child process. |
687 | 696 |
688 char** program_arguments_; | 697 char** program_arguments_; |
689 intptr_t program_arguments_count_; | 698 intptr_t program_arguments_count_; |
690 char** program_environment_; | 699 char** program_environment_; |
691 | 700 |
| 701 Namespace* namespc_; |
692 const char* path_; | 702 const char* path_; |
693 const char* working_directory_; | 703 const char* working_directory_; |
694 ProcessStartMode mode_; | 704 ProcessStartMode mode_; |
695 intptr_t* in_; | 705 intptr_t* in_; |
696 intptr_t* out_; | 706 intptr_t* out_; |
697 intptr_t* err_; | 707 intptr_t* err_; |
698 intptr_t* id_; | 708 intptr_t* id_; |
699 intptr_t* exit_event_; | 709 intptr_t* exit_event_; |
700 char** os_error_message_; | 710 char** os_error_message_; |
701 | 711 |
702 DISALLOW_ALLOCATION(); | 712 DISALLOW_ALLOCATION(); |
703 DISALLOW_IMPLICIT_CONSTRUCTORS(ProcessStarter); | 713 DISALLOW_IMPLICIT_CONSTRUCTORS(ProcessStarter); |
704 }; | 714 }; |
705 | 715 |
706 int Process::Start(const char* path, | 716 int Process::Start(Namespace* namespc, |
| 717 const char* path, |
707 char* arguments[], | 718 char* arguments[], |
708 intptr_t arguments_length, | 719 intptr_t arguments_length, |
709 const char* working_directory, | 720 const char* working_directory, |
710 char* environment[], | 721 char* environment[], |
711 intptr_t environment_length, | 722 intptr_t environment_length, |
712 ProcessStartMode mode, | 723 ProcessStartMode mode, |
713 intptr_t* in, | 724 intptr_t* in, |
714 intptr_t* out, | 725 intptr_t* out, |
715 intptr_t* err, | 726 intptr_t* err, |
716 intptr_t* id, | 727 intptr_t* id, |
717 intptr_t* exit_event, | 728 intptr_t* exit_event, |
718 char** os_error_message) { | 729 char** os_error_message) { |
719 if (mode != kNormal) { | 730 if (mode != kNormal) { |
720 *os_error_message = DartUtils::ScopedCopyCString( | 731 *os_error_message = DartUtils::ScopedCopyCString( |
721 "Only ProcessStartMode.NORMAL is supported on this platform"); | 732 "Only ProcessStartMode.NORMAL is supported on this platform"); |
722 return -1; | 733 return -1; |
723 } | 734 } |
724 ProcessStarter starter(path, arguments, arguments_length, working_directory, | 735 ProcessStarter starter(namespc, path, arguments, arguments_length, |
725 environment, environment_length, mode, in, out, err, | 736 working_directory, environment, environment_length, |
726 id, exit_event, os_error_message); | 737 mode, in, out, err, id, exit_event, os_error_message); |
727 return starter.Start(); | 738 return starter.Start(); |
728 } | 739 } |
729 | 740 |
730 intptr_t Process::SetSignalHandler(intptr_t signal) { | 741 intptr_t Process::SetSignalHandler(intptr_t signal) { |
731 errno = ENOSYS; | 742 errno = ENOSYS; |
732 return -1; | 743 return -1; |
733 } | 744 } |
734 | 745 |
735 void Process::ClearSignalHandler(intptr_t signal, Dart_Port port) {} | 746 void Process::ClearSignalHandler(intptr_t signal, Dart_Port port) {} |
736 | 747 |
737 } // namespace bin | 748 } // namespace bin |
738 } // namespace dart | 749 } // namespace dart |
739 | 750 |
740 #endif // defined(HOST_OS_FUCHSIA) | 751 #endif // defined(HOST_OS_FUCHSIA) |
OLD | NEW |