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

Side by Side Diff: chrome/browser/mac/relauncher.cc

Issue 10837149: Don't use NXArgc or NXArgv. Access them via _NSGetArgc() and _NSGetArgv(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make argvp conster Created 8 years, 4 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/app_asan.saves ('k') | chrome/chrome.gyp » ('j') | 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 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 #include "chrome/browser/mac/relauncher.h" 5 #include "chrome/browser/mac/relauncher.h"
6 6
7 #include <ApplicationServices/ApplicationServices.h> 7 #include <ApplicationServices/ApplicationServices.h>
8 #include <AvailabilityMacros.h> 8 #include <AvailabilityMacros.h>
9 #include <crt_externs.h>
9 #include <dlfcn.h> 10 #include <dlfcn.h>
10 #include <string.h> 11 #include <string.h>
11 #include <sys/event.h> 12 #include <sys/event.h>
12 #include <sys/time.h> 13 #include <sys/time.h>
13 #include <sys/types.h> 14 #include <sys/types.h>
14 #include <unistd.h> 15 #include <unistd.h>
15 16
16 #include <string> 17 #include <string>
17 #include <vector> 18 #include <vector>
18 19
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 namespace internal { 258 namespace internal {
258 259
259 int RelauncherMain(const content::MainFunctionParams& main_parameters) { 260 int RelauncherMain(const content::MainFunctionParams& main_parameters) {
260 // CommandLine rearranges the order of the arguments returned by 261 // CommandLine rearranges the order of the arguments returned by
261 // main_parameters.argv(), rendering it impossible to determine which 262 // main_parameters.argv(), rendering it impossible to determine which
262 // arguments originally came before kRelauncherArgSeparator and which came 263 // arguments originally came before kRelauncherArgSeparator and which came
263 // after. It's crucial to distinguish between these because only those 264 // after. It's crucial to distinguish between these because only those
264 // after the separator should be given to the relaunched process; it's also 265 // after the separator should be given to the relaunched process; it's also
265 // important to not treat the path to the relaunched process as a "loose" 266 // important to not treat the path to the relaunched process as a "loose"
266 // argument. NXArgc and NXArgv are pointers to the original argc and argv as 267 // argument. NXArgc and NXArgv are pointers to the original argc and argv as
267 // passed to main(), so use those. The typical mechanism to do this is to 268 // passed to main(), so use those. Access them through _NSGetArgc and
268 // provide "extern" declarations to access these, but they're only present 269 // _NSGetArgv because NXArgc and NXArgv are normally only available to a
269 // in the crt1.o start file. This function will be linked into the framework 270 // main executable via crt1.o and this code will run from a dylib, and
270 // dylib, having no direct access to anything in crt1.o. dlsym to the 271 // because of http://crbug.com/139902.
271 // rescue. 272 const int* argcp = _NSGetArgc();
272 const int* argcp = static_cast<const int*>(dlsym(RTLD_MAIN_ONLY, "NXArgc"));
273 if (!argcp) { 273 if (!argcp) {
274 LOG(ERROR) << "dlsym NXArgc: " << dlerror(); 274 NOTREACHED();
275 return 1; 275 return 1;
276 } 276 }
277 int argc = *argcp; 277 int argc = *argcp;
278 278
279 const char* const** argvp = 279 const char* const* const* argvp = _NSGetArgv();
Nico 2012/08/09 01:07:38 :-D
280 static_cast<const char* const**>(dlsym(RTLD_MAIN_ONLY, "NXArgv"));
281 if (!argvp) { 280 if (!argvp) {
282 LOG(ERROR) << "dlsym NXArgv: " << dlerror(); 281 NOTREACHED();
283 return 1; 282 return 1;
284 } 283 }
285 const char* const* argv = *argvp; 284 const char* const* argv = *argvp;
286 285
287 if (argc < 4 || RelauncherTypeArg() != argv[1]) { 286 if (argc < 4 || RelauncherTypeArg() != argv[1]) {
288 LOG(ERROR) << "relauncher process invoked with unexpected arguments"; 287 LOG(ERROR) << "relauncher process invoked with unexpected arguments";
289 return 1; 288 return 1;
290 } 289 }
291 290
292 RelauncherSynchronizeWithParent(); 291 RelauncherSynchronizeWithParent();
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 if (!dmg_bsd_device_name.empty()) { 381 if (!dmg_bsd_device_name.empty()) {
383 EjectAndTrashDiskImage(dmg_bsd_device_name); 382 EjectAndTrashDiskImage(dmg_bsd_device_name);
384 } 383 }
385 384
386 return 0; 385 return 0;
387 } 386 }
388 387
389 } // namespace internal 388 } // namespace internal
390 389
391 } // namespace mac_relauncher 390 } // namespace mac_relauncher
OLDNEW
« no previous file with comments | « chrome/app/app_asan.saves ('k') | chrome/chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698