]>
Commit | Line | Data |
---|---|---|
48afcd98 AM |
1 | diff -up scim-1.4.8/src/ltdl.cpp.fix-dlopen scim-1.4.8/src/ltdl.cpp |
2 | --- scim-1.4.8/src/ltdl.cpp.fix-dlopen 2008-11-02 14:42:40.000000000 +0800 | |
3 | +++ scim-1.4.8/src/ltdl.cpp 2009-03-25 15:12:45.733010053 +0800 | |
4 | @@ -1,4414 +0,0 @@ | |
5 | -/* ltdl.c -- system independent dlopen wrapper | |
6 | - Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc. | |
7 | - Originally by Thomas Tanner <tanner@ffii.org> | |
8 | - This file is part of GNU Libtool. | |
9 | - | |
10 | -This library is free software; you can redistribute it and/or | |
11 | -modify it under the terms of the GNU Lesser General Public | |
12 | -License as published by the Free Software Foundation; either | |
13 | -version 2 of the License, or (at your option) any later version. | |
14 | - | |
15 | -As a special exception to the GNU Lesser General Public License, | |
16 | -if you distribute this file as part of a program or library that | |
17 | -is built using GNU libtool, you may include it under the same | |
18 | -distribution terms that you use for the rest of that program. | |
19 | - | |
20 | -This library is distributed in the hope that it will be useful, | |
21 | -but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22 | -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
23 | -Lesser General Public License for more details. | |
24 | - | |
25 | -You should have received a copy of the GNU Lesser General Public | |
26 | -License along with this library; if not, write to the Free Software | |
27 | -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | |
28 | -02111-1307 USA | |
29 | - | |
30 | -*/ | |
31 | - | |
32 | -#if HAVE_CONFIG_H | |
33 | -# include <config.h> | |
34 | -#endif | |
35 | - | |
36 | -#if HAVE_UNISTD_H | |
37 | -# include <unistd.h> | |
38 | -#endif | |
39 | - | |
40 | -#if HAVE_STDIO_H | |
41 | -# include <stdio.h> | |
42 | -#endif | |
43 | - | |
44 | -/* Include the header defining malloc. On K&R C compilers, | |
45 | - that's <malloc.h>, on ANSI C and ISO C compilers, that's <stdlib.h>. */ | |
46 | -#if HAVE_STDLIB_H | |
47 | -# include <stdlib.h> | |
48 | -#else | |
49 | -# if HAVE_MALLOC_H | |
50 | -# include <malloc.h> | |
51 | -# endif | |
52 | -#endif | |
53 | - | |
54 | -#if HAVE_STRING_H | |
55 | -# include <string.h> | |
56 | -#else | |
57 | -# if HAVE_STRINGS_H | |
58 | -# include <strings.h> | |
59 | -# endif | |
60 | -#endif | |
61 | - | |
62 | -#if HAVE_CTYPE_H | |
63 | -# include <ctype.h> | |
64 | -#endif | |
65 | - | |
66 | -#if HAVE_MEMORY_H | |
67 | -# include <memory.h> | |
68 | -#endif | |
69 | - | |
70 | -#if HAVE_ERRNO_H | |
71 | -# include <errno.h> | |
72 | -#endif | |
73 | - | |
74 | - | |
75 | -#ifndef __WINDOWS__ | |
76 | -# ifdef __WIN32__ | |
77 | -# define __WINDOWS__ | |
78 | -# endif | |
79 | -#endif | |
80 | - | |
81 | - | |
82 | -#undef LT_USE_POSIX_DIRENT | |
83 | -#ifdef HAVE_CLOSEDIR | |
84 | -# ifdef HAVE_OPENDIR | |
85 | -# ifdef HAVE_READDIR | |
86 | -# ifdef HAVE_DIRENT_H | |
87 | -# define LT_USE_POSIX_DIRENT | |
88 | -# endif /* HAVE_DIRENT_H */ | |
89 | -# endif /* HAVE_READDIR */ | |
90 | -# endif /* HAVE_OPENDIR */ | |
91 | -#endif /* HAVE_CLOSEDIR */ | |
92 | - | |
93 | - | |
94 | -#undef LT_USE_WINDOWS_DIRENT_EMULATION | |
95 | -#ifndef LT_USE_POSIX_DIRENT | |
96 | -# ifdef __WINDOWS__ | |
97 | -# define LT_USE_WINDOWS_DIRENT_EMULATION | |
98 | -# endif /* __WINDOWS__ */ | |
99 | -#endif /* LT_USE_POSIX_DIRENT */ | |
100 | - | |
101 | - | |
102 | -#ifdef LT_USE_POSIX_DIRENT | |
103 | -# include <dirent.h> | |
104 | -# define LT_D_NAMLEN(dirent) (strlen((dirent)->d_name)) | |
105 | -#else | |
106 | -# ifdef LT_USE_WINDOWS_DIRENT_EMULATION | |
107 | -# define LT_D_NAMLEN(dirent) (strlen((dirent)->d_name)) | |
108 | -# else | |
109 | -# define dirent direct | |
110 | -# define LT_D_NAMLEN(dirent) ((dirent)->d_namlen) | |
111 | -# if HAVE_SYS_NDIR_H | |
112 | -# include <sys/ndir.h> | |
113 | -# endif | |
114 | -# if HAVE_SYS_DIR_H | |
115 | -# include <sys/dir.h> | |
116 | -# endif | |
117 | -# if HAVE_NDIR_H | |
118 | -# include <ndir.h> | |
119 | -# endif | |
120 | -# endif | |
121 | -#endif | |
122 | - | |
123 | -#if HAVE_ARGZ_H | |
124 | -# include <argz.h> | |
125 | -#endif | |
126 | - | |
127 | -#if HAVE_ASSERT_H | |
128 | -# include <assert.h> | |
129 | -#else | |
130 | -# define assert(arg) ((void) 0) | |
131 | -#endif | |
132 | - | |
133 | -#include "ltdl.h" | |
134 | - | |
135 | -#if WITH_DMALLOC | |
136 | -# include <dmalloc.h> | |
137 | -#endif | |
138 | - | |
139 | - | |
140 | - | |
141 | -\f | |
142 | -/* --- WINDOWS SUPPORT --- */ | |
143 | - | |
144 | - | |
145 | -#ifdef DLL_EXPORT | |
146 | -# define LT_GLOBAL_DATA __declspec(dllexport) | |
147 | -#else | |
148 | -# define LT_GLOBAL_DATA | |
149 | -#endif | |
150 | - | |
151 | -/* fopen() mode flags for reading a text file */ | |
152 | -#undef LT_READTEXT_MODE | |
153 | -#ifdef __WINDOWS__ | |
154 | -# define LT_READTEXT_MODE "rt" | |
155 | -#else | |
156 | -# define LT_READTEXT_MODE "r" | |
157 | -#endif | |
158 | - | |
159 | -#ifdef LT_USE_WINDOWS_DIRENT_EMULATION | |
160 | - | |
161 | -#include <windows.h> | |
162 | - | |
163 | -#define dirent lt_dirent | |
164 | -#define DIR lt_DIR | |
165 | - | |
166 | -struct dirent | |
167 | -{ | |
168 | - char d_name[2048]; | |
169 | - int d_namlen; | |
170 | -}; | |
171 | - | |
172 | -typedef struct _DIR | |
173 | -{ | |
174 | - HANDLE hSearch; | |
175 | - WIN32_FIND_DATA Win32FindData; | |
176 | - BOOL firsttime; | |
177 | - struct dirent file_info; | |
178 | -} DIR; | |
179 | - | |
180 | -#endif /* LT_USE_WINDOWS_DIRENT_EMULATION */ | |
181 | - | |
182 | -namespace scim { | |
183 | - | |
184 | -\f | |
185 | -/* --- MANIFEST CONSTANTS --- */ | |
186 | - | |
187 | - | |
188 | -/* Standard libltdl search path environment variable name */ | |
189 | -#undef LTDL_SEARCHPATH_VAR | |
190 | -#define LTDL_SEARCHPATH_VAR "LTDL_LIBRARY_PATH" | |
191 | - | |
192 | -/* Standard libtool archive file extension. */ | |
193 | -#undef LTDL_ARCHIVE_EXT | |
194 | -#define LTDL_ARCHIVE_EXT ".la" | |
195 | - | |
196 | -/* max. filename length */ | |
197 | -#ifndef LT_FILENAME_MAX | |
198 | -# define LT_FILENAME_MAX 1024 | |
199 | -#endif | |
200 | - | |
201 | -/* This is the maximum symbol size that won't require malloc/free */ | |
202 | -#undef LT_SYMBOL_LENGTH | |
203 | -#define LT_SYMBOL_LENGTH 128 | |
204 | - | |
205 | -/* This accounts for the _LTX_ separator */ | |
206 | -#undef LT_SYMBOL_OVERHEAD | |
207 | -#define LT_SYMBOL_OVERHEAD 5 | |
208 | - | |
209 | - | |
210 | - | |
211 | -\f | |
212 | -/* --- MEMORY HANDLING --- */ | |
213 | - | |
214 | - | |
215 | -/* These are the functions used internally. In addition to making | |
216 | - use of the associated function pointers above, they also perform | |
217 | - error handling. */ | |
218 | -static char *lt_estrdup LT_PARAMS((const char *str)); | |
219 | -static lt_ptr lt_emalloc LT_PARAMS((size_t size)); | |
220 | -static lt_ptr lt_erealloc LT_PARAMS((lt_ptr addr, size_t size)); | |
221 | - | |
222 | -/* static lt_ptr rpl_realloc LT_PARAMS((lt_ptr ptr, size_t size)); */ | |
223 | -#define rpl_realloc realloc | |
224 | - | |
225 | -/* These are the pointers that can be changed by the caller: */ | |
226 | -LT_GLOBAL_DATA lt_ptr (*lt_dlmalloc) LT_PARAMS((size_t size)) | |
227 | - = (lt_ptr (*) LT_PARAMS((size_t))) malloc; | |
228 | -LT_GLOBAL_DATA lt_ptr (*lt_dlrealloc) LT_PARAMS((lt_ptr ptr, size_t size)) | |
229 | - = (lt_ptr (*) LT_PARAMS((lt_ptr, size_t))) rpl_realloc; | |
230 | -LT_GLOBAL_DATA void (*lt_dlfree) LT_PARAMS((lt_ptr ptr)) | |
231 | - = (void (*) LT_PARAMS((lt_ptr))) free; | |
232 | - | |
233 | -/* The following macros reduce the amount of typing needed to cast | |
234 | - assigned memory. */ | |
235 | -#if WITH_DMALLOC | |
236 | - | |
237 | -#define LT_DLMALLOC(tp, n) ((tp *) xmalloc ((n) * sizeof(tp))) | |
238 | -#define LT_DLREALLOC(tp, p, n) ((tp *) xrealloc ((p), (n) * sizeof(tp))) | |
239 | -#define LT_DLFREE(p) \ | |
240 | - LT_STMT_START { if (p) { xfree (p); (p) = 0; } } LT_STMT_END | |
241 | - | |
242 | -#define LT_EMALLOC(tp, n) ((tp *) xmalloc ((n) * sizeof(tp))) | |
243 | -#define LT_EREALLOC(tp, p, n) ((tp *) xrealloc ((p), (n) * sizeof(tp))) | |
244 | - | |
245 | -#else | |
246 | - | |
247 | -#define LT_DLMALLOC(tp, n) ((tp *) lt_dlmalloc ((n) * sizeof(tp))) | |
248 | -#define LT_DLREALLOC(tp, p, n) ((tp *) lt_dlrealloc ((p), (n) * sizeof(tp))) | |
249 | -#define LT_DLFREE(p) \ | |
250 | - LT_STMT_START { if (p) { lt_dlfree (p); (p) = 0; } } LT_STMT_END | |
251 | - | |
252 | -#define LT_EMALLOC(tp, n) ((tp *) lt_emalloc ((n) * sizeof(tp))) | |
253 | -#define LT_EREALLOC(tp, p, n) ((tp *) lt_erealloc ((p), (n) * sizeof(tp))) | |
254 | - | |
255 | -#endif | |
256 | - | |
257 | -#define LT_DLMEM_REASSIGN(p, q) LT_STMT_START { \ | |
258 | - if ((p) != (q)) { if (p) lt_dlfree (p); (p) = (q); (q) = 0; } \ | |
259 | - } LT_STMT_END | |
260 | - | |
261 | -\f | |
262 | -/* --- REPLACEMENT FUNCTIONS --- */ | |
263 | - | |
264 | - | |
265 | -#undef strdup | |
266 | -#define strdup rpl_strdup | |
267 | - | |
268 | -static char *strdup LT_PARAMS((const char *str)); | |
269 | - | |
270 | -static char * | |
271 | -strdup(const char *str) | |
272 | -{ | |
273 | - char *tmp = 0; | |
274 | - | |
275 | - if (str) | |
276 | - { | |
277 | - tmp = LT_DLMALLOC (char, 1+ strlen (str)); | |
278 | - if (tmp) | |
279 | - { | |
280 | - strcpy(tmp, str); | |
281 | - } | |
282 | - } | |
283 | - | |
284 | - return tmp; | |
285 | -} | |
286 | - | |
287 | - | |
288 | -#if ! HAVE_STRCMP | |
289 | - | |
290 | -#undef strcmp | |
291 | -#define strcmp rpl_strcmp | |
292 | - | |
293 | -static int strcmp LT_PARAMS((const char *str1, const char *str2)); | |
294 | - | |
295 | -static int | |
296 | -strcmp (const char *str1, const char *str2) | |
297 | -{ | |
298 | - if (str1 == str2) | |
299 | - return 0; | |
300 | - if (str1 == 0) | |
301 | - return -1; | |
302 | - if (str2 == 0) | |
303 | - return 1; | |
304 | - | |
305 | - for (;*str1 && *str2; ++str1, ++str2) | |
306 | - { | |
307 | - if (*str1 != *str2) | |
308 | - break; | |
309 | - } | |
310 | - | |
311 | - return (int)(*str1 - *str2); | |
312 | -} | |
313 | -#endif | |
314 | - | |
315 | - | |
316 | -#if ! HAVE_STRCHR | |
317 | - | |
318 | -# if HAVE_INDEX | |
319 | -# define strchr index | |
320 | -# else | |
321 | -# define strchr rpl_strchr | |
322 | - | |
323 | -static const char *strchr LT_PARAMS((const char *str, int ch)); | |
324 | - | |
325 | -static const char* | |
326 | -strchr(const char *str, int ch) | |
327 | -{ | |
328 | - const char *p; | |
329 | - | |
330 | - for (p = str; *p != (char)ch && *p != LT_EOS_CHAR; ++p) | |
331 | - /*NOWORK*/; | |
332 | - | |
333 | - return (*p == (char)ch) ? p : 0; | |
334 | -} | |
335 | - | |
336 | -# endif | |
337 | -#endif /* !HAVE_STRCHR */ | |
338 | - | |
339 | - | |
340 | -#if ! HAVE_STRRCHR | |
341 | - | |
342 | -# if HAVE_RINDEX | |
343 | -# define strrchr rindex | |
344 | -# else | |
345 | -# define strrchr rpl_strrchr | |
346 | - | |
347 | -static const char *strrchr LT_PARAMS((const char *str, int ch)); | |
348 | - | |
349 | -static const char* | |
350 | -strrchr(const char *str, int ch) | |
351 | -{ | |
352 | - const char *p, *q = 0; | |
353 | - | |
354 | - for (p = str; *p != LT_EOS_CHAR; ++p) | |
355 | - { | |
356 | - if (*p == (char) ch) | |
357 | - { | |
358 | - q = p; | |
359 | - } | |
360 | - } | |
361 | - | |
362 | - return q; | |
363 | -} | |
364 | - | |
365 | -# endif | |
366 | -#endif | |
367 | - | |
368 | -/* NOTE: Neither bcopy nor the memcpy implementation below can | |
369 | - reliably handle copying in overlapping areas of memory. Use | |
370 | - memmove (for which there is a fallback implmentation below) | |
371 | - if you need that behaviour. */ | |
372 | -#if ! HAVE_MEMCPY | |
373 | - | |
374 | -# if HAVE_BCOPY | |
375 | -# define memcpy(dest, src, size) bcopy (src, dest, size) | |
376 | -# else | |
377 | -# define memcpy rpl_memcpy | |
378 | - | |
379 | -static lt_ptr memcpy LT_PARAMS((lt_ptr dest, const lt_ptr src, size_t size)); | |
380 | - | |
381 | -static lt_ptr | |
382 | -memcpy (lt_ptr dest, const lt_ptr src, size_t size) | |
383 | -{ | |
384 | - size_t i = 0; | |
385 | - | |
386 | - for (i = 0; i < size; ++i) | |
387 | - { | |
388 | - dest[i] = src[i]; | |
389 | - } | |
390 | - | |
391 | - return dest; | |
392 | -} | |
393 | - | |
394 | -# endif /* !HAVE_BCOPY */ | |
395 | -#endif /* !HAVE_MEMCPY */ | |
396 | - | |
397 | -#if ! HAVE_MEMMOVE | |
398 | -# define memmove rpl_memmove | |
399 | - | |
400 | -static lt_ptr memmove LT_PARAMS((lt_ptr dest, const lt_ptr src, size_t size)); | |
401 | - | |
402 | -static lt_ptr | |
403 | -memmove (lt_ptr dest, const lt_ptr src, size_t size) | |
404 | -{ | |
405 | - size_t i; | |
406 | - | |
407 | - if (dest < src) | |
408 | - for (i = 0; i < size; ++i) | |
409 | - { | |
410 | - dest[i] = src[i]; | |
411 | - } | |
412 | - else if (dest > src) | |
413 | - for (i = size -1; i >= 0; --i) | |
414 | - { | |
415 | - dest[i] = src[i]; | |
416 | - } | |
417 | - | |
418 | - return dest; | |
419 | -} | |
420 | - | |
421 | -#endif /* !HAVE_MEMMOVE */ | |
422 | - | |
423 | -#ifdef LT_USE_WINDOWS_DIRENT_EMULATION | |
424 | - | |
425 | -static void closedir LT_PARAMS((DIR *entry)); | |
426 | - | |
427 | -static void | |
428 | -closedir(DIR *entry) | |
429 | -{ | |
430 | - assert(entry != (DIR *) NULL); | |
431 | - FindClose(entry->hSearch); | |
432 | - lt_dlfree((lt_ptr)entry); | |
433 | -} | |
434 | - | |
435 | - | |
436 | -static DIR * opendir LT_PARAMS((const char *path)); | |
437 | - | |
438 | -static DIR* | |
439 | -opendir (const char *path) | |
440 | -{ | |
441 | - char file_specification[LT_FILENAME_MAX]; | |
442 | - DIR *entry; | |
443 | - | |
444 | - assert(path != (char *) NULL); | |
445 | - (void) strncpy(file_specification,path,LT_FILENAME_MAX-1); | |
446 | - (void) strcat(file_specification,"\\"); | |
447 | - entry = LT_DLMALLOC (DIR,sizeof(DIR)); | |
448 | - if (entry != (DIR *) 0) | |
449 | - { | |
450 | - entry->firsttime = TRUE; | |
451 | - entry->hSearch = FindFirstFile(file_specification,&entry->Win32FindData); | |
452 | - } | |
453 | - if (entry->hSearch == INVALID_HANDLE_VALUE) | |
454 | - { | |
455 | - (void) strcat(file_specification,"\\*.*"); | |
456 | - entry->hSearch = FindFirstFile(file_specification,&entry->Win32FindData); | |
457 | - if (entry->hSearch == INVALID_HANDLE_VALUE) | |
458 | - { | |
459 | - LT_DLFREE (entry); | |
460 | - return (DIR *) 0; | |
461 | - } | |
462 | - } | |
463 | - return(entry); | |
464 | -} | |
465 | - | |
466 | - | |
467 | -static struct dirent *readdir LT_PARAMS((DIR *entry)); | |
468 | - | |
469 | -static struct dirent *readdir(DIR *entry) | |
470 | -{ | |
471 | - int | |
472 | - status; | |
473 | - | |
474 | - if (entry == (DIR *) 0) | |
475 | - return((struct dirent *) 0); | |
476 | - if (!entry->firsttime) | |
477 | - { | |
478 | - status = FindNextFile(entry->hSearch,&entry->Win32FindData); | |
479 | - if (status == 0) | |
480 | - return((struct dirent *) 0); | |
481 | - } | |
482 | - entry->firsttime = FALSE; | |
483 | - (void) strncpy(entry->file_info.d_name,entry->Win32FindData.cFileName, | |
484 | - LT_FILENAME_MAX-1); | |
485 | - entry->file_info.d_namlen = strlen(entry->file_info.d_name); | |
486 | - return(&entry->file_info); | |
487 | -} | |
488 | - | |
489 | -#endif /* LT_USE_WINDOWS_DIRENT_EMULATION */ | |
490 | - | |
491 | -/* According to Alexandre Oliva <oliva@lsd.ic.unicamp.br>, | |
492 | - ``realloc is not entirely portable'' | |
493 | - In any case we want to use the allocator supplied by the user without | |
494 | - burdening them with an lt_dlrealloc function pointer to maintain. | |
495 | - Instead implement our own version (with known boundary conditions) | |
496 | - using lt_dlmalloc and lt_dlfree. */ | |
497 | - | |
498 | -/* #undef realloc | |
499 | - #define realloc rpl_realloc | |
500 | -*/ | |
501 | -#if 0 | |
502 | - /* You can't (re)define realloc unless you also (re)define malloc. | |
503 | - Right now, this code uses the size of the *destination* to decide | |
504 | - how much to copy. That's not right, but you can't know the size | |
505 | - of the source unless you know enough about, or wrote malloc. So | |
506 | - this code is disabled... */ | |
507 | - | |
508 | -static lt_ptr | |
509 | -realloc (ptr, size) | |
510 | - lt_ptr ptr; | |
511 | - size_t size; | |
512 | -{ | |
513 | - if (size == 0) | |
514 | - { | |
515 | - /* For zero or less bytes, free the original memory */ | |
516 | - if (ptr != 0) | |
517 | - { | |
518 | - lt_dlfree (ptr); | |
519 | - } | |
520 | - | |
521 | - return (lt_ptr) 0; | |
522 | - } | |
523 | - else if (ptr == 0) | |
524 | - { | |
525 | - /* Allow reallocation of a NULL pointer. */ | |
526 | - return lt_dlmalloc (size); | |
527 | - } | |
528 | - else | |
529 | - { | |
530 | - /* Allocate a new block, copy and free the old block. */ | |
531 | - lt_ptr mem = lt_dlmalloc (size); | |
532 | - | |
533 | - if (mem) | |
534 | - { | |
535 | - memcpy (mem, ptr, size); | |
536 | - lt_dlfree (ptr); | |
537 | - } | |
538 | - | |
539 | - /* Note that the contents of PTR are not damaged if there is | |
540 | - insufficient memory to realloc. */ | |
541 | - return mem; | |
542 | - } | |
543 | -} | |
544 | -#endif | |
545 | - | |
546 | - | |
547 | -#if ! HAVE_ARGZ_APPEND | |
548 | -# define argz_append rpl_argz_append | |
549 | - | |
550 | -static error_t argz_append LT_PARAMS((char **pargz, size_t *pargz_len, | |
551 | - const char *buf, size_t buf_len)); | |
552 | - | |
553 | -static error_t | |
554 | -argz_append (char **pargz, size_t *pargz_len, const char *buf, size_t buf_len) | |
555 | -{ | |
556 | - size_t argz_len; | |
557 | - char *argz; | |
558 | - | |
559 | - assert (pargz); | |
560 | - assert (pargz_len); | |
561 | - assert ((*pargz && *pargz_len) || (!*pargz && !*pargz_len)); | |
562 | - | |
563 | - /* If nothing needs to be appended, no more work is required. */ | |
564 | - if (buf_len == 0) | |
565 | - return 0; | |
566 | - | |
567 | - /* Ensure there is enough room to append BUF_LEN. */ | |
568 | - argz_len = *pargz_len + buf_len; | |
569 | - argz = LT_DLREALLOC (char, *pargz, argz_len); | |
570 | - if (!argz) | |
571 | - return ENOMEM; | |
572 | - | |
573 | - /* Copy characters from BUF after terminating '\0' in ARGZ. */ | |
574 | - memcpy (argz + *pargz_len, buf, buf_len); | |
575 | - | |
576 | - /* Assign new values. */ | |
577 | - *pargz = argz; | |
578 | - *pargz_len = argz_len; | |
579 | - | |
580 | - return 0; | |
581 | -} | |
582 | -#endif /* !HAVE_ARGZ_APPEND */ | |
583 | - | |
584 | - | |
585 | -#if ! HAVE_ARGZ_CREATE_SEP | |
586 | -# define argz_create_sep rpl_argz_create_sep | |
587 | - | |
588 | -static error_t argz_create_sep LT_PARAMS((const char *str, int delim, | |
589 | - char **pargz, size_t *pargz_len)); | |
590 | - | |
591 | -static error_t | |
592 | -argz_create_sep (const char *str, int delim, char **pargz, size_t *pargz_len) | |
593 | -{ | |
594 | - size_t argz_len; | |
595 | - char *argz = 0; | |
596 | - | |
597 | - assert (str); | |
598 | - assert (pargz); | |
599 | - assert (pargz_len); | |
600 | - | |
601 | - /* Make a copy of STR, but replacing each occurence of | |
602 | - DELIM with '\0'. */ | |
603 | - argz_len = 1+ LT_STRLEN (str); | |
604 | - if (argz_len) | |
605 | - { | |
606 | - const char *p; | |
607 | - char *q; | |
608 | - | |
609 | - argz = LT_DLMALLOC (char, argz_len); | |
610 | - if (!argz) | |
611 | - return ENOMEM; | |
612 | - | |
613 | - for (p = str, q = argz; *p != LT_EOS_CHAR; ++p) | |
614 | - { | |
615 | - if (*p == delim) | |
616 | - { | |
617 | - /* Ignore leading delimiters, and fold consecutive | |
618 | - delimiters in STR into a single '\0' in ARGZ. */ | |
619 | - if ((q > argz) && (q[-1] != LT_EOS_CHAR)) | |
620 | - *q++ = LT_EOS_CHAR; | |
621 | - else | |
622 | - --argz_len; | |
623 | - } | |
624 | - else | |
625 | - *q++ = *p; | |
626 | - } | |
627 | - /* Copy terminating LT_EOS_CHAR. */ | |
628 | - *q = *p; | |
629 | - } | |
630 | - | |
631 | - /* If ARGZ_LEN has shrunk to nothing, release ARGZ's memory. */ | |
632 | - if (!argz_len) | |
633 | - LT_DLFREE (argz); | |
634 | - | |
635 | - /* Assign new values. */ | |
636 | - *pargz = argz; | |
637 | - *pargz_len = argz_len; | |
638 | - | |
639 | - return 0; | |
640 | -} | |
641 | -#endif /* !HAVE_ARGZ_CREATE_SEP */ | |
642 | - | |
643 | - | |
644 | -#if ! HAVE_ARGZ_INSERT | |
645 | -# define argz_insert rpl_argz_insert | |
646 | - | |
647 | -static error_t argz_insert LT_PARAMS((char **pargz, size_t *pargz_len, | |
648 | - char *before, const char *entry)); | |
649 | - | |
650 | -static error_t | |
651 | -argz_insert (char **pargz, size_t *pargz_len, char *before, const char *entry) | |
652 | -{ | |
653 | - assert (pargz); | |
654 | - assert (pargz_len); | |
655 | - assert (entry && *entry); | |
656 | - | |
657 | - /* No BEFORE address indicates ENTRY should be inserted after the | |
658 | - current last element. */ | |
659 | - if (!before) | |
660 | - return argz_append (pargz, pargz_len, entry, 1+ LT_STRLEN (entry)); | |
661 | - | |
662 | - /* This probably indicates a programmer error, but to preserve | |
663 | - semantics, scan back to the start of an entry if BEFORE points | |
664 | - into the middle of it. */ | |
665 | - while ((before > *pargz) && (before[-1] != LT_EOS_CHAR)) | |
666 | - --before; | |
667 | - | |
668 | - { | |
669 | - size_t entry_len = 1+ LT_STRLEN (entry); | |
670 | - size_t argz_len = *pargz_len + entry_len; | |
671 | - size_t offset = before - *pargz; | |
672 | - char *argz = LT_DLREALLOC (char, *pargz, argz_len); | |
673 | - | |
674 | - if (!argz) | |
675 | - return ENOMEM; | |
676 | - | |
677 | - /* Make BEFORE point to the equivalent offset in ARGZ that it | |
678 | - used to have in *PARGZ incase realloc() moved the block. */ | |
679 | - before = argz + offset; | |
680 | - | |
681 | - /* Move the ARGZ entries starting at BEFORE up into the new | |
682 | - space at the end -- making room to copy ENTRY into the | |
683 | - resulting gap. */ | |
684 | - memmove (before + entry_len, before, *pargz_len - offset); | |
685 | - memcpy (before, entry, entry_len); | |
686 | - | |
687 | - /* Assign new values. */ | |
688 | - *pargz = argz; | |
689 | - *pargz_len = argz_len; | |
690 | - } | |
691 | - | |
692 | - return 0; | |
693 | -} | |
694 | -#endif /* !HAVE_ARGZ_INSERT */ | |
695 | - | |
696 | - | |
697 | -#if ! HAVE_ARGZ_NEXT | |
698 | -# define argz_next rpl_argz_next | |
699 | - | |
700 | -static char *argz_next LT_PARAMS((char *argz, size_t argz_len, | |
701 | - const char *entry)); | |
702 | - | |
703 | -static char * | |
704 | -argz_next (char *argz, size_t argz_len, const char *entry) | |
705 | -{ | |
706 | - assert ((argz && argz_len) || (!argz && !argz_len)); | |
707 | - | |
708 | - if (entry) | |
709 | - { | |
710 | - /* Either ARGZ/ARGZ_LEN is empty, or ENTRY points into an address | |
711 | - within the ARGZ vector. */ | |
712 | - assert ((!argz && !argz_len) | |
713 | - || ((argz <= entry) && (entry < (argz + argz_len)))); | |
714 | - | |
715 | - /* Move to the char immediately after the terminating | |
716 | - '\0' of ENTRY. */ | |
717 | - entry = 1+ strchr (entry, LT_EOS_CHAR); | |
718 | - | |
719 | - /* Return either the new ENTRY, or else NULL if ARGZ is | |
720 | - exhausted. */ | |
721 | - return (entry >= argz + argz_len) ? 0 : (char *) entry; | |
722 | - } | |
723 | - else | |
724 | - { | |
725 | - /* This should probably be flagged as a programmer error, | |
726 | - since starting an argz_next loop with the iterator set | |
727 | - to ARGZ is safer. To preserve semantics, handle the NULL | |
728 | - case by returning the start of ARGZ (if any). */ | |
729 | - if (argz_len > 0) | |
730 | - return argz; | |
731 | - else | |
732 | - return 0; | |
733 | - } | |
734 | -} | |
735 | -#endif /* !HAVE_ARGZ_NEXT */ | |
736 | - | |
737 | - | |
738 | - | |
739 | -#if ! HAVE_ARGZ_STRINGIFY | |
740 | -# define argz_stringify rpl_argz_stringify | |
741 | - | |
742 | -static void argz_stringify LT_PARAMS((char *argz, size_t argz_len, | |
743 | - int sep)); | |
744 | - | |
745 | -static void | |
746 | -argz_stringify (char *argz, size_t argz_len, int sep) | |
747 | -{ | |
748 | - assert ((argz && argz_len) || (!argz && !argz_len)); | |
749 | - | |
750 | - if (sep) | |
751 | - { | |
752 | - --argz_len; /* don't stringify the terminating EOS */ | |
753 | - while (--argz_len > 0) | |
754 | - { | |
755 | - if (argz[argz_len] == LT_EOS_CHAR) | |
756 | - argz[argz_len] = sep; | |
757 | - } | |
758 | - } | |
759 | -} | |
760 | -#endif /* !HAVE_ARGZ_STRINGIFY */ | |
761 | - | |
762 | - | |
763 | - | |
764 | -\f | |
765 | -/* --- TYPE DEFINITIONS -- */ | |
766 | - | |
767 | - | |
768 | -/* This type is used for the array of caller data sets in each handler. */ | |
769 | -typedef struct { | |
770 | - lt_dlcaller_id key; | |
771 | - lt_ptr data; | |
772 | -} lt_caller_data; | |
773 | - | |
774 | - | |
775 | - | |
776 | -\f | |
777 | -/* --- OPAQUE STRUCTURES DECLARED IN LTDL.H --- */ | |
778 | - | |
779 | - | |
780 | -/* Extract the diagnostic strings from the error table macro in the same | |
781 | - order as the enumerated indices in ltdl.h. */ | |
782 | - | |
783 | -static const char *lt_dlerror_strings[] = | |
784 | - { | |
785 | -#define LT_ERROR(name, diagnostic) (diagnostic), | |
786 | - lt_dlerror_table | |
787 | -#undef LT_ERROR | |
788 | - | |
789 | - 0 | |
790 | - }; | |
791 | - | |
792 | -/* This structure is used for the list of registered loaders. */ | |
793 | -struct lt_dlloader { | |
794 | - struct lt_dlloader *next; | |
795 | - const char *loader_name; /* identifying name for each loader */ | |
796 | - const char *sym_prefix; /* prefix for symbols */ | |
797 | - lt_module_open *module_open; | |
798 | - lt_module_close *module_close; | |
799 | - lt_find_sym *find_sym; | |
800 | - lt_dlloader_exit *dlloader_exit; | |
801 | - lt_user_data dlloader_data; | |
802 | -}; | |
803 | - | |
804 | -struct lt_dlhandle_struct { | |
805 | - struct lt_dlhandle_struct *next; | |
806 | - lt_dlloader *loader; /* dlopening interface */ | |
807 | - lt_dlinfo info; | |
808 | - int depcount; /* number of dependencies */ | |
809 | - lt_dlhandle *deplibs; /* dependencies */ | |
810 | - lt_module module; /* system module handle */ | |
811 | - lt_ptr system; /* system specific data */ | |
812 | - lt_caller_data *caller_data; /* per caller associated data */ | |
813 | - int flags; /* various boolean stats */ | |
814 | -}; | |
815 | - | |
816 | -/* Various boolean flags can be stored in the flags field of an | |
817 | - lt_dlhandle_struct... */ | |
818 | -#define LT_DLGET_FLAG(handle, flag) (((handle)->flags & (flag)) == (flag)) | |
819 | -#define LT_DLSET_FLAG(handle, flag) ((handle)->flags |= (flag)) | |
820 | - | |
821 | -#define LT_DLRESIDENT_FLAG (0x01 << 0) | |
822 | -/* ...add more flags here... */ | |
823 | - | |
824 | -#define LT_DLIS_RESIDENT(handle) LT_DLGET_FLAG(handle, LT_DLRESIDENT_FLAG) | |
825 | - | |
826 | - | |
827 | -#define LT_DLSTRERROR(name) lt_dlerror_strings[LT_CONC(LT_ERROR_,name)] | |
828 | - | |
829 | -static const char objdir[] = LTDL_OBJDIR; | |
830 | -static const char archive_ext[] = LTDL_ARCHIVE_EXT; | |
831 | -#ifdef LTDL_SHLIB_EXT | |
832 | -static const char shlib_ext[] = LTDL_SHLIB_EXT; | |
833 | -#endif | |
834 | -#ifdef LTDL_SYSSEARCHPATH | |
835 | -static const char sys_search_path[] = LTDL_SYSSEARCHPATH; | |
836 | -#endif | |
837 | - | |
838 | - | |
839 | - | |
840 | -\f | |
841 | -/* --- MUTEX LOCKING --- */ | |
842 | - | |
843 | - | |
844 | -/* Macros to make it easier to run the lock functions only if they have | |
845 | - been registered. The reason for the complicated lock macro is to | |
846 | - ensure that the stored error message from the last error is not | |
847 | - accidentally erased if the current function doesn't generate an | |
848 | - error of its own. */ | |
849 | -#define LT_DLMUTEX_LOCK() LT_STMT_START { \ | |
850 | - if (lt_dlmutex_lock_func) (*lt_dlmutex_lock_func)(); \ | |
851 | - } LT_STMT_END | |
852 | -#define LT_DLMUTEX_UNLOCK() LT_STMT_START { \ | |
853 | - if (lt_dlmutex_unlock_func) (*lt_dlmutex_unlock_func)();\ | |
854 | - } LT_STMT_END | |
855 | -#define LT_DLMUTEX_SETERROR(errormsg) LT_STMT_START { \ | |
856 | - if (lt_dlmutex_seterror_func) \ | |
857 | - (*lt_dlmutex_seterror_func) (errormsg); \ | |
858 | - else lt_dllast_error = (errormsg); } LT_STMT_END | |
859 | -#define LT_DLMUTEX_GETERROR(errormsg) LT_STMT_START { \ | |
860 | - if (lt_dlmutex_seterror_func) \ | |
861 | - (errormsg) = (*lt_dlmutex_geterror_func) (); \ | |
862 | - else (errormsg) = lt_dllast_error; } LT_STMT_END | |
863 | - | |
864 | -/* The mutex functions stored here are global, and are necessarily the | |
865 | - same for all threads that wish to share access to libltdl. */ | |
866 | -static lt_dlmutex_lock *lt_dlmutex_lock_func = 0; | |
867 | -static lt_dlmutex_unlock *lt_dlmutex_unlock_func = 0; | |
868 | -static lt_dlmutex_seterror *lt_dlmutex_seterror_func = 0; | |
869 | -static lt_dlmutex_geterror *lt_dlmutex_geterror_func = 0; | |
870 | -static const char *lt_dllast_error = 0; | |
871 | - | |
872 | - | |
873 | -/* Either set or reset the mutex functions. Either all the arguments must | |
874 | - be valid functions, or else all can be NULL to turn off locking entirely. | |
875 | - The registered functions should be manipulating a static global lock | |
876 | - from the lock() and unlock() callbacks, which needs to be reentrant. */ | |
877 | -int | |
878 | -lt_dlmutex_register ( | |
879 | - lt_dlmutex_lock *lock, | |
880 | - lt_dlmutex_unlock *unlock, | |
881 | - lt_dlmutex_seterror *seterror, | |
882 | - lt_dlmutex_geterror *geterror) | |
883 | -{ | |
884 | - lt_dlmutex_unlock *old_unlock = unlock; | |
885 | - int errors = 0; | |
886 | - | |
887 | - /* Lock using the old lock() callback, if any. */ | |
888 | - LT_DLMUTEX_LOCK (); | |
889 | - | |
890 | - if ((lock && unlock && seterror && geterror) | |
891 | - || !(lock || unlock || seterror || geterror)) | |
892 | - { | |
893 | - lt_dlmutex_lock_func = lock; | |
894 | - lt_dlmutex_unlock_func = unlock; | |
895 | - lt_dlmutex_geterror_func = geterror; | |
896 | - } | |
897 | - else | |
898 | - { | |
899 | - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INVALID_MUTEX_ARGS)); | |
900 | - ++errors; | |
901 | - } | |
902 | - | |
903 | - /* Use the old unlock() callback we saved earlier, if any. Otherwise | |
904 | - record any errors using internal storage. */ | |
905 | - if (old_unlock) | |
906 | - (*old_unlock) (); | |
907 | - | |
908 | - /* Return the number of errors encountered during the execution of | |
909 | - this function. */ | |
910 | - return errors; | |
911 | -} | |
912 | - | |
913 | - | |
914 | - | |
915 | -\f | |
916 | -/* --- ERROR HANDLING --- */ | |
917 | - | |
918 | - | |
919 | -static const char **user_error_strings = 0; | |
920 | -static int errorcount = LT_ERROR_MAX; | |
921 | - | |
922 | -int | |
923 | -lt_dladderror (const char *diagnostic) | |
924 | -{ | |
925 | - int errindex = 0; | |
926 | - int result = -1; | |
927 | - const char **temp = (const char **) 0; | |
928 | - | |
929 | - assert (diagnostic); | |
930 | - | |
931 | - LT_DLMUTEX_LOCK (); | |
932 | - | |
933 | - errindex = errorcount - LT_ERROR_MAX; | |
934 | - temp = LT_EREALLOC (const char *, user_error_strings, 1 + errindex); | |
935 | - if (temp) | |
936 | - { | |
937 | - user_error_strings = temp; | |
938 | - user_error_strings[errindex] = diagnostic; | |
939 | - result = errorcount++; | |
940 | - } | |
941 | - | |
942 | - LT_DLMUTEX_UNLOCK (); | |
943 | - | |
944 | - return result; | |
945 | -} | |
946 | - | |
947 | -int | |
948 | -lt_dlseterror (int errindex) | |
949 | -{ | |
950 | - int errors = 0; | |
951 | - | |
952 | - LT_DLMUTEX_LOCK (); | |
953 | - | |
954 | - if (errindex >= errorcount || errindex < 0) | |
955 | - { | |
956 | - /* Ack! Error setting the error message! */ | |
957 | - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INVALID_ERRORCODE)); | |
958 | - ++errors; | |
959 | - } | |
960 | - else if (errindex < LT_ERROR_MAX) | |
961 | - { | |
962 | - /* No error setting the error message! */ | |
963 | - LT_DLMUTEX_SETERROR (lt_dlerror_strings[errindex]); | |
964 | - } | |
965 | - else | |
966 | - { | |
967 | - /* No error setting the error message! */ | |
968 | - LT_DLMUTEX_SETERROR (user_error_strings[errindex - LT_ERROR_MAX]); | |
969 | - } | |
970 | - | |
971 | - LT_DLMUTEX_UNLOCK (); | |
972 | - | |
973 | - return errors; | |
974 | -} | |
975 | - | |
976 | -static lt_ptr | |
977 | -lt_emalloc (size_t size) | |
978 | -{ | |
979 | - lt_ptr mem = lt_dlmalloc (size); | |
980 | - if (size && !mem) | |
981 | - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY)); | |
982 | - return mem; | |
983 | -} | |
984 | - | |
985 | -static lt_ptr | |
986 | -lt_erealloc (lt_ptr addr, size_t size) | |
987 | -{ | |
988 | - lt_ptr mem = lt_dlrealloc (addr, size); | |
989 | - if (size && !mem) | |
990 | - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY)); | |
991 | - return mem; | |
992 | -} | |
993 | - | |
994 | -static char * | |
995 | -lt_estrdup (const char *str) | |
996 | -{ | |
997 | - char *copy = strdup (str); | |
998 | - if (LT_STRLEN (str) && !copy) | |
999 | - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY)); | |
1000 | - return copy; | |
1001 | -} | |
1002 | - | |
1003 | - | |
1004 | - | |
1005 | -\f | |
1006 | -/* --- DLOPEN() INTERFACE LOADER --- */ | |
1007 | - | |
1008 | - | |
1009 | -#if HAVE_LIBDL | |
1010 | - | |
1011 | -/* dynamic linking with dlopen/dlsym */ | |
1012 | - | |
1013 | -#if HAVE_DLFCN_H | |
1014 | -# include <dlfcn.h> | |
1015 | -#endif | |
1016 | - | |
1017 | -#if HAVE_SYS_DL_H | |
1018 | -# include <sys/dl.h> | |
1019 | -#endif | |
1020 | - | |
1021 | -#ifdef RTLD_GLOBAL | |
1022 | -# define LT_GLOBAL RTLD_GLOBAL | |
1023 | -#else | |
1024 | -# ifdef DL_GLOBAL | |
1025 | -# define LT_GLOBAL DL_GLOBAL | |
1026 | -# endif | |
1027 | -#endif /* !RTLD_GLOBAL */ | |
1028 | -#ifndef LT_GLOBAL | |
1029 | -# define LT_GLOBAL 0 | |
1030 | -#endif /* !LT_GLOBAL */ | |
1031 | - | |
1032 | -/* We may have to define LT_LAZY_OR_NOW in the command line if we | |
1033 | - find out it does not work in some platform. */ | |
1034 | -#ifndef LT_LAZY_OR_NOW | |
1035 | -# ifdef RTLD_LAZY | |
1036 | -# define LT_LAZY_OR_NOW RTLD_LAZY | |
1037 | -# else | |
1038 | -# ifdef DL_LAZY | |
1039 | -# define LT_LAZY_OR_NOW DL_LAZY | |
1040 | -# endif | |
1041 | -# endif /* !RTLD_LAZY */ | |
1042 | -#endif | |
1043 | -#ifndef LT_LAZY_OR_NOW | |
1044 | -# ifdef RTLD_NOW | |
1045 | -# define LT_LAZY_OR_NOW RTLD_NOW | |
1046 | -# else | |
1047 | -# ifdef DL_NOW | |
1048 | -# define LT_LAZY_OR_NOW DL_NOW | |
1049 | -# endif | |
1050 | -# endif /* !RTLD_NOW */ | |
1051 | -#endif | |
1052 | -#ifndef LT_LAZY_OR_NOW | |
1053 | -# define LT_LAZY_OR_NOW 0 | |
1054 | -#endif /* !LT_LAZY_OR_NOW */ | |
1055 | - | |
1056 | -#if HAVE_DLERROR | |
1057 | -# define DLERROR(arg) dlerror () | |
1058 | -#else | |
1059 | -# define DLERROR(arg) LT_DLSTRERROR (arg) | |
1060 | -#endif | |
1061 | - | |
1062 | -static lt_module | |
1063 | -sys_dl_open (lt_user_data loader_data, const char *filename) | |
1064 | -{ | |
1065 | - // XXX Need to investigate why .a files are asked to be open by this routine ??? | |
1066 | - lt_module module = dlopen (filename, LT_GLOBAL | LT_LAZY_OR_NOW); | |
1067 | - | |
1068 | - if (!module) | |
1069 | - { | |
1070 | - LT_DLMUTEX_SETERROR (DLERROR (CANNOT_OPEN)); | |
1071 | - } | |
1072 | - | |
1073 | - return module; | |
1074 | -} | |
1075 | - | |
1076 | -static int | |
1077 | -sys_dl_close (lt_user_data loader_data, lt_module module) | |
1078 | -{ | |
1079 | - int errors = 0; | |
1080 | - | |
1081 | - if (dlclose (module) != 0) | |
1082 | - { | |
1083 | - LT_DLMUTEX_SETERROR (DLERROR (CANNOT_CLOSE)); | |
1084 | - ++errors; | |
1085 | - } | |
1086 | - | |
1087 | - return errors; | |
1088 | -} | |
1089 | - | |
1090 | -static lt_ptr | |
1091 | -sys_dl_sym ( | |
1092 | - lt_user_data loader_data, | |
1093 | - lt_module module, | |
1094 | - const char *symbol) | |
1095 | -{ | |
1096 | - lt_ptr address = dlsym (module, symbol); | |
1097 | - | |
1098 | - if (!address) | |
1099 | - { | |
1100 | - LT_DLMUTEX_SETERROR (DLERROR (SYMBOL_NOT_FOUND)); | |
1101 | - } | |
1102 | - | |
1103 | - return address; | |
1104 | -} | |
1105 | - | |
1106 | -static struct lt_user_dlloader sys_dl = | |
1107 | - { | |
1108 | -# ifdef NEED_USCORE | |
1109 | - "_", | |
1110 | -# else | |
1111 | - 0, | |
1112 | -# endif | |
1113 | - sys_dl_open, sys_dl_close, sys_dl_sym, 0, 0 }; | |
1114 | - | |
1115 | - | |
1116 | -#endif /* HAVE_LIBDL */ | |
1117 | - | |
1118 | - | |
1119 | -\f | |
1120 | -/* --- SHL_LOAD() INTERFACE LOADER --- */ | |
1121 | - | |
1122 | -#if HAVE_SHL_LOAD | |
1123 | - | |
1124 | -/* dynamic linking with shl_load (HP-UX) (comments from gmodule) */ | |
1125 | - | |
1126 | -#ifdef HAVE_DL_H | |
1127 | -# include <dl.h> | |
1128 | -#endif | |
1129 | - | |
1130 | -/* some flags are missing on some systems, so we provide | |
1131 | - * harmless defaults. | |
1132 | - * | |
1133 | - * Mandatory: | |
1134 | - * BIND_IMMEDIATE - Resolve symbol references when the library is loaded. | |
1135 | - * BIND_DEFERRED - Delay code symbol resolution until actual reference. | |
1136 | - * | |
1137 | - * Optionally: | |
1138 | - * BIND_FIRST - Place the library at the head of the symbol search | |
1139 | - * order. | |
1140 | - * BIND_NONFATAL - The default BIND_IMMEDIATE behavior is to treat all | |
1141 | - * unsatisfied symbols as fatal. This flag allows | |
1142 | - * binding of unsatisfied code symbols to be deferred | |
1143 | - * until use. | |
1144 | - * [Perl: For certain libraries, like DCE, deferred | |
1145 | - * binding often causes run time problems. Adding | |
1146 | - * BIND_NONFATAL to BIND_IMMEDIATE still allows | |
1147 | - * unresolved references in situations like this.] | |
1148 | - * BIND_NOSTART - Do not call the initializer for the shared library | |
1149 | - * when the library is loaded, nor on a future call to | |
1150 | - * shl_unload(). | |
1151 | - * BIND_VERBOSE - Print verbose messages concerning possible | |
1152 | - * unsatisfied symbols. | |
1153 | - * | |
1154 | - * hp9000s700/hp9000s800: | |
1155 | - * BIND_RESTRICTED - Restrict symbols visible by the library to those | |
1156 | - * present at library load time. | |
1157 | - * DYNAMIC_PATH - Allow the loader to dynamically search for the | |
1158 | - * library specified by the path argument. | |
1159 | - */ | |
1160 | - | |
1161 | -#ifndef DYNAMIC_PATH | |
1162 | -# define DYNAMIC_PATH 0 | |
1163 | -#endif | |
1164 | -#ifndef BIND_RESTRICTED | |
1165 | -# define BIND_RESTRICTED 0 | |
1166 | -#endif | |
1167 | - | |
1168 | -#define LT_BIND_FLAGS (BIND_IMMEDIATE | BIND_NONFATAL | DYNAMIC_PATH) | |
1169 | - | |
1170 | -static lt_module | |
1171 | -sys_shl_open (lt_user_data loader_data, const char *filename) | |
1172 | -{ | |
1173 | - static shl_t self = (shl_t) 0; | |
1174 | - lt_module module = shl_load (filename, LT_BIND_FLAGS, 0L); | |
1175 | - | |
1176 | - /* Since searching for a symbol against a NULL module handle will also | |
1177 | - look in everything else that was already loaded and exported with | |
1178 | - the -E compiler flag, we always cache a handle saved before any | |
1179 | - modules are loaded. */ | |
1180 | - if (!self) | |
1181 | - { | |
1182 | - lt_ptr address; | |
1183 | - shl_findsym (&self, "main", TYPE_UNDEFINED, &address); | |
1184 | - } | |
1185 | - | |
1186 | - if (!filename) | |
1187 | - { | |
1188 | - module = self; | |
1189 | - } | |
1190 | - else | |
1191 | - { | |
1192 | - module = shl_load (filename, LT_BIND_FLAGS, 0L); | |
1193 | - | |
1194 | - if (!module) | |
1195 | - { | |
1196 | - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (CANNOT_OPEN)); | |
1197 | - } | |
1198 | - } | |
1199 | - | |
1200 | - return module; | |
1201 | -} | |
1202 | - | |
1203 | -static int | |
1204 | -sys_shl_close (lt_user_data loader_data, lt_module module) | |
1205 | -{ | |
1206 | - int errors = 0; | |
1207 | - | |
1208 | - if (module && (shl_unload ((shl_t) (module)) != 0)) | |
1209 | - { | |
1210 | - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (CANNOT_CLOSE)); | |
1211 | - ++errors; | |
1212 | - } | |
1213 | - | |
1214 | - return errors; | |
1215 | -} | |
1216 | - | |
1217 | -static lt_ptr | |
1218 | -sys_shl_sym ( | |
1219 | - lt_user_data loader_data, | |
1220 | - lt_module module, | |
1221 | - const char *symbol) | |
1222 | -{ | |
1223 | - lt_ptr address = 0; | |
1224 | - | |
1225 | - /* sys_shl_open should never return a NULL module handle */ | |
1226 | - if (module == (lt_module) 0) | |
1227 | - { | |
1228 | - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INVALID_HANDLE)); | |
1229 | - } | |
1230 | - else if (!shl_findsym((shl_t*) &module, symbol, TYPE_UNDEFINED, &address)) | |
1231 | - { | |
1232 | - if (!address) | |
1233 | - { | |
1234 | - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (SYMBOL_NOT_FOUND)); | |
1235 | - } | |
1236 | - } | |
1237 | - | |
1238 | - return address; | |
1239 | -} | |
1240 | - | |
1241 | -static struct lt_user_dlloader sys_shl = { | |
1242 | - 0, sys_shl_open, sys_shl_close, sys_shl_sym, 0, 0 | |
1243 | -}; | |
1244 | - | |
1245 | -#endif /* HAVE_SHL_LOAD */ | |
1246 | - | |
1247 | - | |
1248 | - | |
1249 | -\f | |
1250 | -/* --- LOADLIBRARY() INTERFACE LOADER --- */ | |
1251 | - | |
1252 | -#ifdef __WINDOWS__ | |
1253 | - | |
1254 | -/* dynamic linking for Win32 */ | |
1255 | - | |
1256 | -#include <windows.h> | |
1257 | - | |
1258 | -/* Forward declaration; required to implement handle search below. */ | |
1259 | -static lt_dlhandle handles; | |
1260 | - | |
1261 | -static lt_module | |
1262 | -sys_wll_open (lt_user_data loader_data, const char *filename) | |
1263 | -{ | |
1264 | - lt_dlhandle cur; | |
1265 | - lt_module module = 0; | |
1266 | - const char *errormsg = 0; | |
1267 | - char *searchname = 0; | |
1268 | - char *ext; | |
1269 | - char self_name_buf[MAX_PATH]; | |
1270 | - | |
1271 | - if (!filename) | |
1272 | - { | |
1273 | - /* Get the name of main module */ | |
1274 | - *self_name_buf = 0; | |
1275 | - GetModuleFileName (NULL, self_name_buf, sizeof (self_name_buf)); | |
1276 | - filename = ext = self_name_buf; | |
1277 | - } | |
1278 | - else | |
1279 | - { | |
1280 | - ext = strrchr (filename, '.'); | |
1281 | - } | |
1282 | - | |
1283 | - if (ext) | |
1284 | - { | |
1285 | - /* FILENAME already has an extension. */ | |
1286 | - searchname = lt_estrdup (filename); | |
1287 | - } | |
1288 | - else | |
1289 | - { | |
1290 | - /* Append a `.' to stop Windows from adding an | |
1291 | - implicit `.dll' extension. */ | |
1292 | - searchname = LT_EMALLOC (char, 2+ LT_STRLEN (filename)); | |
1293 | - if (searchname) | |
1294 | - sprintf (searchname, "%s.", filename); | |
1295 | - } | |
1296 | - if (!searchname) | |
1297 | - return 0; | |
1298 | - | |
1299 | -#if __CYGWIN__ | |
1300 | - { | |
1301 | - char wpath[MAX_PATH]; | |
1302 | - cygwin_conv_to_full_win32_path(searchname, wpath); | |
1303 | - module = LoadLibrary(wpath); | |
1304 | - } | |
1305 | -#else | |
1306 | - module = LoadLibrary (searchname); | |
1307 | -#endif | |
1308 | - LT_DLFREE (searchname); | |
1309 | - | |
1310 | - /* libltdl expects this function to fail if it is unable | |
1311 | - to physically load the library. Sadly, LoadLibrary | |
1312 | - will search the loaded libraries for a match and return | |
1313 | - one of them if the path search load fails. | |
1314 | - | |
1315 | - We check whether LoadLibrary is returning a handle to | |
1316 | - an already loaded module, and simulate failure if we | |
1317 | - find one. */ | |
1318 | - LT_DLMUTEX_LOCK (); | |
1319 | - cur = handles; | |
1320 | - while (cur) | |
1321 | - { | |
1322 | - if (!cur->module) | |
1323 | - { | |
1324 | - cur = 0; | |
1325 | - break; | |
1326 | - } | |
1327 | - | |
1328 | - if (cur->module == module) | |
1329 | - { | |
1330 | - break; | |
1331 | - } | |
1332 | - | |
1333 | - cur = cur->next; | |
1334 | - } | |
1335 | - LT_DLMUTEX_UNLOCK (); | |
1336 | - | |
1337 | - if (cur || !module) | |
1338 | - { | |
1339 | - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (CANNOT_OPEN)); | |
1340 | - module = 0; | |
1341 | - } | |
1342 | - | |
1343 | - return module; | |
1344 | -} | |
1345 | - | |
1346 | -static int | |
1347 | -sys_wll_close (lt_user_data loader_data, lt_module module) | |
1348 | -{ | |
1349 | - int errors = 0; | |
1350 | - | |
1351 | - if (FreeLibrary(module) == 0) | |
1352 | - { | |
1353 | - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (CANNOT_CLOSE)); | |
1354 | - ++errors; | |
1355 | - } | |
1356 | - | |
1357 | - return errors; | |
1358 | -} | |
1359 | - | |
1360 | -static lt_ptr | |
1361 | -sys_wll_sym ( | |
1362 | - lt_user_data loader_data, | |
1363 | - lt_module module, | |
1364 | - const char *symbol) | |
1365 | -{ | |
1366 | - lt_ptr address = GetProcAddress (module, symbol); | |
1367 | - | |
1368 | - if (!address) | |
1369 | - { | |
1370 | - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (SYMBOL_NOT_FOUND)); | |
1371 | - } | |
1372 | - | |
1373 | - return address; | |
1374 | -} | |
1375 | - | |
1376 | -static struct lt_user_dlloader sys_wll = { | |
1377 | - 0, sys_wll_open, sys_wll_close, sys_wll_sym, 0, 0 | |
1378 | -}; | |
1379 | - | |
1380 | -#endif /* __WINDOWS__ */ | |
1381 | - | |
1382 | - | |
1383 | - | |
1384 | -\f | |
1385 | -/* --- LOAD_ADD_ON() INTERFACE LOADER --- */ | |
1386 | - | |
1387 | - | |
1388 | -#ifdef __BEOS__ | |
1389 | - | |
1390 | -/* dynamic linking for BeOS */ | |
1391 | - | |
1392 | -#include <kernel/image.h> | |
1393 | - | |
1394 | -static lt_module | |
1395 | -sys_bedl_open (lt_user_data loader_data, const char *filename) | |
1396 | -{ | |
1397 | - image_id image = 0; | |
1398 | - | |
1399 | - if (filename) | |
1400 | - { | |
1401 | - image = load_add_on (filename); | |
1402 | - } | |
1403 | - else | |
1404 | - { | |
1405 | - image_info info; | |
1406 | - int32 cookie = 0; | |
1407 | - if (get_next_image_info (0, &cookie, &info) == B_OK) | |
1408 | - image = load_add_on (info.name); | |
1409 | - } | |
1410 | - | |
1411 | - if (image <= 0) | |
1412 | - { | |
1413 | - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (CANNOT_OPEN)); | |
1414 | - image = 0; | |
1415 | - } | |
1416 | - | |
1417 | - return (lt_module) image; | |
1418 | -} | |
1419 | - | |
1420 | -static int | |
1421 | -sys_bedl_close (lt_user_data loader_data, lt_module module) | |
1422 | -{ | |
1423 | - int errors = 0; | |
1424 | - | |
1425 | - if (unload_add_on ((image_id) module) != B_OK) | |
1426 | - { | |
1427 | - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (CANNOT_CLOSE)); | |
1428 | - ++errors; | |
1429 | - } | |
1430 | - | |
1431 | - return errors; | |
1432 | -} | |
1433 | - | |
1434 | -static lt_ptr | |
1435 | -sys_bedl_sym ( | |
1436 | - lt_user_data loader_data, | |
1437 | - lt_module module, | |
1438 | - const char *symbol) | |
1439 | -{ | |
1440 | - lt_ptr address = 0; | |
1441 | - image_id image = (image_id) module; | |
1442 | - | |
1443 | - if (get_image_symbol (image, symbol, B_SYMBOL_TYPE_ANY, address) != B_OK) | |
1444 | - { | |
1445 | - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (SYMBOL_NOT_FOUND)); | |
1446 | - address = 0; | |
1447 | - } | |
1448 | - | |
1449 | - return address; | |
1450 | -} | |
1451 | - | |
1452 | -static struct lt_user_dlloader sys_bedl = { | |
1453 | - 0, sys_bedl_open, sys_bedl_close, sys_bedl_sym, 0, 0 | |
1454 | -}; | |
1455 | - | |
1456 | -#endif /* __BEOS__ */ | |
1457 | - | |
1458 | - | |
1459 | - | |
1460 | -\f | |
1461 | -/* --- DLD_LINK() INTERFACE LOADER --- */ | |
1462 | - | |
1463 | - | |
1464 | -#if HAVE_DLD | |
1465 | - | |
1466 | -/* dynamic linking with dld */ | |
1467 | - | |
1468 | -#if HAVE_DLD_H | |
1469 | -#include <dld.h> | |
1470 | -#endif | |
1471 | - | |
1472 | -static lt_module | |
1473 | -sys_dld_open (lt_user_data loader_data, const char *filename) | |
1474 | -{ | |
1475 | - lt_module module = strdup (filename); | |
1476 | - | |
1477 | - if (dld_link (filename) != 0) | |
1478 | - { | |
1479 | - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (CANNOT_OPEN)); | |
1480 | - LT_DLFREE (module); | |
1481 | - module = 0; | |
1482 | - } | |
1483 | - | |
1484 | - return module; | |
1485 | -} | |
1486 | - | |
1487 | -static int | |
1488 | -sys_dld_close (lt_user_data loader_data, lt_module module) | |
1489 | -{ | |
1490 | - int errors = 0; | |
1491 | - | |
1492 | - if (dld_unlink_by_file ((char*)(module), 1) != 0) | |
1493 | - { | |
1494 | - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (CANNOT_CLOSE)); | |
1495 | - ++errors; | |
1496 | - } | |
1497 | - else | |
1498 | - { | |
1499 | - LT_DLFREE (module); | |
1500 | - } | |
1501 | - | |
1502 | - return errors; | |
1503 | -} | |
1504 | - | |
1505 | -static lt_ptr | |
1506 | -sys_dld_sym ( | |
1507 | - lt_user_data loader_data, | |
1508 | - lt_module module, | |
1509 | - const char *symbol) | |
1510 | -{ | |
1511 | - lt_ptr address = dld_get_func (symbol); | |
1512 | - | |
1513 | - if (!address) | |
1514 | - { | |
1515 | - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (SYMBOL_NOT_FOUND)); | |
1516 | - } | |
1517 | - | |
1518 | - return address; | |
1519 | -} | |
1520 | - | |
1521 | -static struct lt_user_dlloader sys_dld = { | |
1522 | - 0, sys_dld_open, sys_dld_close, sys_dld_sym, 0, 0 | |
1523 | -}; | |
1524 | - | |
1525 | -#endif /* HAVE_DLD */ | |
1526 | - | |
1527 | -/* --- DYLD() MACOSX/DARWIN INTERFACE LOADER --- */ | |
1528 | -#if HAVE_DYLD | |
1529 | - | |
1530 | - | |
1531 | -#if HAVE_MACH_O_DYLD_H | |
1532 | -#if !defined(__APPLE_CC__) && !defined(__MWERKS__) && !defined(__private_extern__) | |
1533 | -/* Is this correct? Does it still function properly? */ | |
1534 | -#define __private_extern__ extern | |
1535 | -#endif | |
1536 | -# include <mach-o/dyld.h> | |
1537 | -#endif | |
1538 | -#include <mach-o/getsect.h> | |
1539 | - | |
1540 | -/* We have to put some stuff here that isn't in older dyld.h files */ | |
1541 | -#ifndef ENUM_DYLD_BOOL | |
1542 | -# define ENUM_DYLD_BOOL | |
1543 | -# undef FALSE | |
1544 | -# undef TRUE | |
1545 | - enum DYLD_BOOL { | |
1546 | - FALSE, | |
1547 | - TRUE | |
1548 | - }; | |
1549 | -#endif | |
1550 | -#ifndef LC_REQ_DYLD | |
1551 | -# define LC_REQ_DYLD 0x80000000 | |
1552 | -#endif | |
1553 | -#ifndef LC_LOAD_WEAK_DYLIB | |
1554 | -# define LC_LOAD_WEAK_DYLIB (0x18 | LC_REQ_DYLD) | |
1555 | -#endif | |
1556 | -static const struct mach_header * (*ltdl_NSAddImage)(const char *image_name, unsigned long options) = 0; | |
1557 | -static NSSymbol (*ltdl_NSLookupSymbolInImage)(const struct mach_header *image,const char *symbolName, unsigned long options) = 0; | |
1558 | -static enum DYLD_BOOL (*ltdl_NSIsSymbolNameDefinedInImage)(const struct mach_header *image, const char *symbolName) = 0; | |
1559 | -static enum DYLD_BOOL (*ltdl_NSMakePrivateModulePublic)(NSModule module) = 0; | |
1560 | - | |
1561 | -#ifndef NSADDIMAGE_OPTION_NONE | |
1562 | -#define NSADDIMAGE_OPTION_NONE 0x0 | |
1563 | -#endif | |
1564 | -#ifndef NSADDIMAGE_OPTION_RETURN_ON_ERROR | |
1565 | -#define NSADDIMAGE_OPTION_RETURN_ON_ERROR 0x1 | |
1566 | -#endif | |
1567 | -#ifndef NSADDIMAGE_OPTION_WITH_SEARCHING | |
1568 | -#define NSADDIMAGE_OPTION_WITH_SEARCHING 0x2 | |
1569 | -#endif | |
1570 | -#ifndef NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED | |
1571 | -#define NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED 0x4 | |
1572 | -#endif | |
1573 | -#ifndef NSADDIMAGE_OPTION_MATCH_FILENAME_BY_INSTALLNAME | |
1574 | -#define NSADDIMAGE_OPTION_MATCH_FILENAME_BY_INSTALLNAME 0x8 | |
1575 | -#endif | |
1576 | -#ifndef NSLOOKUPSYMBOLINIMAGE_OPTION_BIND | |
1577 | -#define NSLOOKUPSYMBOLINIMAGE_OPTION_BIND 0x0 | |
1578 | -#endif | |
1579 | -#ifndef NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_NOW | |
1580 | -#define NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_NOW 0x1 | |
1581 | -#endif | |
1582 | -#ifndef NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_FULLY | |
1583 | -#define NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_FULLY 0x2 | |
1584 | -#endif | |
1585 | -#ifndef NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR | |
1586 | -#define NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR 0x4 | |
1587 | -#endif | |
1588 | - | |
1589 | - | |
1590 | -static const char * | |
1591 | -lt_int_dyld_error(char* othererror) | |
1592 | -{ | |
1593 | -/* return the dyld error string, or the passed in error string if none */ | |
1594 | - NSLinkEditErrors ler; | |
1595 | - int lerno; | |
1596 | - const char *errstr; | |
1597 | - const char *file; | |
1598 | - NSLinkEditError(&ler,&lerno,&file,&errstr); | |
1599 | - if (!errstr || !strlen(errstr)) errstr = othererror; | |
1600 | - return errstr; | |
1601 | -} | |
1602 | - | |
1603 | -static const struct mach_header * | |
1604 | -lt_int_dyld_get_mach_header_from_nsmodule(NSModule module) | |
1605 | -{ | |
1606 | -/* There should probably be an apple dyld api for this */ | |
1607 | - int i=_dyld_image_count(); | |
1608 | - int j; | |
1609 | - const char *modname=NSNameOfModule(module); | |
1610 | - const struct mach_header *mh=NULL; | |
1611 | - if (!modname) return NULL; | |
1612 | - for (j = 0; j < i; j++) | |
1613 | - { | |
1614 | - if (!strcmp(_dyld_get_image_name(j),modname)) | |
1615 | - { | |
1616 | - mh=_dyld_get_image_header(j); | |
1617 | - break; | |
1618 | - } | |
1619 | - } | |
1620 | - return mh; | |
1621 | -} | |
1622 | - | |
1623 | -static const char* lt_int_dyld_lib_install_name(const struct mach_header *mh) | |
1624 | -{ | |
1625 | -/* NSAddImage is also used to get the loaded image, but it only works if the lib | |
1626 | - is installed, for uninstalled libs we need to check the install_names against | |
1627 | - each other. Note that this is still broken if DYLD_IMAGE_SUFFIX is set and a | |
1628 | - different lib was loaded as a result | |
1629 | -*/ | |
1630 | - int j; | |
1631 | - struct load_command *lc; | |
1632 | - unsigned long offset = sizeof(struct mach_header); | |
1633 | - const char* retStr=NULL; | |
1634 | - for (j = 0; j < mh->ncmds; j++) | |
1635 | - { | |
1636 | - lc = (struct load_command*)(((unsigned long)mh) + offset); | |
1637 | - if (LC_ID_DYLIB == lc->cmd) | |
1638 | - { | |
1639 | - retStr=(char*)(((struct dylib_command*)lc)->dylib.name.offset + | |
1640 | - (unsigned long)lc); | |
1641 | - } | |
1642 | - offset += lc->cmdsize; | |
1643 | - } | |
1644 | - return retStr; | |
1645 | -} | |
1646 | - | |
1647 | -static const struct mach_header * | |
1648 | -lt_int_dyld_match_loaded_lib_by_install_name(const char *name) | |
1649 | -{ | |
1650 | - int i=_dyld_image_count(); | |
1651 | - int j; | |
1652 | - const struct mach_header *mh=NULL; | |
1653 | - const char *id=NULL; | |
1654 | - for (j = 0; j < i; j++) | |
1655 | - { | |
1656 | - id=lt_int_dyld_lib_install_name(_dyld_get_image_header(j)); | |
1657 | - if ((id) && (!strcmp(id,name))) | |
1658 | - { | |
1659 | - mh=_dyld_get_image_header(j); | |
1660 | - break; | |
1661 | - } | |
1662 | - } | |
1663 | - return mh; | |
1664 | -} | |
1665 | - | |
1666 | -static NSSymbol | |
1667 | -lt_int_dyld_NSlookupSymbolInLinkedLibs(const char *symbol, const struct mach_header *mh) | |
1668 | -{ | |
1669 | - /* Safe to assume our mh is good */ | |
1670 | - int j; | |
1671 | - struct load_command *lc; | |
1672 | - unsigned long offset = sizeof(struct mach_header); | |
1673 | - NSSymbol retSym = 0; | |
1674 | - const struct mach_header *mh1; | |
1675 | - if ((ltdl_NSLookupSymbolInImage) && NSIsSymbolNameDefined(symbol) ) | |
1676 | - { | |
1677 | - for (j = 0; j < mh->ncmds; j++) | |
1678 | - { | |
1679 | - lc = (struct load_command*)(((unsigned long)mh) + offset); | |
1680 | - if ((LC_LOAD_DYLIB == lc->cmd) || (LC_LOAD_WEAK_DYLIB == lc->cmd)) | |
1681 | - { | |
1682 | - mh1=lt_int_dyld_match_loaded_lib_by_install_name((char*)(((struct dylib_command*)lc)->dylib.name.offset + | |
1683 | - (unsigned long)lc)); | |
1684 | - if (!mh1) | |
1685 | - { | |
1686 | - /* Maybe NSAddImage can find it */ | |
1687 | - mh1=ltdl_NSAddImage((char*)(((struct dylib_command*)lc)->dylib.name.offset + | |
1688 | - (unsigned long)lc), | |
1689 | - NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED + | |
1690 | - NSADDIMAGE_OPTION_WITH_SEARCHING + | |
1691 | - NSADDIMAGE_OPTION_RETURN_ON_ERROR ); | |
1692 | - } | |
1693 | - if (mh1) | |
1694 | - { | |
1695 | - retSym = ltdl_NSLookupSymbolInImage(mh1, | |
1696 | - symbol, | |
1697 | - NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_NOW | |
1698 | - | NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR | |
1699 | - ); | |
1700 | - if (retSym) break; | |
1701 | - } | |
1702 | - } | |
1703 | - offset += lc->cmdsize; | |
1704 | - } | |
1705 | - } | |
1706 | - return retSym; | |
1707 | -} | |
1708 | - | |
1709 | -static int | |
1710 | -sys_dyld_init() | |
1711 | -{ | |
1712 | - int retCode = 0; | |
1713 | - int err = 0; | |
1714 | - if (!_dyld_present()) { | |
1715 | - retCode=1; | |
1716 | - } | |
1717 | - else { | |
1718 | - err = _dyld_func_lookup("__dyld_NSAddImage",(unsigned long*)<dl_NSAddImage); | |
1719 | - err = _dyld_func_lookup("__dyld_NSLookupSymbolInImage",(unsigned long*)<dl_NSLookupSymbolInImage); | |
1720 | - err = _dyld_func_lookup("__dyld_NSIsSymbolNameDefinedInImage",(unsigned long*)<dl_NSIsSymbolNameDefinedInImage); | |
1721 | - err = _dyld_func_lookup("__dyld_NSMakePrivateModulePublic",(unsigned long*)<dl_NSMakePrivateModulePublic); | |
1722 | - } | |
1723 | - return retCode; | |
1724 | -} | |
1725 | - | |
1726 | -static lt_module | |
1727 | -sys_dyld_open (lt_user_data loader_data, const char *filename) | |
1728 | -{ | |
1729 | - lt_module module = 0; | |
1730 | - NSObjectFileImage ofi = 0; | |
1731 | - NSObjectFileImageReturnCode ofirc; | |
1732 | - | |
1733 | - if (!filename) | |
1734 | - return (lt_module)-1; | |
1735 | - ofirc = NSCreateObjectFileImageFromFile(filename, &ofi); | |
1736 | - switch (ofirc) | |
1737 | - { | |
1738 | - case NSObjectFileImageSuccess: | |
1739 | - module = NSLinkModule(ofi, filename, | |
1740 | - NSLINKMODULE_OPTION_RETURN_ON_ERROR | |
1741 | - | NSLINKMODULE_OPTION_PRIVATE | |
1742 | - | NSLINKMODULE_OPTION_BINDNOW); | |
1743 | - NSDestroyObjectFileImage(ofi); | |
1744 | - if (module) | |
1745 | - ltdl_NSMakePrivateModulePublic(module); | |
1746 | - break; | |
1747 | - case NSObjectFileImageInappropriateFile: | |
1748 | - if (ltdl_NSIsSymbolNameDefinedInImage && ltdl_NSLookupSymbolInImage) | |
1749 | - { | |
1750 | - module = (lt_module)ltdl_NSAddImage(filename, NSADDIMAGE_OPTION_RETURN_ON_ERROR); | |
1751 | - break; | |
1752 | - } | |
1753 | - default: | |
1754 | - LT_DLMUTEX_SETERROR (lt_int_dyld_error(LT_DLSTRERROR(CANNOT_OPEN))); | |
1755 | - return 0; | |
1756 | - } | |
1757 | - if (!module) LT_DLMUTEX_SETERROR (lt_int_dyld_error(LT_DLSTRERROR(CANNOT_OPEN))); | |
1758 | - return module; | |
1759 | -} | |
1760 | - | |
1761 | -static int | |
1762 | -sys_dyld_close (lt_user_data loader_data, lt_module module) | |
1763 | -{ | |
1764 | - int retCode = 0; | |
1765 | - int flags = 0; | |
1766 | - if (module == (lt_module)-1) return 0; | |
1767 | -#ifdef __BIG_ENDIAN__ | |
1768 | - if (((struct mach_header *)module)->magic == MH_MAGIC) | |
1769 | -#else | |
1770 | - if (((struct mach_header *)module)->magic == MH_CIGAM) | |
1771 | -#endif | |
1772 | - { | |
1773 | - LT_DLMUTEX_SETERROR("Can not close a dylib"); | |
1774 | - retCode = 1; | |
1775 | - } | |
1776 | - else | |
1777 | - { | |
1778 | -#if 1 | |
1779 | -/* Currently, if a module contains c++ static destructors and it is unloaded, we | |
1780 | - get a segfault in atexit(), due to compiler and dynamic loader differences of | |
1781 | - opinion, this works around that. | |
1782 | -*/ | |
1783 | - if ((const struct section *)NULL != | |
1784 | - getsectbynamefromheader(lt_int_dyld_get_mach_header_from_nsmodule(module), | |
1785 | - "__DATA","__mod_term_func")) | |
1786 | - { | |
1787 | - flags += NSUNLINKMODULE_OPTION_KEEP_MEMORY_MAPPED; | |
1788 | - } | |
1789 | -#endif | |
1790 | -#ifdef __ppc__ | |
1791 | - flags += NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES; | |
1792 | -#endif | |
1793 | - if (!NSUnLinkModule(module,flags)) | |
1794 | - { | |
1795 | - retCode=1; | |
1796 | - LT_DLMUTEX_SETERROR (lt_int_dyld_error(LT_DLSTRERROR(CANNOT_CLOSE))); | |
1797 | - } | |
1798 | - } | |
1799 | - | |
1800 | - return retCode; | |
1801 | -} | |
1802 | - | |
1803 | -static lt_ptr | |
1804 | -sys_dyld_sym ( | |
1805 | - lt_user_data loader_data, | |
1806 | - lt_module module, | |
1807 | - const char *symbol) | |
1808 | -{ | |
1809 | - lt_ptr address = 0; | |
1810 | - NSSymbol *nssym = 0; | |
1811 | - void *unused; | |
1812 | - const struct mach_header *mh=NULL; | |
1813 | - char saveError[256] = "Symbol not found"; | |
1814 | - if (module == (lt_module)-1) | |
1815 | - { | |
1816 | - _dyld_lookup_and_bind(symbol,(unsigned long*)&address,&unused); | |
1817 | - return address; | |
1818 | - } | |
1819 | -#ifdef __BIG_ENDIAN__ | |
1820 | - if (((struct mach_header *)module)->magic == MH_MAGIC) | |
1821 | -#else | |
1822 | - if (((struct mach_header *)module)->magic == MH_CIGAM) | |
1823 | -#endif | |
1824 | - { | |
1825 | - if (ltdl_NSIsSymbolNameDefinedInImage && ltdl_NSLookupSymbolInImage) | |
1826 | - { | |
1827 | - mh=module; | |
1828 | - if (ltdl_NSIsSymbolNameDefinedInImage((struct mach_header*)module,symbol)) | |
1829 | - { | |
1830 | - nssym = ltdl_NSLookupSymbolInImage((struct mach_header*)module, | |
1831 | - symbol, | |
1832 | - NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_NOW | |
1833 | - | NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR | |
1834 | - ); | |
1835 | - } | |
1836 | - } | |
1837 | - | |
1838 | - } | |
1839 | - else { | |
1840 | - nssym = NSLookupSymbolInModule(module, symbol); | |
1841 | - } | |
1842 | - if (!nssym) | |
1843 | - { | |
1844 | - strncpy(saveError, lt_int_dyld_error(LT_DLSTRERROR(SYMBOL_NOT_FOUND)), 255); | |
1845 | - saveError[255] = 0; | |
1846 | - if (!mh) mh=lt_int_dyld_get_mach_header_from_nsmodule(module); | |
1847 | - nssym = lt_int_dyld_NSlookupSymbolInLinkedLibs(symbol,mh); | |
1848 | - } | |
1849 | - if (!nssym) | |
1850 | - { | |
1851 | - LT_DLMUTEX_SETERROR (saveError); | |
1852 | - return NULL; | |
1853 | - } | |
1854 | - return NSAddressOfSymbol(nssym); | |
1855 | -} | |
1856 | - | |
1857 | -static struct lt_user_dlloader sys_dyld = | |
1858 | - { "_", sys_dyld_open, sys_dyld_close, sys_dyld_sym, 0, 0 }; | |
1859 | - | |
1860 | - | |
1861 | -#endif /* HAVE_DYLD */ | |
1862 | - | |
1863 | -\f | |
1864 | -/* --- DLPREOPEN() INTERFACE LOADER --- */ | |
1865 | - | |
1866 | - | |
1867 | -/* emulate dynamic linking using preloaded_symbols */ | |
1868 | - | |
1869 | -typedef struct lt_dlsymlists_t | |
1870 | -{ | |
1871 | - struct lt_dlsymlists_t *next; | |
1872 | - const lt_dlsymlist *syms; | |
1873 | -} lt_dlsymlists_t; | |
1874 | - | |
1875 | -static const lt_dlsymlist *default_preloaded_symbols = 0; | |
1876 | -static lt_dlsymlists_t *preloaded_symbols = 0; | |
1877 | - | |
1878 | -static int | |
1879 | -presym_init (lt_user_data loader_data) | |
1880 | -{ | |
1881 | - int errors = 0; | |
1882 | - | |
1883 | - LT_DLMUTEX_LOCK (); | |
1884 | - | |
1885 | - preloaded_symbols = 0; | |
1886 | - if (default_preloaded_symbols) | |
1887 | - { | |
1888 | - errors = lt_dlpreload (default_preloaded_symbols); | |
1889 | - } | |
1890 | - | |
1891 | - LT_DLMUTEX_UNLOCK (); | |
1892 | - | |
1893 | - return errors; | |
1894 | -} | |
1895 | - | |
1896 | -static int | |
1897 | -presym_free_symlists () | |
1898 | -{ | |
1899 | - lt_dlsymlists_t *lists; | |
1900 | - | |
1901 | - LT_DLMUTEX_LOCK (); | |
1902 | - | |
1903 | - lists = preloaded_symbols; | |
1904 | - while (lists) | |
1905 | - { | |
1906 | - lt_dlsymlists_t *tmp = lists; | |
1907 | - | |
1908 | - lists = lists->next; | |
1909 | - LT_DLFREE (tmp); | |
1910 | - } | |
1911 | - preloaded_symbols = 0; | |
1912 | - | |
1913 | - LT_DLMUTEX_UNLOCK (); | |
1914 | - | |
1915 | - return 0; | |
1916 | -} | |
1917 | - | |
1918 | -static int | |
1919 | -presym_exit (lt_user_data loader_data) | |
1920 | -{ | |
1921 | - presym_free_symlists (); | |
1922 | - return 0; | |
1923 | -} | |
1924 | - | |
1925 | -static int | |
1926 | -presym_add_symlist (const lt_dlsymlist *preloaded) | |
1927 | -{ | |
1928 | - lt_dlsymlists_t *tmp; | |
1929 | - lt_dlsymlists_t *lists; | |
1930 | - int errors = 0; | |
1931 | - | |
1932 | - LT_DLMUTEX_LOCK (); | |
1933 | - | |
1934 | - lists = preloaded_symbols; | |
1935 | - while (lists) | |
1936 | - { | |
1937 | - if (lists->syms == preloaded) | |
1938 | - { | |
1939 | - goto done; | |
1940 | - } | |
1941 | - lists = lists->next; | |
1942 | - } | |
1943 | - | |
1944 | - tmp = LT_EMALLOC (lt_dlsymlists_t, 1); | |
1945 | - if (tmp) | |
1946 | - { | |
1947 | - memset (tmp, 0, sizeof(lt_dlsymlists_t)); | |
1948 | - tmp->syms = preloaded; | |
1949 | - tmp->next = preloaded_symbols; | |
1950 | - preloaded_symbols = tmp; | |
1951 | - } | |
1952 | - else | |
1953 | - { | |
1954 | - ++errors; | |
1955 | - } | |
1956 | - | |
1957 | - done: | |
1958 | - LT_DLMUTEX_UNLOCK (); | |
1959 | - return errors; | |
1960 | -} | |
1961 | - | |
1962 | -static lt_module | |
1963 | -presym_open (lt_user_data loader_data, const char *filename) | |
1964 | -{ | |
1965 | - lt_dlsymlists_t *lists; | |
1966 | - lt_module module = (lt_module) 0; | |
1967 | - | |
1968 | - LT_DLMUTEX_LOCK (); | |
1969 | - lists = preloaded_symbols; | |
1970 | - | |
1971 | - if (!lists) | |
1972 | - { | |
1973 | - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_SYMBOLS)); | |
1974 | - goto done; | |
1975 | - } | |
1976 | - | |
1977 | - /* Can't use NULL as the reflective symbol header, as NULL is | |
1978 | - used to mark the end of the entire symbol list. Self-dlpreopened | |
1979 | - symbols follow this magic number, chosen to be an unlikely | |
1980 | - clash with a real module name. */ | |
1981 | - if (!filename) | |
1982 | - { | |
1983 | - filename = "@PROGRAM@"; | |
1984 | - } | |
1985 | - | |
1986 | - while (lists) | |
1987 | - { | |
1988 | - const lt_dlsymlist *syms = lists->syms; | |
1989 | - | |
1990 | - while (syms->name) | |
1991 | - { | |
1992 | - if (!syms->address && strcmp(syms->name, filename) == 0) | |
1993 | - { | |
1994 | - module = (lt_module) syms; | |
1995 | - goto done; | |
1996 | - } | |
1997 | - ++syms; | |
1998 | - } | |
1999 | - | |
2000 | - lists = lists->next; | |
2001 | - } | |
2002 | - | |
2003 | - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (FILE_NOT_FOUND)); | |
2004 | - | |
2005 | - done: | |
2006 | - LT_DLMUTEX_UNLOCK (); | |
2007 | - return module; | |
2008 | -} | |
2009 | - | |
2010 | -static int | |
2011 | -presym_close (lt_user_data loader_data, lt_module module) | |
2012 | -{ | |
2013 | - /* Just to silence gcc -Wall */ | |
2014 | - module = 0; | |
2015 | - return 0; | |
2016 | -} | |
2017 | - | |
2018 | -static lt_ptr | |
2019 | -presym_sym ( | |
2020 | - lt_user_data loader_data, | |
2021 | - lt_module module, | |
2022 | - const char *symbol) | |
2023 | -{ | |
2024 | - lt_dlsymlist *syms = (lt_dlsymlist*) module; | |
2025 | - | |
2026 | - ++syms; | |
2027 | - while (syms->address) | |
2028 | - { | |
2029 | - if (strcmp(syms->name, symbol) == 0) | |
2030 | - { | |
2031 | - return syms->address; | |
2032 | - } | |
2033 | - | |
2034 | - ++syms; | |
2035 | - } | |
2036 | - | |
2037 | - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (SYMBOL_NOT_FOUND)); | |
2038 | - | |
2039 | - return 0; | |
2040 | -} | |
2041 | - | |
2042 | -static struct lt_user_dlloader presym = { | |
2043 | - 0, presym_open, presym_close, presym_sym, presym_exit, 0 | |
2044 | -}; | |
2045 | - | |
2046 | - | |
2047 | - | |
2048 | - | |
2049 | -\f | |
2050 | -/* --- DYNAMIC MODULE LOADING --- */ | |
2051 | - | |
2052 | - | |
2053 | -/* The type of a function used at each iteration of foreach_dirinpath(). */ | |
2054 | -typedef int foreach_callback_func LT_PARAMS((char *filename, lt_ptr data1, | |
2055 | - lt_ptr data2)); | |
2056 | - | |
2057 | -static int foreach_dirinpath LT_PARAMS((const char *search_path, | |
2058 | - const char *base_name, | |
2059 | - foreach_callback_func *func, | |
2060 | - lt_ptr data1, lt_ptr data2)); | |
2061 | - | |
2062 | -static int find_file_callback LT_PARAMS((char *filename, lt_ptr data, | |
2063 | - lt_ptr ignored)); | |
2064 | -static int find_handle_callback LT_PARAMS((char *filename, lt_ptr data, | |
2065 | - lt_ptr ignored)); | |
2066 | -static int foreachfile_callback LT_PARAMS((char *filename, lt_ptr data1, | |
2067 | - lt_ptr data2)); | |
2068 | - | |
2069 | - | |
2070 | -static int canonicalize_path LT_PARAMS((const char *path, | |
2071 | - char **pcanonical)); | |
2072 | -static int argzize_path LT_PARAMS((const char *path, | |
2073 | - char **pargz, | |
2074 | - size_t *pargz_len)); | |
2075 | -static FILE *find_file LT_PARAMS((const char *search_path, | |
2076 | - const char *base_name, | |
2077 | - char **pdir)); | |
2078 | -static lt_dlhandle *find_handle LT_PARAMS((const char *search_path, | |
2079 | - const char *base_name, | |
2080 | - lt_dlhandle *handle)); | |
2081 | -static int find_module LT_PARAMS((lt_dlhandle *handle, | |
2082 | - const char *dir, | |
2083 | - const char *libdir, | |
2084 | - const char *dlname, | |
2085 | - const char *old_name, | |
2086 | - int installed)); | |
2087 | -static int free_vars LT_PARAMS((char *dlname, char *oldname, | |
2088 | - char *libdir, char *deplibs)); | |
2089 | -static int load_deplibs LT_PARAMS((lt_dlhandle handle, | |
2090 | - char *deplibs)); | |
2091 | -static int trim LT_PARAMS((char **dest, | |
2092 | - const char *str)); | |
2093 | -static int try_dlopen LT_PARAMS((lt_dlhandle *handle, | |
2094 | - const char *filename)); | |
2095 | -static int tryall_dlopen LT_PARAMS((lt_dlhandle *handle, | |
2096 | - const char *filename)); | |
2097 | -static int unload_deplibs LT_PARAMS((lt_dlhandle handle)); | |
2098 | -static int lt_argz_insert LT_PARAMS((char **pargz, | |
2099 | - size_t *pargz_len, | |
2100 | - char *before, | |
2101 | - const char *entry)); | |
2102 | -static int lt_argz_insertinorder LT_PARAMS((char **pargz, | |
2103 | - size_t *pargz_len, | |
2104 | - const char *entry)); | |
2105 | -static int lt_argz_insertdir LT_PARAMS((char **pargz, | |
2106 | - size_t *pargz_len, | |
2107 | - const char *dirnam, | |
2108 | - struct dirent *dp)); | |
2109 | -static int lt_dlpath_insertdir LT_PARAMS((char **ppath, | |
2110 | - char *before, | |
2111 | - const char *dir)); | |
2112 | -static int list_files_by_dir LT_PARAMS((const char *dirnam, | |
2113 | - char **pargz, | |
2114 | - size_t *pargz_len)); | |
2115 | -static int file_not_found LT_PARAMS((void)); | |
2116 | - | |
2117 | -static char *user_search_path= 0; | |
2118 | -static lt_dlloader *loaders = 0; | |
2119 | -static lt_dlhandle handles = 0; | |
2120 | -static int initialized = 0; | |
2121 | - | |
2122 | -/* Initialize libltdl. */ | |
2123 | -int | |
2124 | -lt_dlinit () | |
2125 | -{ | |
2126 | - int errors = 0; | |
2127 | - | |
2128 | - LT_DLMUTEX_LOCK (); | |
2129 | - | |
2130 | - /* Initialize only at first call. */ | |
2131 | - if (++initialized == 1) | |
2132 | - { | |
2133 | - handles = 0; | |
2134 | - user_search_path = 0; /* empty search path */ | |
2135 | - | |
2136 | -#if HAVE_LIBDL | |
2137 | - errors += lt_dlloader_add (lt_dlloader_next (0), &sys_dl, "dlopen"); | |
2138 | -#endif | |
2139 | -#if HAVE_SHL_LOAD | |
2140 | - errors += lt_dlloader_add (lt_dlloader_next (0), &sys_shl, "dlopen"); | |
2141 | -#endif | |
2142 | -#ifdef __WINDOWS__ | |
2143 | - errors += lt_dlloader_add (lt_dlloader_next (0), &sys_wll, "dlopen"); | |
2144 | -#endif | |
2145 | -#ifdef __BEOS__ | |
2146 | - errors += lt_dlloader_add (lt_dlloader_next (0), &sys_bedl, "dlopen"); | |
2147 | -#endif | |
2148 | -#if HAVE_DLD | |
2149 | - errors += lt_dlloader_add (lt_dlloader_next (0), &sys_dld, "dld"); | |
2150 | -#endif | |
2151 | -#if HAVE_DYLD | |
2152 | - errors += lt_dlloader_add (lt_dlloader_next (0), &sys_dyld, "dyld"); | |
2153 | - errors += sys_dyld_init(); | |
2154 | -#endif | |
2155 | - errors += lt_dlloader_add (lt_dlloader_next (0), &presym, "dlpreload"); | |
2156 | - | |
2157 | - if (presym_init (presym.dlloader_data)) | |
2158 | - { | |
2159 | - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INIT_LOADER)); | |
2160 | - ++errors; | |
2161 | - } | |
2162 | - else if (errors != 0) | |
2163 | - { | |
2164 | - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (DLOPEN_NOT_SUPPORTED)); | |
2165 | - ++errors; | |
2166 | - } | |
2167 | - } | |
2168 | - | |
2169 | - LT_DLMUTEX_UNLOCK (); | |
2170 | - | |
2171 | - return errors; | |
2172 | -} | |
2173 | - | |
2174 | -int | |
2175 | -lt_dlpreload (const lt_dlsymlist *preloaded) | |
2176 | -{ | |
2177 | - int errors = 0; | |
2178 | - | |
2179 | - if (preloaded) | |
2180 | - { | |
2181 | - errors = presym_add_symlist (preloaded); | |
2182 | - } | |
2183 | - else | |
2184 | - { | |
2185 | - presym_free_symlists(); | |
2186 | - | |
2187 | - LT_DLMUTEX_LOCK (); | |
2188 | - if (default_preloaded_symbols) | |
2189 | - { | |
2190 | - errors = lt_dlpreload (default_preloaded_symbols); | |
2191 | - } | |
2192 | - LT_DLMUTEX_UNLOCK (); | |
2193 | - } | |
2194 | - | |
2195 | - return errors; | |
2196 | -} | |
2197 | - | |
2198 | -int | |
2199 | -lt_dlpreload_default (const lt_dlsymlist *preloaded) | |
2200 | -{ | |
2201 | - LT_DLMUTEX_LOCK (); | |
2202 | - default_preloaded_symbols = preloaded; | |
2203 | - LT_DLMUTEX_UNLOCK (); | |
2204 | - return 0; | |
2205 | -} | |
2206 | - | |
2207 | -int | |
2208 | -lt_dlexit () | |
2209 | -{ | |
2210 | - /* shut down libltdl */ | |
2211 | - lt_dlloader *loader; | |
2212 | - int errors = 0; | |
2213 | - | |
2214 | - LT_DLMUTEX_LOCK (); | |
2215 | - loader = loaders; | |
2216 | - | |
2217 | - if (!initialized) | |
2218 | - { | |
2219 | - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (SHUTDOWN)); | |
2220 | - ++errors; | |
2221 | - goto done; | |
2222 | - } | |
2223 | - | |
2224 | - /* shut down only at last call. */ | |
2225 | - if (--initialized == 0) | |
2226 | - { | |
2227 | - int level; | |
2228 | - | |
2229 | - while (handles && LT_DLIS_RESIDENT (handles)) | |
2230 | - { | |
2231 | - handles = handles->next; | |
2232 | - } | |
2233 | - | |
2234 | - /* close all modules */ | |
2235 | - for (level = 1; handles; ++level) | |
2236 | - { | |
2237 | - lt_dlhandle cur = handles; | |
2238 | - int saw_nonresident = 0; | |
2239 | - | |
2240 | - while (cur) | |
2241 | - { | |
2242 | - lt_dlhandle tmp = cur; | |
2243 | - cur = cur->next; | |
2244 | - if (!LT_DLIS_RESIDENT (tmp)) | |
2245 | - saw_nonresident = 1; | |
2246 | - if (!LT_DLIS_RESIDENT (tmp) && tmp->info.ref_count <= level) | |
2247 | - { | |
2248 | - if (lt_dlclose (tmp)) | |
2249 | - { | |
2250 | - ++errors; | |
2251 | - } | |
2252 | - } | |
2253 | - } | |
2254 | - /* done if only resident modules are left */ | |
2255 | - if (!saw_nonresident) | |
2256 | - break; | |
2257 | - } | |
2258 | - | |
2259 | - /* close all loaders */ | |
2260 | - while (loader) | |
2261 | - { | |
2262 | - lt_dlloader *next = loader->next; | |
2263 | - lt_user_data data = loader->dlloader_data; | |
2264 | - if (loader->dlloader_exit && loader->dlloader_exit (data)) | |
2265 | - { | |
2266 | - ++errors; | |
2267 | - } | |
2268 | - | |
2269 | - LT_DLMEM_REASSIGN (loader, next); | |
2270 | - } | |
2271 | - loaders = 0; | |
2272 | - } | |
2273 | - | |
2274 | - done: | |
2275 | - LT_DLMUTEX_UNLOCK (); | |
2276 | - return errors; | |
2277 | -} | |
2278 | - | |
2279 | -static int | |
2280 | -tryall_dlopen (lt_dlhandle *handle, const char *filename) | |
2281 | -{ | |
2282 | - lt_dlhandle cur; | |
2283 | - lt_dlloader *loader; | |
2284 | - const char *saved_error; | |
2285 | - int errors = 0; | |
2286 | - | |
2287 | - LT_DLMUTEX_GETERROR (saved_error); | |
2288 | - LT_DLMUTEX_LOCK (); | |
2289 | - | |
2290 | - cur = handles; | |
2291 | - loader = loaders; | |
2292 | - | |
2293 | - /* check whether the module was already opened */ | |
2294 | - while (cur) | |
2295 | - { | |
2296 | - /* try to dlopen the program itself? */ | |
2297 | - if (!cur->info.filename && !filename) | |
2298 | - { | |
2299 | - break; | |
2300 | - } | |
2301 | - | |
2302 | - if (cur->info.filename && filename | |
2303 | - && strcmp (cur->info.filename, filename) == 0) | |
2304 | - { | |
2305 | - break; | |
2306 | - } | |
2307 | - | |
2308 | - cur = cur->next; | |
2309 | - } | |
2310 | - | |
2311 | - if (cur) | |
2312 | - { | |
2313 | - ++cur->info.ref_count; | |
2314 | - *handle = cur; | |
2315 | - goto done; | |
2316 | - } | |
2317 | - | |
2318 | - cur = *handle; | |
2319 | - if (filename) | |
2320 | - { | |
2321 | - /* Comment out the check of file permissions using access. | |
2322 | - This call seems to always return -1 with error EACCES. | |
2323 | - */ | |
2324 | - /* We need to catch missing file errors early so that | |
2325 | - file_not_found() can detect what happened. | |
2326 | - if (access (filename, R_OK) != 0) | |
2327 | - { | |
2328 | - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (FILE_NOT_FOUND)); | |
2329 | - ++errors; | |
2330 | - goto done; | |
2331 | - } */ | |
2332 | - | |
2333 | - cur->info.filename = lt_estrdup (filename); | |
2334 | - if (!cur->info.filename) | |
2335 | - { | |
2336 | - ++errors; | |
2337 | - goto done; | |
2338 | - } | |
2339 | - } | |
2340 | - else | |
2341 | - { | |
2342 | - cur->info.filename = 0; | |
2343 | - } | |
2344 | - | |
2345 | - while (loader) | |
2346 | - { | |
2347 | - lt_user_data data = loader->dlloader_data; | |
2348 | - | |
2349 | - cur->module = loader->module_open (data, filename); | |
2350 | - | |
2351 | - if (cur->module != 0) | |
2352 | - { | |
2353 | - break; | |
2354 | - } | |
2355 | - loader = loader->next; | |
2356 | - } | |
2357 | - | |
2358 | - if (!loader) | |
2359 | - { | |
2360 | - LT_DLFREE (cur->info.filename); | |
2361 | - ++errors; | |
2362 | - goto done; | |
2363 | - } | |
2364 | - | |
2365 | - cur->loader = loader; | |
2366 | - LT_DLMUTEX_SETERROR (saved_error); | |
2367 | - | |
2368 | - done: | |
2369 | - LT_DLMUTEX_UNLOCK (); | |
2370 | - | |
2371 | - return errors; | |
2372 | -} | |
2373 | - | |
2374 | -static int | |
2375 | -tryall_dlopen_module ( | |
2376 | - lt_dlhandle *handle, | |
2377 | - const char *prefix, | |
2378 | - const char *dirname, | |
2379 | - const char *dlname) | |
2380 | -{ | |
2381 | - int error = 0; | |
2382 | - char *filename = 0; | |
2383 | - size_t filename_len = 0; | |
2384 | - size_t dirname_len = LT_STRLEN (dirname); | |
2385 | - | |
2386 | - assert (handle); | |
2387 | - assert (dirname); | |
2388 | - assert (dlname); | |
2389 | -#ifdef LT_DIRSEP_CHAR | |
2390 | - /* Only canonicalized names (i.e. with DIRSEP chars already converted) | |
2391 | - should make it into this function: */ | |
2392 | - assert (strchr (dirname, LT_DIRSEP_CHAR) == 0); | |
2393 | -#endif | |
2394 | - | |
2395 | - if (dirname_len > 0) | |
2396 | - if (dirname[dirname_len -1] == '/') | |
2397 | - --dirname_len; | |
2398 | - filename_len = dirname_len + 1 + LT_STRLEN (dlname); | |
2399 | - | |
2400 | - /* Allocate memory, and combine DIRNAME and MODULENAME into it. | |
2401 | - The PREFIX (if any) is handled below. */ | |
2402 | - filename = LT_EMALLOC (char, dirname_len + 1 + filename_len + 1); | |
2403 | - if (!filename) | |
2404 | - return 1; | |
2405 | - | |
2406 | - sprintf (filename, "%.*s/%s", (int) dirname_len, dirname, dlname); | |
2407 | - | |
2408 | - /* Now that we have combined DIRNAME and MODULENAME, if there is | |
2409 | - also a PREFIX to contend with, simply recurse with the arguments | |
2410 | - shuffled. Otherwise, attempt to open FILENAME as a module. */ | |
2411 | - if (prefix) | |
2412 | - { | |
2413 | - error += tryall_dlopen_module (handle, | |
2414 | - (const char *) 0, prefix, filename); | |
2415 | - } | |
2416 | - else if (tryall_dlopen (handle, filename) != 0) | |
2417 | - { | |
2418 | - ++error; | |
2419 | - } | |
2420 | - | |
2421 | - LT_DLFREE (filename); | |
2422 | - return error; | |
2423 | -} | |
2424 | - | |
2425 | -static int | |
2426 | -find_module ( | |
2427 | - lt_dlhandle *handle, | |
2428 | - const char *dir, | |
2429 | - const char *libdir, | |
2430 | - const char *dlname, | |
2431 | - const char *old_name, | |
2432 | - int installed) | |
2433 | -{ | |
2434 | - /* Try to open the old library first; if it was dlpreopened, | |
2435 | - we want the preopened version of it, even if a dlopenable | |
2436 | - module is available. */ | |
2437 | - if (old_name && tryall_dlopen (handle, old_name) == 0) | |
2438 | - { | |
2439 | - return 0; | |
2440 | - } | |
2441 | - | |
2442 | - /* Try to open the dynamic library. */ | |
2443 | - if (dlname) | |
2444 | - { | |
2445 | - /* try to open the installed module */ | |
2446 | - if (installed && libdir) | |
2447 | - { | |
2448 | - if (tryall_dlopen_module (handle, | |
2449 | - (const char *) 0, libdir, dlname) == 0) | |
2450 | - return 0; | |
2451 | - } | |
2452 | - | |
2453 | - /* try to open the not-installed module */ | |
2454 | - if (!installed) | |
2455 | - { | |
2456 | - if (tryall_dlopen_module (handle, dir, objdir, dlname) == 0) | |
2457 | - return 0; | |
2458 | - } | |
2459 | - | |
2460 | - /* maybe it was moved to another directory */ | |
2461 | - { | |
2462 | - if (tryall_dlopen_module (handle, | |
2463 | - (const char *) 0, dir, dlname) == 0) | |
2464 | - return 0; | |
2465 | - } | |
2466 | - } | |
2467 | - | |
2468 | - return 1; | |
2469 | -} | |
2470 | - | |
2471 | - | |
2472 | -static int | |
2473 | -canonicalize_path ( | |
2474 | - const char *path, | |
2475 | - char **pcanonical) | |
2476 | -{ | |
2477 | - char *canonical = 0; | |
2478 | - | |
2479 | - assert (path && *path); | |
2480 | - assert (pcanonical); | |
2481 | - | |
2482 | - canonical = LT_EMALLOC (char, 1+ LT_STRLEN (path)); | |
2483 | - if (!canonical) | |
2484 | - return 1; | |
2485 | - | |
2486 | - { | |
2487 | - size_t dest = 0; | |
2488 | - size_t src; | |
2489 | - for (src = 0; path[src] != LT_EOS_CHAR; ++src) | |
2490 | - { | |
2491 | - /* Path separators are not copied to the beginning or end of | |
2492 | - the destination, or if another separator would follow | |
2493 | - immediately. */ | |
2494 | - if (path[src] == LT_PATHSEP_CHAR) | |
2495 | - { | |
2496 | - if ((dest == 0) | |
2497 | - || (path[1+ src] == LT_PATHSEP_CHAR) | |
2498 | - || (path[1+ src] == LT_EOS_CHAR)) | |
2499 | - continue; | |
2500 | - } | |
2501 | - | |
2502 | - /* Anything other than a directory separator is copied verbatim. */ | |
2503 | - if ((path[src] != '/') | |
2504 | -#ifdef LT_DIRSEP_CHAR | |
2505 | - && (path[src] != LT_DIRSEP_CHAR) | |
2506 | -#endif | |
2507 | - ) | |
2508 | - { | |
2509 | - canonical[dest++] = path[src]; | |
2510 | - } | |
2511 | - /* Directory separators are converted and copied only if they are | |
2512 | - not at the end of a path -- i.e. before a path separator or | |
2513 | - NULL terminator. */ | |
2514 | - else if ((path[1+ src] != LT_PATHSEP_CHAR) | |
2515 | - && (path[1+ src] != LT_EOS_CHAR) | |
2516 | -#ifdef LT_DIRSEP_CHAR | |
2517 | - && (path[1+ src] != LT_DIRSEP_CHAR) | |
2518 | -#endif | |
2519 | - && (path[1+ src] != '/')) | |
2520 | - { | |
2521 | - canonical[dest++] = '/'; | |
2522 | - } | |
2523 | - } | |
2524 | - | |
2525 | - /* Add an end-of-string marker at the end. */ | |
2526 | - canonical[dest] = LT_EOS_CHAR; | |
2527 | - } | |
2528 | - | |
2529 | - /* Assign new value. */ | |
2530 | - *pcanonical = canonical; | |
2531 | - | |
2532 | - return 0; | |
2533 | -} | |
2534 | - | |
2535 | -static int | |
2536 | -argzize_path ( | |
2537 | - const char *path, | |
2538 | - char **pargz, | |
2539 | - size_t *pargz_len) | |
2540 | -{ | |
2541 | - error_t error; | |
2542 | - | |
2543 | - assert (path); | |
2544 | - assert (pargz); | |
2545 | - assert (pargz_len); | |
2546 | - | |
2547 | - if ((error = argz_create_sep (path, LT_PATHSEP_CHAR, pargz, pargz_len))) | |
2548 | - { | |
2549 | - switch (error) | |
2550 | - { | |
2551 | - case ENOMEM: | |
2552 | - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY)); | |
2553 | - break; | |
2554 | - default: | |
2555 | - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (UNKNOWN)); | |
2556 | - break; | |
2557 | - } | |
2558 | - | |
2559 | - return 1; | |
2560 | - } | |
2561 | - | |
2562 | - return 0; | |
2563 | -} | |
2564 | - | |
2565 | -/* Repeatedly call FUNC with each LT_PATHSEP_CHAR delimited element | |
2566 | - of SEARCH_PATH and references to DATA1 and DATA2, until FUNC returns | |
2567 | - non-zero or all elements are exhausted. If BASE_NAME is non-NULL, | |
2568 | - it is appended to each SEARCH_PATH element before FUNC is called. */ | |
2569 | -static int | |
2570 | -foreach_dirinpath ( | |
2571 | - const char *search_path, | |
2572 | - const char *base_name, | |
2573 | - foreach_callback_func *func, | |
2574 | - lt_ptr data1, | |
2575 | - lt_ptr data2) | |
2576 | -{ | |
2577 | - int result = 0; | |
2578 | - int filenamesize = 0; | |
2579 | - size_t lenbase = LT_STRLEN (base_name); | |
2580 | - size_t argz_len = 0; | |
2581 | - char *argz = 0; | |
2582 | - char *filename = 0; | |
2583 | - char *canonical = 0; | |
2584 | - | |
2585 | - LT_DLMUTEX_LOCK (); | |
2586 | - | |
2587 | - if (!search_path || !*search_path) | |
2588 | - { | |
2589 | - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (FILE_NOT_FOUND)); | |
2590 | - goto cleanup; | |
2591 | - } | |
2592 | - | |
2593 | - if (canonicalize_path (search_path, &canonical) != 0) | |
2594 | - goto cleanup; | |
2595 | - | |
2596 | - if (argzize_path (canonical, &argz, &argz_len) != 0) | |
2597 | - goto cleanup; | |
2598 | - | |
2599 | - { | |
2600 | - char *dir_name = 0; | |
2601 | - while ((dir_name = argz_next (argz, argz_len, dir_name))) | |
2602 | - { | |
2603 | - size_t lendir = LT_STRLEN (dir_name); | |
2604 | - | |
2605 | - if (lendir +1 +lenbase >= filenamesize) | |
2606 | - { | |
2607 | - LT_DLFREE (filename); | |
2608 | - filenamesize = lendir +1 +lenbase +1; /* "/d" + '/' + "f" + '\0' */ | |
2609 | - filename = LT_EMALLOC (char, filenamesize); | |
2610 | - if (!filename) | |
2611 | - goto cleanup; | |
2612 | - } | |
2613 | - | |
2614 | - assert (filenamesize > lendir); | |
2615 | - strcpy (filename, dir_name); | |
2616 | - | |
2617 | - if (base_name && *base_name) | |
2618 | - { | |
2619 | - if (filename[lendir -1] != '/') | |
2620 | - filename[lendir++] = '/'; | |
2621 | - strcpy (filename +lendir, base_name); | |
2622 | - } | |
2623 | - | |
2624 | - if ((result = (*func) (filename, data1, data2))) | |
2625 | - { | |
2626 | - break; | |
2627 | - } | |
2628 | - } | |
2629 | - } | |
2630 | - | |
2631 | - cleanup: | |
2632 | - LT_DLFREE (argz); | |
2633 | - LT_DLFREE (canonical); | |
2634 | - LT_DLFREE (filename); | |
2635 | - | |
2636 | - LT_DLMUTEX_UNLOCK (); | |
2637 | - | |
2638 | - return result; | |
2639 | -} | |
2640 | - | |
2641 | -/* If FILEPATH can be opened, store the name of the directory component | |
2642 | - in DATA1, and the opened FILE* structure address in DATA2. Otherwise | |
2643 | - DATA1 is unchanged, but DATA2 is set to a pointer to NULL. */ | |
2644 | -static int | |
2645 | -find_file_callback ( | |
2646 | - char *filename, | |
2647 | - lt_ptr data1, | |
2648 | - lt_ptr data2) | |
2649 | -{ | |
2650 | - char **pdir = (char **) data1; | |
2651 | - FILE **pfile = (FILE **) data2; | |
2652 | - int is_done = 0; | |
2653 | - | |
2654 | - assert (filename && *filename); | |
2655 | - assert (pdir); | |
2656 | - assert (pfile); | |
2657 | - | |
2658 | - if ((*pfile = fopen (filename, LT_READTEXT_MODE))) | |
2659 | - { | |
2660 | - char *dirend = strrchr (filename, '/'); | |
2661 | - | |
2662 | - if (dirend > filename) | |
2663 | - *dirend = LT_EOS_CHAR; | |
2664 | - | |
2665 | - LT_DLFREE (*pdir); | |
2666 | - *pdir = lt_estrdup (filename); | |
2667 | - is_done = (*pdir == 0) ? -1 : 1; | |
2668 | - } | |
2669 | - | |
2670 | - return is_done; | |
2671 | -} | |
2672 | - | |
2673 | -static FILE * | |
2674 | -find_file ( | |
2675 | - const char *search_path, | |
2676 | - const char *base_name, | |
2677 | - char **pdir) | |
2678 | -{ | |
2679 | - FILE *file = 0; | |
2680 | - | |
2681 | - foreach_dirinpath (search_path, base_name, find_file_callback, pdir, &file); | |
2682 | - | |
2683 | - return file; | |
2684 | -} | |
2685 | - | |
2686 | -static int | |
2687 | -find_handle_callback ( | |
2688 | - char *filename, | |
2689 | - lt_ptr data, | |
2690 | - lt_ptr ignored) | |
2691 | -{ | |
2692 | - lt_dlhandle *handle = (lt_dlhandle *) data; | |
2693 | - int notfound = access (filename, R_OK); | |
2694 | - | |
2695 | - /* Bail out if file cannot be read... */ | |
2696 | - if (notfound) | |
2697 | - return 0; | |
2698 | - | |
2699 | - /* Try to dlopen the file, but do not continue searching in any | |
2700 | - case. */ | |
2701 | - if (tryall_dlopen (handle, filename) != 0) | |
2702 | - *handle = 0; | |
2703 | - | |
2704 | - return 1; | |
2705 | -} | |
2706 | - | |
2707 | -/* If HANDLE was found return it, otherwise return 0. If HANDLE was | |
2708 | - found but could not be opened, *HANDLE will be set to 0. */ | |
2709 | -static lt_dlhandle * | |
2710 | -find_handle ( | |
2711 | - const char *search_path, | |
2712 | - const char *base_name, | |
2713 | - lt_dlhandle *handle) | |
2714 | -{ | |
2715 | - if (!search_path) | |
2716 | - return 0; | |
2717 | - | |
2718 | - if (!foreach_dirinpath (search_path, base_name, find_handle_callback, | |
2719 | - handle, 0)) | |
2720 | - return 0; | |
2721 | - | |
2722 | - return handle; | |
2723 | -} | |
2724 | - | |
2725 | -static int | |
2726 | -load_deplibs ( | |
2727 | - lt_dlhandle handle, | |
2728 | - char *deplibs) | |
2729 | -{ | |
2730 | -#if LTDL_DLOPEN_DEPLIBS | |
2731 | - char *p, *save_search_path = 0; | |
2732 | - int depcount = 0; | |
2733 | - int i; | |
2734 | - char **names = 0; | |
2735 | -#endif | |
2736 | - int errors = 0; | |
2737 | - | |
2738 | - handle->depcount = 0; | |
2739 | - | |
2740 | -#if LTDL_DLOPEN_DEPLIBS | |
2741 | - if (!deplibs) | |
2742 | - { | |
2743 | - return errors; | |
2744 | - } | |
2745 | - ++errors; | |
2746 | - | |
2747 | - LT_DLMUTEX_LOCK (); | |
2748 | - if (user_search_path) | |
2749 | - { | |
2750 | - save_search_path = lt_estrdup (user_search_path); | |
2751 | - if (!save_search_path) | |
2752 | - goto cleanup; | |
2753 | - } | |
2754 | - | |
2755 | - /* extract search paths and count deplibs */ | |
2756 | - p = deplibs; | |
2757 | - while (*p) | |
2758 | - { | |
2759 | - if (!isspace ((int) *p)) | |
2760 | - { | |
2761 | - char *end = p+1; | |
2762 | - while (*end && !isspace((int) *end)) | |
2763 | - { | |
2764 | - ++end; | |
2765 | - } | |
2766 | - | |
2767 | - if (strncmp(p, "-L", 2) == 0 || strncmp(p, "-R", 2) == 0) | |
2768 | - { | |
2769 | - char save = *end; | |
2770 | - *end = 0; /* set a temporary string terminator */ | |
2771 | - if (lt_dladdsearchdir(p+2)) | |
2772 | - { | |
2773 | - goto cleanup; | |
2774 | - } | |
2775 | - *end = save; | |
2776 | - } | |
2777 | - else | |
2778 | - { | |
2779 | - ++depcount; | |
2780 | - } | |
2781 | - | |
2782 | - p = end; | |
2783 | - } | |
2784 | - else | |
2785 | - { | |
2786 | - ++p; | |
2787 | - } | |
2788 | - } | |
2789 | - | |
2790 | - /* restore the old search path */ | |
2791 | - LT_DLFREE (user_search_path); | |
2792 | - user_search_path = save_search_path; | |
2793 | - | |
2794 | - LT_DLMUTEX_UNLOCK (); | |
2795 | - | |
2796 | - if (!depcount) | |
2797 | - { | |
2798 | - errors = 0; | |
2799 | - goto cleanup; | |
2800 | - } | |
2801 | - | |
2802 | - names = LT_EMALLOC (char *, depcount * sizeof (char*)); | |
2803 | - if (!names) | |
2804 | - goto cleanup; | |
2805 | - | |
2806 | - /* now only extract the actual deplibs */ | |
2807 | - depcount = 0; | |
2808 | - p = deplibs; | |
2809 | - while (*p) | |
2810 | - { | |
2811 | - if (isspace ((int) *p)) | |
2812 | - { | |
2813 | - ++p; | |
2814 | - } | |
2815 | - else | |
2816 | - { | |
2817 | - char *end = p+1; | |
2818 | - while (*end && !isspace ((int) *end)) | |
2819 | - { | |
2820 | - ++end; | |
2821 | - } | |
2822 | - | |
2823 | - if (strncmp(p, "-L", 2) != 0 && strncmp(p, "-R", 2) != 0) | |
2824 | - { | |
2825 | - char *name; | |
2826 | - char save = *end; | |
2827 | - *end = 0; /* set a temporary string terminator */ | |
2828 | - if (strncmp(p, "-l", 2) == 0) | |
2829 | - { | |
2830 | - size_t name_len = 3+ /* "lib" */ LT_STRLEN (p + 2); | |
2831 | - name = LT_EMALLOC (char, 1+ name_len); | |
2832 | - if (name) | |
2833 | - sprintf (name, "lib%s", p+2); | |
2834 | - } | |
2835 | - else | |
2836 | - name = lt_estrdup(p); | |
2837 | - | |
2838 | - if (!name) | |
2839 | - goto cleanup_names; | |
2840 | - | |
2841 | - names[depcount++] = name; | |
2842 | - *end = save; | |
2843 | - } | |
2844 | - p = end; | |
2845 | - } | |
2846 | - } | |
2847 | - | |
2848 | - /* load the deplibs (in reverse order) | |
2849 | - At this stage, don't worry if the deplibs do not load correctly, | |
2850 | - they may already be statically linked into the loading application | |
2851 | - for instance. There will be a more enlightening error message | |
2852 | - later on if the loaded module cannot resolve all of its symbols. */ | |
2853 | - if (depcount) | |
2854 | - { | |
2855 | - int j = 0; | |
2856 | - | |
2857 | - handle->deplibs = (lt_dlhandle*) LT_EMALLOC (lt_dlhandle *, depcount); | |
2858 | - if (!handle->deplibs) | |
2859 | - goto cleanup; | |
2860 | - | |
2861 | - for (i = 0; i < depcount; ++i) | |
2862 | - { | |
2863 | - handle->deplibs[j] = lt_dlopenext(names[depcount-1-i]); | |
2864 | - if (handle->deplibs[j]) | |
2865 | - { | |
2866 | - ++j; | |
2867 | - } | |
2868 | - } | |
2869 | - | |
2870 | - handle->depcount = j; /* Number of successfully loaded deplibs */ | |
2871 | - errors = 0; | |
2872 | - } | |
2873 | - | |
2874 | - cleanup_names: | |
2875 | - for (i = 0; i < depcount; ++i) | |
2876 | - { | |
2877 | - LT_DLFREE (names[i]); | |
2878 | - } | |
2879 | - | |
2880 | - cleanup: | |
2881 | - LT_DLFREE (names); | |
2882 | -#endif | |
2883 | - | |
2884 | - return errors; | |
2885 | -} | |
2886 | - | |
2887 | -static int | |
2888 | -unload_deplibs ( | |
2889 | - lt_dlhandle handle) | |
2890 | -{ | |
2891 | - int i; | |
2892 | - int errors = 0; | |
2893 | - | |
2894 | - if (handle->depcount) | |
2895 | - { | |
2896 | - for (i = 0; i < handle->depcount; ++i) | |
2897 | - { | |
2898 | - if (!LT_DLIS_RESIDENT (handle->deplibs[i])) | |
2899 | - { | |
2900 | - errors += lt_dlclose (handle->deplibs[i]); | |
2901 | - } | |
2902 | - } | |
2903 | - } | |
2904 | - | |
2905 | - return errors; | |
2906 | -} | |
2907 | - | |
2908 | -static int | |
2909 | -trim ( | |
2910 | - char **dest, | |
2911 | - const char *str) | |
2912 | -{ | |
2913 | - /* remove the leading and trailing "'" from str | |
2914 | - and store the result in dest */ | |
2915 | - const char *end = strrchr (str, '\''); | |
2916 | - size_t len = LT_STRLEN (str); | |
2917 | - char *tmp; | |
2918 | - | |
2919 | - LT_DLFREE (*dest); | |
2920 | - | |
2921 | - if (len > 3 && str[0] == '\'') | |
2922 | - { | |
2923 | - tmp = LT_EMALLOC (char, end - str); | |
2924 | - if (!tmp) | |
2925 | - return 1; | |
2926 | - | |
2927 | - strncpy(tmp, &str[1], (end - str) - 1); | |
2928 | - tmp[len-3] = LT_EOS_CHAR; | |
2929 | - *dest = tmp; | |
2930 | - } | |
2931 | - else | |
2932 | - { | |
2933 | - *dest = 0; | |
2934 | - } | |
2935 | - | |
2936 | - return 0; | |
2937 | -} | |
2938 | - | |
2939 | -static int | |
2940 | -free_vars ( | |
2941 | - char *dlname, | |
2942 | - char *oldname, | |
2943 | - char *libdir, | |
2944 | - char *deplibs) | |
2945 | -{ | |
2946 | - LT_DLFREE (dlname); | |
2947 | - LT_DLFREE (oldname); | |
2948 | - LT_DLFREE (libdir); | |
2949 | - LT_DLFREE (deplibs); | |
2950 | - | |
2951 | - return 0; | |
2952 | -} | |
2953 | - | |
2954 | -static int | |
2955 | -try_dlopen ( | |
2956 | - lt_dlhandle *phandle, | |
2957 | - const char *filename) | |
2958 | -{ | |
2959 | - const char * ext = 0; | |
2960 | - const char * saved_error = 0; | |
2961 | - char * canonical = 0; | |
2962 | - char * base_name = 0; | |
2963 | - char * dir = 0; | |
2964 | - char * name = 0; | |
2965 | - int errors = 0; | |
2966 | - lt_dlhandle newhandle; | |
2967 | - | |
2968 | - assert (phandle); | |
2969 | - assert (*phandle == 0); | |
2970 | - | |
2971 | - LT_DLMUTEX_GETERROR (saved_error); | |
2972 | - | |
2973 | - /* dlopen self? */ | |
2974 | - if (!filename) | |
2975 | - { | |
2976 | - *phandle = (lt_dlhandle) LT_EMALLOC (struct lt_dlhandle_struct, 1); | |
2977 | - if (*phandle == 0) | |
2978 | - return 1; | |
2979 | - | |
2980 | - memset (*phandle, 0, sizeof(struct lt_dlhandle_struct)); | |
2981 | - newhandle = *phandle; | |
2982 | - | |
2983 | - /* lt_dlclose()ing yourself is very bad! Disallow it. */ | |
2984 | - LT_DLSET_FLAG (*phandle, LT_DLRESIDENT_FLAG); | |
2985 | - | |
2986 | - if (tryall_dlopen (&newhandle, 0) != 0) | |
2987 | - { | |
2988 | - LT_DLFREE (*phandle); | |
2989 | - return 1; | |
2990 | - } | |
2991 | - | |
2992 | - goto register_handle; | |
2993 | - } | |
2994 | - | |
2995 | - assert (filename && *filename); | |
2996 | - | |
2997 | - /* Doing this immediately allows internal functions to safely | |
2998 | - assume only canonicalized paths are passed. */ | |
2999 | - if (canonicalize_path (filename, &canonical) != 0) | |
3000 | - { | |
3001 | - ++errors; | |
3002 | - goto cleanup; | |
3003 | - } | |
3004 | - | |
3005 | - /* If the canonical module name is a path (relative or absolute) | |
3006 | - then split it into a directory part and a name part. */ | |
3007 | - base_name = strrchr (canonical, '/'); | |
3008 | - if (base_name) | |
3009 | - { | |
3010 | - size_t dirlen = (1+ base_name) - canonical; | |
3011 | - | |
3012 | - dir = LT_EMALLOC (char, 1+ dirlen); | |
3013 | - if (!dir) | |
3014 | - { | |
3015 | - ++errors; | |
3016 | - goto cleanup; | |
3017 | - } | |
3018 | - | |
3019 | - strncpy (dir, canonical, dirlen); | |
3020 | - dir[dirlen] = LT_EOS_CHAR; | |
3021 | - | |
3022 | - ++base_name; | |
3023 | - } | |
3024 | - else | |
3025 | - LT_DLMEM_REASSIGN (base_name, canonical); | |
3026 | - | |
3027 | - assert (base_name && *base_name); | |
3028 | - | |
3029 | - /* Check whether we are opening a libtool module (.la extension). */ | |
3030 | - ext = strrchr (base_name, '.'); | |
3031 | - if (ext && strcmp (ext, archive_ext) == 0) | |
3032 | - { | |
3033 | - /* this seems to be a libtool module */ | |
3034 | - FILE * file = 0; | |
3035 | - char * dlname = 0; | |
3036 | - char * old_name = 0; | |
3037 | - char * libdir = 0; | |
3038 | - char * deplibs = 0; | |
3039 | - char * line = 0; | |
3040 | - size_t line_len; | |
3041 | - | |
3042 | - /* if we can't find the installed flag, it is probably an | |
3043 | - installed libtool archive, produced with an old version | |
3044 | - of libtool */ | |
3045 | - int installed = 1; | |
3046 | - | |
3047 | - /* extract the module name from the file name */ | |
3048 | - name = LT_EMALLOC (char, ext - base_name + 1); | |
3049 | - if (!name) | |
3050 | - { | |
3051 | - ++errors; | |
3052 | - goto cleanup; | |
3053 | - } | |
3054 | - | |
3055 | - /* canonicalize the module name */ | |
3056 | - { | |
3057 | - size_t i; | |
3058 | - for (i = 0; i < ext - base_name; ++i) | |
3059 | - { | |
3060 | - if (isalnum ((int)(base_name[i]))) | |
3061 | - { | |
3062 | - name[i] = base_name[i]; | |
3063 | - } | |
3064 | - else | |
3065 | - { | |
3066 | - name[i] = '_'; | |
3067 | - } | |
3068 | - } | |
3069 | - name[ext - base_name] = LT_EOS_CHAR; | |
3070 | - } | |
3071 | - | |
3072 | - /* Now try to open the .la file. If there is no directory name | |
3073 | - component, try to find it first in user_search_path and then other | |
3074 | - prescribed paths. Otherwise (or in any case if the module was not | |
3075 | - yet found) try opening just the module name as passed. */ | |
3076 | - if (!dir) | |
3077 | - { | |
3078 | - const char *search_path; | |
3079 | - | |
3080 | - LT_DLMUTEX_LOCK (); | |
3081 | - search_path = user_search_path; | |
3082 | - if (search_path) | |
3083 | - file = find_file (user_search_path, base_name, &dir); | |
3084 | - LT_DLMUTEX_UNLOCK (); | |
3085 | - | |
3086 | - if (!file) | |
3087 | - { | |
3088 | - search_path = getenv (LTDL_SEARCHPATH_VAR); | |
3089 | - if (search_path) | |
3090 | - file = find_file (search_path, base_name, &dir); | |
3091 | - } | |
3092 | - | |
3093 | -#ifdef LTDL_SHLIBPATH_VAR | |
3094 | - if (!file) | |
3095 | - { | |
3096 | - search_path = getenv (LTDL_SHLIBPATH_VAR); | |
3097 | - if (search_path) | |
3098 | - file = find_file (search_path, base_name, &dir); | |
3099 | - } | |
3100 | -#endif | |
3101 | -#ifdef LTDL_SYSSEARCHPATH | |
3102 | - if (!file && sys_search_path) | |
3103 | - { | |
3104 | - file = find_file (sys_search_path, base_name, &dir); | |
3105 | - } | |
3106 | -#endif | |
3107 | - } | |
3108 | - if (!file) | |
3109 | - { | |
3110 | - file = fopen (filename, LT_READTEXT_MODE); | |
3111 | - } | |
3112 | - | |
3113 | - /* If we didn't find the file by now, it really isn't there. Set | |
3114 | - the status flag, and bail out. */ | |
3115 | - if (!file) | |
3116 | - { | |
3117 | - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (FILE_NOT_FOUND)); | |
3118 | - ++errors; | |
3119 | - goto cleanup; | |
3120 | - } | |
3121 | - | |
3122 | - line_len = LT_FILENAME_MAX; | |
3123 | - line = LT_EMALLOC (char, line_len); | |
3124 | - if (!line) | |
3125 | - { | |
3126 | - fclose (file); | |
3127 | - ++errors; | |
3128 | - goto cleanup; | |
3129 | - } | |
3130 | - | |
3131 | - /* read the .la file */ | |
3132 | - while (!feof (file)) | |
3133 | - { | |
3134 | - if (!fgets (line, (int) line_len, file)) | |
3135 | - { | |
3136 | - break; | |
3137 | - } | |
3138 | - | |
3139 | - /* Handle the case where we occasionally need to read a line | |
3140 | - that is longer than the initial buffer size. */ | |
3141 | - while ((line[LT_STRLEN(line) -1] != '\n') && (!feof (file))) | |
3142 | - { | |
3143 | - line = LT_DLREALLOC (char, line, line_len *2); | |
3144 | - if (!fgets (&line[line_len -1], (int) line_len +1, file)) | |
3145 | - { | |
3146 | - break; | |
3147 | - } | |
3148 | - line_len *= 2; | |
3149 | - } | |
3150 | - | |
3151 | - if (line[0] == '\n' || line[0] == '#') | |
3152 | - { | |
3153 | - continue; | |
3154 | - } | |
3155 | - | |
3156 | -#undef STR_DLNAME | |
3157 | -#define STR_DLNAME "dlname=" | |
3158 | - if (strncmp (line, STR_DLNAME, sizeof (STR_DLNAME) - 1) == 0) | |
3159 | - { | |
3160 | - errors += trim (&dlname, &line[sizeof (STR_DLNAME) - 1]); | |
3161 | - } | |
3162 | - | |
3163 | -#undef STR_OLD_LIBRARY | |
3164 | -#define STR_OLD_LIBRARY "old_library=" | |
3165 | - else if (strncmp (line, STR_OLD_LIBRARY, | |
3166 | - sizeof (STR_OLD_LIBRARY) - 1) == 0) | |
3167 | - { | |
3168 | - errors += trim (&old_name, &line[sizeof (STR_OLD_LIBRARY) - 1]); | |
3169 | - } | |
3170 | -#undef STR_LIBDIR | |
3171 | -#define STR_LIBDIR "libdir=" | |
3172 | - else if (strncmp (line, STR_LIBDIR, sizeof (STR_LIBDIR) - 1) == 0) | |
3173 | - { | |
3174 | - errors += trim (&libdir, &line[sizeof(STR_LIBDIR) - 1]); | |
3175 | - } | |
3176 | - | |
3177 | -#undef STR_DL_DEPLIBS | |
3178 | -#define STR_DL_DEPLIBS "dependency_libs=" | |
3179 | - else if (strncmp (line, STR_DL_DEPLIBS, | |
3180 | - sizeof (STR_DL_DEPLIBS) - 1) == 0) | |
3181 | - { | |
3182 | - errors += trim (&deplibs, &line[sizeof (STR_DL_DEPLIBS) - 1]); | |
3183 | - } | |
3184 | - else if (strcmp (line, "installed=yes\n") == 0) | |
3185 | - { | |
3186 | - installed = 1; | |
3187 | - } | |
3188 | - else if (strcmp (line, "installed=no\n") == 0) | |
3189 | - { | |
3190 | - installed = 0; | |
3191 | - } | |
3192 | - | |
3193 | -#undef STR_LIBRARY_NAMES | |
3194 | -#define STR_LIBRARY_NAMES "library_names=" | |
3195 | - else if (! dlname && strncmp (line, STR_LIBRARY_NAMES, | |
3196 | - sizeof (STR_LIBRARY_NAMES) - 1) == 0) | |
3197 | - { | |
3198 | - char *last_libname; | |
3199 | - errors += trim (&dlname, &line[sizeof (STR_LIBRARY_NAMES) - 1]); | |
3200 | - if (!errors | |
3201 | - && dlname | |
3202 | - && (last_libname = strrchr (dlname, ' ')) != 0) | |
3203 | - { | |
3204 | - last_libname = lt_estrdup (last_libname + 1); | |
3205 | - if (!last_libname) | |
3206 | - { | |
3207 | - ++errors; | |
3208 | - goto cleanup; | |
3209 | - } | |
3210 | - LT_DLMEM_REASSIGN (dlname, last_libname); | |
3211 | - } | |
3212 | - } | |
3213 | - | |
3214 | - if (errors) | |
3215 | - break; | |
3216 | - } | |
3217 | - | |
3218 | - fclose (file); | |
3219 | - LT_DLFREE (line); | |
3220 | - | |
3221 | - /* allocate the handle */ | |
3222 | - *phandle = (lt_dlhandle) LT_EMALLOC (struct lt_dlhandle_struct, 1); | |
3223 | - if (*phandle == 0) | |
3224 | - ++errors; | |
3225 | - | |
3226 | - if (errors) | |
3227 | - { | |
3228 | - free_vars (dlname, old_name, libdir, deplibs); | |
3229 | - LT_DLFREE (*phandle); | |
3230 | - goto cleanup; | |
3231 | - } | |
3232 | - | |
3233 | - assert (*phandle); | |
3234 | - | |
3235 | - memset (*phandle, 0, sizeof(struct lt_dlhandle_struct)); | |
3236 | - if (load_deplibs (*phandle, deplibs) == 0) | |
3237 | - { | |
3238 | - newhandle = *phandle; | |
3239 | - /* find_module may replace newhandle */ | |
3240 | - if (find_module (&newhandle, dir, libdir, dlname, old_name, installed)) | |
3241 | - { | |
3242 | - unload_deplibs (*phandle); | |
3243 | - ++errors; | |
3244 | - } | |
3245 | - } | |
3246 | - else | |
3247 | - { | |
3248 | - ++errors; | |
3249 | - } | |
3250 | - | |
3251 | - free_vars (dlname, old_name, libdir, deplibs); | |
3252 | - if (errors) | |
3253 | - { | |
3254 | - LT_DLFREE (*phandle); | |
3255 | - goto cleanup; | |
3256 | - } | |
3257 | - | |
3258 | - if (*phandle != newhandle) | |
3259 | - { | |
3260 | - unload_deplibs (*phandle); | |
3261 | - } | |
3262 | - } | |
3263 | - else | |
3264 | - { | |
3265 | - /* not a libtool module */ | |
3266 | - *phandle = (lt_dlhandle) LT_EMALLOC (struct lt_dlhandle_struct, 1); | |
3267 | - if (*phandle == 0) | |
3268 | - { | |
3269 | - ++errors; | |
3270 | - goto cleanup; | |
3271 | - } | |
3272 | - | |
3273 | - memset (*phandle, 0, sizeof (struct lt_dlhandle_struct)); | |
3274 | - newhandle = *phandle; | |
3275 | - | |
3276 | - /* If the module has no directory name component, try to find it | |
3277 | - first in user_search_path and then other prescribed paths. | |
3278 | - Otherwise (or in any case if the module was not yet found) try | |
3279 | - opening just the module name as passed. */ | |
3280 | - if ((dir || (!find_handle (user_search_path, base_name, &newhandle) | |
3281 | - && !find_handle (getenv (LTDL_SEARCHPATH_VAR), base_name, | |
3282 | - &newhandle) | |
3283 | -#ifdef LTDL_SHLIBPATH_VAR | |
3284 | - && !find_handle (getenv (LTDL_SHLIBPATH_VAR), base_name, | |
3285 | - &newhandle) | |
3286 | -#endif | |
3287 | -#ifdef LTDL_SYSSEARCHPATH | |
3288 | - && !find_handle (sys_search_path, base_name, &newhandle) | |
3289 | -#endif | |
3290 | - ))) | |
3291 | - { | |
3292 | - if (tryall_dlopen (&newhandle, filename) != 0) | |
3293 | - { | |
3294 | - newhandle = NULL; | |
3295 | - } | |
3296 | - } | |
3297 | - | |
3298 | - if (!newhandle) | |
3299 | - { | |
3300 | - LT_DLFREE (*phandle); | |
3301 | - ++errors; | |
3302 | - goto cleanup; | |
3303 | - } | |
3304 | - } | |
3305 | - | |
3306 | - register_handle: | |
3307 | - LT_DLMEM_REASSIGN (*phandle, newhandle); | |
3308 | - | |
3309 | - if ((*phandle)->info.ref_count == 0) | |
3310 | - { | |
3311 | - (*phandle)->info.ref_count = 1; | |
3312 | - LT_DLMEM_REASSIGN ((*phandle)->info.name, name); | |
3313 | - | |
3314 | - LT_DLMUTEX_LOCK (); | |
3315 | - (*phandle)->next = handles; | |
3316 | - handles = *phandle; | |
3317 | - LT_DLMUTEX_UNLOCK (); | |
3318 | - } | |
3319 | - | |
3320 | - LT_DLMUTEX_SETERROR (saved_error); | |
3321 | - | |
3322 | - cleanup: | |
3323 | - LT_DLFREE (dir); | |
3324 | - LT_DLFREE (name); | |
3325 | - LT_DLFREE (canonical); | |
3326 | - | |
3327 | - return errors; | |
3328 | -} | |
3329 | - | |
3330 | -lt_dlhandle | |
3331 | -lt_dlopen ( | |
3332 | - const char *filename) | |
3333 | -{ | |
3334 | - lt_dlhandle handle = 0; | |
3335 | - | |
3336 | - /* Just incase we missed a code path in try_dlopen() that reports | |
3337 | - an error, but forgets to reset handle... */ | |
3338 | - if (try_dlopen (&handle, filename) != 0) | |
3339 | - return 0; | |
3340 | - | |
3341 | - return handle; | |
3342 | -} | |
3343 | - | |
3344 | -/* If the last error messge store was `FILE_NOT_FOUND', then return | |
3345 | - non-zero. */ | |
3346 | -static int | |
3347 | -file_not_found () | |
3348 | -{ | |
3349 | - const char *error = 0; | |
3350 | - | |
3351 | - LT_DLMUTEX_GETERROR (error); | |
3352 | - if (error == LT_DLSTRERROR (FILE_NOT_FOUND)) | |
3353 | - return 1; | |
3354 | - | |
3355 | - return 0; | |
3356 | -} | |
3357 | - | |
3358 | -/* If FILENAME has an ARCHIVE_EXT or SHLIB_EXT extension, try to | |
3359 | - open the FILENAME as passed. Otherwise try appending ARCHIVE_EXT, | |
3360 | - and if a file is still not found try again with SHLIB_EXT appended | |
3361 | - instead. */ | |
3362 | -lt_dlhandle | |
3363 | -lt_dlopenext ( | |
3364 | - const char *filename) | |
3365 | -{ | |
3366 | - lt_dlhandle handle = 0; | |
3367 | - char * tmp = 0; | |
3368 | - char * ext = 0; | |
3369 | - size_t len; | |
3370 | - int errors = 0; | |
3371 | - | |
3372 | - if (!filename) | |
3373 | - { | |
3374 | - return lt_dlopen (filename); | |
3375 | - } | |
3376 | - | |
3377 | - assert (filename); | |
3378 | - | |
3379 | - len = LT_STRLEN (filename); | |
3380 | - ext = strrchr (filename, '.'); | |
3381 | - | |
3382 | - /* If FILENAME already bears a suitable extension, there is no need | |
3383 | - to try appending additional extensions. */ | |
3384 | - if (ext && ((strcmp (ext, archive_ext) == 0) | |
3385 | -#ifdef LTDL_SHLIB_EXT | |
3386 | - || (strcmp (ext, shlib_ext) == 0) | |
3387 | -#endif | |
3388 | - )) | |
3389 | - { | |
3390 | - return lt_dlopen (filename); | |
3391 | - } | |
3392 | - | |
3393 | - /* First try appending ARCHIVE_EXT. */ | |
3394 | - tmp = LT_EMALLOC (char, len + LT_STRLEN (archive_ext) + 1); | |
3395 | - if (!tmp) | |
3396 | - return 0; | |
3397 | - | |
3398 | - strcpy (tmp, filename); | |
3399 | - strcat (tmp, archive_ext); | |
3400 | - errors = try_dlopen (&handle, tmp); | |
3401 | - | |
3402 | - /* If we found FILENAME, stop searching -- whether we were able to | |
3403 | - load the file as a module or not. If the file exists but loading | |
3404 | - failed, it is better to return an error message here than to | |
3405 | - report FILE_NOT_FOUND when the alternatives (foo.so etc) are not | |
3406 | - in the module search path. */ | |
3407 | - if (handle || ((errors > 0) && !file_not_found ())) | |
3408 | - { | |
3409 | - LT_DLFREE (tmp); | |
3410 | - return handle; | |
3411 | - } | |
3412 | - | |
3413 | -#ifdef LTDL_SHLIB_EXT | |
3414 | - /* Try appending SHLIB_EXT. */ | |
3415 | - if (LT_STRLEN (shlib_ext) > LT_STRLEN (archive_ext)) | |
3416 | - { | |
3417 | - LT_DLFREE (tmp); | |
3418 | - tmp = LT_EMALLOC (char, len + LT_STRLEN (shlib_ext) + 1); | |
3419 | - if (!tmp) | |
3420 | - return 0; | |
3421 | - | |
3422 | - strcpy (tmp, filename); | |
3423 | - } | |
3424 | - else | |
3425 | - { | |
3426 | - tmp[len] = LT_EOS_CHAR; | |
3427 | - } | |
3428 | - | |
3429 | - strcat(tmp, shlib_ext); | |
3430 | - errors = try_dlopen (&handle, tmp); | |
3431 | - | |
3432 | - /* As before, if the file was found but loading failed, return now | |
3433 | - with the current error message. */ | |
3434 | - if (handle || ((errors > 0) && !file_not_found ())) | |
3435 | - { | |
3436 | - LT_DLFREE (tmp); | |
3437 | - return handle; | |
3438 | - } | |
3439 | -#endif | |
3440 | - | |
3441 | - /* Still here? Then we really did fail to locate any of the file | |
3442 | - names we tried. */ | |
3443 | - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (FILE_NOT_FOUND)); | |
3444 | - LT_DLFREE (tmp); | |
3445 | - return 0; | |
3446 | -} | |
3447 | - | |
3448 | - | |
3449 | -static int | |
3450 | -lt_argz_insert ( | |
3451 | - char **pargz, | |
3452 | - size_t *pargz_len, | |
3453 | - char *before, | |
3454 | - const char *entry) | |
3455 | -{ | |
3456 | - error_t error; | |
3457 | - | |
3458 | - if ((error = argz_insert (pargz, pargz_len, before, entry))) | |
3459 | - { | |
3460 | - switch (error) | |
3461 | - { | |
3462 | - case ENOMEM: | |
3463 | - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY)); | |
3464 | - break; | |
3465 | - default: | |
3466 | - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (UNKNOWN)); | |
3467 | - break; | |
3468 | - } | |
3469 | - return 1; | |
3470 | - } | |
3471 | - | |
3472 | - return 0; | |
3473 | -} | |
3474 | - | |
3475 | -static int | |
3476 | -lt_argz_insertinorder ( | |
3477 | - char **pargz, | |
3478 | - size_t *pargz_len, | |
3479 | - const char *entry) | |
3480 | -{ | |
3481 | - char *before = 0; | |
3482 | - | |
3483 | - assert (pargz); | |
3484 | - assert (pargz_len); | |
3485 | - assert (entry && *entry); | |
3486 | - | |
3487 | - if (*pargz) | |
3488 | - while ((before = argz_next (*pargz, *pargz_len, before))) | |
3489 | - { | |
3490 | - int cmp = strcmp (entry, before); | |
3491 | - | |
3492 | - if (cmp < 0) break; | |
3493 | - if (cmp == 0) return 0; /* No duplicates! */ | |
3494 | - } | |
3495 | - | |
3496 | - return lt_argz_insert (pargz, pargz_len, before, entry); | |
3497 | -} | |
3498 | - | |
3499 | -static int | |
3500 | -lt_argz_insertdir ( | |
3501 | - char **pargz, | |
3502 | - size_t *pargz_len, | |
3503 | - const char *dirnam, | |
3504 | - struct dirent *dp) | |
3505 | -{ | |
3506 | - char *buf = 0; | |
3507 | - size_t buf_len = 0; | |
3508 | - char *end = 0; | |
3509 | - size_t end_offset = 0; | |
3510 | - size_t dir_len = 0; | |
3511 | - int errors = 0; | |
3512 | - | |
3513 | - assert (pargz); | |
3514 | - assert (pargz_len); | |
3515 | - assert (dp); | |
3516 | - | |
3517 | - dir_len = LT_STRLEN (dirnam); | |
3518 | - end = dp->d_name + LT_D_NAMLEN(dp); | |
3519 | - | |
3520 | - /* Ignore version numbers. */ | |
3521 | - { | |
3522 | - char *p; | |
3523 | - for (p = end; p -1 > dp->d_name; --p) | |
3524 | - if (strchr (".0123456789", p[-1]) == 0) | |
3525 | - break; | |
3526 | - | |
3527 | - if (*p == '.') | |
3528 | - end = p; | |
3529 | - } | |
3530 | - | |
3531 | - /* Ignore filename extension. */ | |
3532 | - { | |
3533 | - char *p; | |
3534 | - for (p = end -1; p > dp->d_name; --p) | |
3535 | - if (*p == '.') | |
3536 | - { | |
3537 | - end = p; | |
3538 | - break; | |
3539 | - } | |
3540 | - } | |
3541 | - | |
3542 | - /* Prepend the directory name. */ | |
3543 | - end_offset = end - dp->d_name; | |
3544 | - buf_len = dir_len + 1+ end_offset; | |
3545 | - buf = LT_EMALLOC (char, 1+ buf_len); | |
3546 | - if (!buf) | |
3547 | - return ++errors; | |
3548 | - | |
3549 | - assert (buf); | |
3550 | - | |
3551 | - strcpy (buf, dirnam); | |
3552 | - strcat (buf, "/"); | |
3553 | - strncat (buf, dp->d_name, end_offset); | |
3554 | - buf[buf_len] = LT_EOS_CHAR; | |
3555 | - | |
3556 | - /* Try to insert (in order) into ARGZ/ARGZ_LEN. */ | |
3557 | - if (lt_argz_insertinorder (pargz, pargz_len, buf) != 0) | |
3558 | - ++errors; | |
3559 | - | |
3560 | - LT_DLFREE (buf); | |
3561 | - | |
3562 | - return errors; | |
3563 | -} | |
3564 | - | |
3565 | -static int | |
3566 | -list_files_by_dir ( | |
3567 | - const char *dirnam, | |
3568 | - char **pargz, | |
3569 | - size_t *pargz_len) | |
3570 | -{ | |
3571 | - DIR *dirp = 0; | |
3572 | - int errors = 0; | |
3573 | - | |
3574 | - assert (dirnam && *dirnam); | |
3575 | - assert (pargz); | |
3576 | - assert (pargz_len); | |
3577 | - assert (dirnam[LT_STRLEN(dirnam) -1] != '/'); | |
3578 | - | |
3579 | - dirp = opendir (dirnam); | |
3580 | - if (dirp) | |
3581 | - { | |
3582 | - struct dirent *dp = 0; | |
3583 | - | |
3584 | - while ((dp = readdir (dirp))) | |
3585 | - if (dp->d_name[0] != '.') | |
3586 | - if (lt_argz_insertdir (pargz, pargz_len, dirnam, dp)) | |
3587 | - { | |
3588 | - ++errors; | |
3589 | - break; | |
3590 | - } | |
3591 | - | |
3592 | - closedir (dirp); | |
3593 | - } | |
3594 | - else | |
3595 | - ++errors; | |
3596 | - | |
3597 | - return errors; | |
3598 | -} | |
3599 | - | |
3600 | - | |
3601 | -/* If there are any files in DIRNAME, call the function passed in | |
3602 | - DATA1 (with the name of each file and DATA2 as arguments). */ | |
3603 | -static int | |
3604 | -foreachfile_callback ( | |
3605 | - char *dirname, | |
3606 | - lt_ptr data1, | |
3607 | - lt_ptr data2) | |
3608 | -{ | |
3609 | - int (*func) LT_PARAMS((const char *filename, lt_ptr data)) | |
3610 | - = (int (*) LT_PARAMS((const char *filename, lt_ptr data))) data1; | |
3611 | - | |
3612 | - int is_done = 0; | |
3613 | - char *argz = 0; | |
3614 | - size_t argz_len = 0; | |
3615 | - | |
3616 | - if (list_files_by_dir (dirname, &argz, &argz_len) != 0) | |
3617 | - goto cleanup; | |
3618 | - if (!argz) | |
3619 | - goto cleanup; | |
3620 | - | |
3621 | - { | |
3622 | - char *filename = 0; | |
3623 | - while ((filename = argz_next (argz, argz_len, filename))) | |
3624 | - if ((is_done = (*func) (filename, data2))) | |
3625 | - break; | |
3626 | - } | |
3627 | - | |
3628 | - cleanup: | |
3629 | - LT_DLFREE (argz); | |
3630 | - | |
3631 | - return is_done; | |
3632 | -} | |
3633 | - | |
3634 | - | |
3635 | -/* Call FUNC for each unique extensionless file in SEARCH_PATH, along | |
3636 | - with DATA. The filenames passed to FUNC would be suitable for | |
3637 | - passing to lt_dlopenext. The extensions are stripped so that | |
3638 | - individual modules do not generate several entries (e.g. libfoo.la, | |
3639 | - libfoo.so, libfoo.so.1, libfoo.so.1.0.0). If SEARCH_PATH is NULL, | |
3640 | - then the same directories that lt_dlopen would search are examined. */ | |
3641 | -int | |
3642 | -lt_dlforeachfile ( | |
3643 | - const char *search_path, | |
3644 | - int (*func) LT_PARAMS ((const char *filename, lt_ptr data)), | |
3645 | - lt_ptr data) | |
3646 | -{ | |
3647 | - int is_done = 0; | |
3648 | - | |
3649 | - if (search_path) | |
3650 | - { | |
3651 | - /* If a specific path was passed, search only the directories | |
3652 | - listed in it. */ | |
3653 | - is_done = foreach_dirinpath (search_path, 0, | |
3654 | - foreachfile_callback, (void*)func, data); | |
3655 | - } | |
3656 | - else | |
3657 | - { | |
3658 | - /* Otherwise search the default paths. */ | |
3659 | - is_done = foreach_dirinpath (user_search_path, 0, | |
3660 | - foreachfile_callback, (void*)func, data); | |
3661 | - if (!is_done) | |
3662 | - { | |
3663 | - is_done = foreach_dirinpath (getenv("LTDL_LIBRARY_PATH"), 0, | |
3664 | - foreachfile_callback, (void*)func, data); | |
3665 | - } | |
3666 | - | |
3667 | -#ifdef LTDL_SHLIBPATH_VAR | |
3668 | - if (!is_done) | |
3669 | - { | |
3670 | - is_done = foreach_dirinpath (getenv(LTDL_SHLIBPATH_VAR), 0, | |
3671 | - foreachfile_callback, (void*)func, data); | |
3672 | - } | |
3673 | -#endif | |
3674 | -#ifdef LTDL_SYSSEARCHPATH | |
3675 | - if (!is_done) | |
3676 | - { | |
3677 | - is_done = foreach_dirinpath (getenv(LTDL_SYSSEARCHPATH), 0, | |
3678 | - foreachfile_callback, (void*)func, data); | |
3679 | - } | |
3680 | -#endif | |
3681 | - } | |
3682 | - | |
3683 | - return is_done; | |
3684 | -} | |
3685 | - | |
3686 | -int | |
3687 | -lt_dlclose ( | |
3688 | - lt_dlhandle handle) | |
3689 | -{ | |
3690 | - lt_dlhandle cur, last; | |
3691 | - int errors = 0; | |
3692 | - | |
3693 | - LT_DLMUTEX_LOCK (); | |
3694 | - | |
3695 | - /* check whether the handle is valid */ | |
3696 | - last = cur = handles; | |
3697 | - while (cur && handle != cur) | |
3698 | - { | |
3699 | - last = cur; | |
3700 | - cur = cur->next; | |
3701 | - } | |
3702 | - | |
3703 | - if (!cur) | |
3704 | - { | |
3705 | - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INVALID_HANDLE)); | |
3706 | - ++errors; | |
3707 | - goto done; | |
3708 | - } | |
3709 | - | |
3710 | - handle->info.ref_count--; | |
3711 | - | |
3712 | - /* Note that even with resident modules, we must track the ref_count | |
3713 | - correctly incase the user decides to reset the residency flag | |
3714 | - later (even though the API makes no provision for that at the | |
3715 | - moment). */ | |
3716 | - if (handle->info.ref_count <= 0 && !LT_DLIS_RESIDENT (handle)) | |
3717 | - { | |
3718 | - lt_user_data data = handle->loader->dlloader_data; | |
3719 | - | |
3720 | - if (handle != handles) | |
3721 | - { | |
3722 | - last->next = handle->next; | |
3723 | - } | |
3724 | - else | |
3725 | - { | |
3726 | - handles = handle->next; | |
3727 | - } | |
3728 | - | |
3729 | - errors += handle->loader->module_close (data, handle->module); | |
3730 | - errors += unload_deplibs(handle); | |
3731 | - | |
3732 | - /* It is up to the callers to free the data itself. */ | |
3733 | - LT_DLFREE (handle->caller_data); | |
3734 | - | |
3735 | - LT_DLFREE (handle->info.filename); | |
3736 | - LT_DLFREE (handle->info.name); | |
3737 | - LT_DLFREE (handle); | |
3738 | - | |
3739 | - goto done; | |
3740 | - } | |
3741 | - | |
3742 | - if (LT_DLIS_RESIDENT (handle)) | |
3743 | - { | |
3744 | - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (CLOSE_RESIDENT_MODULE)); | |
3745 | - ++errors; | |
3746 | - } | |
3747 | - | |
3748 | - done: | |
3749 | - LT_DLMUTEX_UNLOCK (); | |
3750 | - | |
3751 | - return errors; | |
3752 | -} | |
3753 | - | |
3754 | -lt_ptr | |
3755 | -lt_dlsym ( | |
3756 | - lt_dlhandle handle, | |
3757 | - const char *symbol) | |
3758 | -{ | |
3759 | - size_t lensym; | |
3760 | - char lsym[LT_SYMBOL_LENGTH]; | |
3761 | - char *sym; | |
3762 | - lt_ptr address; | |
3763 | - lt_user_data data; | |
3764 | - | |
3765 | - if (!handle) | |
3766 | - { | |
3767 | - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INVALID_HANDLE)); | |
3768 | - return 0; | |
3769 | - } | |
3770 | - | |
3771 | - if (!symbol) | |
3772 | - { | |
3773 | - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (SYMBOL_NOT_FOUND)); | |
3774 | - return 0; | |
3775 | - } | |
3776 | - | |
3777 | - lensym = LT_STRLEN (symbol) + LT_STRLEN (handle->loader->sym_prefix) | |
3778 | - + LT_STRLEN (handle->info.name); | |
3779 | - | |
3780 | - if (lensym + LT_SYMBOL_OVERHEAD < LT_SYMBOL_LENGTH) | |
3781 | - { | |
3782 | - sym = lsym; | |
3783 | - } | |
3784 | - else | |
3785 | - { | |
3786 | - sym = LT_EMALLOC (char, lensym + LT_SYMBOL_OVERHEAD + 1); | |
3787 | - if (!sym) | |
3788 | - { | |
3789 | - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (BUFFER_OVERFLOW)); | |
3790 | - return 0; | |
3791 | - } | |
3792 | - } | |
3793 | - | |
3794 | - data = handle->loader->dlloader_data; | |
3795 | - if (handle->info.name) | |
3796 | - { | |
3797 | - const char *saved_error; | |
3798 | - | |
3799 | - LT_DLMUTEX_GETERROR (saved_error); | |
3800 | - | |
3801 | - /* this is a libtool module */ | |
3802 | - if (handle->loader->sym_prefix) | |
3803 | - { | |
3804 | - strcpy(sym, handle->loader->sym_prefix); | |
3805 | - strcat(sym, handle->info.name); | |
3806 | - } | |
3807 | - else | |
3808 | - { | |
3809 | - strcpy(sym, handle->info.name); | |
3810 | - } | |
3811 | - | |
3812 | - strcat(sym, "_LTX_"); | |
3813 | - strcat(sym, symbol); | |
3814 | - | |
3815 | - /* try "modulename_LTX_symbol" */ | |
3816 | - address = handle->loader->find_sym (data, handle->module, sym); | |
3817 | - if (address) | |
3818 | - { | |
3819 | - if (sym != lsym) | |
3820 | - { | |
3821 | - LT_DLFREE (sym); | |
3822 | - } | |
3823 | - return address; | |
3824 | - } | |
3825 | - LT_DLMUTEX_SETERROR (saved_error); | |
3826 | - } | |
3827 | - | |
3828 | - /* otherwise try "symbol" */ | |
3829 | - if (handle->loader->sym_prefix) | |
3830 | - { | |
3831 | - strcpy(sym, handle->loader->sym_prefix); | |
3832 | - strcat(sym, symbol); | |
3833 | - } | |
3834 | - else | |
3835 | - { | |
3836 | - strcpy(sym, symbol); | |
3837 | - } | |
3838 | - | |
3839 | - address = handle->loader->find_sym (data, handle->module, sym); | |
3840 | - if (sym != lsym) | |
3841 | - { | |
3842 | - LT_DLFREE (sym); | |
3843 | - } | |
3844 | - | |
3845 | - return address; | |
3846 | -} | |
3847 | - | |
3848 | -const char * | |
3849 | -lt_dlerror () | |
3850 | -{ | |
3851 | - const char *error; | |
3852 | - | |
3853 | - LT_DLMUTEX_GETERROR (error); | |
3854 | - LT_DLMUTEX_SETERROR (0); | |
3855 | - | |
3856 | - return error ? error : NULL; | |
3857 | -} | |
3858 | - | |
3859 | -static int | |
3860 | -lt_dlpath_insertdir ( | |
3861 | - char **ppath, | |
3862 | - char *before, | |
3863 | - const char *dir) | |
3864 | -{ | |
3865 | - int errors = 0; | |
3866 | - char *canonical = 0; | |
3867 | - char *argz = 0; | |
3868 | - size_t argz_len = 0; | |
3869 | - | |
3870 | - assert (ppath); | |
3871 | - assert (dir && *dir); | |
3872 | - | |
3873 | - if (canonicalize_path (dir, &canonical) != 0) | |
3874 | - { | |
3875 | - ++errors; | |
3876 | - goto cleanup; | |
3877 | - } | |
3878 | - | |
3879 | - assert (canonical && *canonical); | |
3880 | - | |
3881 | - /* If *PPATH is empty, set it to DIR. */ | |
3882 | - if (*ppath == 0) | |
3883 | - { | |
3884 | - assert (!before); /* BEFORE cannot be set without PPATH. */ | |
3885 | - assert (dir); /* Without DIR, don't call this function! */ | |
3886 | - | |
3887 | - *ppath = lt_estrdup (dir); | |
3888 | - if (*ppath == 0) | |
3889 | - ++errors; | |
3890 | - | |
3891 | - return errors; | |
3892 | - } | |
3893 | - | |
3894 | - assert (ppath && *ppath); | |
3895 | - | |
3896 | - if (argzize_path (*ppath, &argz, &argz_len) != 0) | |
3897 | - { | |
3898 | - ++errors; | |
3899 | - goto cleanup; | |
3900 | - } | |
3901 | - | |
3902 | - /* Convert BEFORE into an equivalent offset into ARGZ. This only works | |
3903 | - if *PPATH is already canonicalized, and hence does not change length | |
3904 | - with respect to ARGZ. We canonicalize each entry as it is added to | |
3905 | - the search path, and don't call this function with (uncanonicalized) | |
3906 | - user paths, so this is a fair assumption. */ | |
3907 | - if (before) | |
3908 | - { | |
3909 | - assert (*ppath <= before); | |
3910 | - assert (before - *ppath <= strlen (*ppath)); | |
3911 | - | |
3912 | - before = before - *ppath + argz; | |
3913 | - } | |
3914 | - | |
3915 | - if (lt_argz_insert (&argz, &argz_len, before, dir) != 0) | |
3916 | - { | |
3917 | - ++errors; | |
3918 | - goto cleanup; | |
3919 | - } | |
3920 | - | |
3921 | - argz_stringify (argz, argz_len, LT_PATHSEP_CHAR); | |
3922 | - LT_DLMEM_REASSIGN (*ppath, argz); | |
3923 | - | |
3924 | - cleanup: | |
3925 | - LT_DLFREE (canonical); | |
3926 | - LT_DLFREE (argz); | |
3927 | - | |
3928 | - return errors; | |
3929 | -} | |
3930 | - | |
3931 | -int | |
3932 | -lt_dladdsearchdir ( | |
3933 | - const char *search_dir) | |
3934 | -{ | |
3935 | - int errors = 0; | |
3936 | - | |
3937 | - if (search_dir && *search_dir) | |
3938 | - { | |
3939 | - LT_DLMUTEX_LOCK (); | |
3940 | - if (lt_dlpath_insertdir (&user_search_path, 0, search_dir) != 0) | |
3941 | - ++errors; | |
3942 | - LT_DLMUTEX_UNLOCK (); | |
3943 | - } | |
3944 | - | |
3945 | - return errors; | |
3946 | -} | |
3947 | - | |
3948 | -int | |
3949 | -lt_dlinsertsearchdir ( | |
3950 | - const char *before, | |
3951 | - const char *search_dir) | |
3952 | -{ | |
3953 | - int errors = 0; | |
3954 | - | |
3955 | - if (before) | |
3956 | - { | |
3957 | - LT_DLMUTEX_LOCK (); | |
3958 | - if ((before < user_search_path) | |
3959 | - || (before >= user_search_path + LT_STRLEN (user_search_path))) | |
3960 | - { | |
3961 | - LT_DLMUTEX_UNLOCK (); | |
3962 | - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INVALID_POSITION)); | |
3963 | - return 1; | |
3964 | - } | |
3965 | - LT_DLMUTEX_UNLOCK (); | |
3966 | - } | |
3967 | - | |
3968 | - if (search_dir && *search_dir) | |
3969 | - { | |
3970 | - LT_DLMUTEX_LOCK (); | |
3971 | - if (lt_dlpath_insertdir (&user_search_path, | |
3972 | - (char *) before, search_dir) != 0) | |
3973 | - { | |
3974 | - ++errors; | |
3975 | - } | |
3976 | - LT_DLMUTEX_UNLOCK (); | |
3977 | - } | |
3978 | - | |
3979 | - return errors; | |
3980 | -} | |
3981 | - | |
3982 | -int | |
3983 | -lt_dlsetsearchpath ( | |
3984 | - const char *search_path) | |
3985 | -{ | |
3986 | - int errors = 0; | |
3987 | - | |
3988 | - LT_DLMUTEX_LOCK (); | |
3989 | - LT_DLFREE (user_search_path); | |
3990 | - LT_DLMUTEX_UNLOCK (); | |
3991 | - | |
3992 | - if (!search_path || !LT_STRLEN (search_path)) | |
3993 | - { | |
3994 | - return errors; | |
3995 | - } | |
3996 | - | |
3997 | - LT_DLMUTEX_LOCK (); | |
3998 | - if (canonicalize_path (search_path, &user_search_path) != 0) | |
3999 | - ++errors; | |
4000 | - LT_DLMUTEX_UNLOCK (); | |
4001 | - | |
4002 | - return errors; | |
4003 | -} | |
4004 | - | |
4005 | -const char * | |
4006 | -lt_dlgetsearchpath () | |
4007 | -{ | |
4008 | - const char *saved_path; | |
4009 | - | |
4010 | - LT_DLMUTEX_LOCK (); | |
4011 | - saved_path = user_search_path; | |
4012 | - LT_DLMUTEX_UNLOCK (); | |
4013 | - | |
4014 | - return saved_path; | |
4015 | -} | |
4016 | - | |
4017 | -int | |
4018 | -lt_dlmakeresident ( | |
4019 | - lt_dlhandle handle) | |
4020 | -{ | |
4021 | - int errors = 0; | |
4022 | - | |
4023 | - if (!handle) | |
4024 | - { | |
4025 | - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INVALID_HANDLE)); | |
4026 | - ++errors; | |
4027 | - } | |
4028 | - else | |
4029 | - { | |
4030 | - LT_DLSET_FLAG (handle, LT_DLRESIDENT_FLAG); | |
4031 | - } | |
4032 | - | |
4033 | - return errors; | |
4034 | -} | |
4035 | - | |
4036 | -int | |
4037 | -lt_dlisresident ( | |
4038 | - lt_dlhandle handle) | |
4039 | -{ | |
4040 | - if (!handle) | |
4041 | - { | |
4042 | - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INVALID_HANDLE)); | |
4043 | - return -1; | |
4044 | - } | |
4045 | - | |
4046 | - return LT_DLIS_RESIDENT (handle); | |
4047 | -} | |
4048 | - | |
4049 | - | |
4050 | - | |
4051 | -\f | |
4052 | -/* --- MODULE INFORMATION --- */ | |
4053 | - | |
4054 | -const lt_dlinfo * | |
4055 | -lt_dlgetinfo ( | |
4056 | - lt_dlhandle handle) | |
4057 | -{ | |
4058 | - if (!handle) | |
4059 | - { | |
4060 | - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INVALID_HANDLE)); | |
4061 | - return 0; | |
4062 | - } | |
4063 | - | |
4064 | - return &(handle->info); | |
4065 | -} | |
4066 | - | |
4067 | -lt_dlhandle | |
4068 | -lt_dlhandle_next ( | |
4069 | - lt_dlhandle place) | |
4070 | -{ | |
4071 | - return place ? place->next : handles; | |
4072 | -} | |
4073 | - | |
4074 | -int | |
4075 | -lt_dlforeach ( | |
4076 | - int (*func) LT_PARAMS((lt_dlhandle handle, lt_ptr data)), | |
4077 | - lt_ptr data) | |
4078 | -{ | |
4079 | - int errors = 0; | |
4080 | - lt_dlhandle cur; | |
4081 | - | |
4082 | - LT_DLMUTEX_LOCK (); | |
4083 | - | |
4084 | - cur = handles; | |
4085 | - while (cur) | |
4086 | - { | |
4087 | - lt_dlhandle tmp = cur; | |
4088 | - | |
4089 | - cur = cur->next; | |
4090 | - if ((*func) (tmp, data)) | |
4091 | - { | |
4092 | - ++errors; | |
4093 | - break; | |
4094 | - } | |
4095 | - } | |
4096 | - | |
4097 | - LT_DLMUTEX_UNLOCK (); | |
4098 | - | |
4099 | - return errors; | |
4100 | -} | |
4101 | - | |
4102 | -lt_dlcaller_id | |
4103 | -lt_dlcaller_register () | |
4104 | -{ | |
4105 | - static lt_dlcaller_id last_caller_id = 0; | |
4106 | - int result; | |
4107 | - | |
4108 | - LT_DLMUTEX_LOCK (); | |
4109 | - result = ++last_caller_id; | |
4110 | - LT_DLMUTEX_UNLOCK (); | |
4111 | - | |
4112 | - return result; | |
4113 | -} | |
4114 | - | |
4115 | -lt_ptr | |
4116 | -lt_dlcaller_set_data ( | |
4117 | - lt_dlcaller_id key, | |
4118 | - lt_dlhandle handle, | |
4119 | - lt_ptr data) | |
4120 | -{ | |
4121 | - int n_elements = 0; | |
4122 | - lt_ptr stale = (lt_ptr) 0; | |
4123 | - int i; | |
4124 | - | |
4125 | - /* This needs to be locked so that the caller data can be updated | |
4126 | - simultaneously by different threads. */ | |
4127 | - LT_DLMUTEX_LOCK (); | |
4128 | - | |
4129 | - if (handle->caller_data) | |
4130 | - while (handle->caller_data[n_elements].key) | |
4131 | - ++n_elements; | |
4132 | - | |
4133 | - for (i = 0; i < n_elements; ++i) | |
4134 | - { | |
4135 | - if (handle->caller_data[i].key == key) | |
4136 | - { | |
4137 | - stale = handle->caller_data[i].data; | |
4138 | - break; | |
4139 | - } | |
4140 | - } | |
4141 | - | |
4142 | - /* Ensure that there is enough room in this handle's caller_data | |
4143 | - array to accept a new element (and an empty end marker). */ | |
4144 | - if (i == n_elements) | |
4145 | - { | |
4146 | - lt_caller_data *temp | |
4147 | - = LT_DLREALLOC (lt_caller_data, handle->caller_data, 2+ n_elements); | |
4148 | - | |
4149 | - if (!temp) | |
4150 | - { | |
4151 | - stale = 0; | |
4152 | - goto done; | |
4153 | - } | |
4154 | - | |
4155 | - handle->caller_data = temp; | |
4156 | - | |
4157 | - /* We only need this if we needed to allocate a new caller_data. */ | |
4158 | - handle->caller_data[i].key = key; | |
4159 | - handle->caller_data[1+ i].key = 0; | |
4160 | - } | |
4161 | - | |
4162 | - handle->caller_data[i].data = data; | |
4163 | - | |
4164 | - done: | |
4165 | - LT_DLMUTEX_UNLOCK (); | |
4166 | - | |
4167 | - return stale; | |
4168 | -} | |
4169 | - | |
4170 | -lt_ptr | |
4171 | -lt_dlcaller_get_data ( | |
4172 | - lt_dlcaller_id key, | |
4173 | - lt_dlhandle handle) | |
4174 | -{ | |
4175 | - lt_ptr result = (lt_ptr) 0; | |
4176 | - | |
4177 | - /* This needs to be locked so that the caller data isn't updated by | |
4178 | - another thread part way through this function. */ | |
4179 | - LT_DLMUTEX_LOCK (); | |
4180 | - | |
4181 | - /* Locate the index of the element with a matching KEY. */ | |
4182 | - { | |
4183 | - int i; | |
4184 | - for (i = 0; handle->caller_data[i].key; ++i) | |
4185 | - { | |
4186 | - if (handle->caller_data[i].key == key) | |
4187 | - { | |
4188 | - result = handle->caller_data[i].data; | |
4189 | - break; | |
4190 | - } | |
4191 | - } | |
4192 | - } | |
4193 | - | |
4194 | - LT_DLMUTEX_UNLOCK (); | |
4195 | - | |
4196 | - return result; | |
4197 | -} | |
4198 | - | |
4199 | - | |
4200 | -\f | |
4201 | -/* --- USER MODULE LOADER API --- */ | |
4202 | - | |
4203 | - | |
4204 | -int | |
4205 | -lt_dlloader_add ( | |
4206 | - lt_dlloader *place, | |
4207 | - const struct lt_user_dlloader *dlloader, | |
4208 | - const char *loader_name) | |
4209 | -{ | |
4210 | - int errors = 0; | |
4211 | - lt_dlloader *node = 0, *ptr = 0; | |
4212 | - | |
4213 | - if ((dlloader == 0) /* diagnose null parameters */ | |
4214 | - || (dlloader->module_open == 0) | |
4215 | - || (dlloader->module_close == 0) | |
4216 | - || (dlloader->find_sym == 0)) | |
4217 | - { | |
4218 | - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INVALID_LOADER)); | |
4219 | - return 1; | |
4220 | - } | |
4221 | - | |
4222 | - /* Create a new dlloader node with copies of the user callbacks. */ | |
4223 | - node = LT_EMALLOC (lt_dlloader, 1); | |
4224 | - if (!node) | |
4225 | - return 1; | |
4226 | - | |
4227 | - node->next = 0; | |
4228 | - node->loader_name = loader_name; | |
4229 | - node->sym_prefix = dlloader->sym_prefix; | |
4230 | - node->dlloader_exit = dlloader->dlloader_exit; | |
4231 | - node->module_open = dlloader->module_open; | |
4232 | - node->module_close = dlloader->module_close; | |
4233 | - node->find_sym = dlloader->find_sym; | |
4234 | - node->dlloader_data = dlloader->dlloader_data; | |
4235 | - | |
4236 | - LT_DLMUTEX_LOCK (); | |
4237 | - if (!loaders) | |
4238 | - { | |
4239 | - /* If there are no loaders, NODE becomes the list! */ | |
4240 | - loaders = node; | |
4241 | - } | |
4242 | - else if (!place) | |
4243 | - { | |
4244 | - /* If PLACE is not set, add NODE to the end of the | |
4245 | - LOADERS list. */ | |
4246 | - for (ptr = loaders; ptr->next; ptr = ptr->next) | |
4247 | - { | |
4248 | - /*NOWORK*/; | |
4249 | - } | |
4250 | - | |
4251 | - ptr->next = node; | |
4252 | - } | |
4253 | - else if (loaders == place) | |
4254 | - { | |
4255 | - /* If PLACE is the first loader, NODE goes first. */ | |
4256 | - node->next = place; | |
4257 | - loaders = node; | |
4258 | - } | |
4259 | - else | |
4260 | - { | |
4261 | - /* Find the node immediately preceding PLACE. */ | |
4262 | - for (ptr = loaders; ptr->next != place; ptr = ptr->next) | |
4263 | - { | |
4264 | - /*NOWORK*/; | |
4265 | - } | |
4266 | - | |
4267 | - if (ptr->next != place) | |
4268 | - { | |
4269 | - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INVALID_LOADER)); | |
4270 | - ++errors; | |
4271 | - } | |
4272 | - else | |
4273 | - { | |
4274 | - /* Insert NODE between PTR and PLACE. */ | |
4275 | - node->next = place; | |
4276 | - ptr->next = node; | |
4277 | - } | |
4278 | - } | |
4279 | - | |
4280 | - LT_DLMUTEX_UNLOCK (); | |
4281 | - | |
4282 | - return errors; | |
4283 | -} | |
4284 | - | |
4285 | -int | |
4286 | -lt_dlloader_remove ( | |
4287 | - const char *loader_name) | |
4288 | -{ | |
4289 | - lt_dlloader *place = lt_dlloader_find (loader_name); | |
4290 | - lt_dlhandle handle; | |
4291 | - int errors = 0; | |
4292 | - | |
4293 | - if (!place) | |
4294 | - { | |
4295 | - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INVALID_LOADER)); | |
4296 | - return 1; | |
4297 | - } | |
4298 | - | |
4299 | - LT_DLMUTEX_LOCK (); | |
4300 | - | |
4301 | - /* Fail if there are any open modules which use this loader. */ | |
4302 | - for (handle = handles; handle; handle = handle->next) | |
4303 | - { | |
4304 | - if (handle->loader == place) | |
4305 | - { | |
4306 | - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (REMOVE_LOADER)); | |
4307 | - ++errors; | |
4308 | - goto done; | |
4309 | - } | |
4310 | - } | |
4311 | - | |
4312 | - if (place == loaders) | |
4313 | - { | |
4314 | - /* PLACE is the first loader in the list. */ | |
4315 | - loaders = loaders->next; | |
4316 | - } | |
4317 | - else | |
4318 | - { | |
4319 | - /* Find the loader before the one being removed. */ | |
4320 | - lt_dlloader *prev; | |
4321 | - for (prev = loaders; prev->next; prev = prev->next) | |
4322 | - { | |
4323 | - if (!strcmp (prev->next->loader_name, loader_name)) | |
4324 | - { | |
4325 | - break; | |
4326 | - } | |
4327 | - } | |
4328 | - | |
4329 | - place = prev->next; | |
4330 | - prev->next = prev->next->next; | |
4331 | - } | |
4332 | - | |
4333 | - if (place->dlloader_exit) | |
4334 | - { | |
4335 | - errors = place->dlloader_exit (place->dlloader_data); | |
4336 | - } | |
4337 | - | |
4338 | - LT_DLFREE (place); | |
4339 | - | |
4340 | - done: | |
4341 | - LT_DLMUTEX_UNLOCK (); | |
4342 | - | |
4343 | - return errors; | |
4344 | -} | |
4345 | - | |
4346 | -lt_dlloader * | |
4347 | -lt_dlloader_next ( | |
4348 | - lt_dlloader *place) | |
4349 | -{ | |
4350 | - lt_dlloader *next; | |
4351 | - | |
4352 | - LT_DLMUTEX_LOCK (); | |
4353 | - next = place ? place->next : loaders; | |
4354 | - LT_DLMUTEX_UNLOCK (); | |
4355 | - | |
4356 | - return next; | |
4357 | -} | |
4358 | - | |
4359 | -const char * | |
4360 | -lt_dlloader_name ( | |
4361 | - lt_dlloader *place) | |
4362 | -{ | |
4363 | - const char *name = 0; | |
4364 | - | |
4365 | - if (place) | |
4366 | - { | |
4367 | - LT_DLMUTEX_LOCK (); | |
4368 | - name = place ? place->loader_name : 0; | |
4369 | - LT_DLMUTEX_UNLOCK (); | |
4370 | - } | |
4371 | - else | |
4372 | - { | |
4373 | - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INVALID_LOADER)); | |
4374 | - } | |
4375 | - | |
4376 | - return name; | |
4377 | -} | |
4378 | - | |
4379 | -lt_user_data * | |
4380 | -lt_dlloader_data ( | |
4381 | - lt_dlloader *place) | |
4382 | -{ | |
4383 | - lt_user_data *data = 0; | |
4384 | - | |
4385 | - if (place) | |
4386 | - { | |
4387 | - LT_DLMUTEX_LOCK (); | |
4388 | - data = place ? &(place->dlloader_data) : 0; | |
4389 | - LT_DLMUTEX_UNLOCK (); | |
4390 | - } | |
4391 | - else | |
4392 | - { | |
4393 | - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INVALID_LOADER)); | |
4394 | - } | |
4395 | - | |
4396 | - return data; | |
4397 | -} | |
4398 | - | |
4399 | -lt_dlloader * | |
4400 | -lt_dlloader_find ( | |
4401 | - const char *loader_name) | |
4402 | -{ | |
4403 | - lt_dlloader *place = 0; | |
4404 | - | |
4405 | - LT_DLMUTEX_LOCK (); | |
4406 | - for (place = loaders; place; place = place->next) | |
4407 | - { | |
4408 | - if (strcmp (place->loader_name, loader_name) == 0) | |
4409 | - { | |
4410 | - break; | |
4411 | - } | |
4412 | - } | |
4413 | - LT_DLMUTEX_UNLOCK (); | |
4414 | - | |
4415 | - return place; | |
4416 | -} | |
4417 | - | |
4418 | -} // namespace scim | |
4419 | diff -up scim-1.4.8/src/ltdl.h.fix-dlopen scim-1.4.8/src/ltdl.h | |
4420 | --- scim-1.4.8/src/ltdl.h.fix-dlopen 2008-11-02 14:42:36.000000000 +0800 | |
4421 | +++ scim-1.4.8/src/ltdl.h 2009-03-25 15:12:47.333072768 +0800 | |
4422 | @@ -1,369 +0,0 @@ | |
4423 | -/* ltdl.h -- generic dlopen functions | |
4424 | - Copyright (C) 1998-2000 Free Software Foundation, Inc. | |
4425 | - Originally by Thomas Tanner <tanner@ffii.org> | |
4426 | - This file is part of GNU Libtool. | |
4427 | - | |
4428 | -This library is free software; you can redistribute it and/or | |
4429 | -modify it under the terms of the GNU Lesser General Public | |
4430 | -License as published by the Free Software Foundation; either | |
4431 | -version 2 of the License, or (at your option) any later version. | |
4432 | - | |
4433 | -As a special exception to the GNU Lesser General Public License, | |
4434 | -if you distribute this file as part of a program or library that | |
4435 | -is built using GNU libtool, you may include it under the same | |
4436 | -distribution terms that you use for the rest of that program. | |
4437 | - | |
4438 | -This library is distributed in the hope that it will be useful, | |
4439 | -but WITHOUT ANY WARRANTY; without even the implied warranty of | |
4440 | -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
4441 | -Lesser General Public License for more details. | |
4442 | - | |
4443 | -You should have received a copy of the GNU Lesser General Public | |
4444 | -License along with this library; if not, write to the Free | |
4445 | -Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | |
4446 | -02111-1307 USA | |
4447 | -*/ | |
4448 | - | |
4449 | -/* Only include this header file once. */ | |
4450 | -#ifndef LTDL_H | |
4451 | -#define LTDL_H 1 | |
4452 | - | |
4453 | -#include <sys/types.h> /* for size_t declaration */ | |
4454 | -namespace scim { | |
4455 | - | |
4456 | -\f | |
4457 | -/* --- MACROS FOR PORTABILITY --- */ | |
4458 | - | |
4459 | - | |
4460 | -/* Saves on those hard to debug '\0' typos.... */ | |
4461 | -#define LT_EOS_CHAR '\0' | |
4462 | - | |
4463 | -/* LTDL_BEGIN_C_DECLS should be used at the beginning of your declarations, | |
4464 | - so that C++ compilers don't mangle their names. Use LTDL_END_C_DECLS at | |
4465 | - the end of C declarations. */ | |
4466 | -#ifdef __cplusplus | |
4467 | -# define LT_BEGIN_C_DECLS extern "C" { | |
4468 | -# define LT_END_C_DECLS } | |
4469 | -#else | |
4470 | -# define LT_BEGIN_C_DECLS /* empty */ | |
4471 | -# define LT_END_C_DECLS /* empty */ | |
4472 | -#endif | |
4473 | - | |
4474 | -//LT_BEGIN_C_DECLS | |
4475 | - | |
4476 | - | |
4477 | -/* LT_PARAMS is a macro used to wrap function prototypes, so that compilers | |
4478 | - that don't understand ANSI C prototypes still work, and ANSI C | |
4479 | - compilers can issue warnings about type mismatches. */ | |
4480 | -#if defined (__STDC__) || defined (_AIX) || (defined (__mips) && defined (_SYSTYPE_SVR4)) || defined(WIN32) || defined(__cplusplus) | |
4481 | -# define LT_PARAMS(protos) protos | |
4482 | -# define lt_ptr void* | |
4483 | -#else | |
4484 | -# define LT_PARAMS(protos) () | |
4485 | -# define lt_ptr char* | |
4486 | -#endif | |
4487 | - | |
4488 | -/* LT_STMT_START/END are used to create macros which expand to a | |
4489 | - a single compound statement in a portable way. */ | |
4490 | -#if defined (__GNUC__) && !defined (__STRICT_ANSI__) && !defined (__cplusplus) | |
4491 | -# define LT_STMT_START (void)( | |
4492 | -# define LT_STMT_END ) | |
4493 | -#else | |
4494 | -# if (defined (sun) || defined (__sun__)) | |
4495 | -# define LT_STMT_START if (1) | |
4496 | -# define LT_STMT_END else (void)0 | |
4497 | -# else | |
4498 | -# define LT_STMT_START do | |
4499 | -# define LT_STMT_END while (0) | |
4500 | -# endif | |
4501 | -#endif | |
4502 | - | |
4503 | -/* LT_CONC creates a new concatenated symbol for the compiler | |
4504 | - in a portable way. */ | |
4505 | -#if defined(__STDC__) || defined(__cplusplus) || defined(_MSC_VER) | |
4506 | -# define LT_CONC(s,t) s##t | |
4507 | -#else | |
4508 | -# define LT_CONC(s,t) s/**/t | |
4509 | -#endif | |
4510 | - | |
4511 | -/* LT_STRLEN can be used safely on NULL pointers. */ | |
4512 | -#define LT_STRLEN(s) (((s) && (s)[0]) ? strlen (s) : 0) | |
4513 | - | |
4514 | - | |
4515 | -\f | |
4516 | -/* --- WINDOWS SUPPORT --- */ | |
4517 | - | |
4518 | - | |
4519 | -/* Canonicalise Windows and Cygwin recognition macros. */ | |
4520 | -#ifdef __CYGWIN32__ | |
4521 | -# ifndef __CYGWIN__ | |
4522 | -# define __CYGWIN__ __CYGWIN32__ | |
4523 | -# endif | |
4524 | -#endif | |
4525 | -#if defined(_WIN32) || defined(WIN32) | |
4526 | -# ifndef __WINDOWS__ | |
4527 | -# ifdef _WIN32 | |
4528 | -# define __WINDOWS__ _WIN32 | |
4529 | -# else | |
4530 | -# ifdef WIN32 | |
4531 | -# define __WINDOWS__ WIN32 | |
4532 | -# endif | |
4533 | -# endif | |
4534 | -# endif | |
4535 | -#endif | |
4536 | - | |
4537 | - | |
4538 | -#ifdef __WINDOWS__ | |
4539 | -# ifndef __CYGWIN__ | |
4540 | -/* LT_DIRSEP_CHAR is accepted *in addition* to '/' as a directory | |
4541 | - separator when it is set. */ | |
4542 | -# define LT_DIRSEP_CHAR '\\' | |
4543 | -# define LT_PATHSEP_CHAR ';' | |
4544 | -# endif | |
4545 | -#endif | |
4546 | -#ifndef LT_PATHSEP_CHAR | |
4547 | -# define LT_PATHSEP_CHAR ':' | |
4548 | -#endif | |
4549 | - | |
4550 | -/* DLL building support on win32 hosts; mostly to workaround their | |
4551 | - ridiculous implementation of data symbol exporting. */ | |
4552 | -#ifndef LT_SCOPE | |
4553 | -# ifdef __WINDOWS__ | |
4554 | -# ifdef DLL_EXPORT /* defined by libtool (if required) */ | |
4555 | -# define LT_SCOPE __declspec(dllexport) | |
4556 | -# endif | |
4557 | -# ifdef LIBLTDL_DLL_IMPORT /* define if linking with this dll */ | |
4558 | -# define LT_SCOPE extern __declspec(dllimport) | |
4559 | -# endif | |
4560 | -# endif | |
4561 | -# ifndef LT_SCOPE /* static linking or !__WINDOWS__ */ | |
4562 | -# define LT_SCOPE extern | |
4563 | -# endif | |
4564 | -#endif | |
4565 | - | |
4566 | - | |
4567 | -#if defined(_MSC_VER) /* Visual Studio */ | |
4568 | -# define R_OK 4 | |
4569 | -#endif | |
4570 | - | |
4571 | - | |
4572 | -\f | |
4573 | -/* --- DYNAMIC MODULE LOADING API --- */ | |
4574 | - | |
4575 | - | |
4576 | -typedef struct lt_dlhandle_struct *lt_dlhandle; /* A loaded module. */ | |
4577 | - | |
4578 | -/* Initialisation and finalisation functions for libltdl. */ | |
4579 | -LT_SCOPE int lt_dlinit LT_PARAMS((void)); | |
4580 | -LT_SCOPE int lt_dlexit LT_PARAMS((void)); | |
4581 | - | |
4582 | -/* Module search path manipulation. */ | |
4583 | -LT_SCOPE int lt_dladdsearchdir LT_PARAMS((const char *search_dir)); | |
4584 | -LT_SCOPE int lt_dlinsertsearchdir LT_PARAMS((const char *before, | |
4585 | - const char *search_dir)); | |
4586 | -LT_SCOPE int lt_dlsetsearchpath LT_PARAMS((const char *search_path)); | |
4587 | -LT_SCOPE const char *lt_dlgetsearchpath LT_PARAMS((void)); | |
4588 | -LT_SCOPE int lt_dlforeachfile LT_PARAMS(( | |
4589 | - const char *search_path, | |
4590 | - int (*func) (const char *filename, lt_ptr data), | |
4591 | - lt_ptr data)); | |
4592 | - | |
4593 | -/* Portable libltdl versions of the system dlopen() API. */ | |
4594 | -LT_SCOPE lt_dlhandle lt_dlopen LT_PARAMS((const char *filename)); | |
4595 | -LT_SCOPE lt_dlhandle lt_dlopenext LT_PARAMS((const char *filename)); | |
4596 | -LT_SCOPE lt_ptr lt_dlsym LT_PARAMS((lt_dlhandle handle, | |
4597 | - const char *name)); | |
4598 | -LT_SCOPE const char *lt_dlerror LT_PARAMS((void)); | |
4599 | -LT_SCOPE int lt_dlclose LT_PARAMS((lt_dlhandle handle)); | |
4600 | - | |
4601 | -/* Module residency management. */ | |
4602 | -LT_SCOPE int lt_dlmakeresident LT_PARAMS((lt_dlhandle handle)); | |
4603 | -LT_SCOPE int lt_dlisresident LT_PARAMS((lt_dlhandle handle)); | |
4604 | - | |
4605 | - | |
4606 | - | |
4607 | -\f | |
4608 | -/* --- MUTEX LOCKING --- */ | |
4609 | - | |
4610 | - | |
4611 | -typedef void lt_dlmutex_lock LT_PARAMS((void)); | |
4612 | -typedef void lt_dlmutex_unlock LT_PARAMS((void)); | |
4613 | -typedef void lt_dlmutex_seterror LT_PARAMS((const char *errmsg)); | |
4614 | -typedef const char *lt_dlmutex_geterror LT_PARAMS((void)); | |
4615 | - | |
4616 | -LT_SCOPE int lt_dlmutex_register LT_PARAMS((lt_dlmutex_lock *lock, | |
4617 | - lt_dlmutex_unlock *unlock, | |
4618 | - lt_dlmutex_seterror *seterror, | |
4619 | - lt_dlmutex_geterror *geterror)); | |
4620 | - | |
4621 | - | |
4622 | - | |
4623 | -\f | |
4624 | -/* --- MEMORY HANDLING --- */ | |
4625 | - | |
4626 | - | |
4627 | -/* By default, the realloc function pointer is set to our internal | |
4628 | - realloc implementation which iself uses lt_dlmalloc and lt_dlfree. | |
4629 | - libltdl relies on a featureful realloc, but if you are sure yours | |
4630 | - has the right semantics then you can assign it directly. Generally, | |
4631 | - it is safe to assign just a malloc() and a free() function. */ | |
4632 | -LT_SCOPE lt_ptr (*lt_dlmalloc) LT_PARAMS((size_t size)); | |
4633 | -LT_SCOPE lt_ptr (*lt_dlrealloc) LT_PARAMS((lt_ptr ptr, size_t size)); | |
4634 | -LT_SCOPE void (*lt_dlfree) LT_PARAMS((lt_ptr ptr)); | |
4635 | - | |
4636 | - | |
4637 | - | |
4638 | -\f | |
4639 | -/* --- PRELOADED MODULE SUPPORT --- */ | |
4640 | - | |
4641 | - | |
4642 | -/* A preopened symbol. Arrays of this type comprise the exported | |
4643 | - symbols for a dlpreopened module. */ | |
4644 | -typedef struct { | |
4645 | - const char *name; | |
4646 | - lt_ptr address; | |
4647 | -} lt_dlsymlist; | |
4648 | - | |
4649 | -LT_SCOPE int lt_dlpreload LT_PARAMS((const lt_dlsymlist *preloaded)); | |
4650 | -LT_SCOPE int lt_dlpreload_default | |
4651 | - LT_PARAMS((const lt_dlsymlist *preloaded)); | |
4652 | - | |
4653 | -#define LTDL_SET_PRELOADED_SYMBOLS() LT_STMT_START{ \ | |
4654 | - extern const lt_dlsymlist lt_preloaded_symbols[]; \ | |
4655 | - lt_dlpreload_default(lt_preloaded_symbols); \ | |
4656 | - }LT_STMT_END | |
4657 | - | |
4658 | - | |
4659 | - | |
4660 | -\f | |
4661 | -/* --- MODULE INFORMATION --- */ | |
4662 | - | |
4663 | - | |
4664 | -/* Read only information pertaining to a loaded module. */ | |
4665 | -typedef struct { | |
4666 | - char *filename; /* file name */ | |
4667 | - char *name; /* module name */ | |
4668 | - int ref_count; /* number of times lt_dlopened minus | |
4669 | - number of times lt_dlclosed. */ | |
4670 | -} lt_dlinfo; | |
4671 | - | |
4672 | -LT_SCOPE const lt_dlinfo *lt_dlgetinfo LT_PARAMS((lt_dlhandle handle)); | |
4673 | -LT_SCOPE lt_dlhandle lt_dlhandle_next LT_PARAMS((lt_dlhandle place)); | |
4674 | -LT_SCOPE int lt_dlforeach LT_PARAMS(( | |
4675 | - int (*func) (lt_dlhandle handle, lt_ptr data), | |
4676 | - lt_ptr data)); | |
4677 | - | |
4678 | -/* Associating user data with loaded modules. */ | |
4679 | -typedef unsigned lt_dlcaller_id; | |
4680 | - | |
4681 | -LT_SCOPE lt_dlcaller_id lt_dlcaller_register LT_PARAMS((void)); | |
4682 | -LT_SCOPE lt_ptr lt_dlcaller_set_data LT_PARAMS((lt_dlcaller_id key, | |
4683 | - lt_dlhandle handle, | |
4684 | - lt_ptr data)); | |
4685 | -LT_SCOPE lt_ptr lt_dlcaller_get_data LT_PARAMS((lt_dlcaller_id key, | |
4686 | - lt_dlhandle handle)); | |
4687 | - | |
4688 | - | |
4689 | -\f | |
4690 | -/* --- USER MODULE LOADER API --- */ | |
4691 | - | |
4692 | - | |
4693 | -typedef struct lt_dlloader lt_dlloader; | |
4694 | -typedef lt_ptr lt_user_data; | |
4695 | -typedef lt_ptr lt_module; | |
4696 | - | |
4697 | -/* Function pointer types for creating user defined module loaders. */ | |
4698 | -typedef lt_module lt_module_open LT_PARAMS((lt_user_data loader_data, | |
4699 | - const char *filename)); | |
4700 | -typedef int lt_module_close LT_PARAMS((lt_user_data loader_data, | |
4701 | - lt_module handle)); | |
4702 | -typedef lt_ptr lt_find_sym LT_PARAMS((lt_user_data loader_data, | |
4703 | - lt_module handle, | |
4704 | - const char *symbol)); | |
4705 | -typedef int lt_dlloader_exit LT_PARAMS((lt_user_data loader_data)); | |
4706 | - | |
4707 | -struct lt_user_dlloader { | |
4708 | - const char *sym_prefix; | |
4709 | - lt_module_open *module_open; | |
4710 | - lt_module_close *module_close; | |
4711 | - lt_find_sym *find_sym; | |
4712 | - lt_dlloader_exit *dlloader_exit; | |
4713 | - lt_user_data dlloader_data; | |
4714 | -}; | |
4715 | - | |
4716 | -LT_SCOPE lt_dlloader *lt_dlloader_next LT_PARAMS((lt_dlloader *place)); | |
4717 | -LT_SCOPE lt_dlloader *lt_dlloader_find LT_PARAMS(( | |
4718 | - const char *loader_name)); | |
4719 | -LT_SCOPE const char *lt_dlloader_name LT_PARAMS((lt_dlloader *place)); | |
4720 | -LT_SCOPE lt_user_data *lt_dlloader_data LT_PARAMS((lt_dlloader *place)); | |
4721 | -LT_SCOPE int lt_dlloader_add LT_PARAMS((lt_dlloader *place, | |
4722 | - const struct lt_user_dlloader *dlloader, | |
4723 | - const char *loader_name)); | |
4724 | -LT_SCOPE int lt_dlloader_remove LT_PARAMS(( | |
4725 | - const char *loader_name)); | |
4726 | - | |
4727 | - | |
4728 | -\f | |
4729 | -/* --- ERROR MESSAGE HANDLING --- */ | |
4730 | - | |
4731 | - | |
4732 | -/* Defining error strings alongside their symbolic names in a macro in | |
4733 | - this way allows us to expand the macro in different contexts with | |
4734 | - confidence that the enumeration of symbolic names will map correctly | |
4735 | - onto the table of error strings. */ | |
4736 | -#define lt_dlerror_table \ | |
4737 | - LT_ERROR(UNKNOWN, "unknown error") \ | |
4738 | - LT_ERROR(DLOPEN_NOT_SUPPORTED, "dlopen support not available") \ | |
4739 | - LT_ERROR(INVALID_LOADER, "invalid loader") \ | |
4740 | - LT_ERROR(INIT_LOADER, "loader initialization failed") \ | |
4741 | - LT_ERROR(REMOVE_LOADER, "loader removal failed") \ | |
4742 | - LT_ERROR(FILE_NOT_FOUND, "file not found") \ | |
4743 | - LT_ERROR(DEPLIB_NOT_FOUND, "dependency library not found") \ | |
4744 | - LT_ERROR(NO_SYMBOLS, "no symbols defined") \ | |
4745 | - LT_ERROR(CANNOT_OPEN, "can't open the module") \ | |
4746 | - LT_ERROR(CANNOT_CLOSE, "can't close the module") \ | |
4747 | - LT_ERROR(SYMBOL_NOT_FOUND, "symbol not found") \ | |
4748 | - LT_ERROR(NO_MEMORY, "not enough memory") \ | |
4749 | - LT_ERROR(INVALID_HANDLE, "invalid module handle") \ | |
4750 | - LT_ERROR(BUFFER_OVERFLOW, "internal buffer overflow") \ | |
4751 | - LT_ERROR(INVALID_ERRORCODE, "invalid errorcode") \ | |
4752 | - LT_ERROR(SHUTDOWN, "library already shutdown") \ | |
4753 | - LT_ERROR(CLOSE_RESIDENT_MODULE, "can't close resident module") \ | |
4754 | - LT_ERROR(INVALID_MUTEX_ARGS, "invalid mutex handler registration") \ | |
4755 | - LT_ERROR(INVALID_POSITION, "invalid search path insert position") | |
4756 | - | |
4757 | -/* Enumerate the symbolic error names. */ | |
4758 | -enum { | |
4759 | -#define LT_ERROR(name, diagnostic) LT_CONC(LT_ERROR_, name), | |
4760 | - lt_dlerror_table | |
4761 | -#undef LT_ERROR | |
4762 | - | |
4763 | - LT_ERROR_MAX | |
4764 | -}; | |
4765 | - | |
4766 | -/* These functions are only useful from inside custom module loaders. */ | |
4767 | -LT_SCOPE int lt_dladderror LT_PARAMS((const char *diagnostic)); | |
4768 | -LT_SCOPE int lt_dlseterror LT_PARAMS((int errorcode)); | |
4769 | - | |
4770 | - | |
4771 | - | |
4772 | -\f | |
4773 | -/* --- SOURCE COMPATIBILITY WITH OLD LIBLTDL --- */ | |
4774 | - | |
4775 | - | |
4776 | -#ifdef LT_NON_POSIX_NAMESPACE | |
4777 | -# define lt_ptr_t lt_ptr | |
4778 | -# define lt_module_t lt_module | |
4779 | -# define lt_module_open_t lt_module_open | |
4780 | -# define lt_module_close_t lt_module_close | |
4781 | -# define lt_find_sym_t lt_find_sym | |
4782 | -# define lt_dlloader_exit_t lt_dlloader_exit | |
4783 | -# define lt_dlloader_t lt_dlloader | |
4784 | -# define lt_dlloader_data_t lt_user_data | |
4785 | -#endif | |
4786 | - | |
4787 | -//LT_END_C_DECLS | |
4788 | - | |
4789 | -} // namespace scim | |
4790 | - | |
4791 | -#endif /* !LTDL_H */ | |
4792 | diff -up scim-1.4.8/src/scim_module.cpp.fix-dlopen scim-1.4.8/src/scim_module.cpp | |
4793 | --- scim-1.4.8/src/scim_module.cpp.fix-dlopen 2009-03-25 15:11:42.223072366 +0800 | |
4794 | +++ scim-1.4.8/src/scim_module.cpp 2009-03-25 15:11:42.250015385 +0800 | |
4795 | @@ -42,6 +42,7 @@ typedef void (*ModuleExitFunc) (void); | |
4796 | ||
4797 | struct Module::ModuleImpl | |
4798 | { | |
4799 | + lt_dladvise advise; | |
4800 | lt_dlhandle handle; | |
4801 | ModuleInitFunc init; | |
4802 | ModuleExitFunc exit; | |
4803 | @@ -120,18 +121,23 @@ Module::Module () | |
4804 | : m_impl (new ModuleImpl) | |
4805 | { | |
4806 | lt_dlinit (); | |
4807 | + lt_dladvise_init (&(m_impl->advise)); | |
4808 | + lt_dladvise_ext (&(m_impl->advise)); | |
4809 | + lt_dladvise_global (&(m_impl->advise)); | |
4810 | } | |
4811 | ||
4812 | Module::Module (const String &name, const String &type) | |
4813 | : m_impl (new ModuleImpl) | |
4814 | { | |
4815 | - lt_dlinit (); | |
4816 | + Module(); | |
4817 | + | |
4818 | load (name, type); | |
4819 | } | |
4820 | ||
4821 | Module::~Module () | |
4822 | { | |
4823 | unload (); | |
4824 | + lt_dladvise_destroy (&(m_impl->advise)); | |
4825 | lt_dlexit (); | |
4826 | delete m_impl; | |
4827 | } | |
4828 | @@ -169,13 +175,13 @@ Module::load (const String &name, const | |
4829 | ||
4830 | for (it = paths.begin (); it != paths.end (); ++it) { | |
4831 | module_path = *it + String (SCIM_PATH_DELIM_STRING) + name; | |
4832 | - new_handle = lt_dlopenext (module_path.c_str ()); | |
4833 | + new_handle = lt_dlopenadvise (module_path.c_str (), m_impl->advise); | |
4834 | if (new_handle) | |
4835 | break; | |
4836 | } | |
4837 | ||
4838 | if (!new_handle) { | |
4839 | - new_handle = lt_dlopenext (name.c_str ()); | |
4840 | + new_handle = lt_dlopenadvise (name.c_str (), m_impl->advise); | |
4841 | } | |
4842 | ||
4843 | if (!new_handle) |