1 /* $OpenBSD: dlfcn_stubs.c,v 1.12 2013/03/24 01:37:23 deraadt Exp $ */ 2 3 /* 4 * Copyright (c) 1998 Per Fogelstrom, Opsycon AB 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 16 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 19 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * 27 */ 28 29 #include <stddef.h> 30 31 /* 32 * All functions here are just stubs that will be overridden 33 * by the real functions in ld.so when dynamic loading is 34 * performed at exec. The symbols here are provided as a link 35 * helper so we can link a program using the dl functions 36 * without getting any unresolved references. 37 */ 38 39 void *dlopen(const char *libname, int how) __attribute__((weak)); 40 int dlclose(void *handle) __attribute__((weak)); 41 void *dlsym(void *handle, const char *name) __attribute__((weak)); 42 int dlctl(void *handle, int command, void *data) __attribute__((weak)); 43 char *dlerror(void) __attribute__((weak)); 44 45 struct dl_info; 46 int dladdr(const void *addr, struct dl_info *info) __attribute__((weak)); 47 48 struct dl_phdr_info; 49 int dl_iterate_phdr(int (*callback)(struct dl_phdr_info *, size_t, void *), void *date) __attribute__((weak)); 50 51 #include <stdio.h> 52 53 /*ARGSUSED*/ 54 void * 55 dlopen(const char *libname, int how) 56 { 57 printf("Wrong dl symbols!\n"); 58 return NULL; 59 } 60 61 /*ARGSUSED*/ 62 int 63 dlclose(void *handle) 64 { 65 printf("Wrong dl symbols!\n"); 66 return 0; 67 } 68 69 /*ARGSUSED*/ 70 void * 71 dlsym(void *handle, const char *name) 72 { 73 printf("Wrong dl symbols!\n"); 74 return NULL; 75 } 76 77 /*ARGSUSED*/ 78 int 79 dlctl(void *handle, int command, void *data) 80 { 81 return -1; 82 } 83 84 /*ARGSUSED*/ 85 char * 86 dlerror(void) 87 { 88 return "Wrong dl symbols!\n"; 89 } 90 91 /*ARGSUSED*/ 92 int 93 dl_iterate_phdr(int (*callback)(struct dl_phdr_info *, size_t, void *), 94 void *data) 95 { 96 return -1; 97 } 98 99 /*ARGSUSED*/ 100 int 101 dladdr(const void *addr, struct dl_info *info) 102 { 103 printf("Wrong dl symbols!\n"); 104 return -1; 105 } 106