Fix: don't call __builtin_return_address(0) on 32-bit powerpc
[lttng-ust.git] / liblttng-ust-dl / lttng-ust-dl.c
... / ...
CommitLineData
1/*
2 * Copyright (C) 2013 Paul Woegerer <paul.woegerer@mentor.com>
3 *
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
7 * the License.
8 *
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.
13 *
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
17 */
18
19#define _LGPL_SOURCE
20#define _GNU_SOURCE
21#include <lttng/ust-dlfcn.h>
22#include <inttypes.h>
23#include <link.h>
24#include <unistd.h>
25#include <stdio.h>
26#include <limits.h>
27#include <sys/types.h>
28#include <sys/stat.h>
29#include <signal.h>
30#include <sched.h>
31#include <stdarg.h>
32#include <helper.h>
33#include "usterr-signal-safe.h"
34
35#include <lttng/ust-compiler.h>
36#include <lttng/ust.h>
37
38#define TRACEPOINT_DEFINE
39#include "ust_dl.h"
40
41static void *(*__lttng_ust_plibc_dlopen)(const char *filename, int flag);
42static int (*__lttng_ust_plibc_dlclose)(void *handle);
43
44static
45void *_lttng_ust_dl_libc_dlopen(const char *filename, int flag)
46{
47 if (!__lttng_ust_plibc_dlopen) {
48 __lttng_ust_plibc_dlopen = dlsym(RTLD_NEXT, "dlopen");
49 if (__lttng_ust_plibc_dlopen == NULL) {
50 fprintf(stderr, "%s\n", dlerror());
51 return NULL;
52 }
53 }
54 return __lttng_ust_plibc_dlopen(filename, flag);
55}
56
57static
58int _lttng_ust_dl_libc_dlclose(void *handle)
59{
60 if (!__lttng_ust_plibc_dlclose) {
61 __lttng_ust_plibc_dlclose = dlsym(RTLD_NEXT, "dlclose");
62 if (__lttng_ust_plibc_dlclose == NULL) {
63 fprintf(stderr, "%s\n", dlerror());
64 return -1;
65 }
66 }
67 return __lttng_ust_plibc_dlclose(handle);
68}
69
70static
71void lttng_ust_dl_dlopen(void *so_base, const char *so_name, void *ip)
72{
73 char resolved_path[PATH_MAX];
74 struct stat sostat;
75
76 if (!realpath(so_name, resolved_path)) {
77 ERR("could not resolve path '%s'", so_name);
78 return;
79 }
80
81 if (stat(resolved_path, &sostat)) {
82 ERR("could not access file status for %s", resolved_path);
83 return;
84 }
85
86 tracepoint(lttng_ust_dl, dlopen,
87 so_base, resolved_path, sostat.st_size, sostat.st_mtime, ip);
88 return;
89}
90
91void *dlopen(const char *filename, int flag)
92{
93 void *handle = _lttng_ust_dl_libc_dlopen(filename, flag);
94 if (__tracepoint_ptrs_registered && handle) {
95 struct link_map *p = NULL;
96 if (dlinfo(handle, RTLD_DI_LINKMAP, &p) != -1 && p != NULL
97 && p->l_addr != 0)
98 lttng_ust_dl_dlopen((void *) p->l_addr, p->l_name,
99 LTTNG_UST_CALLER_IP());
100 }
101 return handle;
102}
103
104int dlclose(void *handle)
105{
106 if (__tracepoint_ptrs_registered && handle) {
107 struct link_map *p = NULL;
108 if (dlinfo(handle, RTLD_DI_LINKMAP, &p) != -1 && p != NULL
109 && p->l_addr != 0)
110 tracepoint(lttng_ust_dl, dlclose, (void *) p->l_addr,
111 LTTNG_UST_CALLER_IP());
112 }
113 return _lttng_ust_dl_libc_dlclose(handle);
114}
This page took 0.022879 seconds and 4 git commands to generate.