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

Side by Side Diff: ipc/ipc_channel_posix.cc

Issue 695353005: Non-SFI mode: Use dummy PID for NaCl's IPC channel on Linux platform. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ipc/ipc_channel_posix.h" 5 #include "ipc/ipc_channel_posix.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 #include <sys/socket.h> 10 #include <sys/socket.h>
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 #if defined(OS_ANDROID) 169 #if defined(OS_ANDROID)
170 // When we fork for simple tests on Android, we can't 'exec', so we need to 170 // When we fork for simple tests on Android, we can't 'exec', so we need to
171 // reset these entries manually to get the expected testing behavior. 171 // reset these entries manually to get the expected testing behavior.
172 void Channel::NotifyProcessForkedForTesting() { 172 void Channel::NotifyProcessForkedForTesting() {
173 PipeMap::GetInstance()->map_.clear(); 173 PipeMap::GetInstance()->map_.clear();
174 } 174 }
175 #endif 175 #endif
176 176
177 //------------------------------------------------------------------------------ 177 //------------------------------------------------------------------------------
178 178
179 #if defined(OS_LINUX) 179 #if defined(OS_LINUX) || defined(OS_NACL_NONSFI)
180 int ChannelPosix::global_pid_ = 0; 180 int ChannelPosix::global_pid_ = 0;
181 #endif // OS_LINUX 181 #endif // defined(OS_LINUX) || defined(OS_NACL_NONSFI)
182 182
183 ChannelPosix::ChannelPosix(const IPC::ChannelHandle& channel_handle, 183 ChannelPosix::ChannelPosix(const IPC::ChannelHandle& channel_handle,
184 Mode mode, Listener* listener) 184 Mode mode, Listener* listener)
185 : ChannelReader(listener), 185 : ChannelReader(listener),
186 mode_(mode), 186 mode_(mode),
187 peer_pid_(base::kNullProcessId), 187 peer_pid_(base::kNullProcessId),
188 is_blocked_on_write_(false), 188 is_blocked_on_write_(false),
189 waiting_connect_(true), 189 waiting_connect_(true),
190 message_send_bytes_written_(0), 190 message_send_bytes_written_(0),
191 pipe_name_(channel_handle.name), 191 pipe_name_(channel_handle.name),
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 fds_to_close_.clear(); 638 fds_to_close_.clear();
639 #endif 639 #endif
640 } 640 }
641 641
642 // static 642 // static
643 bool ChannelPosix::IsNamedServerInitialized( 643 bool ChannelPosix::IsNamedServerInitialized(
644 const std::string& channel_id) { 644 const std::string& channel_id) {
645 return base::PathExists(base::FilePath(channel_id)); 645 return base::PathExists(base::FilePath(channel_id));
646 } 646 }
647 647
648 #if defined(OS_LINUX) 648 #if defined(OS_LINUX) || defined(OS_NACL_NONSFI)
649 // static 649 // static
650 void ChannelPosix::SetGlobalPid(int pid) { 650 void ChannelPosix::SetGlobalPid(int pid) {
651 global_pid_ = pid; 651 global_pid_ = pid;
652 } 652 }
653 #endif // OS_LINUX 653 #endif // defined(OS_LINUX) || defined(OS_NACL_NONSFI)
654 654
655 // Called by libevent when we can read from the pipe without blocking. 655 // Called by libevent when we can read from the pipe without blocking.
656 void ChannelPosix::OnFileCanReadWithoutBlocking(int fd) { 656 void ChannelPosix::OnFileCanReadWithoutBlocking(int fd) {
657 if (fd == server_listen_pipe_.get()) { 657 if (fd == server_listen_pipe_.get()) {
658 #if defined(OS_NACL_NONSFI) 658 #if defined(OS_NACL_NONSFI)
659 LOG(FATAL) 659 LOG(FATAL)
660 << "IPC channels in nacl_helper_nonsfi should not be SERVER mode."; 660 << "IPC channels in nacl_helper_nonsfi should not be SERVER mode.";
661 #else 661 #else
662 int new_pipe = 0; 662 int new_pipe = 0;
663 if (!ServerAcceptConnection(server_listen_pipe_.get(), &new_pipe) || 663 if (!ServerAcceptConnection(server_listen_pipe_.get(), &new_pipe) ||
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 Close(); 764 Close();
765 if (AcceptsConnections()) { 765 if (AcceptsConnections()) {
766 listener()->OnChannelListenError(); 766 listener()->OnChannelListenError();
767 } else { 767 } else {
768 listener()->OnChannelError(); 768 listener()->OnChannelError();
769 } 769 }
770 } 770 }
771 } 771 }
772 772
773 int ChannelPosix::GetHelloMessageProcId() const { 773 int ChannelPosix::GetHelloMessageProcId() const {
774 int pid = base::GetCurrentProcId(); 774 #if defined(OS_LINUX) || defined(OS_NACL_NONSFI)
775 #if defined(OS_LINUX) 775 // Our process may be in a sandbox with a separate PID namespace in Linux.
776 // Our process may be in a sandbox with a separate PID namespace. 776 // In nacl_helper_nonsfi, getpid() invoked by GetCurrentProcId() is not
777 if (global_pid_) { 777 // allowed and would cause a SIGSYS crashing because of the seccomp sandbox.
778 pid = global_pid_; 778 // |global_pid_| should be initialized in advance in the process.
779 } 779 if (global_pid_)
780 return global_pid_;
mdempsky 2014/11/07 03:05:34 Will global_pid_ ever be set to anything other tha
hidehiko 2014/11/07 05:43:21 This is both for SFI (under OS_LINUX) and Non-SFI
Mark Seaborn 2014/12/03 01:54:00 I agree with Matthew's comment about doing: #if de
hidehiko 2014/12/03 17:03:19 Ok, done, in mdempsky@'s way. My focus is Non-SFI.
780 #endif 781 #endif
781 return pid; 782 return base::GetCurrentProcId();
782 } 783 }
783 784
784 void ChannelPosix::QueueHelloMessage() { 785 void ChannelPosix::QueueHelloMessage() {
785 // Create the Hello message 786 // Create the Hello message
786 scoped_ptr<Message> msg(new Message(MSG_ROUTING_NONE, 787 scoped_ptr<Message> msg(new Message(MSG_ROUTING_NONE,
787 HELLO_MESSAGE_TYPE, 788 HELLO_MESSAGE_TYPE,
788 IPC::Message::PRIORITY_NORMAL)); 789 IPC::Message::PRIORITY_NORMAL));
789 if (!msg->WriteInt(GetHelloMessageProcId())) { 790 if (!msg->WriteInt(GetHelloMessageProcId())) {
790 NOTREACHED() << "Unable to pickle hello message proc id"; 791 NOTREACHED() << "Unable to pickle hello message proc id";
791 } 792 }
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
1104 1105
1105 return id.append(GenerateUniqueRandomChannelID()); 1106 return id.append(GenerateUniqueRandomChannelID());
1106 } 1107 }
1107 1108
1108 1109
1109 bool Channel::IsNamedServerInitialized( 1110 bool Channel::IsNamedServerInitialized(
1110 const std::string& channel_id) { 1111 const std::string& channel_id) {
1111 return ChannelPosix::IsNamedServerInitialized(channel_id); 1112 return ChannelPosix::IsNamedServerInitialized(channel_id);
1112 } 1113 }
1113 1114
1114 #if defined(OS_LINUX) 1115 #if defined(OS_LINUX) || defined(OS_NACL_NONSFI)
1115 // static 1116 // static
1116 void Channel::SetGlobalPid(int pid) { 1117 void Channel::SetGlobalPid(int pid) {
1117 ChannelPosix::SetGlobalPid(pid); 1118 ChannelPosix::SetGlobalPid(pid);
1118 } 1119 }
1119 #endif // OS_LINUX 1120 #endif // defined(OS_LINUX) || defined(OS_NACL_NONSFI)
1120 1121
1121 } // namespace IPC 1122 } // namespace IPC
OLDNEW
« components/nacl/loader/nacl_helper_linux.cc ('K') | « ipc/ipc_channel_posix.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698