Index: base/base_paths_mac.mm |
diff --git a/base/base_paths_mac.mm b/base/base_paths_mac.mm |
index ec1398bf2c501701984a9a3d650ba3db7067a031..9bbc080937fd18735a4b86b547ae08dce79622cd 100644 |
--- a/base/base_paths_mac.mm |
+++ b/base/base_paths_mac.mm |
@@ -4,6 +4,7 @@ |
#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; |
Mark Mentovai
2011/05/23 20:59:17
Didn’t spot WARN_UNUSED_RESULT before. OK.
|
+ |
+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: |