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

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

Issue 11745021: NaCl: Use C++-style comments as per the Chromium style (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 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/app/nacl_fork_delegate_linux.cc ('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) 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 != sizeof(childpid)) { 121 != sizeof(childpid)) {
122 LOG(ERROR) << "*** send() to zygote failed"; 122 LOG(ERROR) << "*** send() to zygote failed";
123 } 123 }
124 } 124 }
125 125
126 } // namespace 126 } // namespace
127 127
128 static const char kNaClHelperReservedAtZero[] = "reserved_at_zero"; 128 static const char kNaClHelperReservedAtZero[] = "reserved_at_zero";
129 static const char kNaClHelperRDebug[] = "r_debug"; 129 static const char kNaClHelperRDebug[] = "r_debug";
130 130
131 /* 131 // Since we were started by nacl_helper_bootstrap rather than in the
132 * Since we were started by nacl_helper_bootstrap rather than in the 132 // usual way, the debugger cannot figure out where our executable
133 * usual way, the debugger cannot figure out where our executable 133 // or the dynamic linker or the shared libraries are in memory,
134 * or the dynamic linker or the shared libraries are in memory, 134 // so it won't find any symbols. But we can fake it out to find us.
135 * so it won't find any symbols. But we can fake it out to find us. 135 //
136 * 136 // The zygote passes --r_debug=0xXXXXXXXXXXXXXXXX.
137 * The zygote passes --r_debug=0xXXXXXXXXXXXXXXXX. 137 // nacl_helper_bootstrap replaces the Xs with the address of its _r_debug
138 * nacl_helper_bootstrap replaces the Xs with the address of its _r_debug 138 // structure. The debugger will look for that symbol by name to
139 * structure. The debugger will look for that symbol by name to 139 // discover the addresses of key dynamic linker data structures.
140 * discover the addresses of key dynamic linker data structures. 140 // Since all it knows about is the original main executable, which
141 * Since all it knows about is the original main executable, which 141 // is the bootstrap program, it finds the symbol defined there. The
142 * is the bootstrap program, it finds the symbol defined there. The 142 // dynamic linker's structure is somewhere else, but it is filled in
143 * dynamic linker's structure is somewhere else, but it is filled in 143 // after initialization. The parts that really matter to the
144 * after initialization. The parts that really matter to the 144 // debugger never change. So we just copy the contents of the
145 * debugger never change. So we just copy the contents of the 145 // dynamic linker's structure into the address provided by the option.
146 * dynamic linker's structure into the address provided by the option. 146 // Hereafter, if someone attaches a debugger (or examines a core dump),
147 * Hereafter, if someone attaches a debugger (or examines a core dump), 147 // the debugger will find all the symbols in the normal way.
148 * the debugger will find all the symbols in the normal way.
149 */
150 static void CheckRDebug(char *argv0) { 148 static void CheckRDebug(char *argv0) {
151 std::string r_debug_switch_value = 149 std::string r_debug_switch_value =
152 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(kNaClHelperRDebug); 150 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(kNaClHelperRDebug);
153 if (!r_debug_switch_value.empty()) { 151 if (!r_debug_switch_value.empty()) {
154 char *endp; 152 char *endp;
155 uintptr_t r_debug_addr = strtoul(r_debug_switch_value.c_str(), &endp, 0); 153 uintptr_t r_debug_addr = strtoul(r_debug_switch_value.c_str(), &endp, 0);
156 if (r_debug_addr != 0 && *endp == '\0') { 154 if (r_debug_addr != 0 && *endp == '\0') {
157 struct r_debug *bootstrap_r_debug = (struct r_debug *) r_debug_addr; 155 struct r_debug *bootstrap_r_debug = (struct r_debug *) r_debug_addr;
158 *bootstrap_r_debug = _r_debug; 156 *bootstrap_r_debug = _r_debug;
159 157
160 /* 158 // Since the main executable (the bootstrap program) does not
161 * Since the main executable (the bootstrap program) does not 159 // have a dynamic section, the debugger will not skip the
162 * have a dynamic section, the debugger will not skip the 160 // first element of the link_map list as it usually would for
163 * first element of the link_map list as it usually would for 161 // an executable or PIE that was loaded normally. But the
164 * an executable or PIE that was loaded normally. But the 162 // dynamic linker has set l_name for the PIE to "" as is
165 * dynamic linker has set l_name for the PIE to "" as is 163 // normal for the main executable. So the debugger doesn't
166 * normal for the main executable. So the debugger doesn't 164 // know which file it is. Fill in the actual file name, which
167 * know which file it is. Fill in the actual file name, which 165 // came in as our argv[0].
168 * came in as our argv[0].
169 */
170 struct link_map *l = _r_debug.r_map; 166 struct link_map *l = _r_debug.r_map;
171 if (l->l_name[0] == '\0') 167 if (l->l_name[0] == '\0')
172 l->l_name = argv0; 168 l->l_name = argv0;
173 } 169 }
174 } 170 }
175 } 171 }
176 172
177 /* 173 // The zygote passes --reserved_at_zero=0xXXXXXXXXXXXXXXXX.
178 * The zygote passes --reserved_at_zero=0xXXXXXXXXXXXXXXXX. 174 // nacl_helper_bootstrap replaces the Xs with the amount of prereserved
179 * nacl_helper_bootstrap replaces the Xs with the amount of prereserved 175 // sandbox memory.
180 * sandbox memory. 176 //
181 * 177 // CheckReservedAtZero parses the value of the argument reserved_at_zero
182 * CheckReservedAtZero parses the value of the argument reserved_at_zero 178 // and returns the amount of prereserved sandbox memory.
183 * and returns the amount of prereserved sandbox memory.
184 */
185 static size_t CheckReservedAtZero() { 179 static size_t CheckReservedAtZero() {
186 size_t prereserved_sandbox_size = 0; 180 size_t prereserved_sandbox_size = 0;
187 std::string reserved_at_zero_switch_value = 181 std::string reserved_at_zero_switch_value =
188 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 182 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
189 kNaClHelperReservedAtZero); 183 kNaClHelperReservedAtZero);
190 if (!reserved_at_zero_switch_value.empty()) { 184 if (!reserved_at_zero_switch_value.empty()) {
191 char *endp; 185 char *endp;
192 prereserved_sandbox_size = 186 prereserved_sandbox_size =
193 strtoul(reserved_at_zero_switch_value.c_str(), &endp, 0); 187 strtoul(reserved_at_zero_switch_value.c_str(), &endp, 0);
194 if (*endp != '\0') 188 if (*endp != '\0')
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 _exit(-1); 268 _exit(-1);
275 } 269 }
276 // if fork fails, send PID=-1 to zygote 270 // if fork fails, send PID=-1 to zygote
277 if (!UnixDomainSocket::SendMsg(kNaClZygoteDescriptor, &badpid, 271 if (!UnixDomainSocket::SendMsg(kNaClZygoteDescriptor, &badpid,
278 sizeof(badpid), empty)) { 272 sizeof(badpid), empty)) {
279 LOG(ERROR) << "*** send() to zygote failed"; 273 LOG(ERROR) << "*** send() to zygote failed";
280 } 274 }
281 } 275 }
282 CHECK(false); // This routine must not return 276 CHECK(false); // This routine must not return
283 } 277 }
OLDNEW
« no previous file with comments | « chrome/app/nacl_fork_delegate_linux.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698