dlfcn.c revision 168314
133180Sjdp/*-
233180Sjdp * Copyright (c) 1998 John D. Polstra
333180Sjdp * All rights reserved.
433180Sjdp *
533180Sjdp * Redistribution and use in source and binary forms, with or without
633180Sjdp * modification, are permitted provided that the following conditions
733180Sjdp * are met:
833180Sjdp * 1. Redistributions of source code must retain the above copyright
933180Sjdp *    notice, this list of conditions and the following disclaimer.
1033180Sjdp * 2. Redistributions in binary form must reproduce the above copyright
1133180Sjdp *    notice, this list of conditions and the following disclaimer in the
1233180Sjdp *    documentation and/or other materials provided with the distribution.
1333180Sjdp *
1433180Sjdp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1533180Sjdp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1633180Sjdp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1733180Sjdp * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1833180Sjdp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1933180Sjdp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2033180Sjdp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2133180Sjdp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2233180Sjdp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2333180Sjdp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2433180Sjdp * SUCH DAMAGE.
2533180Sjdp */
2633180Sjdp
2790039Sobrien#include <sys/cdefs.h>
2890039Sobrien__FBSDID("$FreeBSD: head/lib/libc/gen/dlfcn.c 168314 2007-04-03 18:35:20Z kan $");
2990039Sobrien
3033180Sjdp/*
31103436Speter * Linkage to services provided by the dynamic linker.
3233180Sjdp */
3334196Sjdp#include <dlfcn.h>
34168314Skan#include <link.h>
3534196Sjdp#include <stddef.h>
3634196Sjdp
3734196Sjdpstatic const char sorry[] = "Service unavailable";
3834196Sjdp
3934196Sjdp/*
4034196Sjdp * For ELF, the dynamic linker directly resolves references to its
4134196Sjdp * services to functions inside the dynamic linker itself.  These
4234196Sjdp * weak-symbol stubs are necessary so that "ld" won't complain about
4334196Sjdp * undefined symbols.  The stubs are executed only when the program is
4434196Sjdp * linked statically, or when a given service isn't implemented in the
4534196Sjdp * dynamic linker.  They must return an error if called, and they must
4634196Sjdp * be weak symbols so that the dynamic linker can override them.
4734196Sjdp */
4834196Sjdp
4934196Sjdp#pragma weak _rtld_error
5034196Sjdpvoid
5134196Sjdp_rtld_error(const char *fmt, ...)
5234196Sjdp{
5334196Sjdp}
5434196Sjdp
5534196Sjdp#pragma weak dladdr
5634196Sjdpint
5734196Sjdpdladdr(const void *addr, Dl_info *dlip)
5834196Sjdp{
5934196Sjdp	_rtld_error(sorry);
6034196Sjdp	return 0;
6134196Sjdp}
6234196Sjdp
6334196Sjdp#pragma weak dlclose
6434196Sjdpint
6534196Sjdpdlclose(void *handle)
6634196Sjdp{
6734196Sjdp	_rtld_error(sorry);
6834196Sjdp	return -1;
6934196Sjdp}
7034196Sjdp
7134196Sjdp#pragma weak dlerror
7234196Sjdpconst char *
7334196Sjdpdlerror(void)
7434196Sjdp{
7534196Sjdp	return sorry;
7634196Sjdp}
7734196Sjdp
7855122Sjdp#pragma weak dllockinit
7955122Sjdpvoid
8055122Sjdpdllockinit(void *context,
8155122Sjdp	   void *(*lock_create)(void *context),
8255122Sjdp	   void (*rlock_acquire)(void *lock),
8355122Sjdp	   void (*wlock_acquire)(void *lock),
8455122Sjdp	   void (*lock_release)(void *lock),
8555122Sjdp	   void (*lock_destroy)(void *lock),
8655122Sjdp	   void (*context_destroy)(void *context))
8755122Sjdp{
8855122Sjdp	if (context_destroy != NULL)
8955122Sjdp		context_destroy(context);
9055122Sjdp}
9155122Sjdp
9234196Sjdp#pragma weak dlopen
9334196Sjdpvoid *
9434196Sjdpdlopen(const char *name, int mode)
9534196Sjdp{
9634196Sjdp	_rtld_error(sorry);
9734196Sjdp	return NULL;
9834196Sjdp}
9934196Sjdp
10034196Sjdp#pragma weak dlsym
10134196Sjdpvoid *
102103213Smikedlsym(void * __restrict handle, const char * __restrict name)
10334196Sjdp{
10434196Sjdp	_rtld_error(sorry);
10534196Sjdp	return NULL;
10634196Sjdp}
107110804Skan
108153515Skan#pragma weak dlvsym
109153515Skanvoid *
110153515Skandlvsym(void * __restrict handle, const char * __restrict name,
111153515Skan    const char * __restrict version)
112153515Skan{
113153515Skan	_rtld_error(sorry);
114153515Skan	return NULL;
115153515Skan}
116153515Skan
117110804Skan#pragma weak dlinfo
118110804Skanint
119110804Skandlinfo(void * __restrict handle, int request, void * __restrict p)
120110804Skan{
121110804Skan	_rtld_error(sorry);
122126643Smarkm	return 0;
123110804Skan}
124115401Skan
125115401Skan#pragma weak _rtld_thread_init
126115401Skanvoid
127115401Skan_rtld_thread_init(void * li)
128115401Skan{
129115401Skan	_rtld_error(sorry);
130115401Skan}
131168314Skan
132168314Skan#pragma weak dl_iterate_phdr
133168314Skanint
134168314Skandl_iterate_phdr(int (*callback)(struct dl_phdr_info *, size_t, void *),
135168314Skan    void *data)
136168314Skan{
137168314Skan	_rtld_error(sorry);
138168314Skan	return 0;
139168314Skan}
140