2 * Copyright (C) 2013 Paul Woegerer <paul.woegerer@mentor.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; version 2.1 of
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <lttng/ust-dlfcn.h>
27 #include <sys/types.h>
34 #include <lttng/ust-compiler.h>
35 #include <lttng/ust.h>
37 #define TRACEPOINT_DEFINE
38 #include "ust_baddr.h"
40 static void *(*__lttng_ust_plibc_dlopen
)(const char *filename
, int flag
);
41 static int (*__lttng_ust_plibc_dlclose
)(void *handle
);
44 void *_lttng_ust_dl_libc_dlopen(const char *filename
, int flag
)
46 if (!__lttng_ust_plibc_dlopen
) {
47 __lttng_ust_plibc_dlopen
= dlsym(RTLD_NEXT
, "dlopen");
48 if (__lttng_ust_plibc_dlopen
== NULL
) {
49 fprintf(stderr
, "%s\n", dlerror());
53 return __lttng_ust_plibc_dlopen(filename
, flag
);
57 int _lttng_ust_dl_libc_dlclose(void *handle
)
59 if (!__lttng_ust_plibc_dlclose
) {
60 __lttng_ust_plibc_dlclose
= dlsym(RTLD_NEXT
, "dlclose");
61 if (__lttng_ust_plibc_dlclose
== NULL
) {
62 fprintf(stderr
, "%s\n", dlerror());
66 return __lttng_ust_plibc_dlclose(handle
);
70 void lttng_ust_baddr_push(void *so_base
, const char *so_name
)
72 char resolved_path
[PATH_MAX
];
75 if (!realpath(so_name
, resolved_path
)) {
76 ERR("could not resolve path '%s'", so_name
);
80 if (stat(resolved_path
, &sostat
)) {
81 ERR("could not access file status for %s", resolved_path
);
85 tracepoint(ust_baddr
, push
,
86 so_base
, resolved_path
, sostat
.st_size
, sostat
.st_mtime
);
90 void *dlopen(const char *filename
, int flag
)
92 void *handle
= _lttng_ust_dl_libc_dlopen(filename
, flag
);
93 if (__tracepoint_ptrs_registered
&& handle
) {
94 struct link_map
*p
= NULL
;
95 if (dlinfo(handle
, RTLD_DI_LINKMAP
, &p
) != -1 && p
!= NULL
97 lttng_ust_baddr_push((void *) p
->l_addr
, p
->l_name
);
102 int dlclose(void *handle
)
104 if (__tracepoint_ptrs_registered
&& handle
) {
105 struct link_map
*p
= NULL
;
106 if (dlinfo(handle
, RTLD_DI_LINKMAP
, &p
) != -1 && p
!= NULL
108 tracepoint(ust_baddr
, pop
, (void *) p
->l_addr
);
110 return _lttng_ust_dl_libc_dlclose(handle
);