summaryrefslogtreecommitdiffstats
path: root/base/base_paths_mac.mm
diff options
context:
space:
mode:
authordmaclach@chromium.org <dmaclach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-25 16:23:06 +0000
committerdmaclach@chromium.org <dmaclach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-25 16:23:06 +0000
commit9e3fe3d34268d0193032d59dcf3a9c089110b88b (patch)
tree51d58d43ff4b13072da5d3b207862d78fa636790 /base/base_paths_mac.mm
parentdbbab20801ffa9e0018f2244bdbcb854c52b27d7 (diff)
downloadchromium_src-9e3fe3d34268d0193032d59dcf3a9c089110b88b.zip
chromium_src-9e3fe3d34268d0193032d59dcf3a9c089110b88b.tar.gz
chromium_src-9e3fe3d34268d0193032d59dcf3a9c089110b88b.tar.bz2
Fix up PathProvider on the Mac for FILE_MODULE.
PathProvider on the Mac always returned the FILE_EXE for FILE_MODULE, which isn't necessarily correct. BUG=NONE TEST=BUILD Review URL: http://codereview.chromium.org/7019041 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86631 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/base_paths_mac.mm')
-rw-r--r--base/base_paths_mac.mm21
1 files changed, 18 insertions, 3 deletions
diff --git a/base/base_paths_mac.mm b/base/base_paths_mac.mm
index ec1398b..90a274c 100644
--- a/base/base_paths_mac.mm
+++ b/base/base_paths_mac.mm
@@ -1,9 +1,10 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/base_paths_mac.h"
+#include <dlfcn.h>
#import <Foundation/Foundation.h>
#include <mach-o/dyld.h>
@@ -37,6 +38,19 @@ bool GetNSExecutablePath(FilePath* path) {
return true;
}
+// Returns true if the module for |address| is found. |path| will contain
+// the path to the module. Note that |path| may not be absolute.
+bool GetModulePathForAddress(FilePath* path,
+ const void* address) WARN_UNUSED_RESULT;
+
+bool GetModulePathForAddress(FilePath* path, const void* address) {
+ Dl_info info;
+ if (dladdr(address, &info) == 0)
+ return false;
+ *path = FilePath(info.dli_fname);
+ return true;
+}
+
} // namespace
namespace base {
@@ -44,9 +58,10 @@ namespace base {
bool PathProviderMac(int key, FilePath* result) {
switch (key) {
case base::FILE_EXE:
- case base::FILE_MODULE: {
return GetNSExecutablePath(result);
- }
+ case base::FILE_MODULE:
+ return GetModulePathForAddress(result,
+ reinterpret_cast<const void*>(&base::PathProviderMac));
case base::DIR_CACHE:
return base::mac::GetUserDirectory(NSCachesDirectory, result);
case base::DIR_APP_DATA: