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 #include <stdlib.h> | 8 #include <stdlib.h> |
| 9 #include <string.h> | |
| 10 | |
| 11 #if defined(ADDRESS_SANITIZER) | |
| 12 // NaCl doesn't play well with ASan's signal handler, so we need to add | |
|
Mark Seaborn
2013/11/29 16:50:36
You mean ASan doesn't play well with NaCl's signal
Alexander Potapenko
2013/12/02 15:50:19
I think we've discussed signal handler chaining so
| |
| 13 // handle_segv=0 to ASAN_OPTIONS. This is done by injecting | |
| 14 // __asan_default_options into the executable. | |
| 15 // Because there's no distinct NaCl executable on OSX, we have to look at the | |
| 16 // command line arguments to understand whether the process is a NaCl loader. | |
| 17 | |
| 18 static const char kNaClDefaultOptions[] = "handle_segv=0"; | |
| 19 static const char kNaclFlag[] = "--type=nacl-loader"; | |
|
Mark Seaborn
2013/11/29 16:50:36
"Nacl" -> "NaCl"
Alexander Potapenko
2013/12/02 15:50:19
Done.
| |
| 20 | |
| 21 extern "C" { | |
| 22 char ***_NSGetArgv(); | |
|
Mark Seaborn
2013/11/29 16:50:36
You can get this decl from crt_externs.h
Alexander Potapenko
2013/12/02 15:50:19
Done. Let me know if you prefer not having #ifdef
| |
| 23 | |
| 24 // __asan_default_options() is called at ASan initialization, so it must | |
| 25 // not be instrumented with ASan -- thus the "no_sanitize_address" attribute. | |
| 26 __attribute__((no_sanitize_address)) | |
| 27 __attribute__((used)) | |
|
Mark Seaborn
2013/11/29 16:50:36
Why do you need this? I thought this is only used
Alexander Potapenko
2013/12/02 15:50:19
Because this function is only referenced from the
Mark Seaborn
2013/12/02 16:51:32
Ah, with Clang, __attribute__((used)) adds the fun
| |
| 28 __attribute__((visibility("default"))) | |
| 29 const char* __asan_default_options() { | |
| 30 char ***argvp = _NSGetArgv(); | |
|
Mark Seaborn
2013/11/29 16:50:36
Nit: Use "*** " spacing (Chromium style)
Alexander Potapenko
2013/12/02 15:50:19
Done.
| |
| 31 if (!argvp) return NULL; | |
| 32 char **argv = *argvp; | |
| 33 bool is_nacl = false; | |
| 34 const int kNaclFlagLen = strlen(kNaclFlag); | |
| 35 for (int i = 0; argv[i]; ++i) { | |
|
Mark Seaborn
2013/11/29 16:50:36
Should you use _NSGetArgc() rather than assuming t
Alexander Potapenko
2013/12/02 15:50:19
I think the system somewhat guarantees that, but _
| |
| 36 if (strncmp(argv[i], kNaclFlag, kNaclFlagLen + 1) == 0) { | |
|
Mark Seaborn
2013/11/29 16:50:36
Why not "strcmp(argv[i], kNaClFlag)"? You don't n
Alexander Potapenko
2013/12/02 15:50:19
Done.
| |
| 37 is_nacl = true; | |
|
Mark Seaborn
2013/11/29 16:50:36
You could just do "return kNaClDefaultOptions" her
Alexander Potapenko
2013/12/02 15:50:19
True.
| |
| 38 break; | |
| 39 } | |
| 40 } | |
| 41 if (is_nacl) { | |
| 42 return kNaClDefaultOptions; | |
| 43 } else { | |
| 44 return NULL; | |
| 45 } | |
| 46 } | |
| 47 } | |
| 48 #endif | |
| 9 | 49 |
| 10 extern "C" { | 50 extern "C" { |
| 11 int ChromeMain(int argc, char** argv); | 51 int ChromeMain(int argc, char** argv); |
| 12 } // extern "C" | 52 } // extern "C" |
| 13 | 53 |
| 14 __attribute__((visibility("default"))) | 54 __attribute__((visibility("default"))) |
| 15 int main(int argc, char* argv[]) { | 55 int main(int argc, char* argv[]) { |
| 16 int rv = ChromeMain(argc, argv); | 56 int rv = ChromeMain(argc, argv); |
| 17 | 57 |
| 18 // exit, don't return from main, to avoid the apparent removal of main from | 58 // exit, don't return from main, to avoid the apparent removal of main from |
| 19 // stack backtraces under tail call optimization. | 59 // stack backtraces under tail call optimization. |
| 20 exit(rv); | 60 exit(rv); |
| 21 } | 61 } |
| OLD | NEW |