1 | // Licensed to the .NET Foundation under one or more agreements. |
2 | // The .NET Foundation licenses this file to you under the MIT license. |
3 | // See the LICENSE file in the project root for more information. |
4 | |
5 | /*++ |
6 | |
7 | |
8 | |
9 | Module Name: |
10 | |
11 | modulename.cpp |
12 | |
13 | Abstract: |
14 | |
15 | Implementation of internal functions to get module names |
16 | |
17 | |
18 | |
19 | --*/ |
20 | |
21 | #include "pal/thread.hpp" |
22 | #include "pal/malloc.hpp" |
23 | #include "pal/palinternal.h" |
24 | #include "pal/dbgmsg.h" |
25 | #include "pal/modulename.h" |
26 | |
27 | #if NEED_DLCOMPAT |
28 | #include "dlcompat.h" |
29 | #else // NEED_DLCOMPAT |
30 | #include <dlfcn.h> |
31 | #endif // NEED_DLCOMPAT |
32 | |
33 | using namespace CorUnix; |
34 | |
35 | SET_DEFAULT_DEBUG_CHANNEL(LOADER); |
36 | |
37 | /*++ |
38 | PAL_dladdr |
39 | |
40 | Internal wrapper for dladder used only to get module name |
41 | |
42 | Parameters: |
43 | LPVOID ProcAddress: a pointer to a function in a shared library |
44 | |
45 | Return value: |
46 | Pointer to string with the fullpath to the shared library containing |
47 | ProcAddress. |
48 | |
49 | NULL if error occurred. |
50 | |
51 | Notes: |
52 | The string returned by this function is owned by the OS. |
53 | If you need to keep it, strdup() it, because it is unknown how long |
54 | this ptr will point at the string you want (over the lifetime of |
55 | the system running) It is only safe to use it immediately after calling |
56 | this function. |
57 | --*/ |
58 | const char *PAL_dladdr(LPVOID ProcAddress) |
59 | { |
60 | Dl_info dl_info; |
61 | if (!dladdr(ProcAddress, &dl_info)) |
62 | { |
63 | WARN("dladdr() call failed!\n" ); |
64 | /* If we get an error, return NULL */ |
65 | return (NULL); |
66 | } |
67 | else |
68 | { |
69 | /* Return the module name */ |
70 | return dl_info.dli_fname; |
71 | } |
72 | } |
73 | |
74 | |