Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(479)

Side by Side Diff: runtime/bin/process_fuchsia.cc

Issue 2974233002: VM: Re-format to use at most one newline between functions (Closed)
Patch Set: Rebase and merge Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/bin/process_android.cc ('k') | runtime/bin/process_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 void set_next(ProcessInfo* info) { next_ = info; } 73 void set_next(ProcessInfo* info) { next_ = info; }
74 74
75 private: 75 private:
76 mx_handle_t process_; 76 mx_handle_t process_;
77 intptr_t exit_pipe_fd_; 77 intptr_t exit_pipe_fd_;
78 ProcessInfo* next_; 78 ProcessInfo* next_;
79 79
80 DISALLOW_COPY_AND_ASSIGN(ProcessInfo); 80 DISALLOW_COPY_AND_ASSIGN(ProcessInfo);
81 }; 81 };
82 82
83
84 // Singly-linked list of ProcessInfo objects for all active processes 83 // Singly-linked list of ProcessInfo objects for all active processes
85 // started from Dart. 84 // started from Dart.
86 class ProcessInfoList { 85 class ProcessInfoList {
87 public: 86 public:
88 static void AddProcess(mx_handle_t process, intptr_t fd) { 87 static void AddProcess(mx_handle_t process, intptr_t fd) {
89 MutexLocker locker(mutex_); 88 MutexLocker locker(mutex_);
90 ProcessInfo* info = new ProcessInfo(process, fd); 89 ProcessInfo* info = new ProcessInfo(process, fd);
91 info->set_next(active_processes_); 90 info->set_next(active_processes_);
92 active_processes_ = info; 91 active_processes_ = info;
93 } 92 }
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 420
422 bool ExitCodeHandler::do_shutdown_ = false; 421 bool ExitCodeHandler::do_shutdown_ = false;
423 bool ExitCodeHandler::running_ = false; 422 bool ExitCodeHandler::running_ = false;
424 bool ExitCodeHandler::terminate_done_ = false; 423 bool ExitCodeHandler::terminate_done_ = false;
425 Monitor* ExitCodeHandler::monitor_ = new Monitor(); 424 Monitor* ExitCodeHandler::monitor_ = new Monitor();
426 425
427 void Process::TerminateExitCodeHandler() { 426 void Process::TerminateExitCodeHandler() {
428 ExitCodeHandler::Terminate(); 427 ExitCodeHandler::Terminate();
429 } 428 }
430 429
431
432 intptr_t Process::CurrentProcessId() { 430 intptr_t Process::CurrentProcessId() {
433 return static_cast<intptr_t>(getpid()); 431 return static_cast<intptr_t>(getpid());
434 } 432 }
435 433
436
437 int64_t Process::CurrentRSS() { 434 int64_t Process::CurrentRSS() {
438 mx_info_task_stats_t task_stats; 435 mx_info_task_stats_t task_stats;
439 mx_handle_t process = mx_process_self(); 436 mx_handle_t process = mx_process_self();
440 mx_status_t status = mx_object_get_info( 437 mx_status_t status = mx_object_get_info(
441 process, MX_INFO_TASK_STATS, &task_stats, sizeof(task_stats), NULL, NULL); 438 process, MX_INFO_TASK_STATS, &task_stats, sizeof(task_stats), NULL, NULL);
442 if (status != MX_OK) { 439 if (status != MX_OK) {
443 // TODO(zra): Translate this to a Unix errno. 440 // TODO(zra): Translate this to a Unix errno.
444 errno = status; 441 errno = status;
445 return -1; 442 return -1;
446 } 443 }
447 return task_stats.mem_private_bytes + task_stats.mem_shared_bytes; 444 return task_stats.mem_private_bytes + task_stats.mem_shared_bytes;
448 } 445 }
449 446
450
451 int64_t Process::MaxRSS() { 447 int64_t Process::MaxRSS() {
452 // There is currently no way to get the high watermark value on Fuchsia, so 448 // There is currently no way to get the high watermark value on Fuchsia, so
453 // just return the current RSS value. 449 // just return the current RSS value.
454 return CurrentRSS(); 450 return CurrentRSS();
455 } 451 }
456 452
457
458 class IOHandleScope { 453 class IOHandleScope {
459 public: 454 public:
460 explicit IOHandleScope(IOHandle* io_handle) : io_handle_(io_handle) {} 455 explicit IOHandleScope(IOHandle* io_handle) : io_handle_(io_handle) {}
461 ~IOHandleScope() { 456 ~IOHandleScope() {
462 io_handle_->Close(); 457 io_handle_->Close();
463 io_handle_->Release(); 458 io_handle_->Release();
464 } 459 }
465 460
466 private: 461 private:
467 IOHandle* io_handle_; 462 IOHandle* io_handle_;
468 463
469 DISALLOW_ALLOCATION(); 464 DISALLOW_ALLOCATION();
470 DISALLOW_COPY_AND_ASSIGN(IOHandleScope); 465 DISALLOW_COPY_AND_ASSIGN(IOHandleScope);
471 }; 466 };
472 467
473
474 bool Process::Wait(intptr_t pid, 468 bool Process::Wait(intptr_t pid,
475 intptr_t in, 469 intptr_t in,
476 intptr_t out, 470 intptr_t out,
477 intptr_t err, 471 intptr_t err,
478 intptr_t exit_event, 472 intptr_t exit_event,
479 ProcessResult* result) { 473 ProcessResult* result) {
480 // input not needed. 474 // input not needed.
481 IOHandle* in_iohandle = reinterpret_cast<IOHandle*>(in); 475 IOHandle* in_iohandle = reinterpret_cast<IOHandle*>(in);
482 in_iohandle->Close(); 476 in_iohandle->Close();
483 in_iohandle->Release(); 477 in_iohandle->Release();
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 exit_code = -exit_code; 600 exit_code = -exit_code;
607 } 601 }
608 result->set_exit_code(exit_code); 602 result->set_exit_code(exit_code);
609 603
610 // Close the process handle. 604 // Close the process handle.
611 mx_handle_t process = static_cast<mx_handle_t>(pid); 605 mx_handle_t process = static_cast<mx_handle_t>(pid);
612 mx_handle_close(process); 606 mx_handle_close(process);
613 return true; 607 return true;
614 } 608 }
615 609
616
617 bool Process::Kill(intptr_t id, int signal) { 610 bool Process::Kill(intptr_t id, int signal) {
618 LOG_INFO("Sending signal %d to process with id %ld\n", signal, id); 611 LOG_INFO("Sending signal %d to process with id %ld\n", signal, id);
619 // mx_task_kill is definitely going to kill the process. 612 // mx_task_kill is definitely going to kill the process.
620 if ((signal != SIGTERM) && (signal != SIGKILL)) { 613 if ((signal != SIGTERM) && (signal != SIGKILL)) {
621 LOG_ERR("Signal %d not supported\n", signal); 614 LOG_ERR("Signal %d not supported\n", signal);
622 errno = ENOSYS; 615 errno = ENOSYS;
623 return false; 616 return false;
624 } 617 }
625 // We can only use mx_task_kill if we know id is a process handle, and we only 618 // We can only use mx_task_kill if we know id is a process handle, and we only
626 // know that for sure if it's in our list. 619 // know that for sure if it's in our list.
627 mx_handle_t process = static_cast<mx_handle_t>(id); 620 mx_handle_t process = static_cast<mx_handle_t>(id);
628 if (!ProcessInfoList::Exists(process)) { 621 if (!ProcessInfoList::Exists(process)) {
629 LOG_ERR("Process %ld wasn't in the ProcessInfoList\n", id); 622 LOG_ERR("Process %ld wasn't in the ProcessInfoList\n", id);
630 errno = ESRCH; // No such process. 623 errno = ESRCH; // No such process.
631 return false; 624 return false;
632 } 625 }
633 mx_status_t status = mx_task_kill(process); 626 mx_status_t status = mx_task_kill(process);
634 if (status != MX_OK) { 627 if (status != MX_OK) {
635 LOG_ERR("mx_task_kill failed: %s\n", mx_status_get_string(status)); 628 LOG_ERR("mx_task_kill failed: %s\n", mx_status_get_string(status));
636 errno = EPERM; // TODO(zra): Figure out what it really should be. 629 errno = EPERM; // TODO(zra): Figure out what it really should be.
637 return false; 630 return false;
638 } 631 }
639 LOG_INFO("Signal %d sent successfully to process %ld\n", signal, id); 632 LOG_INFO("Signal %d sent successfully to process %ld\n", signal, id);
640 return true; 633 return true;
641 } 634 }
642 635
643
644 class ProcessStarter { 636 class ProcessStarter {
645 public: 637 public:
646 ProcessStarter(const char* path, 638 ProcessStarter(const char* path,
647 char* arguments[], 639 char* arguments[],
648 intptr_t arguments_length, 640 intptr_t arguments_length,
649 const char* working_directory, 641 const char* working_directory,
650 char* environment[], 642 char* environment[],
651 intptr_t environment_length, 643 intptr_t environment_length,
652 ProcessStartMode mode, 644 ProcessStartMode mode,
653 intptr_t* in, 645 intptr_t* in,
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 intptr_t* out_; 822 intptr_t* out_;
831 intptr_t* err_; 823 intptr_t* err_;
832 intptr_t* id_; 824 intptr_t* id_;
833 intptr_t* exit_event_; 825 intptr_t* exit_event_;
834 char** os_error_message_; 826 char** os_error_message_;
835 827
836 DISALLOW_ALLOCATION(); 828 DISALLOW_ALLOCATION();
837 DISALLOW_IMPLICIT_CONSTRUCTORS(ProcessStarter); 829 DISALLOW_IMPLICIT_CONSTRUCTORS(ProcessStarter);
838 }; 830 };
839 831
840
841 int Process::Start(const char* path, 832 int Process::Start(const char* path,
842 char* arguments[], 833 char* arguments[],
843 intptr_t arguments_length, 834 intptr_t arguments_length,
844 const char* working_directory, 835 const char* working_directory,
845 char* environment[], 836 char* environment[],
846 intptr_t environment_length, 837 intptr_t environment_length,
847 ProcessStartMode mode, 838 ProcessStartMode mode,
848 intptr_t* in, 839 intptr_t* in,
849 intptr_t* out, 840 intptr_t* out,
850 intptr_t* err, 841 intptr_t* err,
(...skipping 17 matching lines...) Expand all
868 } 859 }
869 860
870 void Process::ClearSignalHandler(intptr_t signal, Dart_Port port) {} 861 void Process::ClearSignalHandler(intptr_t signal, Dart_Port port) {}
871 862
872 } // namespace bin 863 } // namespace bin
873 } // namespace dart 864 } // namespace dart
874 865
875 #endif // defined(HOST_OS_FUCHSIA) 866 #endif // defined(HOST_OS_FUCHSIA)
876 867
877 #endif // !defined(DART_IO_DISABLED) 868 #endif // !defined(DART_IO_DISABLED)
OLDNEW
« no previous file with comments | « runtime/bin/process_android.cc ('k') | runtime/bin/process_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698