dlfcn.c revision 230410
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: stable/9/lib/libc/gen/dlfcn.c 230410 2012-01-21 01:24:06Z kib $");
2990039Sobrien
3033180Sjdp/*
31103436Speter * Linkage to services provided by the dynamic linker.
3233180Sjdp */
33217154Skib#include <sys/mman.h>
3434196Sjdp#include <dlfcn.h>
35168314Skan#include <link.h>
3634196Sjdp#include <stddef.h>
3734196Sjdp
38205606Sgahrstatic char sorry[] = "Service unavailable";
3934196Sjdp
4034196Sjdp/*
4134196Sjdp * For ELF, the dynamic linker directly resolves references to its
4234196Sjdp * services to functions inside the dynamic linker itself.  These
4334196Sjdp * weak-symbol stubs are necessary so that "ld" won't complain about
4434196Sjdp * undefined symbols.  The stubs are executed only when the program is
4534196Sjdp * linked statically, or when a given service isn't implemented in the
4634196Sjdp * dynamic linker.  They must return an error if called, and they must
4734196Sjdp * be weak symbols so that the dynamic linker can override them.
4834196Sjdp */
4934196Sjdp
5034196Sjdp#pragma weak _rtld_error
5134196Sjdpvoid
5234196Sjdp_rtld_error(const char *fmt, ...)
5334196Sjdp{
5434196Sjdp}
5534196Sjdp
5634196Sjdp#pragma weak dladdr
5734196Sjdpint
5834196Sjdpdladdr(const void *addr, Dl_info *dlip)
5934196Sjdp{
6034196Sjdp	_rtld_error(sorry);
6134196Sjdp	return 0;
6234196Sjdp}
6334196Sjdp
6434196Sjdp#pragma weak dlclose
6534196Sjdpint
6634196Sjdpdlclose(void *handle)
6734196Sjdp{
6834196Sjdp	_rtld_error(sorry);
6934196Sjdp	return -1;
7034196Sjdp}
7134196Sjdp
7234196Sjdp#pragma weak dlerror
73205606Sgahrchar *
7434196Sjdpdlerror(void)
7534196Sjdp{
7634196Sjdp	return sorry;
7734196Sjdp}
7834196Sjdp
7955122Sjdp#pragma weak dllockinit
8055122Sjdpvoid
8155122Sjdpdllockinit(void *context,
8255122Sjdp	   void *(*lock_create)(void *context),
8355122Sjdp	   void (*rlock_acquire)(void *lock),
8455122Sjdp	   void (*wlock_acquire)(void *lock),
8555122Sjdp	   void (*lock_release)(void *lock),
8655122Sjdp	   void (*lock_destroy)(void *lock),
8755122Sjdp	   void (*context_destroy)(void *context))
8855122Sjdp{
8955122Sjdp	if (context_destroy != NULL)
9055122Sjdp		context_destroy(context);
9155122Sjdp}
9255122Sjdp
9334196Sjdp#pragma weak dlopen
9434196Sjdpvoid *
9534196Sjdpdlopen(const char *name, int mode)
9634196Sjdp{
9734196Sjdp	_rtld_error(sorry);
9834196Sjdp	return NULL;
9934196Sjdp}
10034196Sjdp
10134196Sjdp#pragma weak dlsym
10234196Sjdpvoid *
103103213Smikedlsym(void * __restrict handle, const char * __restrict name)
10434196Sjdp{
10534196Sjdp	_rtld_error(sorry);
10634196Sjdp	return NULL;
10734196Sjdp}
108110804Skan
109190673Skib#pragma weak dlfunc
110190673Skibdlfunc_t
111190673Skibdlfunc(void * __restrict handle, const char * __restrict name)
112190673Skib{
113190673Skib	_rtld_error(sorry);
114190673Skib	return NULL;
115190673Skib}
116190673Skib
117153515Skan#pragma weak dlvsym
118153515Skanvoid *
119153515Skandlvsym(void * __restrict handle, const char * __restrict name,
120153515Skan    const char * __restrict version)
121153515Skan{
122153515Skan	_rtld_error(sorry);
123153515Skan	return NULL;
124153515Skan}
125153515Skan
126110804Skan#pragma weak dlinfo
127110804Skanint
128110804Skandlinfo(void * __restrict handle, int request, void * __restrict p)
129110804Skan{
130110804Skan	_rtld_error(sorry);
131126643Smarkm	return 0;
132110804Skan}
133115401Skan
134115401Skan#pragma weak _rtld_thread_init
135115401Skanvoid
136115401Skan_rtld_thread_init(void * li)
137115401Skan{
138115401Skan	_rtld_error(sorry);
139115401Skan}
140168314Skan
141168314Skan#pragma weak dl_iterate_phdr
142168314Skanint
143168314Skandl_iterate_phdr(int (*callback)(struct dl_phdr_info *, size_t, void *),
144168314Skan    void *data)
145168314Skan{
146168314Skan	_rtld_error(sorry);
147168314Skan	return 0;
148168314Skan}
149185369Skib
150230410Skib#pragma weak fdlopen
151230410Skibvoid *
152230410Skibfdlopen(int fd, int mode)
153230410Skib{
154230410Skib
155230410Skib	_rtld_error(sorry);
156230410Skib	return NULL;
157230410Skib}
158230410Skib
159185369Skib#pragma weak _rtld_atfork_pre
160185369Skibvoid
161185369Skib_rtld_atfork_pre(int *locks)
162185369Skib{
163185369Skib}
164185369Skib
165185369Skib#pragma weak _rtld_atfork_post
166185369Skibvoid
167185369Skib_rtld_atfork_post(int *locks)
168185369Skib{
169185369Skib}
170211705Skib
171211705Skib#pragma weak _rtld_addr_phdr
172211705Skibint
173211705Skib_rtld_addr_phdr(const void *addr, struct dl_phdr_info *phdr_info)
174211705Skib{
175211705Skib
176211705Skib	return (0);
177211705Skib}
178217154Skib
179217154Skib#pragma weak _rtld_get_stack_prot
180217154Skibint
181217154Skib_rtld_get_stack_prot(void)
182217154Skib{
183217154Skib
184217154Skib	return (PROT_EXEC | PROT_READ | PROT_WRITE);
185217154Skib}
186217154Skib
187