xref: /dragonfly/lib/libc/gen/dlfcn.c (revision 650094e1)
1 /*-
2  * Copyright (c) 1998 John D. Polstra
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD: src/lib/libc/gen/dlfcn.c 217154 2011-01-08 17:13:43Z kib $
27  */
28 
29 #include <sys/mman.h>
30 #include <dlfcn.h>
31 #include <link.h>
32 #include <stddef.h>
33 
34 void	_rtld_error(const char *, ...);
35 
36 static char sorry[] = "Service unavailable";
37 
38 /*
39  * For ELF, the dynamic linker directly resolves references to its
40  * services to functions inside the dynamic linker itself.  These
41  * weak-symbol stubs are necessary so that "ld" won't complain about
42  * undefined symbols.  The stubs are executed only when the program is
43  * linked statically, or when a given service isn't implemented in the
44  * dynamic linker.  They must return an error if called, and they must
45  * be weak symbols so that the dynamic linker can override them.
46  */
47 
48 #pragma weak _rtld_error
49 void
50 _rtld_error(const char *fmt __unused, ...)
51 {
52 }
53 
54 #pragma weak dladdr
55 int
56 dladdr(const void *addr __unused, Dl_info *dlip __unused)
57 {
58 	_rtld_error(sorry);
59 	return 0;
60 }
61 
62 #pragma weak dlclose
63 int
64 dlclose(void *handle __unused)
65 {
66 	_rtld_error(sorry);
67 	return -1;
68 }
69 
70 #pragma weak dlerror
71 char *
72 dlerror(void)
73 {
74 	return sorry;
75 }
76 
77 #pragma weak dlopen
78 void *
79 dlopen(const char *name __unused, int mode __unused)
80 {
81 	_rtld_error(sorry);
82 	return NULL;
83 }
84 
85 #pragma weak dlsym
86 void *
87 dlsym(void *handle __unused, const char *name __unused)
88 {
89 	_rtld_error(sorry);
90 	return NULL;
91 }
92 
93 #pragma weak dlfunc
94 dlfunc_t
95 dlfunc(void * handle __unused, const char * name __unused)
96 {
97 	_rtld_error(sorry);
98 	return NULL;
99 }
100 
101 #pragma weak dlvsym
102 void *
103 dlvsym(void *handle __unused,const char *name __unused,
104     const char *version __unused)
105 {
106 	_rtld_error(sorry);
107 	return NULL;
108 }
109 
110 #pragma weak dlinfo
111 int
112 dlinfo(void *handle __unused, int request __unused, void *p __unused)
113 {
114 	_rtld_error(sorry);
115 	return 0;
116 }
117 
118 #pragma weak dl_iterate_phdr
119 int
120 dl_iterate_phdr(int (*callback)(struct dl_phdr_info *, size_t, void *),
121     void *data)
122 {
123 	_rtld_error(sorry);
124 	return 0;
125 }
126 
127 #pragma weak _rtld_addr_phdr
128 int
129 _rtld_addr_phdr(const void *addr, struct dl_phdr_info *phdr_info)
130 {
131 
132 	return (0);
133 }
134 
135 #pragma weak _rtld_get_stack_prot
136 int
137 _rtld_get_stack_prot(void)
138 {
139 	return (PROT_EXEC | PROT_READ | PROT_WRITE);
140 }
141