| OLD | NEW |
| 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 // A mini-zygote specifically for Native Client. | 5 // A mini-zygote specifically for Native Client. |
| 6 | 6 |
| 7 #include "chrome/common/nacl_helper_linux.h" | 7 #include "chrome/common/nacl_helper_linux.h" |
| 8 | 8 |
| 9 #include <errno.h> | 9 #include <errno.h> |
| 10 #include <link.h> | 10 #include <link.h> |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 // The child must mimic the behavior of zygote_main_linux.cc on the child | 36 // The child must mimic the behavior of zygote_main_linux.cc on the child |
| 37 // side of the fork. See zygote_main_linux.cc:HandleForkRequest from | 37 // side of the fork. See zygote_main_linux.cc:HandleForkRequest from |
| 38 // if (!child) { | 38 // if (!child) { |
| 39 // Note: this code doesn't attempt to support SELINUX or the SECCOMP sandbox. | 39 // Note: this code doesn't attempt to support SELINUX or the SECCOMP sandbox. |
| 40 void BecomeNaClLoader(const std::vector<int>& child_fds, | 40 void BecomeNaClLoader(const std::vector<int>& child_fds, |
| 41 size_t prereserved_sandbox_size) { | 41 size_t prereserved_sandbox_size) { |
| 42 VLOG(1) << "NaCl loader: setting up IPC descriptor"; | 42 VLOG(1) << "NaCl loader: setting up IPC descriptor"; |
| 43 // don't need zygote FD any more | 43 // don't need zygote FD any more |
| 44 if (HANDLE_EINTR(close(kNaClZygoteDescriptor)) != 0) | 44 if (HANDLE_EINTR(close(kNaClZygoteDescriptor)) != 0) |
| 45 LOG(ERROR) << "close(kNaClZygoteDescriptor) failed."; | 45 LOG(ERROR) << "close(kNaClZygoteDescriptor) failed."; |
| 46 // Set up browser descriptor on fd 3 and IPC as expected by Chrome. | |
| 47 base::GlobalDescriptors::GetInstance()->Set(kPrimaryIPCChannel, | 46 base::GlobalDescriptors::GetInstance()->Set(kPrimaryIPCChannel, |
| 48 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor); | 47 child_fds[kNaClBrowserFDIndex]); |
| 49 int zfd = dup2(child_fds[kNaClBrowserFDIndex], kNaClBrowserDescriptor); | |
| 50 if (zfd != kNaClBrowserDescriptor) { | |
| 51 LOG(ERROR) << "Could not initialize kNaClBrowserDescriptor"; | |
| 52 _exit(-1); | |
| 53 } | |
| 54 | 48 |
| 55 MessageLoopForIO main_message_loop; | 49 MessageLoopForIO main_message_loop; |
| 56 NaClListener listener; | 50 NaClListener listener; |
| 57 listener.set_prereserved_sandbox_size(prereserved_sandbox_size); | 51 listener.set_prereserved_sandbox_size(prereserved_sandbox_size); |
| 58 listener.Listen(); | 52 listener.Listen(); |
| 59 _exit(0); | 53 _exit(0); |
| 60 } | 54 } |
| 61 | 55 |
| 62 // Some of this code was lifted from | 56 // Some of this code was lifted from |
| 63 // content/browser/zygote_main_linux.cc:ForkWithRealPid() | 57 // content/browser/zygote_main_linux.cc:ForkWithRealPid() |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 _exit(-1); | 262 _exit(-1); |
| 269 } | 263 } |
| 270 // if fork fails, send PID=-1 to zygote | 264 // if fork fails, send PID=-1 to zygote |
| 271 if (!UnixDomainSocket::SendMsg(kNaClZygoteDescriptor, &badpid, | 265 if (!UnixDomainSocket::SendMsg(kNaClZygoteDescriptor, &badpid, |
| 272 sizeof(badpid), empty)) { | 266 sizeof(badpid), empty)) { |
| 273 LOG(ERROR) << "*** send() to zygote failed"; | 267 LOG(ERROR) << "*** send() to zygote failed"; |
| 274 } | 268 } |
| 275 } | 269 } |
| 276 CHECK(false); // This routine must not return | 270 CHECK(false); // This routine must not return |
| 277 } | 271 } |
| OLD | NEW |