| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <dlfcn.h> | 8 #include <dlfcn.h> |
| 9 #include <errno.h> | 9 #include <errno.h> |
| 10 #include <libgen.h> | 10 #include <libgen.h> |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 " Framework.framework/" PRODUCT_FULLNAME_STRING " Framework"; | 31 " Framework.framework/" PRODUCT_FULLNAME_STRING " Framework"; |
| 32 #endif // defined(HELPER_EXECUTABLE) | 32 #endif // defined(HELPER_EXECUTABLE) |
| 33 | 33 |
| 34 uint32_t exec_path_size = 0; | 34 uint32_t exec_path_size = 0; |
| 35 int rv = _NSGetExecutablePath(NULL, &exec_path_size); | 35 int rv = _NSGetExecutablePath(NULL, &exec_path_size); |
| 36 if (rv != -1) { | 36 if (rv != -1) { |
| 37 fprintf(stderr, "_NSGetExecutablePath: get length failed\n"); | 37 fprintf(stderr, "_NSGetExecutablePath: get length failed\n"); |
| 38 abort(); | 38 abort(); |
| 39 } | 39 } |
| 40 | 40 |
| 41 char* exec_path = malloc(exec_path_size); | 41 char* exec_path = new char[exec_path_size]; |
| 42 if (!exec_path) { | 42 if (!exec_path) { |
| 43 fprintf(stderr, "malloc %u: %s\n", exec_path_size, strerror(errno)); | 43 fprintf(stderr, "malloc %u: %s\n", exec_path_size, strerror(errno)); |
| 44 abort(); | 44 abort(); |
| 45 } | 45 } |
| 46 | 46 |
| 47 rv = _NSGetExecutablePath(exec_path, &exec_path_size); | 47 rv = _NSGetExecutablePath(exec_path, &exec_path_size); |
| 48 if (rv != 0) { | 48 if (rv != 0) { |
| 49 fprintf(stderr, "_NSGetExecutablePath: get path failed\n"); | 49 fprintf(stderr, "_NSGetExecutablePath: get path failed\n"); |
| 50 abort(); | 50 abort(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 // Slice off the last part of the main executable path, and append the | 53 // Slice off the last part of the main executable path, and append the |
| 54 // version framework information. | 54 // version framework information. |
| 55 const char* parent_dir = dirname(exec_path); | 55 const char* parent_dir = dirname(exec_path); |
| 56 if (!parent_dir) { | 56 if (!parent_dir) { |
| 57 fprintf(stderr, "dirname %s: %s\n", exec_path, strerror(errno)); | 57 fprintf(stderr, "dirname %s: %s\n", exec_path, strerror(errno)); |
| 58 abort(); | 58 abort(); |
| 59 } | 59 } |
| 60 free(exec_path); | 60 delete[] exec_path; |
| 61 | 61 |
| 62 const size_t parent_path_len = strlen(parent_dir); | 62 const size_t parent_path_len = strlen(parent_dir); |
| 63 const size_t rel_path_len = strlen(rel_path); | 63 const size_t rel_path_len = strlen(rel_path); |
| 64 // 2 accounts for a trailing NUL byte and the '/' in the middle of the paths. | 64 // 2 accounts for a trailing NUL byte and the '/' in the middle of the paths. |
| 65 const size_t framework_path_size = parent_path_len + rel_path_len + 2; | 65 const size_t framework_path_size = parent_path_len + rel_path_len + 2; |
| 66 char* framework_path = malloc(framework_path_size); | 66 char* framework_path = new char[framework_path_size]; |
| 67 if (!framework_path) { | 67 if (!framework_path) { |
| 68 fprintf(stderr, "malloc %zu: %s\n", framework_path_size, strerror(errno)); | 68 fprintf(stderr, "malloc %zu: %s\n", framework_path_size, strerror(errno)); |
| 69 abort(); | 69 abort(); |
| 70 } | 70 } |
| 71 snprintf(framework_path, framework_path_size, "%s/%s", parent_dir, rel_path); | 71 snprintf(framework_path, framework_path_size, "%s/%s", parent_dir, rel_path); |
| 72 | 72 |
| 73 void* library = dlopen(framework_path, RTLD_LAZY | RTLD_LOCAL | RTLD_FIRST); | 73 void* library = dlopen(framework_path, RTLD_LAZY | RTLD_LOCAL | RTLD_FIRST); |
| 74 if (!library) { | 74 if (!library) { |
| 75 fprintf(stderr, "dlopen %s: %s\n", framework_path, dlerror()); | 75 fprintf(stderr, "dlopen %s: %s\n", framework_path, dlerror()); |
| 76 abort(); | 76 abort(); |
| 77 } | 77 } |
| 78 free(framework_path); | 78 delete[] framework_path; |
| 79 | 79 |
| 80 const ChromeMainPtr chrome_main = dlsym(library, "ChromeMain"); | 80 const ChromeMainPtr chrome_main = |
| 81 reinterpret_cast<ChromeMainPtr>(dlsym(library, "ChromeMain")); |
| 81 if (!chrome_main) { | 82 if (!chrome_main) { |
| 82 fprintf(stderr, "dlsym ChromeMain: %s\n", dlerror()); | 83 fprintf(stderr, "dlsym ChromeMain: %s\n", dlerror()); |
| 83 abort(); | 84 abort(); |
| 84 } | 85 } |
| 85 rv = chrome_main(argc, argv); | 86 rv = chrome_main(argc, argv); |
| 86 | 87 |
| 87 // exit, don't return from main, to avoid the apparent removal of main from | 88 // exit, don't return from main, to avoid the apparent removal of main from |
| 88 // stack backtraces under tail call optimization. | 89 // stack backtraces under tail call optimization. |
| 89 exit(rv); | 90 exit(rv); |
| 90 } | 91 } |
| OLD | NEW |