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