Index: chrome/app/chrome_exe_main_mac.c |
diff --git a/chrome/app/chrome_exe_main_mac.c b/chrome/app/chrome_exe_main_mac.c |
new file mode 100644 |
index 0000000000000000000000000000000000000000..aec408f95c6fead9a3bc92a7d58f5a15cc8c9993 |
--- /dev/null |
+++ b/chrome/app/chrome_exe_main_mac.c |
@@ -0,0 +1,91 @@ |
+// 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.
|
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+// The entry point for all Mac Chromium processes, including the outer app |
+// bundle (browser) and helper app (renderer, plugin, and friends). |
+ |
+#include <dlfcn.h> |
+#include <errno.h> |
+#include <libgen.h> |
+#include <mach-o/dyld.h> |
+#include <stdio.h> |
+#include <stdlib.h> |
+#include <string.h> |
+#include <unistd.h> |
+ |
+#include "chrome/common/chrome_version.h" |
+ |
+typedef int (*ChromeMainPtr)(int, char**); |
+ |
+__attribute__((visibility("default"))) int main(int argc, char* argv[]) { |
+#if defined(HELPER_EXECUTABLE) |
+ const char* const rel_path = |
+ "../../../" PRODUCT_FULLNAME_STRING |
+ " Framework.framework/" PRODUCT_FULLNAME_STRING " Framework"; |
+#else |
+ const char* const rel_path = |
+ "../Versions/" CHROME_VERSION_STRING "/" PRODUCT_FULLNAME_STRING |
+ " Framework.framework/" PRODUCT_FULLNAME_STRING " Framework"; |
+#endif // defined(HELPER_EXECUTABLE) |
+ |
+ uint32_t exec_path_size = 0; |
+ int rc = _NSGetExecutablePath(NULL, &exec_path_size); |
+ if (rc != -1) { |
+ fprintf(stderr, |
+ "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.
|
+ abort(); |
+ } |
+ |
+ char* exec_path = malloc(exec_path_size); |
+ if (!exec_path) { |
+ fprintf(stderr, "malloc %u: %s\n", exec_path_size, strerror(errno)); |
+ abort(); |
+ } |
+ |
+ rc = _NSGetExecutablePath(exec_path, &exec_path_size); |
+ if (rc != 0) { |
+ fprintf(stderr, |
+ "_NSGetExecutablePath() call failed, " |
+ "cannot calculate framework path.\n"); |
+ abort(); |
+ } |
+ |
+ // Slice off the last part of the main executable path, and append the |
+ // version framework information. |
+ char* parent_dir = dirname(exec_path); |
+ if (!parent_dir) { |
+ fprintf(stderr, "dirname %s: %s\n", exec_path, strerror(errno)); |
+ abort(); |
+ } |
+ free(exec_path); |
+ |
+ size_t parent_path_len = strlen(parent_dir); |
+ size_t rel_path_len = strlen(rel_path); |
+ // 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.
|
+ size_t framework_path_size = parent_path_len + rel_path_len + 2; |
+ char* framework_path = malloc(framework_path_size); |
+ if (!framework_path) { |
+ fprintf(stderr, "malloc %zu: %s\n", framework_path_size, strerror(errno)); |
+ abort(); |
+ } |
+ snprintf(framework_path, framework_path_size, "%s/%s", parent_dir, rel_path); |
+ |
+ void* library = dlopen(framework_path, RTLD_LAZY | RTLD_LOCAL | RTLD_FIRST); |
+ if (!library) { |
+ fprintf(stderr, "dlopen %s: %s\n", framework_path, dlerror()); |
+ abort(); |
+ } |
+ free(framework_path); |
+ |
+ ChromeMainPtr chrome_main = dlsym(library, "ChromeMain"); |
+ if (!chrome_main) { |
+ 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.
|
+ abort(); |
+ } |
+ int rv = chrome_main(argc, argv); |
Mark Mentovai
2015/10/23 20:56:35
Share rc and rv (probably named rv)
|
+ |
+ // exit, don't return from main, to avoid the apparent removal of main from |
+ // stack backtraces under tail call optimization. |
+ exit(rv); |
+} |