Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
|
Mark Mentovai
2015/10/23 20:56:35
Basically a new file, Copyright 2015, no (c)
Greg K
2015/10/30 20:12:16
Done.
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // The entry point for all Mac Chromium processes, including the outer app | |
| 6 // bundle (browser) and helper app (renderer, plugin, and friends). | |
| 7 | |
| 8 #include <dlfcn.h> | |
| 9 #include <errno.h> | |
| 10 #include <libgen.h> | |
| 11 #include <mach-o/dyld.h> | |
| 12 #include <stdio.h> | |
| 13 #include <stdlib.h> | |
| 14 #include <string.h> | |
| 15 #include <unistd.h> | |
| 16 | |
| 17 #include "chrome/common/chrome_version.h" | |
| 18 | |
| 19 typedef int (*ChromeMainPtr)(int, char**); | |
| 20 | |
| 21 __attribute__((visibility("default"))) int main(int argc, char* argv[]) { | |
| 22 #if defined(HELPER_EXECUTABLE) | |
| 23 const char* const rel_path = | |
| 24 "../../../" PRODUCT_FULLNAME_STRING | |
| 25 " Framework.framework/" PRODUCT_FULLNAME_STRING " Framework"; | |
| 26 #else | |
| 27 const char* const rel_path = | |
| 28 "../Versions/" CHROME_VERSION_STRING "/" PRODUCT_FULLNAME_STRING | |
| 29 " Framework.framework/" PRODUCT_FULLNAME_STRING " Framework"; | |
| 30 #endif // defined(HELPER_EXECUTABLE) | |
| 31 | |
| 32 uint32_t exec_path_size = 0; | |
| 33 int rc = _NSGetExecutablePath(NULL, &exec_path_size); | |
| 34 if (rc != -1) { | |
| 35 fprintf(stderr, | |
| 36 "Unexpected return condition from _NSGetExecutablePath().\n"); | |
|
Mark Mentovai
2015/10/23 20:56:35
Let’s rationalize these too, so, like, "_NSGetExec
Greg K
2015/10/30 20:12:16
Done.
| |
| 37 abort(); | |
| 38 } | |
| 39 | |
| 40 char* exec_path = malloc(exec_path_size); | |
| 41 if (!exec_path) { | |
| 42 fprintf(stderr, "malloc %u: %s\n", exec_path_size, strerror(errno)); | |
| 43 abort(); | |
| 44 } | |
| 45 | |
| 46 rc = _NSGetExecutablePath(exec_path, &exec_path_size); | |
| 47 if (rc != 0) { | |
| 48 fprintf(stderr, | |
| 49 "_NSGetExecutablePath() call failed, " | |
| 50 "cannot calculate framework path.\n"); | |
| 51 abort(); | |
| 52 } | |
| 53 | |
| 54 // Slice off the last part of the main executable path, and append the | |
| 55 // version framework information. | |
| 56 char* parent_dir = dirname(exec_path); | |
| 57 if (!parent_dir) { | |
| 58 fprintf(stderr, "dirname %s: %s\n", exec_path, strerror(errno)); | |
| 59 abort(); | |
| 60 } | |
| 61 free(exec_path); | |
| 62 | |
| 63 size_t parent_path_len = strlen(parent_dir); | |
| 64 size_t rel_path_len = strlen(rel_path); | |
| 65 // 2 accounts for a trailing NIL byte and the '/' in the middle of the paths. | |
|
Mark Mentovai
2015/10/23 20:56:35
NUL, not NIL
Greg K
2015/10/30 20:12:16
Done.
| |
| 66 size_t framework_path_size = parent_path_len + rel_path_len + 2; | |
| 67 char* framework_path = malloc(framework_path_size); | |
| 68 if (!framework_path) { | |
| 69 fprintf(stderr, "malloc %zu: %s\n", framework_path_size, strerror(errno)); | |
| 70 abort(); | |
| 71 } | |
| 72 snprintf(framework_path, framework_path_size, "%s/%s", parent_dir, rel_path); | |
| 73 | |
| 74 void* library = dlopen(framework_path, RTLD_LAZY | RTLD_LOCAL | RTLD_FIRST); | |
| 75 if (!library) { | |
| 76 fprintf(stderr, "dlopen %s: %s\n", framework_path, dlerror()); | |
| 77 abort(); | |
| 78 } | |
| 79 free(framework_path); | |
| 80 | |
| 81 ChromeMainPtr chrome_main = dlsym(library, "ChromeMain"); | |
| 82 if (!chrome_main) { | |
| 83 fprintf(stderr, "dlopen ChromeMain: %s\n", dlerror()); | |
|
Mark Mentovai
2015/10/23 20:56:35
dlsym
Greg K
2015/10/30 20:12:16
Done.
| |
| 84 abort(); | |
| 85 } | |
| 86 int rv = chrome_main(argc, argv); | |
|
Mark Mentovai
2015/10/23 20:56:35
Share rc and rv (probably named rv)
| |
| 87 | |
| 88 // exit, don't return from main, to avoid the apparent removal of main from | |
| 89 // stack backtraces under tail call optimization. | |
| 90 exit(rv); | |
| 91 } | |
| OLD | NEW |