| 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" |
| 11 | 11 |
| 12 #include <errno.h> | 12 #include <errno.h> |
| 13 #include <fcntl.h> | 13 #include <fcntl.h> |
| 14 #include <launchpad/launchpad.h> | 14 #include <launchpad/launchpad.h> |
| 15 #include <launchpad/vmo.h> | 15 #include <launchpad/vmo.h> |
| 16 #include <magenta/process.h> | 16 #include <magenta/process.h> |
| 17 #include <magenta/status.h> | 17 #include <magenta/status.h> |
| 18 #include <magenta/syscalls.h> | 18 #include <magenta/syscalls.h> |
| 19 #include <magenta/syscalls/object.h> | 19 #include <magenta/syscalls/object.h> |
| 20 #include <magenta/types.h> | 20 #include <magenta/types.h> |
| 21 #include <mxio/private.h> | 21 #include <mxio/private.h> |
| 22 #include <mxio/util.h> | 22 #include <mxio/util.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 <sys/epoll.h> | |
| 29 #include <unistd.h> | 29 #include <unistd.h> |
| 30 | 30 |
| 31 #include "bin/dartutils.h" | 31 #include "bin/dartutils.h" |
| 32 #include "bin/eventhandler.h" | 32 #include "bin/eventhandler.h" |
| 33 #include "bin/fdutils.h" | 33 #include "bin/fdutils.h" |
| 34 #include "bin/lockers.h" | 34 #include "bin/lockers.h" |
| 35 #include "bin/log.h" | 35 #include "bin/log.h" |
| 36 #include "platform/signal_blocker.h" | 36 #include "platform/signal_blocker.h" |
| 37 #include "platform/utils.h" | 37 #include "platform/utils.h" |
| 38 | 38 |
| (...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 mx_status_get_string(status)); | 508 mx_status_get_string(status)); |
| 509 return false; | 509 return false; |
| 510 } | 510 } |
| 511 | 511 |
| 512 IOHandle* out_tmp = out_iohandle; | 512 IOHandle* out_tmp = out_iohandle; |
| 513 IOHandle* err_tmp = err_iohandle; | 513 IOHandle* err_tmp = err_iohandle; |
| 514 IOHandle* exit_tmp = exit_iohandle; | 514 IOHandle* exit_tmp = exit_iohandle; |
| 515 const uint64_t out_key = reinterpret_cast<uint64_t>(out_tmp); | 515 const uint64_t out_key = reinterpret_cast<uint64_t>(out_tmp); |
| 516 const uint64_t err_key = reinterpret_cast<uint64_t>(err_tmp); | 516 const uint64_t err_key = reinterpret_cast<uint64_t>(err_tmp); |
| 517 const uint64_t exit_key = reinterpret_cast<uint64_t>(exit_tmp); | 517 const uint64_t exit_key = reinterpret_cast<uint64_t>(exit_tmp); |
| 518 const uint32_t events = EPOLLRDHUP | EPOLLIN; | 518 const uint32_t events = POLLRDHUP | POLLIN; |
| 519 if (!out_tmp->AsyncWait(port, events, out_key)) { | 519 if (!out_tmp->AsyncWait(port, events, out_key)) { |
| 520 return false; | 520 return false; |
| 521 } | 521 } |
| 522 if (!err_tmp->AsyncWait(port, events, err_key)) { | 522 if (!err_tmp->AsyncWait(port, events, err_key)) { |
| 523 return false; | 523 return false; |
| 524 } | 524 } |
| 525 if (!exit_tmp->AsyncWait(port, events, exit_key)) { | 525 if (!exit_tmp->AsyncWait(port, events, exit_key)) { |
| 526 return false; | 526 return false; |
| 527 } | 527 } |
| 528 while ((out_tmp != NULL) || (err_tmp != NULL) || (exit_tmp != NULL)) { | 528 while ((out_tmp != NULL) || (err_tmp != NULL) || (exit_tmp != NULL)) { |
| 529 mx_port_packet_t pkt; | 529 mx_port_packet_t pkt; |
| 530 status = | 530 status = |
| 531 mx_port_wait(port, MX_TIME_INFINITE, reinterpret_cast<void*>(&pkt), 0); | 531 mx_port_wait(port, MX_TIME_INFINITE, reinterpret_cast<void*>(&pkt), 0); |
| 532 if (status != MX_OK) { | 532 if (status != MX_OK) { |
| 533 Log::PrintErr("Process::Wait: mx_port_wait failed: %s\n", | 533 Log::PrintErr("Process::Wait: mx_port_wait failed: %s\n", |
| 534 mx_status_get_string(status)); | 534 mx_status_get_string(status)); |
| 535 return false; | 535 return false; |
| 536 } | 536 } |
| 537 IOHandle* event_handle = reinterpret_cast<IOHandle*>(pkt.key); | 537 IOHandle* event_handle = reinterpret_cast<IOHandle*>(pkt.key); |
| 538 const intptr_t event_mask = event_handle->WaitEnd(pkt.signal.observed); | 538 const intptr_t event_mask = event_handle->WaitEnd(pkt.signal.observed); |
| 539 if (event_handle == out_tmp) { | 539 if (event_handle == out_tmp) { |
| 540 if ((event_mask & EPOLLIN) != 0) { | 540 if ((event_mask & POLLIN) != 0) { |
| 541 const intptr_t avail = FDUtils::AvailableBytes(out_tmp->fd()); | 541 const intptr_t avail = FDUtils::AvailableBytes(out_tmp->fd()); |
| 542 if (!out_data.Read(out_tmp->fd(), avail)) { | 542 if (!out_data.Read(out_tmp->fd(), avail)) { |
| 543 return false; | 543 return false; |
| 544 } | 544 } |
| 545 } | 545 } |
| 546 if ((event_mask & EPOLLRDHUP) != 0) { | 546 if ((event_mask & POLLRDHUP) != 0) { |
| 547 out_tmp->CancelWait(port, out_key); | 547 out_tmp->CancelWait(port, out_key); |
| 548 out_tmp = NULL; | 548 out_tmp = NULL; |
| 549 } | 549 } |
| 550 } else if (event_handle == err_tmp) { | 550 } else if (event_handle == err_tmp) { |
| 551 if ((event_mask & EPOLLIN) != 0) { | 551 if ((event_mask & POLLIN) != 0) { |
| 552 const intptr_t avail = FDUtils::AvailableBytes(err_tmp->fd()); | 552 const intptr_t avail = FDUtils::AvailableBytes(err_tmp->fd()); |
| 553 if (!err_data.Read(err_tmp->fd(), avail)) { | 553 if (!err_data.Read(err_tmp->fd(), avail)) { |
| 554 return false; | 554 return false; |
| 555 } | 555 } |
| 556 } | 556 } |
| 557 if ((event_mask & EPOLLRDHUP) != 0) { | 557 if ((event_mask & POLLRDHUP) != 0) { |
| 558 err_tmp->CancelWait(port, err_key); | 558 err_tmp->CancelWait(port, err_key); |
| 559 err_tmp = NULL; | 559 err_tmp = NULL; |
| 560 } | 560 } |
| 561 } else if (event_handle == exit_tmp) { | 561 } else if (event_handle == exit_tmp) { |
| 562 if ((event_mask & EPOLLIN) != 0) { | 562 if ((event_mask & POLLIN) != 0) { |
| 563 const intptr_t avail = FDUtils::AvailableBytes(exit_tmp->fd()); | 563 const intptr_t avail = FDUtils::AvailableBytes(exit_tmp->fd()); |
| 564 if (avail == 8) { | 564 if (avail == 8) { |
| 565 intptr_t b = | 565 intptr_t b = |
| 566 NO_RETRY_EXPECTED(read(exit_tmp->fd(), exit_code_data.bytes, 8)); | 566 NO_RETRY_EXPECTED(read(exit_tmp->fd(), exit_code_data.bytes, 8)); |
| 567 if (b != 8) { | 567 if (b != 8) { |
| 568 return false; | 568 return false; |
| 569 } | 569 } |
| 570 } | 570 } |
| 571 } | 571 } |
| 572 if ((event_mask & EPOLLRDHUP) != 0) { | 572 if ((event_mask & POLLRDHUP) != 0) { |
| 573 exit_tmp->CancelWait(port, exit_key); | 573 exit_tmp->CancelWait(port, exit_key); |
| 574 exit_tmp = NULL; | 574 exit_tmp = NULL; |
| 575 } | 575 } |
| 576 } else { | 576 } else { |
| 577 Log::PrintErr("Process::Wait: Unexpected wait key: %p\n", event_handle); | 577 Log::PrintErr("Process::Wait: Unexpected wait key: %p\n", event_handle); |
| 578 } | 578 } |
| 579 if (out_tmp != NULL) { | 579 if (out_tmp != NULL) { |
| 580 if (!out_tmp->AsyncWait(port, events, out_key)) { | 580 if (!out_tmp->AsyncWait(port, events, out_key)) { |
| 581 return false; | 581 return false; |
| 582 } | 582 } |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 868 } | 868 } |
| 869 | 869 |
| 870 void Process::ClearSignalHandler(intptr_t signal) {} | 870 void Process::ClearSignalHandler(intptr_t signal) {} |
| 871 | 871 |
| 872 } // namespace bin | 872 } // namespace bin |
| 873 } // namespace dart | 873 } // namespace dart |
| 874 | 874 |
| 875 #endif // defined(HOST_OS_FUCHSIA) | 875 #endif // defined(HOST_OS_FUCHSIA) |
| 876 | 876 |
| 877 #endif // !defined(DART_IO_DISABLED) | 877 #endif // !defined(DART_IO_DISABLED) |
| OLD | NEW |