Chromium Code Reviews| 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 // The entry point for all Mac Chromium processes, including the outer app | 5 // The entry point for all Mac Chromium processes, including the outer app |
| 6 // bundle (browser) and helper app (renderer, plugin, and friends). | 6 // bundle (browser) and helper app (renderer, plugin, and friends). |
| 7 | 7 |
| 8 #if defined(ADDRESS_SANITIZER) | |
| 9 #include <crt_externs.h> // for _NSGetArgc, _NSGetArgv | |
| 10 #endif // ADDRESS_SANITIZER | |
| 8 #include <stdlib.h> | 11 #include <stdlib.h> |
| 12 #include <string.h> | |
| 13 | |
| 14 #if defined(ADDRESS_SANITIZER) | |
| 15 // NaCl requires its own SEGV handler, so we need to add handle_segv=0 to | |
| 16 // ASAN_OPTIONS. This is done by injecting __asan_default_options into the | |
| 17 // executable. | |
| 18 // Because there's no distinct NaCl executable on OSX, we have to look at the | |
| 19 // command line arguments to understand whether the process is a NaCl loader. | |
| 20 | |
| 21 static const char kNaClDefaultOptions[] = "handle_segv=0"; | |
| 22 static const char kNaClFlag[] = "--type=nacl-loader"; | |
| 23 | |
| 24 extern "C" | |
| 25 // __asan_default_options() is called at ASan initialization, so it must | |
| 26 // not be instrumented with ASan -- thus the "no_sanitize_address" attribute. | |
| 27 __attribute__((no_sanitize_address)) | |
| 28 // The function isn't referenced from the executable itself. Make sure it isn't | |
| 29 // stripped by the linker. | |
| 30 __attribute__((used)) | |
| 31 __attribute__((visibility("default"))) | |
| 32 const char* __asan_default_options() { | |
| 33 char*** argvp = _NSGetArgv(); | |
| 34 int* argcp = _NSGetArgc(); | |
| 35 if (!argvp || !argcp) return NULL; | |
| 36 char** argv = *argvp; | |
| 37 int argc = *argcp; | |
| 38 const int kNaClFlagLen = strlen(kNaClFlag); | |
|
Mark Seaborn
2013/12/02 16:51:32
This isn't used
Alexander Potapenko
2013/12/03 09:40:39
Done.
| |
| 39 for (int i = 0; i < argc; ++i) { | |
| 40 if (strcmp(argv[i], kNaClFlag) == 0) { | |
| 41 return kNaClDefaultOptions; | |
| 42 } | |
| 43 } | |
| 44 return NULL; | |
| 45 } | |
| 46 #endif // ADDRESS_SANITIZER | |
| 9 | 47 |
| 10 extern "C" { | 48 extern "C" { |
| 11 int ChromeMain(int argc, char** argv); | 49 int ChromeMain(int argc, char** argv); |
| 12 } // extern "C" | 50 } // extern "C" |
| 13 | 51 |
| 14 __attribute__((visibility("default"))) | 52 __attribute__((visibility("default"))) |
| 15 int main(int argc, char* argv[]) { | 53 int main(int argc, char* argv[]) { |
| 16 int rv = ChromeMain(argc, argv); | 54 int rv = ChromeMain(argc, argv); |
| 17 | 55 |
| 18 // exit, don't return from main, to avoid the apparent removal of main from | 56 // exit, don't return from main, to avoid the apparent removal of main from |
| 19 // stack backtraces under tail call optimization. | 57 // stack backtraces under tail call optimization. |
| 20 exit(rv); | 58 exit(rv); |
| 21 } | 59 } |
| OLD | NEW |