Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <string.h> |
| 4 | #include <unistd.h> |
| 5 | #include <stdint.h> |
| 6 | #include <elf.h> |
| 7 | #include <sys/mman.h> |
| 8 | #include <limits.h> |
| 9 | #include <stdint.h> |
| 10 | #include <fcntl.h> |
| 11 | #include <sys/stat.h> |
| 12 | #include <errno.h> |
| 13 | #include <limits.h> |
| 14 | #include <elf.h> |
Rich Felker | 6b3d5e5 | 2011-06-26 17:39:17 -0400 | [diff] [blame] | 15 | #include <setjmp.h> |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 16 | #include <pthread.h> |
Rich Felker | 2719cc8 | 2011-08-16 00:24:36 -0400 | [diff] [blame] | 17 | #include <ctype.h> |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 18 | #include <dlfcn.h> |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 19 | |
| 20 | #include "reloc.h" |
| 21 | |
| 22 | #if ULONG_MAX == 0xffffffff |
| 23 | typedef Elf32_Ehdr Ehdr; |
| 24 | typedef Elf32_Phdr Phdr; |
| 25 | typedef Elf32_Sym Sym; |
| 26 | #define R_TYPE(x) ((x)&255) |
| 27 | #define R_SYM(x) ((x)>>8) |
| 28 | #else |
| 29 | typedef Elf64_Ehdr Ehdr; |
| 30 | typedef Elf64_Phdr Phdr; |
| 31 | typedef Elf64_Sym Sym; |
| 32 | #define R_TYPE(x) ((x)&0xffffffff) |
| 33 | #define R_SYM(x) ((x)>>32) |
| 34 | #endif |
| 35 | |
| 36 | struct dso |
| 37 | { |
| 38 | struct dso *next, *prev; |
| 39 | int refcnt; |
| 40 | size_t *dynv; |
| 41 | Sym *syms; |
Rich Felker | 596d60c | 2011-06-18 22:52:01 -0400 | [diff] [blame] | 42 | uint32_t *hashtab; |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 43 | char *strings; |
| 44 | unsigned char *base; |
| 45 | unsigned char *map; |
| 46 | size_t map_len; |
| 47 | dev_t dev; |
| 48 | ino_t ino; |
| 49 | int global; |
| 50 | int relocated; |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 51 | struct dso **deps; |
Rich Felker | 6b3d5e5 | 2011-06-26 17:39:17 -0400 | [diff] [blame] | 52 | char *name; |
| 53 | char buf[]; |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | static struct dso *head, *tail, *libc; |
Rich Felker | 191ebca | 2011-06-30 23:02:27 -0400 | [diff] [blame] | 57 | static char *env_path, *sys_path, *r_path; |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 58 | static int rtld_used; |
Rich Felker | 6b3d5e5 | 2011-06-26 17:39:17 -0400 | [diff] [blame] | 59 | static int runtime; |
| 60 | static jmp_buf rtld_fail; |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 61 | static pthread_rwlock_t lock; |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 62 | |
| 63 | #define AUX_CNT 15 |
| 64 | #define DYN_CNT 34 |
| 65 | |
| 66 | static void decode_vec(size_t *v, size_t *a, size_t cnt) |
| 67 | { |
| 68 | memset(a, 0, cnt*sizeof(size_t)); |
| 69 | for (; v[0]; v+=2) if (v[0]<cnt) { |
| 70 | a[0] |= 1ULL<<v[0]; |
| 71 | a[v[0]] = v[1]; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | static uint32_t hash(const char *s) |
| 76 | { |
| 77 | uint_fast32_t h = 0; |
| 78 | while (*s) { |
| 79 | h = 16*h + *s++; |
| 80 | h ^= h>>24 & 0xf0; |
| 81 | } |
| 82 | return h & 0xfffffff; |
| 83 | } |
| 84 | |
Rich Felker | 596d60c | 2011-06-18 22:52:01 -0400 | [diff] [blame] | 85 | static Sym *lookup(const char *s, uint32_t h, Sym *syms, uint32_t *hashtab, char *strings) |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 86 | { |
| 87 | size_t i; |
| 88 | for (i=hashtab[2+h%hashtab[0]]; i; i=hashtab[2+hashtab[0]+i]) { |
| 89 | if (!strcmp(s, strings+syms[i].st_name)) |
| 90 | return syms+i; |
| 91 | } |
| 92 | return 0; |
| 93 | } |
| 94 | |
| 95 | #define OK_TYPES (1<<STT_NOTYPE | 1<<STT_OBJECT | 1<<STT_FUNC | 1<<STT_COMMON) |
Rich Felker | 427173b | 2011-07-24 02:19:47 -0400 | [diff] [blame] | 96 | #define OK_BINDS (1<<STB_GLOBAL | 1<<STB_WEAK) |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 97 | |
| 98 | static void *find_sym(struct dso *dso, const char *s, int need_def) |
| 99 | { |
| 100 | uint32_t h = hash(s); |
Rich Felker | 427173b | 2011-07-24 02:19:47 -0400 | [diff] [blame] | 101 | void *def = 0; |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 102 | if (h==0x6b366be && !strcmp(s, "dlopen")) rtld_used = 1; |
| 103 | if (h==0x6b3afd && !strcmp(s, "dlsym")) rtld_used = 1; |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 104 | for (; dso; dso=dso->next) { |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 105 | Sym *sym; |
| 106 | if (!dso->global) continue; |
| 107 | sym = lookup(s, h, dso->syms, dso->hashtab, dso->strings); |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 108 | if (sym && (!need_def || sym->st_shndx) && sym->st_value |
Rich Felker | 427173b | 2011-07-24 02:19:47 -0400 | [diff] [blame] | 109 | && (1<<(sym->st_info&0xf) & OK_TYPES) |
| 110 | && (1<<(sym->st_info>>4) & OK_BINDS)) { |
Rich Felker | e01ac67 | 2011-07-25 09:22:05 -0400 | [diff] [blame] | 111 | if (def && sym->st_info>>4 == STB_WEAK) continue; |
Rich Felker | 427173b | 2011-07-24 02:19:47 -0400 | [diff] [blame] | 112 | def = dso->base + sym->st_value; |
| 113 | if (sym->st_info>>4 == STB_GLOBAL) break; |
| 114 | } |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 115 | } |
Rich Felker | 427173b | 2011-07-24 02:19:47 -0400 | [diff] [blame] | 116 | return def; |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | static void do_relocs(unsigned char *base, size_t *rel, size_t rel_size, size_t stride, Sym *syms, char *strings, struct dso *dso) |
| 120 | { |
| 121 | Sym *sym; |
| 122 | const char *name; |
| 123 | size_t sym_val, sym_size; |
| 124 | size_t *reloc_addr; |
| 125 | void *ctx; |
| 126 | int type; |
| 127 | int sym_index; |
| 128 | |
| 129 | for (; rel_size; rel+=stride, rel_size-=stride*sizeof(size_t)) { |
| 130 | reloc_addr = (void *)(base + rel[0]); |
| 131 | type = R_TYPE(rel[1]); |
| 132 | sym_index = R_SYM(rel[1]); |
| 133 | if (sym_index) { |
| 134 | sym = syms + sym_index; |
| 135 | name = strings + sym->st_name; |
| 136 | ctx = IS_COPY(type) ? dso->next : dso; |
Rich Felker | 32de61e | 2011-06-25 22:36:21 -0400 | [diff] [blame] | 137 | sym_val = (size_t)find_sym(ctx, name, IS_PLT(type)); |
Rich Felker | 6b3d5e5 | 2011-06-26 17:39:17 -0400 | [diff] [blame] | 138 | if (!sym_val && sym->st_info>>4 != STB_WEAK) { |
| 139 | if (runtime) longjmp(rtld_fail, 1); |
| 140 | dprintf(2, "%s: symbol not found\n", name); |
| 141 | _exit(127); |
| 142 | } |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 143 | sym_size = sym->st_size; |
| 144 | } |
| 145 | do_single_reloc(reloc_addr, type, sym_val, sym_size, base, rel[2]); |
| 146 | } |
| 147 | } |
| 148 | |
Rich Felker | 6717e62 | 2011-06-28 19:40:14 -0400 | [diff] [blame] | 149 | /* A huge hack: to make up for the wastefulness of shared libraries |
| 150 | * needing at least a page of dirty memory even if they have no global |
| 151 | * data, we reclaim the gaps at the beginning and end of writable maps |
| 152 | * and "donate" them to the heap by setting up minimal malloc |
| 153 | * structures and then freeing them. */ |
| 154 | |
| 155 | static void reclaim(unsigned char *base, size_t start, size_t end) |
| 156 | { |
| 157 | size_t *a, *z; |
| 158 | start = start + 6*sizeof(size_t)-1 & -4*sizeof(size_t); |
| 159 | end = (end & -4*sizeof(size_t)) - 2*sizeof(size_t); |
| 160 | if (start>end || end-start < 4*sizeof(size_t)) return; |
| 161 | a = (size_t *)(base + start); |
| 162 | z = (size_t *)(base + end); |
| 163 | a[-2] = 1; |
| 164 | a[-1] = z[0] = end-start + 2*sizeof(size_t) | 1; |
| 165 | z[1] = 1; |
| 166 | free(a); |
| 167 | } |
| 168 | |
| 169 | static void reclaim_gaps(unsigned char *base, Phdr *ph, size_t phent, size_t phcnt) |
| 170 | { |
| 171 | for (; phcnt--; ph=(void *)((char *)ph+phent)) { |
| 172 | if (ph->p_type!=PT_LOAD) continue; |
| 173 | if ((ph->p_flags&(PF_R|PF_W))!=(PF_R|PF_W)) continue; |
| 174 | reclaim(base, ph->p_vaddr & -PAGE_SIZE, ph->p_vaddr); |
| 175 | reclaim(base, ph->p_vaddr+ph->p_memsz, |
| 176 | ph->p_vaddr+ph->p_memsz+PAGE_SIZE-1 & -PAGE_SIZE); |
| 177 | } |
| 178 | } |
| 179 | |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 180 | static void *map_library(int fd, size_t *lenp, unsigned char **basep, size_t *dynp) |
| 181 | { |
Rich Felker | 59633c7 | 2011-06-25 12:26:08 -0400 | [diff] [blame] | 182 | Ehdr buf[(896+sizeof(Ehdr))/sizeof(Ehdr)]; |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 183 | size_t phsize; |
| 184 | size_t addr_min=SIZE_MAX, addr_max=0, map_len; |
| 185 | size_t this_min, this_max; |
| 186 | off_t off_start; |
| 187 | Ehdr *eh; |
| 188 | Phdr *ph; |
| 189 | unsigned prot; |
| 190 | unsigned char *map, *base; |
| 191 | size_t dyn; |
| 192 | size_t i; |
| 193 | |
| 194 | ssize_t l = read(fd, buf, sizeof buf); |
| 195 | if (l<sizeof *eh) return 0; |
Rich Felker | 59633c7 | 2011-06-25 12:26:08 -0400 | [diff] [blame] | 196 | eh = buf; |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 197 | phsize = eh->e_phentsize * eh->e_phnum; |
| 198 | if (phsize + sizeof *eh > l) return 0; |
| 199 | if (eh->e_phoff + phsize > l) { |
Rich Felker | 59633c7 | 2011-06-25 12:26:08 -0400 | [diff] [blame] | 200 | l = pread(fd, buf+1, phsize, eh->e_phoff); |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 201 | if (l != phsize) return 0; |
| 202 | eh->e_phoff = sizeof *eh; |
| 203 | } |
| 204 | ph = (void *)((char *)buf + eh->e_phoff); |
| 205 | for (i=eh->e_phnum; i; i--, ph=(void *)((char *)ph+eh->e_phentsize)) { |
| 206 | if (ph->p_type == PT_DYNAMIC) |
| 207 | dyn = ph->p_vaddr; |
| 208 | if (ph->p_type != PT_LOAD) continue; |
| 209 | if (ph->p_vaddr < addr_min) { |
| 210 | addr_min = ph->p_vaddr; |
| 211 | off_start = ph->p_offset; |
| 212 | prot = (((ph->p_flags&PF_R) ? PROT_READ : 0) | |
| 213 | ((ph->p_flags&PF_W) ? PROT_WRITE: 0) | |
| 214 | ((ph->p_flags&PF_X) ? PROT_EXEC : 0)); |
| 215 | } |
| 216 | if (ph->p_vaddr+ph->p_memsz > addr_max) { |
| 217 | addr_max = ph->p_vaddr+ph->p_memsz; |
| 218 | } |
| 219 | } |
| 220 | if (!dyn) return 0; |
| 221 | addr_max += PAGE_SIZE-1; |
| 222 | addr_max &= -PAGE_SIZE; |
| 223 | addr_min &= -PAGE_SIZE; |
| 224 | off_start &= -PAGE_SIZE; |
| 225 | map_len = addr_max - addr_min + off_start; |
| 226 | /* The first time, we map too much, possibly even more than |
| 227 | * the length of the file. This is okay because we will not |
| 228 | * use the invalid part; we just need to reserve the right |
| 229 | * amount of virtual address space to map over later. */ |
Rich Felker | bf30100 | 2011-06-28 14:20:41 -0400 | [diff] [blame] | 230 | map = mmap((void *)addr_min, map_len, prot, MAP_PRIVATE, fd, off_start); |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 231 | if (map==MAP_FAILED) return 0; |
| 232 | base = map - addr_min; |
| 233 | ph = (void *)((char *)buf + eh->e_phoff); |
| 234 | for (i=eh->e_phnum; i; i--, ph=(void *)((char *)ph+eh->e_phentsize)) { |
| 235 | if (ph->p_type != PT_LOAD) continue; |
| 236 | /* Reuse the existing mapping for the lowest-address LOAD */ |
| 237 | if ((ph->p_vaddr & -PAGE_SIZE) == addr_min) continue; |
| 238 | this_min = ph->p_vaddr & -PAGE_SIZE; |
| 239 | this_max = ph->p_vaddr+ph->p_memsz+PAGE_SIZE-1 & -PAGE_SIZE; |
| 240 | off_start = ph->p_offset & -PAGE_SIZE; |
| 241 | prot = (((ph->p_flags&PF_R) ? PROT_READ : 0) | |
| 242 | ((ph->p_flags&PF_W) ? PROT_WRITE: 0) | |
| 243 | ((ph->p_flags&PF_X) ? PROT_EXEC : 0)); |
| 244 | if (mmap(base+this_min, this_max-this_min, prot, MAP_PRIVATE|MAP_FIXED, fd, off_start) == MAP_FAILED) { |
| 245 | munmap(map, map_len); |
| 246 | return 0; |
| 247 | } |
| 248 | if (ph->p_memsz > ph->p_filesz) { |
| 249 | size_t brk = (size_t)base+ph->p_vaddr+ph->p_filesz; |
| 250 | size_t pgbrk = brk+PAGE_SIZE-1 & -PAGE_SIZE; |
| 251 | memset((void *)brk, 0, pgbrk-brk & PAGE_SIZE-1); |
| 252 | if (pgbrk-(size_t)base < this_max && mmap((void *)pgbrk, (size_t)base+this_max-pgbrk, prot, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) == MAP_FAILED) { |
| 253 | munmap(map, map_len); |
| 254 | return 0; |
| 255 | } |
| 256 | } |
| 257 | } |
Rich Felker | 9f17413 | 2011-06-29 00:29:08 -0400 | [diff] [blame] | 258 | for (i=0; ((size_t *)(base+dyn))[i]; i+=2) |
| 259 | if (((size_t *)(base+dyn))[i]==DT_TEXTREL) { |
| 260 | mprotect(map, map_len, PROT_READ|PROT_WRITE|PROT_EXEC); |
| 261 | break; |
| 262 | } |
Rich Felker | 6717e62 | 2011-06-28 19:40:14 -0400 | [diff] [blame] | 263 | if (!runtime) reclaim_gaps(base, (void *)((char *)buf + eh->e_phoff), |
| 264 | eh->e_phentsize, eh->e_phnum); |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 265 | *lenp = map_len; |
| 266 | *basep = base; |
| 267 | *dynp = dyn; |
| 268 | return map; |
| 269 | } |
| 270 | |
Rich Felker | 568b807 | 2011-06-25 01:56:34 -0400 | [diff] [blame] | 271 | static int path_open(const char *name, const char *search) |
| 272 | { |
| 273 | char buf[2*NAME_MAX+2]; |
Rich Felker | 49388f3 | 2011-06-25 17:49:16 -0400 | [diff] [blame] | 274 | const char *s=search, *z; |
Rich Felker | 568b807 | 2011-06-25 01:56:34 -0400 | [diff] [blame] | 275 | int l, fd; |
Rich Felker | 49388f3 | 2011-06-25 17:49:16 -0400 | [diff] [blame] | 276 | for (;;) { |
| 277 | while (*s==':') s++; |
| 278 | if (!*s) return -1; |
Rich Felker | 568b807 | 2011-06-25 01:56:34 -0400 | [diff] [blame] | 279 | z = strchr(s, ':'); |
| 280 | l = z ? z-s : strlen(s); |
| 281 | snprintf(buf, sizeof buf, "%.*s/%s", l, s, name); |
| 282 | if ((fd = open(buf, O_RDONLY))>=0) return fd; |
Rich Felker | 49388f3 | 2011-06-25 17:49:16 -0400 | [diff] [blame] | 283 | s += l; |
Rich Felker | 568b807 | 2011-06-25 01:56:34 -0400 | [diff] [blame] | 284 | } |
Rich Felker | 568b807 | 2011-06-25 01:56:34 -0400 | [diff] [blame] | 285 | } |
| 286 | |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 287 | static struct dso *load_library(const char *name) |
| 288 | { |
| 289 | unsigned char *base, *map; |
| 290 | size_t dyno, map_len; |
| 291 | struct dso *p; |
| 292 | size_t dyn[DYN_CNT] = {0}; |
| 293 | int fd; |
| 294 | struct stat st; |
| 295 | |
| 296 | /* Catch and block attempts to reload the implementation itself */ |
| 297 | if (name[0]=='l' && name[1]=='i' && name[2]=='b') { |
| 298 | static const char *rp, reserved[] = |
| 299 | "c\0pthread\0rt\0m\0dl\0util\0xnet\0"; |
| 300 | char *z = strchr(name, '.'); |
| 301 | if (z) { |
| 302 | size_t l = z-name; |
| 303 | for (rp=reserved; *rp && memcmp(name+3, rp, l-3); rp+=strlen(rp)+1); |
| 304 | if (*rp) { |
| 305 | if (!libc->prev) { |
| 306 | tail->next = libc; |
| 307 | libc->prev = tail; |
Rich Felker | 6ab444d | 2011-07-24 00:54:55 -0400 | [diff] [blame] | 308 | tail = libc->next ? libc->next : libc; |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 309 | } |
| 310 | return libc; |
| 311 | } |
| 312 | } |
| 313 | } |
| 314 | /* Search for the name to see if it's already loaded */ |
| 315 | for (p=head->next; p; p=p->next) { |
| 316 | if (!strcmp(p->name, name)) { |
| 317 | p->refcnt++; |
| 318 | return p; |
| 319 | } |
| 320 | } |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 321 | if (strchr(name, '/')) { |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 322 | fd = open(name, O_RDONLY); |
| 323 | } else { |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 324 | if (strlen(name) > NAME_MAX) return 0; |
Rich Felker | 568b807 | 2011-06-25 01:56:34 -0400 | [diff] [blame] | 325 | fd = -1; |
Rich Felker | 191ebca | 2011-06-30 23:02:27 -0400 | [diff] [blame] | 326 | if (r_path) fd = path_open(name, r_path); |
| 327 | if (fd < 0 && env_path) fd = path_open(name, env_path); |
Rich Felker | 568b807 | 2011-06-25 01:56:34 -0400 | [diff] [blame] | 328 | if (fd < 0) { |
| 329 | if (!sys_path) { |
| 330 | FILE *f = fopen(ETC_LDSO_PATH, "r"); |
| 331 | if (f) { |
| 332 | if (getline(&sys_path, (size_t[1]){0}, f) > 0) |
| 333 | sys_path[strlen(sys_path)-1]=0; |
| 334 | fclose(f); |
| 335 | } |
| 336 | } |
| 337 | if (sys_path) fd = path_open(name, sys_path); |
| 338 | else fd = path_open(name, "/lib:/usr/local/lib:/usr/lib"); |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 339 | } |
| 340 | } |
| 341 | if (fd < 0) return 0; |
| 342 | if (fstat(fd, &st) < 0) { |
| 343 | close(fd); |
| 344 | return 0; |
| 345 | } |
| 346 | for (p=head->next; p; p=p->next) { |
| 347 | if (p->dev == st.st_dev && p->ino == st.st_ino) { |
| 348 | close(fd); |
| 349 | p->refcnt++; |
| 350 | return p; |
| 351 | } |
| 352 | } |
| 353 | map = map_library(fd, &map_len, &base, &dyno); |
| 354 | close(fd); |
| 355 | if (!map) return 0; |
| 356 | p = calloc(1, sizeof *p + strlen(name) + 1); |
| 357 | if (!p) { |
| 358 | munmap(map, map_len); |
| 359 | return 0; |
| 360 | } |
| 361 | |
| 362 | p->map = map; |
| 363 | p->map_len = map_len; |
| 364 | p->base = base; |
| 365 | p->dynv = (void *)(base + dyno); |
| 366 | decode_vec(p->dynv, dyn, DYN_CNT); |
| 367 | |
| 368 | p->syms = (void *)(base + dyn[DT_SYMTAB]); |
| 369 | p->hashtab = (void *)(base + dyn[DT_HASH]); |
| 370 | p->strings = (void *)(base + dyn[DT_STRTAB]); |
| 371 | p->dev = st.st_dev; |
| 372 | p->ino = st.st_ino; |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 373 | p->refcnt = 1; |
Rich Felker | 6b3d5e5 | 2011-06-26 17:39:17 -0400 | [diff] [blame] | 374 | p->name = p->buf; |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 375 | strcpy(p->name, name); |
| 376 | |
| 377 | tail->next = p; |
| 378 | p->prev = tail; |
| 379 | tail = p; |
| 380 | |
| 381 | return p; |
| 382 | } |
| 383 | |
| 384 | static void load_deps(struct dso *p) |
| 385 | { |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 386 | size_t i, ndeps=0; |
| 387 | struct dso ***deps = &p->deps, **tmp, *dep; |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 388 | for (; p; p=p->next) { |
| 389 | for (i=0; p->dynv[i]; i+=2) { |
Rich Felker | 191ebca | 2011-06-30 23:02:27 -0400 | [diff] [blame] | 390 | if (p->dynv[i] != DT_RPATH) continue; |
| 391 | r_path = (void *)(p->strings + p->dynv[i+1]); |
| 392 | } |
| 393 | for (i=0; p->dynv[i]; i+=2) { |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 394 | if (p->dynv[i] != DT_NEEDED) continue; |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 395 | dep = load_library(p->strings + p->dynv[i+1]); |
| 396 | if (!dep) { |
Rich Felker | 6b3d5e5 | 2011-06-26 17:39:17 -0400 | [diff] [blame] | 397 | if (runtime) longjmp(rtld_fail, 1); |
| 398 | dprintf(2, "%s: %m (needed by %s)\n", |
| 399 | p->strings + p->dynv[i+1], p->name); |
| 400 | _exit(127); |
| 401 | } |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 402 | if (runtime) { |
| 403 | tmp = realloc(*deps, sizeof(*tmp)*(ndeps+2)); |
| 404 | if (!tmp) longjmp(rtld_fail, 1); |
| 405 | tmp[ndeps++] = dep; |
| 406 | tmp[ndeps] = 0; |
| 407 | *deps = tmp; |
| 408 | } |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 409 | } |
Rich Felker | 191ebca | 2011-06-30 23:02:27 -0400 | [diff] [blame] | 410 | r_path = 0; |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 411 | } |
| 412 | } |
| 413 | |
Rich Felker | 2719cc8 | 2011-08-16 00:24:36 -0400 | [diff] [blame] | 414 | static void load_preload(char *s) |
| 415 | { |
| 416 | int tmp; |
| 417 | char *z; |
| 418 | for (z=s; *z; s=z) { |
| 419 | for ( ; *s && isspace(*s); s++); |
| 420 | for (z=s; *z && !isspace(*z); z++); |
| 421 | tmp = *z; |
| 422 | *z = 0; |
| 423 | load_library(s); |
| 424 | *z = tmp; |
| 425 | } |
| 426 | } |
| 427 | |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 428 | static void make_global(struct dso *p) |
| 429 | { |
| 430 | for (; p; p=p->next) p->global = 1; |
| 431 | } |
| 432 | |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 433 | static void reloc_all(struct dso *p) |
| 434 | { |
| 435 | size_t dyn[DYN_CNT] = {0}; |
| 436 | for (; p; p=p->next) { |
| 437 | if (p->relocated) continue; |
| 438 | decode_vec(p->dynv, dyn, DYN_CNT); |
| 439 | do_relocs(p->base, (void *)(p->base+dyn[DT_JMPREL]), dyn[DT_PLTRELSZ], |
Rich Felker | 32de61e | 2011-06-25 22:36:21 -0400 | [diff] [blame] | 440 | 2+(dyn[DT_PLTREL]==DT_RELA), p->syms, p->strings, head); |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 441 | do_relocs(p->base, (void *)(p->base+dyn[DT_REL]), dyn[DT_RELSZ], |
Rich Felker | 32de61e | 2011-06-25 22:36:21 -0400 | [diff] [blame] | 442 | 2, p->syms, p->strings, head); |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 443 | do_relocs(p->base, (void *)(p->base+dyn[DT_RELA]), dyn[DT_RELASZ], |
Rich Felker | 32de61e | 2011-06-25 22:36:21 -0400 | [diff] [blame] | 444 | 3, p->syms, p->strings, head); |
Rich Felker | 368ba4a | 2011-06-25 00:18:19 -0400 | [diff] [blame] | 445 | p->relocated = 1; |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 446 | } |
| 447 | } |
| 448 | |
Rich Felker | e8dbf00 | 2011-06-25 00:47:28 -0400 | [diff] [blame] | 449 | static void free_all(struct dso *p) |
| 450 | { |
| 451 | struct dso *n; |
| 452 | while (p) { |
| 453 | n = p->next; |
| 454 | if (p->map) free(p); |
| 455 | p = n; |
| 456 | } |
| 457 | } |
| 458 | |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 459 | void *__dynlink(int argc, char **argv, size_t *got) |
| 460 | { |
| 461 | size_t *auxv, aux[AUX_CNT] = {0}; |
| 462 | size_t app_dyn[DYN_CNT] = {0}; |
| 463 | size_t lib_dyn[DYN_CNT] = {0}; |
Rich Felker | 6ab444d | 2011-07-24 00:54:55 -0400 | [diff] [blame] | 464 | size_t vdso_dyn[DYN_CNT] = {0}; |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 465 | size_t i; |
| 466 | Phdr *phdr; |
Rich Felker | 6717e62 | 2011-06-28 19:40:14 -0400 | [diff] [blame] | 467 | Ehdr *ehdr; |
Rich Felker | 6ab444d | 2011-07-24 00:54:55 -0400 | [diff] [blame] | 468 | static struct dso builtin_dsos[3]; |
Rich Felker | a53de81 | 2011-07-24 00:26:12 -0400 | [diff] [blame] | 469 | struct dso *const app = builtin_dsos+0; |
| 470 | struct dso *const lib = builtin_dsos+1; |
Rich Felker | 6ab444d | 2011-07-24 00:54:55 -0400 | [diff] [blame] | 471 | struct dso *const vdso = builtin_dsos+2; |
| 472 | size_t vdso_base=0; |
Rich Felker | 2719cc8 | 2011-08-16 00:24:36 -0400 | [diff] [blame] | 473 | char *env_preload=0; |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 474 | |
| 475 | /* Find aux vector just past environ[] */ |
Rich Felker | 568b807 | 2011-06-25 01:56:34 -0400 | [diff] [blame] | 476 | for (i=argc+1; argv[i]; i++) |
| 477 | if (!memcmp(argv[i], "LD_LIBRARY_PATH=", 16)) |
| 478 | env_path = argv[i]+16; |
Rich Felker | 2719cc8 | 2011-08-16 00:24:36 -0400 | [diff] [blame] | 479 | else if (!memcmp(argv[i], "LD_PRELOAD=", 11)) |
| 480 | env_preload = argv[i]+11; |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 481 | auxv = (void *)(argv+i+1); |
| 482 | |
| 483 | decode_vec(auxv, aux, AUX_CNT); |
| 484 | |
Rich Felker | 6ab444d | 2011-07-24 00:54:55 -0400 | [diff] [blame] | 485 | for (i=0; auxv[i]; i+=2) { |
| 486 | if (auxv[i]==AT_SYSINFO_EHDR) { |
| 487 | vdso_base = auxv[i+1]; |
| 488 | break; |
| 489 | } |
| 490 | } |
| 491 | |
Rich Felker | 568b807 | 2011-06-25 01:56:34 -0400 | [diff] [blame] | 492 | /* Only trust user/env if kernel says we're not suid/sgid */ |
| 493 | if ((aux[0]&0x7800)!=0x7800 || aux[AT_UID]!=aux[AT_EUID] |
| 494 | || aux[AT_GID]!=aux[AT_EGID]) { |
| 495 | env_path = 0; |
Rich Felker | 2719cc8 | 2011-08-16 00:24:36 -0400 | [diff] [blame] | 496 | env_preload = 0; |
Rich Felker | 568b807 | 2011-06-25 01:56:34 -0400 | [diff] [blame] | 497 | } |
| 498 | |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 499 | /* Relocate ldso's DYNAMIC pointer and load vector */ |
| 500 | decode_vec((void *)(got[0] += aux[AT_BASE]), lib_dyn, DYN_CNT); |
| 501 | |
| 502 | /* Find the program image's DYNAMIC section and decode it */ |
| 503 | phdr = (void *)aux[AT_PHDR]; |
| 504 | for (i=aux[AT_PHNUM]; i--; phdr=(void *)((char *)phdr + aux[AT_PHENT])) { |
| 505 | if (phdr->p_type == PT_DYNAMIC) { |
| 506 | decode_vec((void *)phdr->p_vaddr, app_dyn, DYN_CNT); |
| 507 | break; |
| 508 | } |
| 509 | } |
| 510 | |
Rich Felker | a53de81 | 2011-07-24 00:26:12 -0400 | [diff] [blame] | 511 | *app = (struct dso){ |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 512 | .base = 0, |
| 513 | .strings = (void *)(app_dyn[DT_STRTAB]), |
| 514 | .hashtab = (void *)(app_dyn[DT_HASH]), |
| 515 | .syms = (void *)(app_dyn[DT_SYMTAB]), |
| 516 | .dynv = (void *)(phdr->p_vaddr), |
Rich Felker | 6b3d5e5 | 2011-06-26 17:39:17 -0400 | [diff] [blame] | 517 | .name = argv[0], |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 518 | .global = 1, |
Rich Felker | a53de81 | 2011-07-24 00:26:12 -0400 | [diff] [blame] | 519 | .next = lib |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 520 | }; |
| 521 | |
Rich Felker | a53de81 | 2011-07-24 00:26:12 -0400 | [diff] [blame] | 522 | *lib = (struct dso){ |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 523 | .base = (void *)aux[AT_BASE], |
| 524 | .strings = (void *)(aux[AT_BASE]+lib_dyn[DT_STRTAB]), |
| 525 | .hashtab = (void *)(aux[AT_BASE]+lib_dyn[DT_HASH]), |
| 526 | .syms = (void *)(aux[AT_BASE]+lib_dyn[DT_SYMTAB]), |
| 527 | .dynv = (void *)(got[0]), |
Rich Felker | 6b3d5e5 | 2011-06-26 17:39:17 -0400 | [diff] [blame] | 528 | .name = "libc.so", |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 529 | .global = 1, |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 530 | .relocated = 1 |
| 531 | }; |
| 532 | |
Rich Felker | 6ab444d | 2011-07-24 00:54:55 -0400 | [diff] [blame] | 533 | if (vdso_base) { |
| 534 | ehdr = (void *)vdso_base; |
| 535 | phdr = (void *)(vdso_base + ehdr->e_phoff); |
| 536 | for (i=ehdr->e_phnum; i; i--, phdr=(void *)((char *)phdr + ehdr->e_phentsize)) { |
| 537 | if (phdr->p_type == PT_DYNAMIC) |
| 538 | vdso->dynv = (void *)(vdso_base + phdr->p_offset); |
| 539 | if (phdr->p_type == PT_LOAD) |
| 540 | vdso->base = (void *)(vdso_base - phdr->p_vaddr + phdr->p_offset); |
| 541 | } |
| 542 | decode_vec(vdso->dynv, vdso_dyn, DYN_CNT); |
| 543 | vdso->syms = (void *)(vdso->base + vdso_dyn[DT_SYMTAB]); |
| 544 | vdso->hashtab = (void *)(vdso->base + vdso_dyn[DT_HASH]); |
| 545 | vdso->strings = (void *)(vdso->base + vdso_dyn[DT_STRTAB]); |
| 546 | vdso->name = "linux-gate.so.1"; |
Rich Felker | 427173b | 2011-07-24 02:19:47 -0400 | [diff] [blame] | 547 | vdso->global = 1; |
Rich Felker | 6ab444d | 2011-07-24 00:54:55 -0400 | [diff] [blame] | 548 | |
| 549 | vdso->prev = lib; |
| 550 | lib->next = vdso; |
| 551 | } |
| 552 | |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 553 | /* Relocate the dynamic linker/libc */ |
| 554 | do_relocs((void *)aux[AT_BASE], (void *)(aux[AT_BASE]+lib_dyn[DT_REL]), |
Rich Felker | a53de81 | 2011-07-24 00:26:12 -0400 | [diff] [blame] | 555 | lib_dyn[DT_RELSZ], 2, lib->syms, lib->strings, app); |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 556 | do_relocs((void *)aux[AT_BASE], (void *)(aux[AT_BASE]+lib_dyn[DT_RELA]), |
Rich Felker | a53de81 | 2011-07-24 00:26:12 -0400 | [diff] [blame] | 557 | lib_dyn[DT_RELASZ], 3, lib->syms, lib->strings, app); |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 558 | |
| 559 | /* At this point the standard library is fully functional */ |
| 560 | |
Rich Felker | a53de81 | 2011-07-24 00:26:12 -0400 | [diff] [blame] | 561 | reclaim_gaps(app->base, (void *)aux[AT_PHDR], aux[AT_PHENT], aux[AT_PHNUM]); |
| 562 | ehdr = (void *)lib->base; |
| 563 | reclaim_gaps(lib->base, (void *)(lib->base+ehdr->e_phoff), |
Rich Felker | 6717e62 | 2011-06-28 19:40:14 -0400 | [diff] [blame] | 564 | ehdr->e_phentsize, ehdr->e_phnum); |
| 565 | |
Rich Felker | a53de81 | 2011-07-24 00:26:12 -0400 | [diff] [blame] | 566 | head = tail = app; |
| 567 | libc = lib; |
| 568 | app->next = 0; |
Rich Felker | 2719cc8 | 2011-08-16 00:24:36 -0400 | [diff] [blame] | 569 | if (env_preload) load_preload(env_preload); |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 570 | load_deps(head); |
| 571 | |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 572 | make_global(head); |
Rich Felker | c7debe1 | 2011-06-28 14:13:51 -0400 | [diff] [blame] | 573 | reloc_all(head->next); |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 574 | reloc_all(head); |
| 575 | |
Rich Felker | a53de81 | 2011-07-24 00:26:12 -0400 | [diff] [blame] | 576 | runtime = 1; |
| 577 | if (!rtld_used) { |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 578 | free_all(head); |
| 579 | free(sys_path); |
Rich Felker | a53de81 | 2011-07-24 00:26:12 -0400 | [diff] [blame] | 580 | reclaim((void *)builtin_dsos, 0, sizeof builtin_dsos); |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 581 | } |
Rich Felker | e8dbf00 | 2011-06-25 00:47:28 -0400 | [diff] [blame] | 582 | |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 583 | errno = 0; |
| 584 | return (void *)aux[AT_ENTRY]; |
| 585 | } |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 586 | |
| 587 | void *dlopen(const char *file, int mode) |
| 588 | { |
Rich Felker | 2fdea17 | 2011-07-01 22:40:00 -0400 | [diff] [blame] | 589 | struct dso *volatile p, *orig_tail = tail, *next; |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 590 | size_t i; |
| 591 | |
| 592 | if (!file) return head; |
| 593 | |
| 594 | pthread_rwlock_wrlock(&lock); |
| 595 | |
| 596 | if (setjmp(rtld_fail)) { |
| 597 | /* Clean up anything new that was (partially) loaded */ |
Rich Felker | 92ab5d8 | 2011-06-26 21:21:04 -0400 | [diff] [blame] | 598 | if (p->deps) for (i=0; p->deps[i]; i++) |
| 599 | if (p->deps[i]->global < 0) |
| 600 | p->deps[i]->global = 0; |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 601 | for (p=orig_tail->next; p; p=next) { |
| 602 | next = p->next; |
| 603 | munmap(p->map, p->map_len); |
| 604 | free(p->deps); |
| 605 | free(p); |
| 606 | } |
| 607 | tail = orig_tail; |
| 608 | tail->next = 0; |
| 609 | pthread_rwlock_unlock(&lock); |
| 610 | return 0; |
| 611 | } |
| 612 | |
| 613 | p = load_library(file); |
Rich Felker | 06933cc | 2011-06-26 22:09:32 -0400 | [diff] [blame] | 614 | if (!p) goto end; |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 615 | |
| 616 | /* First load handling */ |
| 617 | if (!p->deps) { |
| 618 | load_deps(p); |
Rich Felker | 0e4dae3 | 2011-06-26 21:36:44 -0400 | [diff] [blame] | 619 | if (p->deps) for (i=0; p->deps[i]; i++) |
Rich Felker | 92ab5d8 | 2011-06-26 21:21:04 -0400 | [diff] [blame] | 620 | if (!p->deps[i]->global) |
| 621 | p->deps[i]->global = -1; |
| 622 | if (!p->global) p->global = -1; |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 623 | reloc_all(p); |
Rich Felker | 0e4dae3 | 2011-06-26 21:36:44 -0400 | [diff] [blame] | 624 | if (p->deps) for (i=0; p->deps[i]; i++) |
Rich Felker | 92ab5d8 | 2011-06-26 21:21:04 -0400 | [diff] [blame] | 625 | if (p->deps[i]->global < 0) |
| 626 | p->deps[i]->global = 0; |
| 627 | if (p->global < 0) p->global = 0; |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | if (mode & RTLD_GLOBAL) { |
Rich Felker | 0e4dae3 | 2011-06-26 21:36:44 -0400 | [diff] [blame] | 631 | if (p->deps) for (i=0; p->deps[i]; i++) |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 632 | p->deps[i]->global = 1; |
| 633 | p->global = 1; |
| 634 | } |
| 635 | |
Rich Felker | 06933cc | 2011-06-26 22:09:32 -0400 | [diff] [blame] | 636 | end: |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 637 | pthread_rwlock_unlock(&lock); |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 638 | return p; |
| 639 | } |
| 640 | |
Rich Felker | 623753a | 2011-08-16 00:42:13 -0400 | [diff] [blame^] | 641 | static void *do_dlsym(struct dso *p, const char *s, void *ra) |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 642 | { |
| 643 | size_t i; |
| 644 | uint32_t h; |
| 645 | Sym *sym; |
Rich Felker | 623753a | 2011-08-16 00:42:13 -0400 | [diff] [blame^] | 646 | if (p == RTLD_NEXT) { |
| 647 | for (p=head; p && (unsigned char *)ra-p->map>p->map_len; p=p->next); |
| 648 | if (!p) p=head; |
| 649 | p=p->next; |
| 650 | } |
Rich Felker | 97507bd | 2011-06-26 21:50:01 -0400 | [diff] [blame] | 651 | if (p == head || p == RTLD_DEFAULT) |
| 652 | return find_sym(head, s, 0); |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 653 | h = hash(s); |
| 654 | sym = lookup(s, h, p->syms, p->hashtab, p->strings); |
| 655 | if (sym && sym->st_value && (1<<(sym->st_info&0xf) & OK_TYPES)) |
| 656 | return p->base + sym->st_value; |
| 657 | if (p->deps) for (i=0; p->deps[i]; i++) { |
| 658 | sym = lookup(s, h, p->deps[i]->syms, |
| 659 | p->deps[i]->hashtab, p->deps[i]->strings); |
| 660 | if (sym && sym->st_value && (1<<(sym->st_info&0xf) & OK_TYPES)) |
| 661 | return p->deps[i]->base + sym->st_value; |
| 662 | } |
| 663 | return 0; |
| 664 | } |
| 665 | |
Rich Felker | 623753a | 2011-08-16 00:42:13 -0400 | [diff] [blame^] | 666 | void *__dlsym(void *p, const char *s, void *ra) |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 667 | { |
| 668 | void *res; |
| 669 | pthread_rwlock_rdlock(&lock); |
Rich Felker | 623753a | 2011-08-16 00:42:13 -0400 | [diff] [blame^] | 670 | res = do_dlsym(p, s, ra); |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 671 | pthread_rwlock_unlock(&lock); |
| 672 | return res; |
| 673 | } |
| 674 | |
| 675 | char *dlerror() |
| 676 | { |
| 677 | return "unknown error"; |
| 678 | } |
| 679 | |
| 680 | int dlclose(void *p) |
| 681 | { |
| 682 | return 0; |
| 683 | } |