dlfcn.c revision 190673
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 190673 2009-04-03 19:17:23Z kib $");
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
108190673Skib#pragma weak dlfunc
109190673Skibdlfunc_t
110190673Skibdlfunc(void * __restrict handle, const char * __restrict name)
111190673Skib{
112190673Skib	_rtld_error(sorry);
113190673Skib	return NULL;
114190673Skib}
115190673Skib
116153515Skan#pragma weak dlvsym
117153515Skanvoid *
118153515Skandlvsym(void * __restrict handle, const char * __restrict name,
119153515Skan    const char * __restrict version)
120153515Skan{
121153515Skan	_rtld_error(sorry);
122153515Skan	return NULL;
123153515Skan}
124153515Skan
125110804Skan#pragma weak dlinfo
126110804Skanint
127110804Skandlinfo(void * __restrict handle, int request, void * __restrict p)
128110804Skan{
129110804Skan	_rtld_error(sorry);
130126643Smarkm	return 0;
131110804Skan}
132115401Skan
133115401Skan#pragma weak _rtld_thread_init
134115401Skanvoid
135115401Skan_rtld_thread_init(void * li)
136115401Skan{
137115401Skan	_rtld_error(sorry);
138115401Skan}
139168314Skan
140168314Skan#pragma weak dl_iterate_phdr
141168314Skanint
142168314Skandl_iterate_phdr(int (*callback)(struct dl_phdr_info *, size_t, void *),
143168314Skan    void *data)
144168314Skan{
145168314Skan	_rtld_error(sorry);
146168314Skan	return 0;
147168314Skan}
148185369Skib
149185369Skib#pragma weak _rtld_atfork_pre
150185369Skibvoid
151185369Skib_rtld_atfork_pre(int *locks)
152185369Skib{
153185369Skib}
154185369Skib
155185369Skib#pragma weak _rtld_atfork_post
156185369Skibvoid
157185369Skib_rtld_atfork_post(int *locks)
158185369Skib{
159185369Skib}
160