]>
code.delx.au - pulseaudio/blob - src/daemon/ltdl-bind-now.c
4 This file is part of PulseAudio.
6 Copyright 2004-2006 Lennart Poettering
7 Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
9 PulseAudio is free software; you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published
11 by the Free Software Foundation; either version 2 of the License,
12 or (at your option) any later version.
14 PulseAudio is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
19 You should have received a copy of the GNU Lesser General Public License
20 along with PulseAudio; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
39 #include <pulsecore/macro.h>
40 #include <pulsecore/mutex.h>
41 #include <pulsecore/thread.h>
42 #include <pulsecore/log.h>
44 #include "ltdl-bind-now.h"
47 #define PA_BIND_NOW RTLD_NOW
49 #define PA_BIND_NOW DL_NOW
54 static pa_mutex
*libtool_mutex
= NULL
;
56 PA_STATIC_TLS_DECLARE_NO_FREE(libtool_tls
);
58 static void libtool_lock(void) {
59 pa_mutex_lock(libtool_mutex
);
62 static void libtool_unlock(void) {
63 pa_mutex_unlock(libtool_mutex
);
66 static void libtool_set_error(const char *error
) {
67 PA_STATIC_TLS_SET(libtool_tls
, (char*) error
);
70 static const char *libtool_get_error(void) {
71 return PA_STATIC_TLS_GET(libtool_tls
);
77 To avoid lazy relocations during runtime in our RT threads we add
78 our own shared object loader with uses RTLD_NOW if it is
79 available. The standard ltdl loader prefers RTLD_LAZY.
81 Please note that this loader doesn't have any influence on
82 relocations on any libraries that are already loaded into our
83 process, i.e. because the pulseaudio binary links directly to
84 them. To disable lazy relocations for those libraries it is possible
85 to set $LT_BIND_NOW before starting the pulsaudio binary.
88 static lt_module
bind_now_open(lt_user_data d
, const char *fname
) {
93 if (!(m
= dlopen(fname
, PA_BIND_NOW
))) {
94 libtool_set_error(dlerror());
101 static int bind_now_close(lt_user_data d
, lt_module m
) {
105 if (dlclose(m
) != 0){
106 libtool_set_error(dlerror());
113 static lt_ptr
bind_now_find_sym(lt_user_data d
, lt_module m
, const char *symbol
) {
119 if (!(ptr
= dlsym(m
, symbol
))) {
120 libtool_set_error(dlerror());
129 void pa_ltdl_init(void) {
133 static const struct lt_user_dlloader loader
= {
134 .module_open
= bind_now_open
,
135 .module_close
= bind_now_close
,
136 .find_sym
= bind_now_find_sym
140 pa_assert_se(lt_dlinit() == 0);
141 pa_assert_se(libtool_mutex
= pa_mutex_new(TRUE
, FALSE
));
142 pa_assert_se(lt_dlmutex_register(libtool_lock
, libtool_unlock
, libtool_set_error
, libtool_get_error
) == 0);
146 if (!(place
= lt_dlloader_find("dlopen")))
147 place
= lt_dlloader_next(NULL
);
149 /* Add our BIND_NOW loader as the default module loader. */
150 if (lt_dlloader_add(place
, &loader
, "bind-now-loader") != 0)
151 pa_log_warn("Failed to add bind-now-loader.");
155 void pa_ltdl_done(void) {
156 pa_assert_se(lt_dlexit() == 0);
157 pa_mutex_free(libtool_mutex
);
158 libtool_mutex
= NULL
;