xref: /titanic_50/usr/src/cmd/sgs/rtld/common/_rtld.h (revision 5253169e90b276216b53d82f9ba4c56334db5740)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  *	Copyright (c) 1988 AT&T
24  *	  All Rights Reserved
25  *
26  * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
27  */
28 #ifndef	__RTLD_H
29 #define	__RTLD_H
30 
31 /*
32  * Common header for run-time linker.
33  */
34 #include <sys/types.h>
35 #include <sys/stat.h>
36 #include <sys/avl.h>
37 #include <sys/mman.h>
38 #include <stdarg.h>
39 #include <synch.h>
40 #include <signal.h>
41 #include <errno.h>
42 #include <unistd.h>
43 #include <link.h>
44 #include <rtld.h>
45 #include <sgs.h>
46 #include <machdep.h>
47 #include <rtc.h>
48 #include <debug.h>
49 #include <msg.h>
50 #include <libc_int.h>
51 
52 #ifdef	__cplusplus
53 extern "C" {
54 #endif
55 
56 /*
57  * Dependency search rule order.
58  */
59 #define	RPLENV		1		/* replaceable LD_LIBRARY_PATH */
60 #define	PRMENV		2		/* permanent LD_LIBRARY_PATH */
61 #define	RUNPATH		3		/* callers runpath */
62 #define	DEFAULT		4		/* default library path */
63 
64 typedef struct fdesc	Fdesc;
65 typedef struct fct	Fct;
66 typedef	struct pdesc	Pdesc;
67 
68 /*
69  * Data structure for file class specific functions and data.
70  */
71 struct fct {
72 	/* Verify that the object is of this class. */
73 	Fct	*(*fct_verify_file)(caddr_t, size_t, Fdesc *, const char *,
74 	    Rej_desc *);
75 
76 	/* Generate a link-map to describe the loaded object. */
77 	Rt_map	*(*fct_new_lmp)(Lm_list *, Aliste, Fdesc *, Addr, size_t,
78 	    void *, int *);
79 
80 	/* Retrieve the entry point of the object. */
81 	Addr	(*fct_entry_pt)(void);
82 
83 	/* Determine the objects dependencies (needed entries). */
84 	int	(*fct_needed)(Lm_list *, Aliste, Rt_map *, int *);
85 
86 	/* Look up a symbol for the object. */
87 	int	(*fct_lookup_sym)(Slookup *, Sresult *, uint_t *, int *);
88 
89 	/* Relocate the object. */
90 	int	(*fct_reloc)(Rt_map *, uint_t, int *, APlist **);
91 
92 	/* List of default directories to search for dependencies. */
93 	Alist	**(*fct_get_def_dirs)(void);
94 
95 	/* List of secure directories to search for dependencies. */
96 	Alist	**(*fct_get_sec_dirs)(void);
97 
98 	/* Transpose the name of the object. */
99 	int	(*fct_fix_name)(const char *, Rt_map *, Alist **, Aliste,
100 	    uint_t);
101 
102 	/* Get a shared object name */
103 	char	*(*fct_get_so)(const char *, const char *, size_t, size_t);
104 
105 	/* Retrieve a symbolic address from the object. */
106 	void	(*fct_dladdr)(ulong_t, Rt_map *, Dl_info *, void **, int);
107 
108 	/* Process a dlsym(3c) request within the object. */
109 	int	(*fct_dlsym)(Grp_hdl *, Slookup *, Sresult *, uint_t *, int *);
110 };
111 
112 /*
113  * Macros for getting to the file class table.
114  */
115 #define	LM_ENTRY_PT(X)		((X)->rt_fct->fct_entry_pt)
116 #define	LM_NEEDED(X)		((X)->rt_fct->fct_needed)
117 #define	LM_LOOKUP_SYM(X)	((X)->rt_fct->fct_lookup_sym)
118 #define	LM_RELOC(X)		((X)->rt_fct->fct_reloc)
119 #define	LM_DEFAULT_DIRS(X)	((X)->rt_fct->fct_get_def_dirs)
120 #define	LM_SECURE_DIRS(X)	((X)->rt_fct->fct_get_sec_dirs)
121 #define	LM_FIX_NAME(X)		((X)->rt_fct->fct_fix_name)
122 #define	LM_GET_SO(X)		((X)->rt_fct->fct_get_so)
123 #define	LM_DLADDR(X)		((X)->rt_fct->fct_dladdr)
124 #define	LM_DLSYM(X)		((X)->rt_fct->fct_dlsym)
125 
126 /*
127  * Initial memory map allocation.  Typical ELF objects contain a text and data
128  * segment, which can be augmented with a bss mapping.  Add a bunch more for
129  * luck.
130  */
131 #define	MMAPFD_NUM	10
132 
133 /*
134  * Define Alist initialization counts.
135  */
136 #define	AL_CNT_ALIAS	2		/* ALIAS() */
137 #define	AL_CNT_DEPENDS	20		/* DEPENDS() */
138 #define	AL_CNT_CALLERS	20		/* CALLERS() */
139 #define	AL_CNT_GROUPS	20		/* GROUPS() */
140 #define	AL_CNT_COPYREL	10		/* COPY() */
141 #define	AL_CNT_LAZYFIND	10		/* elf_lazy_find_sym() */
142 #define	AL_CNT_GRPCLCT	10		/* gdp_collect() */
143 #define	AL_CNT_DEPCLCT	10		/* load_finish() */
144 #define	AL_CNT_RTLDINFO	1		/* RTLDINFO() */
145 #define	AL_CNT_FPNODE	4		/* FPNODE() */
146 #define	AL_CNT_LMLISTS	20		/* lm_lists */
147 #define	AL_CNT_LMNOW	8		/* lm_now */
148 #define	AL_CNT_RELBIND	20		/* relocation binding */
149 #define	AL_CNT_ACTAUDIT	2		/* lm_actaudit */
150 #define	AL_CNT_MOVES	10		/* move_data */
151 #define	AL_CNT_MPOBJS	4		/* elf_obj_file() */
152 #define	AL_CNT_TEXTREL	2		/* text relocation segment */
153 #define	AL_CNT_NEEDED	1		/* dependency path */
154 #define	AL_CNT_SEARCH	4		/* search path */
155 #define	AL_CNT_FILTEES	2		/* filtee path */
156 #define	AL_CNT_HANDLES	1		/* hdl_list[] */
157 #define	AL_CNT_FREELIST	80		/* free_alp */
158 #define	AL_CNT_CAP	10		/* capabilities candidate */
159 #define	AL_CNT_SPATH	4		/* search path */
160 #define	AL_CNT_DYNLIST	2		/* dynlm_list */
161 #define	AL_CNT_PENDING	2		/* pending tsort list (INITFIRST) */
162 #define	AL_CNT_PLTPAD	10		/* plt padding */
163 #define	AL_CNT_AUDITORS	2		/* auditing list */
164 
165 /*
166  * Size of buffer for building error messages.
167  */
168 #define	ERRSIZE		2048		/* MAXPATHLEN * 2 */
169 
170 /*
171  * Configuration file information.
172  */
173 typedef struct config {
174 	const char	*c_name;
175 	Addr		c_bgn;
176 	Addr		c_end;
177 	Word		*c_hashtbl;
178 	Word		*c_hashchain;
179 	const char	*c_strtbl;
180 	Rtc_obj		*c_objtbl;
181 	Rtc_fltr	*c_fltr;
182 	Rtc_flte	*c_flte;
183 } Config;
184 
185 /*
186  * Register symbol list.
187  */
188 typedef struct reglist {
189 	Rt_map		*rl_lmp;	/* defining object */
190 	Sym		*rl_sym;	/* regsym */
191 	struct reglist	*rl_next;	/* next entry */
192 } Reglist;
193 
194 /*
195  * Data structure to hold interpreter information.
196  */
197 typedef struct interp {
198 	char		*i_name;	/* interpreter name */
199 	caddr_t		i_faddr;	/* address interpreter is mapped at */
200 } Interp;
201 
202 /*
203  * Data structure used to keep track of copy relocations.  These relocations
204  * are collected during initial relocation processing and maintained on the
205  * COPY(lmp) list of the defining object.  Each copy list is also added to the
206  * COPY(lmp) of the head object (normally the application dynamic executable)
207  * from which they will be processed after all relocations are done.
208  *
209  * The use of RTLD_GROUP will also reference individual objects COPY(lmp) lists
210  * in case a bound symbol must be assigned to it actual copy relocation.
211  */
212 typedef struct {
213 	const char	*r_name;	/* symbol name */
214 	Sym		*r_rsym;	/* reference symbol table entry */
215 	Rt_map		*r_rlmp;	/* reference link map */
216 	Rt_map		*r_dlmp;	/* definition link map */
217 	Sym		*r_dsym;	/* definition symbol table entry */
218 	void		*r_radd;	/* copy to address */
219 	const void	*r_dadd;	/* copy from address */
220 	ulong_t		r_size;		/* copy size bytes */
221 } Rel_copy;
222 
223 /*
224  * Define a file descriptor, which maintains information regarding a pathname
225  * that has been opened and minimally inspected.
226  */
227 struct fdesc {
228 	Rt_map		*fd_lmp;	/* existing link-map pointer */
229 	Fct		*fd_ftp;	/* file functions pointer */
230 	const char	*fd_oname;	/* original file name */
231 	const char	*fd_odir;	/* original directory name */
232 	const char	*fd_nname;	/* new file (expanded) name */
233 	const char	*fd_pname;	/* new path (resolved) name */
234 	dev_t		fd_dev;		/* file device number */
235 	rtld_ino_t	fd_ino;		/* file inode number */
236 	uint_t		fd_flags;
237 	avl_index_t	fd_avlwhere;	/* avl tree insertion index */
238 	Syscapset	fd_scapset;	/* capabilities */
239 	mmapobj_result_t *fd_mapp;	/* mapping pointer */
240 	uint_t		fd_mapn;	/* mapping number */
241 };
242 
243 #define	FLG_FD_ALTER	0x0001		/* file is an alternate */
244 #define	FLG_FD_SLASH	0x0002		/* file contains a "/" */
245 #define	FLG_FD_RESOLVED	0x0004		/* fd_nname has been resolved */
246 #define	FLG_FD_ALTCHECK	0x0008		/* alternative system capabilities */
247 					/*	checked */
248 #define	FLG_FD_ALTCAP	0x0010		/* alternative system capabilities */
249 					/*	should be used */
250 
251 /*
252  * File descriptor availability flag.
253  */
254 #define	FD_UNAVAIL	-1
255 
256 /*
257  * Disabled filter flag.  Filter objects are referenced using their .dynamic
258  * index (DT_FILTER or DT_AUXILIARY).  This index is saved and used to lookup
259  * the required filter.  Note that 0 is a valid .dynamic index.  The caller's
260  * OBJFLTRNDX() element is initialized using the following flag, and should
261  * the filter's initialization fail, is reset to this value to indicate the
262  * filter is disabled.  UINT_MAX provides a convenient invalid .dynamic index.
263  */
264 #define	FLTR_DISABLED	UINT_MAX
265 
266 /*
267  * Status flags for rtld_flags
268  */
269 #define	RT_FL_THREADS	0x00000001	/* threads are enabled */
270 #define	RT_FL_WARNFLTR	0x00000002	/* warn of missing filtees (ldd) */
271 #define	RT_FL_DBNOTIF	0x00000004	/* binding activity going on */
272 #define	RT_FL_DEFERRED	0x00000008	/* load deferred dependencies (ldd) */
273 #define	RT_FL_NOBIND	0x00000010	/* don't carry out plt binding */
274 #define	RT_FL_NOVERSION	0x00000020	/* disable version checking */
275 #define	RT_FL_SECURE	0x00000040	/* setuid/segid flag */
276 #define	RT_FL_APPLIC	0x00000080	/* are we executing user code */
277 
278 #define	RT_FL_CONFGEN	0x00000200	/* don't relocate initiating object */
279 					/*	set by crle(1). */
280 #define	RT_FL_CONFAPP	0x00000400	/* application specific configuration */
281 					/*	cache required */
282 #define	RT_FL_DEBUGGER	0x00000800	/* a debugger is monitoring us */
283 #define	RT_FL_OPERATION	0x00001000	/* start recording operations */
284 #define	RT_FL_NEWLOCALE	0x00002000	/* message locale has changed */
285 #define	RT_FL_NOBAPLT	0x00004000	/* sparc: don't use ba plt's */
286 #define	RT_FL_NOAUXFLTR	0x00008000	/* disable auxiliary filters */
287 
288 #define	RT_FL_NOAUDIT	0x00020000	/* disable auditing */
289 #define	RT_FL_ATEXIT	0x00040000	/* we're shutting down */
290 #define	RT_FL_SILENCERR	0x00080000	/* silence error messages */
291 
292 #define	RT_FL_INITFIRST	0x00200000	/* processing a DT_INITFIRST object */
293 
294 #define	RT_FL_DEMANGLE	0x01000000	/* demangle C++ symbol names */
295 #define	RT_FL_NOCFG	0x02000000	/* disable config file use */
296 #define	RT_FL_NODIRCFG	0x04000000	/* disable directory config use */
297 #define	RT_FL_NOOBJALT	0x08000000	/* disable object alternative use */
298 #define	RT_FL_NOENVCFG	0x10000000	/* disable config envars use */
299 #define	RT_FL_DIRCFG	0x20000000	/* directory config info available */
300 #define	RT_FL_OBJALT	0x40000000	/* object alternatives are available */
301 #define	RT_FL_MEMRESV	0x80000000	/* memory reservation established */
302 
303 /*
304  * Status flags for rtld_flags2
305  */
306 #define	RT_FL2_HASAUDIT	0x00000001	/* auditing lm_list is present */
307 #define	RT_FL2_RTLDSEEN	0x00000002	/* rtldinfo has been set */
308 #define	RT_FL2_UNIFPROC	0x00000004	/* libc/libthread unified environment */
309 
310 #define	RT_FL2_NOFLTCFG	0x00000010	/* disable config filter use */
311 #define	RT_FL2_FLTCFG	0x00000020	/* filter config info available */
312 #define	RT_FL2_HWCAP	0x00000040	/* hardware capabilities available */
313 #define	RT_FL2_FTL2WARN	0x00000080	/* convert fatal to warning messages */
314 #define	RT_FL2_BINDNOW	0x00000100	/* LD_BIND_NOW in effect */
315 #define	RT_FL2_BINDLAZY	0x00000200	/* disable RTLD_NOW (and LD_BIND_NOW) */
316 #define	RT_FL2_PLMSETUP	0x00000400	/* primary link-map set up complete */
317 #define	RT_FL2_BRANDED	0x00000800	/* process is branded */
318 #define	RT_FL2_NOPLM	0x00001000	/* process has no primary link map */
319 #define	RT_FL2_SETUID	0x00002000	/* ld.so.1 is setuid root */
320 #define	RT_FL2_ADDR32	0x00004000	/* 32-bit address space requirement */
321 
322 /*
323  * Information flags for env_info.
324  */
325 #define	ENV_INF_PATHCFG	0x00000001	/* replaceable LD_LIBRARY_PATH */
326 					/*	originates from configuration */
327 					/*	file */
328 #define	ENV_INF_FLAGCFG	0x00000002	/* replaceable LD_FLAGS originates */
329 					/*	from configuration file */
330 
331 /*
332  * RTLDINFO descriptor.
333  */
334 typedef struct {
335 	Rt_map		*rti_lmp;	/* RTLDINFO provider */
336 	Lc_interface	*rti_info;	/* RTLDINFO data */
337 } Rti_desc;
338 
339 /*
340  * Binding flags for the rt_bind_guard()/rt_bind_clear() routines.
341  * These are defined in usr/src/lib/libc/inc/libc_int.h in the
342  * latest version of the libc/rtld runtime interface (CI_V_FIVE).
343  */
344 #if !defined(CI_V_FIVE)
345 #define	THR_FLG_RTLD	0x00000001	/* rtldlock bind guard flag */
346 #define	THR_FLG_NOLOCK	0x00000000	/* no-op before CI_V_FIVE */
347 #define	THR_FLG_REENTER	0x00000000	/* no-op before CI_V_FIVE */
348 #endif
349 
350 #define	ROUND(x, a)	(((int)(x) + ((int)(a) - 1)) & ~((int)(a) - 1))
351 
352 /*
353  * Print buffer.
354  */
355 typedef struct {
356 	char	*pr_buf;	/* pointer to beginning of buffer */
357 	char	*pr_cur;	/* pointer to next free char in buffer */
358 	size_t	pr_len;		/* buffer size */
359 	int	pr_fd;		/* output fd */
360 } Prfbuf;
361 
362 /*
363  * Path name descriptor.  Used to construct various path names such as search
364  * paths, dependency paths, filter paths etc.  The pd_info element can be used
365  * to hold various pointers, like Grp_hdl, Rtc_obj, etc.
366  */
367 struct pdesc {
368 	const char	*pd_pname;	/* path name - may be expanded */
369 	const char	*pd_oname;	/* original name - unexpanded */
370 	void		*pd_info;	/* possible auxiliary information */
371 	size_t		pd_plen;	/* path name length */
372 	uint_t		pd_flags;	/* descriptor specific flags */
373 };
374 
375 /*
376  * Path name descriptors are passed to expand_path() and expand().  These
377  * routines break down possible multiple path strings (separated with ":"),
378  * and perform any reserved token expansion.  These routines are passed
379  * information that indicates the use of the path, for example, search paths,
380  * i.e., LD_LIBRARY_PATH, RPATHS, etc. are defined using la_objsearch()
381  * information (see LA_SER flags in link.h).  This information is recorded in
382  * the pd_flags field for later use.
383  *
384  * Define expansion path tokens.  These are used to prevent various expansions
385  * from occurring, and record those expansions that do.  Any expansion
386  * information is also recorded in the pd_flags field, and thus is or'd
387  * together with any LA_SER flags.
388  */
389 #define	PD_TKN_ORIGIN	0x00001000	/* $ORIGIN expansion has occurred */
390 #define	PD_TKN_PLATFORM	0x00002000	/* $PLATFORM expansion has occurred */
391 #define	PD_TKN_OSNAME	0x00004000	/* $OSNAME expansion has occurred */
392 #define	PD_TKN_OSREL	0x00008000	/* $OSREL expansion has occurred */
393 #define	PD_TKN_ISALIST	0x00010000	/* $ISALIST expansion has occurred */
394 #define	PD_TKN_CAP	0x00020000	/* $CAPABILITY/$HWCAP expansion has */
395 					/*	occurred */
396 #define	PD_TKN_MACHINE	0x00040000	/* $MACHINE expansion has occurred */
397 #define	PD_TKN_RESOLVED	0x00080000	/* resolvepath() expansion has */
398 					/*	occurred */
399 #define	PD_MSK_EXPAND	0x000ff000	/* mask for all expansions */
400 
401 /*
402  * Define additional path information.  These definitions extend the path
403  * information, and may be passed into expand_path(), or set internally, or
404  * inherited from expand().  These definitions are or'd together with any
405  * LA_SER_ flags and PD_TKN_ flags.
406  */
407 #define	PD_FLG_PNSLASH	0x00100000	/* pd_pname contains a slash */
408 #define	PD_FLG_DUPLICAT	0x00200000	/* path is a duplicate */
409 #define	PD_FLG_EXTLOAD	0x00400000	/* path defines extra loaded objects */
410 					/*	(preload, audit etc.) */
411 #define	PD_FLG_UNIQUE	0x00800000	/* ensure path is unique */
412 #define	PD_FLG_USED	0x01000000	/* indicate that path is used */
413 #define	PD_FLG_FULLPATH	0x02000000	/* ensure path is a full path */
414 
415 #define	PD_MSK_INHERIT	0x0ffff000	/* mask for pd_flags incorporation */
416 
417 /*
418  * Additional token expansion information.  Although these flags may be set
419  * within a token data item return from expand(), they are masked off with
420  * PD_MSK_INHERIT prior to any expansion information being recorded in a path
421  * name descriptor for later diagnostics.
422  */
423 #define	TKN_NONE	0x00000001	/* no token expansion has occurred */
424 #define	TKN_DOTSLASH	0x00000002	/* path contains a "./" */
425 
426 /*
427  * dlopen() handle list size.
428  */
429 #define	HDLIST_SZ	101	/* prime no. for hashing */
430 #define	HDLIST_ORP	102	/* orphan handle list */
431 
432 /*
433  * Define a path name search descriptor.  This "cookie" maintains state as
434  * search paths are processed with get_next_dir().  Note, the path list is an
435  * indirect pointer, as search paths can be reevaluated for secure applications
436  * to provide better error diagnostics.
437  */
438 typedef struct {
439 	uchar_t		*sp_rule;	/* present search rule */
440 	Alist		**sp_dalpp;	/* present path list within rule */
441 	Aliste		sp_idx;		/* present index within path list */
442 } Spath_desc;
443 
444 /*
445  * Define a path name definition descriptor.  Used to maintain initial ELF and
446  * AOUT path name definitions.
447  */
448 typedef struct {
449 	const char	*sd_name;	/* path name */
450 	size_t		sd_len;		/* path name size */
451 } Spath_defn;
452 
453 /*
454  * Define _caller flags.
455  */
456 #define	CL_NONE		0
457 #define	CL_EXECDEF	1		/* supply the executable as a default */
458 					/* if the caller can't be determined */
459 
460 /*
461  * Binding information flags.  These flags are passed up from low level binding
462  * routines to indicate "additional" information, such as why a binding has been
463  * rejected.  These flags use the same data element as is used to record any
464  * DBG_BINFO flags.  The DBG_BINFO flags are used to define the final bindings
465  * information and are used to provide better binding diagnostics.
466  */
467 #define	BINFO_REJDIRECT		0x010000	/* reject a direct binding */
468 #define	BINFO_REJSINGLE		0x100000	/* reject a singleton binding */
469 #define	BINFO_REJGROUP		0x200000	/* reject a group binding */
470 
471 #define	BINFO_MSK_TRYAGAIN	0xf00000	/* a mask of bindings that */
472 						/*    should be retried */
473 #define	BINFO_MSK_REJECTED	0xff0000	/* a mask of bindings that */
474 						/*    have been rejected */
475 
476 /*
477  * The 32-bit version of rtld uses special stat() wrapper functions
478  * that preserve the non-largefile semantics of stat()/fstat() while
479  * allowing for large inode values. The 64-bit rtld uses stat() directly.
480  */
481 #ifdef _LP64
482 #define	rtld_fstat	fstat
483 #define	rtld_stat	stat
484 typedef	struct stat	rtld_stat_t;
485 #else
486 typedef struct {
487 	dev_t		st_dev;
488 	rtld_ino_t	st_ino;
489 	mode_t		st_mode;
490 	uid_t		st_uid;
491 	off_t		st_size;
492 	timestruc_t	st_mtim;
493 #ifdef sparc
494 	blksize_t	st_blksize;
495 #endif
496 } rtld_stat_t;
497 #endif
498 
499 /*
500  * Some capabilities aux vector definitions have been removed over time.
501  * However, existing objects may define these capabilities.  Establish
502  * capability masks that provide for deleting any removed capabilities, so
503  * that these capabilities are not used to validate the associated object.
504  *
505  * These masks are tightly coupled to the aux vector definitions in auxv_386.h
506  * and auxv_SPARC.h, however they are maintained here, as only ld.so.1 needs
507  * to remove these capabilities.  These definitions also describe where the
508  * flags are associated and allow for providing multi-architecture definitions
509  * should they become necessary, without having to pollute global header files.
510  */
511 #if	defined(__x86)
512 #define	AV_HW1_IGNORE	(0x8000 | 0x2000)	/* withdrawn MON and PAUSE */
513 #else						/*    auxv_386.h flags */
514 #define	AV_HW1_IGNORE	0
515 #endif
516 
517 /*
518  * Data declarations.
519  */
520 extern Lc_desc		glcs[];		/* global external interfaces */
521 
522 extern	Rt_lock		rtldlock;	/* rtld lock */
523 extern	int		thr_flg_nolock;
524 extern	int		thr_flg_reenter;
525 
526 extern APlist		*dynlm_list;	/* dynamic list of link-maps */
527 extern char		**environ;	/* environ pointer */
528 
529 extern int		dyn_plt_ent_size; /* Size of dynamic plt's */
530 extern ulong_t		at_flags;	/* machine specific file flags */
531 extern const char	*procname;	/* file name of executing process */
532 extern Rtld_db_priv	r_debug;	/* debugging information */
533 extern char		*lasterr;	/* string describing last error */
534 extern Interp		*interp;	/* ELF executable interpreter info */
535 extern const char	*rtldname;	/* name of the dynamic linker */
536 extern APlist		*hdl_alp[];	/* dlopen() handle list */
537 extern size_t		syspagsz;	/* system page size */
538 extern Isa_desc		*isa;		/* isalist descriptor */
539 extern Uts_desc		*uts;		/* utsname descriptor */
540 extern uint_t		rtld_flags;	/* status flags for RTLD */
541 extern uint_t		rtld_flags2;	/* additional status flags for RTLD */
542 extern uint32_t		pltcnt21d;	/* cnt of 21d PLTs */
543 extern uint32_t		pltcnt24d;	/* cnt of 24d PLTs */
544 extern uint32_t		pltcntu32;	/* cnt of u32 PLTs */
545 extern uint32_t		pltcntu44;	/* cnt of u44 PLTs */
546 extern uint32_t		pltcntfull;	/* cnt of full PLTs */
547 extern uint32_t		pltcntfar;	/* cnt of far PLTs */
548 extern uchar_t		search_rules[];	/* dependency search rules */
549 
550 extern Fct		elf_fct;	/* ELF file class dependent data */
551 
552 #if	defined(__sparc) && !defined(__sparcv9)
553 extern Fct		aout_fct;	/* a.out (4.x) file class dependent */
554 					/*	data */
555 #endif
556 
557 extern Config		*config;		/* configuration structure */
558 extern const char	*locale;		/* locale environment setting */
559 
560 extern const char	*rpl_audit;	/* replaceable LD_AUDIT string */
561 extern const char	*rpl_debug;	/* replaceable LD_DEBUG string */
562 extern const char	*rpl_ldflags;	/* replaceable LD_FLAGS string */
563 extern const char	*rpl_libpath;	/* replaceable LD_LIBRARY string */
564 extern Alist		*rpl_libdirs;	/*	and its associated Pdesc list */
565 extern const char	*rpl_preload;	/* replaceable LD_PRELOAD string */
566 
567 extern const char	*prm_audit;	/* permanent LD_AUDIT string */
568 extern const char	*prm_debug;	/* permanent LD_DEBUG string */
569 extern const char	*prm_ldflags;	/* permanent LD_FLAGS string */
570 extern const char	*prm_libpath;	/* permanent LD_LIBRARY string */
571 extern Alist		*prm_libdirs;	/*	and its associated Pdesc list */
572 extern const char	*prm_preload;	/* permanent LD_PRELOAD string */
573 
574 extern Alist		*elf_def_dirs;	/* ELF default directory seach paths */
575 extern Alist		*elf_sec_dirs;	/* ELF secure directory seach paths */
576 extern Alist		*aout_def_dirs;	/* AOUT default directory seach paths */
577 extern Alist		*aout_sec_dirs;	/* AOUT secure directory seach paths */
578 
579 extern uint_t		env_info;	/* information regarding environment */
580 					/*	variables */
581 extern int		killsig;	/* signal sent on fatal exit */
582 extern APlist		*free_alp;	/* defragmentation list */
583 
584 extern uint_t		audit_argcnt;	/* no. of stack args to copy */
585 extern Audit_desc	*auditors;	/* global auditors */
586 
587 extern char		**_environ;	/* environ reference for libc */
588 
589 extern const char	*dbg_file;	/* debugging directed to a file */
590 
591 extern Reglist		*reglist;	/* list of register symbols */
592 
593 extern const Msg	err_reject[];	/* rejection error message tables */
594 extern const Msg	ldd_reject[];
595 extern const Msg	ldd_warn[];
596 
597 extern const char	*profile_name;	/* object being profiled */
598 extern const char	*profile_out;	/* profile output file */
599 extern const char	*profile_lib;	/* audit library to perform profile */
600 
601 extern Dl_argsinfo	argsinfo;	/* process argument, environment and */
602 					/*	auxv information */
603 
604 extern const char	*err_strs[ERR_NUM];
605 					/* diagnostic error string headers */
606 extern const char	*nosym_str;	/* MSG_GEN_NOSYM message cache */
607 
608 extern Syscapset	*org_scapset;	/* original system capabilities */
609 extern Syscapset	*alt_scapset;	/* alternative system capabilities */
610 
611 extern const char	*rpl_hwcap;	/* replaceable hwcap str */
612 extern const char	*rpl_sfcap;	/* replaceable sfcap str */
613 extern const char	*rpl_machcap;	/* replaceable machcap str */
614 extern const char	*rpl_platcap;	/* replaceable platcap str */
615 extern const char	*rpl_cap_files;	/* associated files */
616 
617 extern const char	*prm_hwcap;	/* permanent hwcap str */
618 extern const char	*prm_sfcap;	/* permanent sfcap str */
619 extern const char	*prm_machcap;	/* permanent machcap str */
620 extern const char	*prm_platcap;	/* permanent platcap str */
621 extern const char	*prm_cap_files;	/* associated files */
622 
623 extern avl_tree_t	*capavl;	/* capabilities files */
624 extern avl_tree_t	*nfavl;		/* not-found path names */
625 extern avl_tree_t	*spavl;		/* secure path names */
626 
627 extern u_longlong_t	cnt_map;	/* Incr. for each object mapped */
628 extern u_longlong_t	cnt_unmap;	/* Incr. for each object unmapped */
629 
630 /*
631  * Function declarations.
632  */
633 extern void		addfree(void *, size_t);
634 extern int		append_alias(Rt_map *, const char *, int *);
635 extern Rt_map		*analyze_lmc(Lm_list *, Aliste, Rt_map *, int *);
636 extern void		atexit_fini(void);
637 extern int		bind_one(Rt_map *, Rt_map *, uint_t);
638 extern int		bufprint(Prfbuf *, const char *, ...);
639 extern void		call_array(Addr *, uint_t, Rt_map *, Word);
640 extern void		call_fini(Lm_list *, Rt_map **);
641 extern void		call_init(Rt_map **, int);
642 extern int		callable(Rt_map *, Rt_map *, Grp_hdl *, uint_t);
643 extern Rt_map		*_caller(caddr_t, int);
644 extern caddr_t		caller(void);
645 extern void		*calloc(size_t, size_t);
646 extern int		cap_alternative(void);
647 extern int		cap_check_fdesc(Fdesc *, Cap *, char *, Rej_desc *);
648 extern int		cap_check_lmp(Rt_map *, Rej_desc *);
649 extern int 		cap_filtees(Alist **, Aliste, const char *, Aliste,
650 			    Rt_map *, const char *, int, uint_t, int *);
651 extern int		cap_match(Sresult *, uint_t, Sym *, char *);
652 extern const char	*_conv_reloc_type(uint_t rel);
653 extern Aliste		create_cntl(Lm_list *, int);
654 extern void		defrag(void);
655 extern int		dbg_setup(const char *, Dbg_desc *);
656 extern const char	*demangle(const char *);
657 extern int		dlclose_intn(Grp_hdl *, Rt_map *);
658 extern int		dlclose_core(Grp_hdl *, Rt_map *, Lm_list *);
659 extern int		dlsym_handle(Grp_hdl *, Slookup *, Sresult *, uint_t *,
660 			    int *);
661 extern void		*dlsym_intn(void *, const char *, Rt_map *, Rt_map **);
662 extern Grp_hdl		*dlmopen_intn(Lm_list *, const char *, int, Rt_map *,
663 			    uint_t, uint_t);
664 extern size_t		doprf(const char *, va_list, Prfbuf *);
665 extern int		dowrite(Prfbuf *);
666 extern void		*dz_map(Lm_list *, caddr_t, size_t, int, int);
667 extern int		enter(int);
668 extern uint_t		expand(char **, size_t *, char **, uint_t, uint_t,
669 			    Rt_map *);
670 extern int		expand_paths(Rt_map *, const char *, Alist **, Aliste,
671 			    uint_t, uint_t);
672 extern void		free_hdl(Grp_hdl *);
673 extern void		file_notfound(Lm_list *, const char *, Rt_map *,
674 			    uint_t, Rej_desc *);
675 extern int		find_path(Lm_list *, Rt_map *, uint_t, Fdesc *,
676 			    Rej_desc *, int *);
677 extern int		fpavl_insert(Lm_list *, Rt_map *, const char *,
678 			    avl_index_t);
679 extern Rt_map		*fpavl_recorded(Lm_list *, const char *, uint_t,
680 			    avl_index_t *);
681 extern void		fpavl_remove(Rt_map *);
682 extern size_t		fullpath(Rt_map *, Fdesc *);
683 extern Lmid_t		get_linkmap_id(Lm_list *);
684 extern Pdesc		*get_next_dir(Spath_desc *, Rt_map *, uint_t);
685 extern Grp_desc		*hdl_add(Grp_hdl *, Rt_map *, uint_t, int *);
686 extern Grp_hdl		*hdl_create(Lm_list *, Rt_map *, Rt_map *, uint_t,
687 			    uint_t, uint_t);
688 extern int		hdl_initialize(Grp_hdl *, Rt_map *, int, int);
689 extern int		hwcap1_check(Syscapset *, Xword, Rej_desc *);
690 extern int		hwcap2_check(Syscapset *, Xword, Rej_desc *);
691 extern void		is_dep_init(Rt_map *, Rt_map *);
692 extern int		is_move_data(caddr_t);
693 extern int		is_path_secure(char *, Rt_map *, uint_t, uint_t);
694 extern int		is_rtld_setuid();
695 extern int		is_sym_interposer(Rt_map *, Sym *);
696 extern void		ldso_plt_init(Rt_map *);
697 extern void		leave(Lm_list *, int);
698 extern void		lm_append(Lm_list *, Aliste, Rt_map *);
699 extern void		lm_delete(Lm_list *, Rt_map *);
700 extern void		lm_move(Lm_list *, Aliste, Aliste, Lm_cntl *,
701 			    Lm_cntl *);
702 extern Rt_map 		*load_cap(Lm_list *, Aliste, const char *, Rt_map *,
703 			    uint_t, uint_t, Grp_hdl **, Rej_desc *, int *);
704 extern void		load_completion(Rt_map *);
705 extern Rt_map		*load_file(Lm_list *, Aliste, Fdesc *, int *);
706 extern Rt_map		*load_path(Lm_list *, Aliste, Rt_map *, int, uint_t,
707 			    Grp_hdl **, Fdesc *, Rej_desc *, int *);
708 extern Rt_map		*load_one(Lm_list *, Aliste, Alist *, Rt_map *, int,
709 			    uint_t, Grp_hdl **, int *);
710 extern const char	*load_trace(Lm_list *, Pdesc *, Rt_map *, Fdesc *);
711 extern void		nfavl_insert(const char *, avl_index_t);
712 extern void		*nu_map(Lm_list *, caddr_t, size_t, int, int);
713 extern Fct		*map_obj(Lm_list *, Fdesc *, size_t, const char *, int,
714 			    Rej_desc *);
715 extern void		*malloc(size_t);
716 extern int		machcap_check(Syscapset *, const char *, Rej_desc *);
717 extern void		machine_name(Syscapset *);
718 extern int		move_data(Rt_map *, APlist **);
719 extern int		platcap_check(Syscapset *, const char *, Rej_desc *);
720 extern void		platform_name(Syscapset *);
721 extern int		pnavl_recorded(avl_tree_t **, const char *, uint_t,
722 			    avl_index_t *);
723 extern void		rd_event(Lm_list *, rd_event_e, r_state_e);
724 extern int		readenv_user(const char **, Word *, Word *, int);
725 extern int		readenv_config(Rtc_env *, Addr, int);
726 extern void		rejection_inherit(Rej_desc *, Rej_desc *);
727 extern int		relocate_lmc(Lm_list *, Aliste, Rt_map *, Rt_map *,
728 			    int *);
729 extern int		relocate_finish(Rt_map *, APlist *, int);
730 extern void		remove_cntl(Lm_list *, Aliste);
731 extern int		remove_hdl(Grp_hdl *, Rt_map *, int *);
732 extern void		remove_lmc(Lm_list *, Rt_map *, Aliste, const char *);
733 extern void		remove_lml(Lm_list *);
734 extern void		remove_plist(Alist **, int);
735 extern void		remove_so(Lm_list *, Rt_map *);
736 extern int		rt_cond_wait(Rt_cond *, Rt_lock *);
737 extern int		rt_critical(void);
738 extern int		rt_bind_guard(int);
739 extern int		rt_bind_clear(int);
740 extern int		rt_get_extern(Lm_list *, Rt_map *);
741 extern int		rt_mutex_lock(Rt_lock *);
742 extern int		rt_mutex_unlock(Rt_lock *);
743 extern void		rt_thr_init(Lm_list *);
744 extern thread_t		rt_thr_self(void);
745 extern void		rtld_db_dlactivity(Lm_list *);
746 extern void		rtld_db_preinit(Lm_list *);
747 extern void		rtld_db_postinit(Lm_list *);
748 extern void		rtldexit(Lm_list *, int);
749 #ifndef _LP64
750 extern int		rtld_fstat(int, rtld_stat_t *restrict);
751 extern int		rtld_stat(const char *restrict, rtld_stat_t *restrict);
752 #endif
753 extern int		rtld_getopt(char **, char ***, auxv_t **, Word *,
754 			    Word *, int);
755 extern void		security(uid_t, uid_t, gid_t, gid_t, int);
756 extern void		set_environ(Lm_list *);
757 extern void		set_dirs(Alist **, Spath_defn *, uint_t);
758 extern int		set_prot(Rt_map *, mmapobj_result_t *, int);
759 extern Rt_map		*setup(char **, auxv_t *, Word, char *, int, char *,
760 			    ulong_t, ulong_t, int fd, Phdr *, char *, char **,
761 			    uid_t, uid_t, gid_t, gid_t, void *, int, uint_t);
762 extern const char	*stravl_insert(const char *, uint_t, size_t, int);
763 extern void		spavl_insert(const char *);
764 extern int		sfcap1_check(Syscapset *, Xword, Rej_desc *);
765 extern int		tls_assign(Lm_list *, Rt_map *, Phdr *);
766 extern void		tls_modaddrem(Rt_map *, uint_t);
767 extern int		tls_statmod(Lm_list *, Rt_map *);
768 extern Rt_map		**tsort(Rt_map *, int, int);
769 extern void		unused(Lm_list *);
770 extern void		unmap_obj(mmapobj_result_t *, uint_t);
771 extern int		update_mode(Rt_map *, int, int);
772 extern void		zero(caddr_t, size_t);
773 
774 #if	defined(__sparc)
775 /*
776  * SPARC Register symbol support.
777  */
778 extern int		elf_regsyms(Rt_map *);
779 extern void		set_sparc_g1(ulong_t);
780 extern void		set_sparc_g2(ulong_t);
781 extern void		set_sparc_g3(ulong_t);
782 extern void		set_sparc_g4(ulong_t);
783 extern void		set_sparc_g5(ulong_t);
784 extern void		set_sparc_g6(ulong_t);
785 extern void		set_sparc_g7(ulong_t);
786 #endif
787 
788 extern long		_sysconfig(int);
789 
790 #ifdef	__cplusplus
791 }
792 #endif
793 
794 #endif /* __RTLD_H */
795