| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <stdlib.h> | 10 #include <stdlib.h> |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 // Now tell childpid to the Chrome zygote. | 109 // Now tell childpid to the Chrome zygote. |
| 110 if (HANDLE_EINTR(send(kNaClZygoteDescriptor, | 110 if (HANDLE_EINTR(send(kNaClZygoteDescriptor, |
| 111 &childpid, sizeof(childpid), MSG_EOR)) | 111 &childpid, sizeof(childpid), MSG_EOR)) |
| 112 != sizeof(childpid)) { | 112 != sizeof(childpid)) { |
| 113 LOG(ERROR) << "*** send() to zygote failed"; | 113 LOG(ERROR) << "*** send() to zygote failed"; |
| 114 } | 114 } |
| 115 } | 115 } |
| 116 | 116 |
| 117 } // namespace | 117 } // namespace |
| 118 | 118 |
| 119 int main(int argc, char *argv[]) { | 119 static const void* g_nacl_reserved_space = NULL; |
| 120 extern "C" __attribute__((visibility("default"))) |
| 121 const void* nacl_helper_get_1G_address() { |
| 122 return g_nacl_reserved_space; |
| 123 } |
| 124 |
| 125 // nacl_helper_init does the real work of this module. It is invoked as |
| 126 // a static constructor and never returns, preventing main() from the |
| 127 // nacl_helper_bootstrap program from being called. |
| 128 // |
| 129 // NOTE This routine must not return. |
| 130 extern "C" __attribute__((visibility("default"))) |
| 131 void nacl_helper_init(int argc, char *argv[], |
| 132 const char *nacl_reserved_space) { |
| 120 CommandLine::Init(argc, argv); | 133 CommandLine::Init(argc, argv); |
| 121 base::AtExitManager exit_manager; | 134 base::AtExitManager exit_manager; |
| 122 base::RandUint64(); // acquire /dev/urandom fd before sandbox is raised | 135 base::RandUint64(); // acquire /dev/urandom fd before sandbox is raised |
| 123 std::vector<int> empty; // for SendMsg() calls | 136 std::vector<int> empty; // for SendMsg() calls |
| 124 | 137 |
| 125 g_suid_sandbox_active = (NULL != getenv("SBX_D")); | 138 g_suid_sandbox_active = (NULL != getenv("SBX_D")); |
| 126 | 139 g_nacl_reserved_space = nacl_reserved_space; |
| 140 if (!nacl_reserved_space) { |
| 141 VLOG(1) << "nacl_reserved_space is NULL"; |
| 142 } else { |
| 143 VLOG(1) << "nacl_reserved_space is at " |
| 144 << (void *)nacl_reserved_space; |
| 145 } |
| 127 // Send the zygote a message to let it know we are ready to help | 146 // Send the zygote a message to let it know we are ready to help |
| 128 if (!UnixDomainSocket::SendMsg(kNaClZygoteDescriptor, | 147 if (!UnixDomainSocket::SendMsg(kNaClZygoteDescriptor, |
| 129 kNaClHelperStartupAck, | 148 kNaClHelperStartupAck, |
| 130 sizeof(kNaClHelperStartupAck), empty)) { | 149 sizeof(kNaClHelperStartupAck), empty)) { |
| 131 LOG(ERROR) << "*** send() to zygote failed"; | 150 LOG(ERROR) << "*** send() to zygote failed"; |
| 132 } | 151 } |
| 133 | 152 |
| 134 while (true) { | 153 while (true) { |
| 135 int badpid = -1; | 154 int badpid = -1; |
| 136 std::vector<int> fds; | 155 std::vector<int> fds; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 156 LOG(ERROR) << "nacl_helper unrecognized request: %s"; | 175 LOG(ERROR) << "nacl_helper unrecognized request: %s"; |
| 157 _exit(-1); | 176 _exit(-1); |
| 158 } | 177 } |
| 159 } | 178 } |
| 160 // if fork fails, send PID=-1 to zygote | 179 // if fork fails, send PID=-1 to zygote |
| 161 if (!UnixDomainSocket::SendMsg(kNaClZygoteDescriptor, &badpid, | 180 if (!UnixDomainSocket::SendMsg(kNaClZygoteDescriptor, &badpid, |
| 162 sizeof(badpid), empty)) { | 181 sizeof(badpid), empty)) { |
| 163 LOG(ERROR) << "*** send() to zygote failed"; | 182 LOG(ERROR) << "*** send() to zygote failed"; |
| 164 } | 183 } |
| 165 } | 184 } |
| 185 CHECK(false); // This routine must not return |
| 166 } | 186 } |
| OLD | NEW |