dlfcn.c revision 115401
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 115401 2003-05-30 00:58:37Z kan $"); 2990039Sobrien 3033180Sjdp/* 31103436Speter * Linkage to services provided by the dynamic linker. 3233180Sjdp */ 3334196Sjdp#include <dlfcn.h> 3434196Sjdp#include <stddef.h> 3534196Sjdp 3634196Sjdpstatic const char sorry[] = "Service unavailable"; 3734196Sjdp 3834196Sjdp/* 3934196Sjdp * For ELF, the dynamic linker directly resolves references to its 4034196Sjdp * services to functions inside the dynamic linker itself. These 4134196Sjdp * weak-symbol stubs are necessary so that "ld" won't complain about 4234196Sjdp * undefined symbols. The stubs are executed only when the program is 4334196Sjdp * linked statically, or when a given service isn't implemented in the 4434196Sjdp * dynamic linker. They must return an error if called, and they must 4534196Sjdp * be weak symbols so that the dynamic linker can override them. 4634196Sjdp */ 4734196Sjdp 4834196Sjdp#pragma weak _rtld_error 4934196Sjdpvoid 5034196Sjdp_rtld_error(const char *fmt, ...) 5134196Sjdp{ 5234196Sjdp} 5334196Sjdp 5434196Sjdp#pragma weak dladdr 5534196Sjdpint 5634196Sjdpdladdr(const void *addr, Dl_info *dlip) 5734196Sjdp{ 5834196Sjdp _rtld_error(sorry); 5934196Sjdp return 0; 6034196Sjdp} 6134196Sjdp 6234196Sjdp#pragma weak dlclose 6334196Sjdpint 6434196Sjdpdlclose(void *handle) 6534196Sjdp{ 6634196Sjdp _rtld_error(sorry); 6734196Sjdp return -1; 6834196Sjdp} 6934196Sjdp 7034196Sjdp#pragma weak dlerror 7134196Sjdpconst char * 7234196Sjdpdlerror(void) 7334196Sjdp{ 7434196Sjdp return sorry; 7534196Sjdp} 7634196Sjdp 7755122Sjdp#pragma weak dllockinit 7855122Sjdpvoid 7955122Sjdpdllockinit(void *context, 8055122Sjdp void *(*lock_create)(void *context), 8155122Sjdp void (*rlock_acquire)(void *lock), 8255122Sjdp void (*wlock_acquire)(void *lock), 8355122Sjdp void (*lock_release)(void *lock), 8455122Sjdp void (*lock_destroy)(void *lock), 8555122Sjdp void (*context_destroy)(void *context)) 8655122Sjdp{ 8755122Sjdp if (context_destroy != NULL) 8855122Sjdp context_destroy(context); 8955122Sjdp} 9055122Sjdp 9134196Sjdp#pragma weak dlopen 9234196Sjdpvoid * 9334196Sjdpdlopen(const char *name, int mode) 9434196Sjdp{ 9534196Sjdp _rtld_error(sorry); 9634196Sjdp return NULL; 9734196Sjdp} 9834196Sjdp 9934196Sjdp#pragma weak dlsym 10034196Sjdpvoid * 101103213Smikedlsym(void * __restrict handle, const char * __restrict name) 10234196Sjdp{ 10334196Sjdp _rtld_error(sorry); 10434196Sjdp return NULL; 10534196Sjdp} 106110804Skan 107110804Skan#pragma weak dlinfo 108110804Skanint 109110804Skandlinfo(void * __restrict handle, int request, void * __restrict p) 110110804Skan{ 111110804Skan _rtld_error(sorry); 112110804Skan return NULL; 113110804Skan} 114115401Skan 115115401Skan#pragma weak _rtld_thread_init 116115401Skanvoid 117115401Skan_rtld_thread_init(void * li) 118115401Skan{ 119115401Skan _rtld_error(sorry); 120115401Skan} 121