2007-10-28 19:13:50 +00:00
|
|
|
/***
|
|
|
|
|
This file is part of PulseAudio.
|
|
|
|
|
|
2008-12-16 19:11:16 +01:00
|
|
|
Copyright 2004-2008 Lennart Poettering
|
2007-10-28 19:13:50 +00:00
|
|
|
Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
|
|
|
|
|
|
|
|
|
|
PulseAudio is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published
|
|
|
|
|
by the Free Software Foundation; either version 2 of the License,
|
|
|
|
|
or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
PulseAudio is distributed in the hope that it will be useful, but
|
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with PulseAudio; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
|
USA.
|
|
|
|
|
***/
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2008-08-19 22:39:54 +02:00
|
|
|
#ifdef HAVE_DLFCN_H
|
2007-10-28 19:13:50 +00:00
|
|
|
#include <dlfcn.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2008-08-19 22:39:54 +02:00
|
|
|
#ifdef HAVE_SYS_DL_H
|
2007-10-28 19:13:50 +00:00
|
|
|
#include <sys/dl.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2008-03-08 23:30:08 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
#include <ltdl.h>
|
|
|
|
|
|
2008-08-06 18:54:13 +02:00
|
|
|
#include <pulse/i18n.h>
|
|
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
#include <pulsecore/macro.h>
|
|
|
|
|
#include <pulsecore/log.h>
|
|
|
|
|
|
|
|
|
|
#include "ltdl-bind-now.h"
|
|
|
|
|
|
|
|
|
|
#ifdef RTLD_NOW
|
|
|
|
|
#define PA_BIND_NOW RTLD_NOW
|
|
|
|
|
#elif defined(DL_NOW)
|
|
|
|
|
#define PA_BIND_NOW DL_NOW
|
|
|
|
|
#else
|
|
|
|
|
#undef PA_BIND_NOW
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef PA_BIND_NOW
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
To avoid lazy relocations during runtime in our RT threads we add
|
|
|
|
|
our own shared object loader with uses RTLD_NOW if it is
|
|
|
|
|
available. The standard ltdl loader prefers RTLD_LAZY.
|
|
|
|
|
|
|
|
|
|
Please note that this loader doesn't have any influence on
|
|
|
|
|
relocations on any libraries that are already loaded into our
|
|
|
|
|
process, i.e. because the pulseaudio binary links directly to
|
|
|
|
|
them. To disable lazy relocations for those libraries it is possible
|
|
|
|
|
to set $LT_BIND_NOW before starting the pulsaudio binary.
|
|
|
|
|
*/
|
|
|
|
|
|
2008-12-16 19:11:16 +01:00
|
|
|
static lt_module bind_now_open(lt_user_data d, const char *fname, lt_dladvise advise) {
|
2007-10-28 19:13:50 +00:00
|
|
|
lt_module m;
|
|
|
|
|
|
|
|
|
|
pa_assert(fname);
|
|
|
|
|
|
|
|
|
|
if (!(m = dlopen(fname, PA_BIND_NOW))) {
|
2008-12-16 19:11:16 +01:00
|
|
|
lt_dlseterror(LT_ERROR_CANNOT_OPEN);
|
2007-10-28 19:13:50 +00:00
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return m;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int bind_now_close(lt_user_data d, lt_module m) {
|
|
|
|
|
|
|
|
|
|
pa_assert(m);
|
|
|
|
|
|
|
|
|
|
if (dlclose(m) != 0){
|
2008-12-16 19:11:16 +01:00
|
|
|
lt_dlseterror(LT_ERROR_CANNOT_CLOSE);
|
2007-10-28 19:13:50 +00:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static lt_ptr bind_now_find_sym(lt_user_data d, lt_module m, const char *symbol) {
|
|
|
|
|
lt_ptr ptr;
|
|
|
|
|
|
|
|
|
|
pa_assert(m);
|
|
|
|
|
pa_assert(symbol);
|
|
|
|
|
|
|
|
|
|
if (!(ptr = dlsym(m, symbol))) {
|
2008-12-16 19:11:16 +01:00
|
|
|
lt_dlseterror(LT_ERROR_SYMBOL_NOT_FOUND);
|
2007-10-28 19:13:50 +00:00
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ptr;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-16 19:11:16 +01:00
|
|
|
static lt_dlvtable *bindnow_loader = NULL;
|
2007-10-28 19:13:50 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
void pa_ltdl_init(void) {
|
|
|
|
|
|
|
|
|
|
#ifdef PA_BIND_NOW
|
2008-12-16 19:11:16 +01:00
|
|
|
const lt_dlvtable *dlopen_loader;
|
2007-10-28 19:13:50 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
pa_assert_se(lt_dlinit() == 0);
|
2008-08-06 18:54:13 +02:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
#ifdef PA_BIND_NOW
|
2008-03-08 23:30:08 +00:00
|
|
|
/* Already initialised */
|
2008-12-16 19:11:16 +01:00
|
|
|
if (bindnow_loader)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!(dlopen_loader = lt_dlloader_find((char*) "lt_dlopen"))) {
|
|
|
|
|
pa_log_warn(_("Failed to find original lt_dlopen loader."));
|
2008-08-06 18:54:13 +02:00
|
|
|
return;
|
2008-12-16 19:11:16 +01:00
|
|
|
}
|
2008-03-08 23:30:08 +00:00
|
|
|
|
2008-12-16 19:11:16 +01:00
|
|
|
if (!(bindnow_loader = malloc(sizeof(lt_dlvtable)))) {
|
|
|
|
|
pa_log_error(_("Failed to allocate new dl loader."));
|
2008-08-06 18:54:13 +02:00
|
|
|
return;
|
2008-03-08 23:30:08 +00:00
|
|
|
}
|
|
|
|
|
|
2008-12-16 19:11:16 +01:00
|
|
|
memcpy(bindnow_loader, dlopen_loader, sizeof(*bindnow_loader));
|
|
|
|
|
bindnow_loader->name = "bind-now-loader";
|
|
|
|
|
bindnow_loader->module_open = bind_now_open;
|
|
|
|
|
bindnow_loader->module_close = bind_now_close;
|
|
|
|
|
bindnow_loader->find_sym = bind_now_find_sym;
|
|
|
|
|
bindnow_loader->priority = LT_DLLOADER_PREPEND;
|
2008-03-08 23:30:08 +00:00
|
|
|
|
|
|
|
|
/* Add our BIND_NOW loader as the default module loader. */
|
2008-12-16 19:11:16 +01:00
|
|
|
if (lt_dlloader_add(bindnow_loader) != 0) {
|
2008-08-06 18:54:13 +02:00
|
|
|
pa_log_warn(_("Failed to add bind-now-loader."));
|
2008-12-16 19:11:16 +01:00
|
|
|
free(bindnow_loader);
|
|
|
|
|
bindnow_loader = NULL;
|
|
|
|
|
}
|
2007-10-28 19:13:50 +00:00
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void pa_ltdl_done(void) {
|
|
|
|
|
pa_assert_se(lt_dlexit() == 0);
|
2008-12-16 19:11:16 +01:00
|
|
|
|
|
|
|
|
#ifdef PA_BIND_NOW
|
|
|
|
|
/* lt_dlexit() will free our loader vtable, hence reset our
|
|
|
|
|
* pointer to it here */
|
|
|
|
|
bindnow_loader = NULL;
|
|
|
|
|
#endif
|
2007-10-28 19:13:50 +00:00
|
|
|
}
|