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

Unified Diff: ipc/ipc_channel_posix.cc

Issue 659243002: Non-SFI Mode: Build ipc/ library by PNaCl toolchain for nacl_helper_nonsfi. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git/+/master
Patch Set: Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: ipc/ipc_channel_posix.cc
diff --git a/ipc/ipc_channel_posix.cc b/ipc/ipc_channel_posix.cc
index 2dfd17e6730cbd305d7a2046def6d90276dea172..eaf5e911d8a13fa2f128bc31f61e53ba006db4cd 100644
--- a/ipc/ipc_channel_posix.cc
+++ b/ipc/ipc_channel_posix.cc
@@ -10,13 +10,16 @@
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
-#include <sys/un.h>
#include <unistd.h>
#if defined(OS_OPENBSD)
#include <sys/uio.h>
#endif
+#if !defined(__native_client_nonsfi__)
+#include <sys/un.h>
+#endif
+
#include <map>
#include <string>
@@ -173,9 +176,9 @@ void Channel::NotifyProcessForkedForTesting() {
//------------------------------------------------------------------------------
-#if defined(OS_LINUX)
+#if defined(OS_LINUX) || defined(__native_client_nonsfi__)
int ChannelPosix::global_pid_ = 0;
-#endif // OS_LINUX
+#endif
ChannelPosix::ChannelPosix(const IPC::ChannelHandle& channel_handle,
Mode mode, Listener* listener)
@@ -255,6 +258,11 @@ bool ChannelPosix::CreatePipe(
}
#endif // IPC_USES_READWRITE
} else if (mode_ & MODE_NAMED_FLAG) {
+#if defined(__native_client_nonsfi__)
+ // IPC channels in nacl_helper_nonsfi should not be NAMED mode.
+ NOTREACHED();
+ return false;
+#else
// Case 2 from comment above.
int local_pipe_fd = -1;
@@ -276,6 +284,7 @@ bool ChannelPosix::CreatePipe(
}
local_pipe.reset(local_pipe_fd);
+#endif // !defined(__native_client_nonsfi__)
} else {
local_pipe.reset(PipeMap::GetInstance()->Lookup(pipe_name_));
if (mode_ & MODE_CLIENT_FLAG) {
@@ -336,10 +345,16 @@ bool ChannelPosix::CreatePipe(
}
#endif // IPC_USES_READWRITE
- if ((mode_ & MODE_SERVER_FLAG) && (mode_ & MODE_NAMED_FLAG))
+ if ((mode_ & MODE_SERVER_FLAG) && (mode_ & MODE_NAMED_FLAG)) {
+#if defined(__native_client_nonsfi__)
+ // IPC channels in nacl_helper_nonsfi should not be NAMED mode.
hamaji 2014/10/20 06:37:41 not be either SERVER mode nor NAMED mode?
hidehiko 2014/10/20 09:25:29 Done.
+ NOTREACHED();
+#else
server_listen_pipe_.reset(local_pipe.release());
- else
+#endif
+ } else {
pipe_.reset(local_pipe.release());
+ }
return true;
}
@@ -351,6 +366,10 @@ bool ChannelPosix::Connect() {
bool did_connect = true;
if (server_listen_pipe_.is_valid()) {
+#if defined(__native_client_nonsfi__)
+ // IPC channels in nacl_helper_nonsfi should always be client mode.
+ NOTREACHED();
+#else
// Watch the pipe for connections, and turn any connections into
// active sockets.
base::MessageLoopForIO::current()->WatchFileDescriptor(
@@ -359,6 +378,7 @@ bool ChannelPosix::Connect() {
base::MessageLoopForIO::WATCH_READ,
&server_listen_connection_watcher_,
this);
+#endif
} else {
did_connect = AcceptConnection();
}
@@ -581,10 +601,13 @@ bool ChannelPosix::HasAcceptedConnection() const {
return AcceptsConnections() && pipe_.is_valid();
}
+#if !defined(__native_client_nonsfi__)
+// GetPeerEuid is not supported in nacl_helper_nonsfi.
bool ChannelPosix::GetPeerEuid(uid_t* peer_euid) const {
DCHECK(!(mode_ & MODE_SERVER) || HasAcceptedConnection());
return IPC::GetPeerEuid(pipe_.get(), peer_euid);
}
+#endif
void ChannelPosix::ResetToAcceptingConnectionState() {
// Unregister libevent for the unix domain socket and close it.
@@ -623,16 +646,20 @@ bool ChannelPosix::IsNamedServerInitialized(
return base::PathExists(base::FilePath(channel_id));
}
-#if defined(OS_LINUX)
+#if defined(OS_LINUX) || defined(__native_client_nonsfi__)
// static
void ChannelPosix::SetGlobalPid(int pid) {
global_pid_ = pid;
}
-#endif // OS_LINUX
+#endif
// Called by libevent when we can read from the pipe without blocking.
void ChannelPosix::OnFileCanReadWithoutBlocking(int fd) {
if (fd == server_listen_pipe_.get()) {
+#if defined(__native_client_nonsfi__)
+ // IPC channels in nacl_helper_nonsfi should not be SERVER mode.
+ NOTREACHED();
+#else
int new_pipe = 0;
if (!ServerAcceptConnection(server_listen_pipe_.get(), &new_pipe) ||
new_pipe < 0) {
@@ -671,6 +698,7 @@ void ChannelPosix::OnFileCanReadWithoutBlocking(int fd) {
NOTREACHED() << "AcceptConnection should not fail on server";
}
waiting_connect_ = false;
+#endif
} else if (fd == pipe_) {
if (waiting_connect_ && (mode_ & MODE_SERVER_FLAG)) {
waiting_connect_ = false;
@@ -744,12 +772,14 @@ void ChannelPosix::ClosePipeOnError() {
}
int ChannelPosix::GetHelloMessageProcId() const {
- int pid = base::GetCurrentProcId();
-#if defined(OS_LINUX)
+#if defined(OS_LINUX) || defined(__native_client_nonsfi__)
// Our process may be in a sandbox with a separate PID namespace.
- if (global_pid_) {
- pid = global_pid_;
- }
+ // In nacl_helper_nonsfi, if sandbox is enabled, our process should be always
+ // in the sandbox. In such a situation, calling GetCurrentProcId() would hit
hamaji 2014/10/20 06:37:41 How about adding "unless --no-sandbox is specified
hidehiko 2014/10/20 09:25:29 Slightly refactored. How about this?
+ // the sandbox restriction.
+ int pid = global_pid_ ? global_pid_ : base::GetCurrentProcId();
+#else
+ int pid = base::GetCurrentProcId();
#endif
return pid;
}
@@ -923,11 +953,15 @@ bool ChannelPosix::ExtractFileDescriptorsFromMsghdr(msghdr* msg) {
file_descriptors,
file_descriptors + num_file_descriptors);
+#if !defined(__native_client_nonsfi__)
+ // The PNaCl toolchain for Non-SFI binary build does not support
+ // MSG_CTRUNC.
// Check this after adding the FDs so we don't leak them.
if (msg->msg_flags & MSG_CTRUNC) {
ClearInputFDs();
return false;
}
+#endif
return true;
}
@@ -1032,9 +1066,14 @@ void ChannelPosix::Close() {
}
if (server_listen_pipe_.is_valid()) {
+#if defined(__native_client_nonsfi__)
+ // IPC channels in nacl_helper_nonsfi should not be SERVER mode.
+ NOTREACHED();
+#else
server_listen_pipe_.reset();
// Unregister libevent for the listening socket and close it.
server_listen_connection_watcher_.StopWatchingFileDescriptor();
+#endif
}
CloseClientFileDescriptor();
@@ -1075,11 +1114,11 @@ bool Channel::IsNamedServerInitialized(
return ChannelPosix::IsNamedServerInitialized(channel_id);
}
-#if defined(OS_LINUX)
+#if defined(OS_LINUX) || defined(__native_client_nonsfi__)
// static
void Channel::SetGlobalPid(int pid) {
ChannelPosix::SetGlobalPid(pid);
}
-#endif // OS_LINUX
+#endif
} // namespace IPC
« ipc/ipc_channel.cc ('K') | « ipc/ipc_channel_posix.h ('k') | ipc/ipc_channel_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698