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

Side by Side Diff: chrome/nacl/nacl_helper_linux.cc

Issue 7811013: Revert 98909 - Use chain-loading for Linux nacl_helper (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 3 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/nacl/nacl_helper_exports.txt ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
11 #include <sys/socket.h> 11 #include <sys/socket.h>
12 #include <sys/types.h> 12 #include <sys/types.h>
13 13
14 #include <string> 14 #include <string>
15 #include <vector> 15 #include <vector>
16 16
17 #include "base/at_exit.h" 17 #include "base/at_exit.h"
18 #include "base/eintr_wrapper.h" 18 #include "base/eintr_wrapper.h"
19 #include "base/logging.h" 19 #include "base/logging.h"
20 #include "base/message_loop.h" 20 #include "base/message_loop.h"
21 #include "base/rand_util.h" 21 #include "base/rand_util.h"
22 #include "chrome/nacl/nacl_listener.h" 22 #include "chrome/nacl/nacl_listener.h"
23 #include "content/common/main_function_params.h" 23 #include "content/common/main_function_params.h"
24 #include "content/common/unix_domain_socket_posix.h" 24 #include "content/common/unix_domain_socket_posix.h"
25 #include "ipc/ipc_switches.h" 25 #include "ipc/ipc_switches.h"
26 #include "native_client/src/trusted/service_runtime/sel_memory.h"
27 26
28 namespace { 27 namespace {
29 28
30 bool g_suid_sandbox_active; 29 bool g_suid_sandbox_active;
31 30
32 // The child must mimic the behavior of zygote_main_linux.cc on the child 31 // The child must mimic the behavior of zygote_main_linux.cc on the child
33 // side of the fork. See zygote_main_linux.cc:HandleForkRequest from 32 // side of the fork. See zygote_main_linux.cc:HandleForkRequest from
34 // if (!child) { 33 // if (!child) {
35 // Note: this code doesn't attempt to support SELINUX or the SECCOMP sandbox. 34 // Note: this code doesn't attempt to support SELINUX or the SECCOMP sandbox.
36 void BecomeNaClLoader(const std::vector<int>& child_fds) { 35 void BecomeNaClLoader(const std::vector<int>& child_fds) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 // Now tell childpid to the Chrome zygote. 109 // Now tell childpid to the Chrome zygote.
111 if (HANDLE_EINTR(send(kNaClZygoteDescriptor, 110 if (HANDLE_EINTR(send(kNaClZygoteDescriptor,
112 &childpid, sizeof(childpid), MSG_EOR)) 111 &childpid, sizeof(childpid), MSG_EOR))
113 != sizeof(childpid)) { 112 != sizeof(childpid)) {
114 LOG(ERROR) << "*** send() to zygote failed"; 113 LOG(ERROR) << "*** send() to zygote failed";
115 } 114 }
116 } 115 }
117 116
118 } // namespace 117 } // namespace
119 118
120 static const char kNaClHelperAtZero[] = "at-zero"; 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 }
121 124
122 int main(int argc, char *argv[]) { 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) {
123 CommandLine::Init(argc, argv); 133 CommandLine::Init(argc, argv);
124 base::AtExitManager exit_manager; 134 base::AtExitManager exit_manager;
125 base::RandUint64(); // acquire /dev/urandom fd before sandbox is raised 135 base::RandUint64(); // acquire /dev/urandom fd before sandbox is raised
126 std::vector<int> empty; // for SendMsg() calls 136 std::vector<int> empty; // for SendMsg() calls
127 137
128 g_suid_sandbox_active = (NULL != getenv("SBX_D")); 138 g_suid_sandbox_active = (NULL != getenv("SBX_D"));
129 139 g_nacl_reserved_space = nacl_reserved_space;
130 if (CommandLine::ForCurrentProcess()->HasSwitch(kNaClHelperAtZero)) { 140 if (!nacl_reserved_space) {
131 g_nacl_prereserved_sandbox_addr = (void *) (uintptr_t) 0x10000; 141 VLOG(1) << "nacl_reserved_space is NULL";
142 } else {
143 VLOG(1) << "nacl_reserved_space is at "
144 << (void *)nacl_reserved_space;
132 } 145 }
133
134 // 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
135 if (!UnixDomainSocket::SendMsg(kNaClZygoteDescriptor, 147 if (!UnixDomainSocket::SendMsg(kNaClZygoteDescriptor,
136 kNaClHelperStartupAck, 148 kNaClHelperStartupAck,
137 sizeof(kNaClHelperStartupAck), empty)) { 149 sizeof(kNaClHelperStartupAck), empty)) {
138 LOG(ERROR) << "*** send() to zygote failed"; 150 LOG(ERROR) << "*** send() to zygote failed";
139 } 151 }
140 152
141 while (true) { 153 while (true) {
142 int badpid = -1; 154 int badpid = -1;
143 std::vector<int> fds; 155 std::vector<int> fds;
(...skipping 21 matching lines...) Expand all
165 } 177 }
166 } 178 }
167 // if fork fails, send PID=-1 to zygote 179 // if fork fails, send PID=-1 to zygote
168 if (!UnixDomainSocket::SendMsg(kNaClZygoteDescriptor, &badpid, 180 if (!UnixDomainSocket::SendMsg(kNaClZygoteDescriptor, &badpid,
169 sizeof(badpid), empty)) { 181 sizeof(badpid), empty)) {
170 LOG(ERROR) << "*** send() to zygote failed"; 182 LOG(ERROR) << "*** send() to zygote failed";
171 } 183 }
172 } 184 }
173 CHECK(false); // This routine must not return 185 CHECK(false); // This routine must not return
174 } 186 }
OLDNEW
« no previous file with comments | « chrome/nacl/nacl_helper_exports.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698