1 /***********************************************************************
3 * This software is part of the ast package *
4 * Copyright (c) 1997-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * Glenn Fowler <gsf@research.att.com> *
19 ***********************************************************************/
29 #ifndef __EXTENSIONS__
30 #define __EXTENSIONS__ 1
36 #if _hdr_rld_interface
37 #include <rld_interface.h>
41 * return a handle for the next layer down,
42 * i.e., the next layer that has symbols covered
43 * by the main prog and dll's loaded so far
45 * intentionally light on external lib calls
46 * so this routine can be used early in process
56 typedef ssize_t (*Write_f
)(int, const void*, size_t);
63 _dll_next(int flags
, _DLL_RLD_SYM_TYPE
* here
)
67 register int found
= 0;
79 if (getenv("DLL_DEBUG") && (vp
= (char*)_rld_new_interface(_RLD_FIRST_PATHNAME
)))
83 if (strcmp(vp
, "MAIN") && (lp
= dllopen(vp
, flags
)))
85 if (xr
= (Write_f
)dlsym(lp
, "write"))
88 } while (vp
= (char*)_rld_new_interface(_RLD_NEXT_PATHNAME
));
91 if (vp
= (char*)_rld_new_interface(_RLD_FIRST_PATHNAME
))
95 if (lp
= dllopen(strcmp(vp
, "MAIN") ? vp
: (char*)0, flags
))
129 if (dlsym(lp
, dummy
))
139 (*wr
)(2, buf
, sfsprintf(buf
, sizeof(buf
), "dll: next %s\n", vp
));
145 (*wr
)(2, buf
, sfsprintf(buf
, sizeof(buf
), "dll: skip %s\n", vp
));
148 else if ((_DLL_RLD_SYM_TYPE
*)dlsym(lp
, _DLL_RLD_SYM_STR
) == here
)
152 (*wr
)(2, buf
, sfsprintf(buf
, sizeof(buf
), "dll: this %s\n", vp
));
157 } while (vp
= (char*)_rld_new_interface(_RLD_NEXT_PATHNAME
));
159 return dllnext(flags
);
169 extern struct link_dynamic _DYNAMIC
;
180 register struct link_map
* map
;
187 static char next
[] = { _DLL_NEXT_PATH
};
195 for (map
= _DYNAMIC
.ld_un
.ld_1
->ld_loaded
; map
; map
= map
->lm_next
)
202 if (b
&& b
[0] == 'l' && b
[1] == 'i' && b
[2] == 'b' && b
[3] == 'c' && b
[4] == '.')
209 ver
= path
+ strlen(path
);
210 while (!(dll
= dllopen(path
, flags
)))
216 } while (*--ver
!= '.');
217 if (*(ver
+ 1) <= '0' || *(ver
+ 1) >= '9')