summaryrefslogtreecommitdiff
path: root/src/pal/src/loader/modulename.cpp
blob: 87c1b026c281782239ff040cccaef58c764c7e1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

/*++



Module Name:

    modulename.cpp

Abstract:

    Implementation of internal functions to get module names



--*/

#include "pal/thread.hpp"
#include "pal/malloc.hpp"
#include "pal/palinternal.h"
#include "pal/dbgmsg.h"
#include "pal/modulename.h"

#if NEED_DLCOMPAT
#include "dlcompat.h"
#else   // NEED_DLCOMPAT
#include <dlfcn.h>
#endif  // NEED_DLCOMPAT

using namespace CorUnix;

SET_DEFAULT_DEBUG_CHANNEL(LOADER);

/*++
    PAL_dladdr

    Internal wrapper for dladder used only to get module name

Parameters:
    None

Return value:
    Pointer to string with the fullpath to the librotor_pal.so being
    used.

    NULL if error occurred.

Notes: 
    The string returned by this function is owned by the OS.
    If you need to keep it, strdup() it, because it is unknown how long
    this ptr will point at the string you want (over the lifetime of
    the system running)  It is only safe to use it immediately after calling
    this function.
--*/
const char *PAL_dladdr(LPVOID ProcAddress)
{
    Dl_info dl_info;
    if (!dladdr(ProcAddress, &dl_info))
    {
        WARN("dladdr() call failed! dlerror says '%s'\n", dlerror());
        /* If we get an error, return NULL */
        return (NULL);
    }
    else 
    {
        /* Return the module name */ 
        return dl_info.dli_fname;
    }
}