-void ChildNaClLoaderInit(const std::vector<int>& child_fds,
- const NaClLoaderSystemInfo& system_info) {
- const int parent_fd = child_fds[content::ZygoteForkDelegate::kParentFDIndex];
- const int dummy_fd = child_fds[content::ZygoteForkDelegate::kDummyFDIndex];
- bool validack = false;
- const size_t kMaxReadSize = 1024;
- char buffer[kMaxReadSize];
- // Wait until the parent process has discovered our PID. We
- // should not fork any child processes (which the seccomp
- // sandbox does) until then, because that can interfere with the
- // parent's discovery of our PID.
- const int nread = HANDLE_EINTR(read(parent_fd, buffer, kMaxReadSize));
- const std::string switch_prefix = std::string("--") +
- switches::kProcessChannelID + std::string("=");
- const size_t len = switch_prefix.length();
-
- if (nread < 0) {
- perror("read");
- LOG(ERROR) << "read returned " << nread;
- } else if (nread > static_cast<int>(len)) {
- if (switch_prefix.compare(0, len, buffer, 0, len) == 0) {
- VLOG(1) << "NaCl loader is synchronised with Chrome zygote";
- CommandLine::ForCurrentProcess()->AppendSwitchASCII(
- switches::kProcessChannelID,
- std::string(&buffer[len], nread - len));
- validack = true;
- }
- }
- if (IGNORE_EINTR(close(dummy_fd)) != 0)
- LOG(ERROR) << "close(dummy_fd) failed";
- if (IGNORE_EINTR(close(parent_fd)) != 0)
- LOG(ERROR) << "close(parent_fd) failed";
- if (validack) {
- BecomeNaClLoader(child_fds, system_info);
- } else {
- LOG(ERROR) << "Failed to synch with zygote";
- }
+void ChildNaClLoaderInit(ScopedVector<base::ScopedFD> child_fds,
+ const NaClLoaderSystemInfo& system_info,
+ bool uses_nonsfi_mode,
+ nacl::NaClSandbox* nacl_sandbox,
+ const std::string& channel_id) {
+ DCHECK(child_fds.size() >
+ std::max(content::ZygoteForkDelegate::kPIDOracleFDIndex,
+ content::ZygoteForkDelegate::kBrowserFDIndex));
+
+ // Ping the PID oracle socket.
+ CHECK(content::SendZygoteChildPing(
+ child_fds[content::ZygoteForkDelegate::kPIDOracleFDIndex]->get()));
+
+ CommandLine::ForCurrentProcess()->AppendSwitchASCII(
+ switches::kProcessChannelID, channel_id);
+
+ // Save the browser socket and close the rest.
+ base::ScopedFD browser_fd(
+ child_fds[content::ZygoteForkDelegate::kBrowserFDIndex]->Pass());
+ child_fds.clear();
+
+ BecomeNaClLoader(
+ browser_fd.Pass(), system_info, uses_nonsfi_mode, nacl_sandbox);