xref: /illumos-gate/usr/src/cmd/sgs/rtld/common/_rtld.h (revision 48125817)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
55aefb655Srie  * Common Development and Distribution License (the "License").
65aefb655Srie  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
2156deab07SRod Evans 
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  *	Copyright (c) 1988 AT&T
247c478bd9Sstevel@tonic-gate  *	  All Rights Reserved
257c478bd9Sstevel@tonic-gate  *
26f441771bSRod Evans  * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
277c478bd9Sstevel@tonic-gate  */
28*ebb8ac07SRobert Mustacchi /*
29*ebb8ac07SRobert Mustacchi  * Copyright (c) 2012, Joyent, Inc.  All rights reserved.
30*ebb8ac07SRobert Mustacchi  */
317c478bd9Sstevel@tonic-gate #ifndef	__RTLD_H
327c478bd9Sstevel@tonic-gate #define	__RTLD_H
347c478bd9Sstevel@tonic-gate /*
357c478bd9Sstevel@tonic-gate  * Common header for run-time linker.
367c478bd9Sstevel@tonic-gate  */
377c478bd9Sstevel@tonic-gate #include <sys/types.h>
387c478bd9Sstevel@tonic-gate #include <sys/stat.h>
397c478bd9Sstevel@tonic-gate #include <sys/avl.h>
4056deab07SRod Evans #include <sys/mman.h>
417c478bd9Sstevel@tonic-gate #include <stdarg.h>
427c478bd9Sstevel@tonic-gate #include <synch.h>
437c478bd9Sstevel@tonic-gate #include <signal.h>
447c478bd9Sstevel@tonic-gate #include <errno.h>
457c478bd9Sstevel@tonic-gate #include <unistd.h>
467c478bd9Sstevel@tonic-gate #include <link.h>
477c478bd9Sstevel@tonic-gate #include <rtld.h>
487c478bd9Sstevel@tonic-gate #include <sgs.h>
497c478bd9Sstevel@tonic-gate #include <machdep.h>
507c478bd9Sstevel@tonic-gate #include <rtc.h>
515aefb655Srie #include <debug.h>
527c478bd9Sstevel@tonic-gate #include <msg.h>
537c478bd9Sstevel@tonic-gate #include <libc_int.h>
557c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
567c478bd9Sstevel@tonic-gate extern "C" {
577c478bd9Sstevel@tonic-gate #endif
597c478bd9Sstevel@tonic-gate /*
607c478bd9Sstevel@tonic-gate  * Dependency search rule order.
617c478bd9Sstevel@tonic-gate  */
627c478bd9Sstevel@tonic-gate #define	RPLENV		1		/* replaceable LD_LIBRARY_PATH */
637c478bd9Sstevel@tonic-gate #define	PRMENV		2		/* permanent LD_LIBRARY_PATH */
647c478bd9Sstevel@tonic-gate #define	RUNPATH		3		/* callers runpath */
657c478bd9Sstevel@tonic-gate #define	DEFAULT		4		/* default library path */
6756deab07SRod Evans typedef struct fdesc	Fdesc;
6856deab07SRod Evans typedef struct fct	Fct;
6956deab07SRod Evans typedef	struct pdesc	Pdesc;
717c478bd9Sstevel@tonic-gate /*
727c478bd9Sstevel@tonic-gate  * Data structure for file class specific functions and data.
737c478bd9Sstevel@tonic-gate  */
7456deab07SRod Evans struct fct {
7556deab07SRod Evans 	/* Verify that the object is of this class. */
7656deab07SRod Evans 	Fct	*(*fct_verify_file)(caddr_t, size_t, Fdesc *, const char *,
7756deab07SRod Evans 	    Rej_desc *);
7856deab07SRod Evans 
7956deab07SRod Evans 	/* Generate a link-map to describe the loaded object. */
8056deab07SRod Evans 	Rt_map	*(*fct_new_lmp)(Lm_list *, Aliste, Fdesc *, Addr, size_t,
812020b2b6SRod Evans 	    void *, Rt_map *, int *);
8256deab07SRod Evans 
8356deab07SRod Evans 	/* Retrieve the entry point of the object. */
8456deab07SRod Evans 	Addr	(*fct_entry_pt)(void);
8556deab07SRod Evans 
8656deab07SRod Evans 	/* Determine the objects dependencies (needed entries). */
879aa23310Srie 	int	(*fct_needed)(Lm_list *, Aliste, Rt_map *, int *);
8856deab07SRod Evans 
8956deab07SRod Evans 	/* Look up a symbol for the object. */
9008278a5eSRod Evans 	int	(*fct_lookup_sym)(Slookup *, Sresult *, uint_t *, int *);
9256deab07SRod Evans 	/* Relocate the object. */
9356deab07SRod Evans 	int	(*fct_reloc)(Rt_map *, uint_t, int *, APlist **);
9556deab07SRod Evans 	/* List of default directories to search for dependencies. */
9656deab07SRod Evans 	Alist	**(*fct_get_def_dirs)(void);
9756deab07SRod Evans 
9856deab07SRod Evans 	/* List of secure directories to search for dependencies. */
9956deab07SRod Evans 	Alist	**(*fct_get_sec_dirs)(void);
10156deab07SRod Evans 	/* Transpose the name of the object. */
10256deab07SRod Evans 	int	(*fct_fix_name)(const char *, Rt_map *, Alist **, Aliste,
10356deab07SRod Evans 	    uint_t);
10456deab07SRod Evans 
10556deab07SRod Evans 	/* Get a shared object name */
10656deab07SRod Evans 	char	*(*fct_get_so)(const char *, const char *, size_t, size_t);
10756deab07SRod Evans 
10856deab07SRod Evans 	/* Retrieve a symbolic address from the object. */
10956deab07SRod Evans 	void	(*fct_dladdr)(ulong_t, Rt_map *, Dl_info *, void **, int);
11056deab07SRod Evans 
11156deab07SRod Evans 	/* Process a dlsym(3c) request within the object. */
11208278a5eSRod Evans 	int	(*fct_dlsym)(Grp_hdl *, Slookup *, Sresult *, uint_t *, int *);
11356deab07SRod Evans };
1157c478bd9Sstevel@tonic-gate /*
1167c478bd9Sstevel@tonic-gate  * Macros for getting to the file class table.
1177c478bd9Sstevel@tonic-gate  */
1187c478bd9Sstevel@tonic-gate #define	LM_ENTRY_PT(X)		((X)->rt_fct->fct_entry_pt)
1197c478bd9Sstevel@tonic-gate #define	LM_NEEDED(X)		((X)->rt_fct->fct_needed)
1207c478bd9Sstevel@tonic-gate #define	LM_LOOKUP_SYM(X)	((X)->rt_fct->fct_lookup_sym)
1217c478bd9Sstevel@tonic-gate #define	LM_RELOC(X)		((X)->rt_fct->fct_reloc)
12256deab07SRod Evans #define	LM_DEFAULT_DIRS(X)	((X)->rt_fct->fct_get_def_dirs)
12356deab07SRod Evans #define	LM_SECURE_DIRS(X)	((X)->rt_fct->fct_get_sec_dirs)
1247c478bd9Sstevel@tonic-gate #define	LM_FIX_NAME(X)		((X)->rt_fct->fct_fix_name)
1257c478bd9Sstevel@tonic-gate #define	LM_GET_SO(X)		((X)->rt_fct->fct_get_so)
1267c478bd9Sstevel@tonic-gate #define	LM_DLADDR(X)		((X)->rt_fct->fct_dladdr)
1277c478bd9Sstevel@tonic-gate #define	LM_DLSYM(X)		((X)->rt_fct->fct_dlsym)
12956deab07SRod Evans /*
13056deab07SRod Evans  * Initial memory map allocation.  Typical ELF objects contain a text and data
13156deab07SRod Evans  * segment, which can be augmented with a bss mapping.  Add a bunch more for
13256deab07SRod Evans  * luck.
13356deab07SRod Evans  */
13456deab07SRod Evans #define	MMAPFD_NUM	10
1367c478bd9Sstevel@tonic-gate /*
13756deab07SRod Evans  * Define Alist initialization counts.
1387c478bd9Sstevel@tonic-gate  */
13956deab07SRod Evans #define	AL_CNT_ALIAS	2		/* ALIAS() */
140a4bc8592SRod Evans #define	AL_CNT_DEPENDS	20		/* DEPENDS() */
141a4bc8592SRod Evans #define	AL_CNT_CALLERS	20		/* CALLERS() */
1422017c965SRod Evans #define	AL_CNT_GROUPS	20		/* GROUPS() */
14356deab07SRod Evans #define	AL_CNT_COPYREL	10		/* COPY() */
14456deab07SRod Evans #define	AL_CNT_LAZYFIND	10		/* elf_lazy_find_sym() */
14556deab07SRod Evans #define	AL_CNT_GRPCLCT	10		/* gdp_collect() */
14656deab07SRod Evans #define	AL_CNT_DEPCLCT	10		/* load_finish() */
14756deab07SRod Evans #define	AL_CNT_RTLDINFO	1		/* RTLDINFO() */
14856deab07SRod Evans #define	AL_CNT_FPNODE	4		/* FPNODE() */
149481bba9eSRod Evans #define	AL_CNT_LMLISTS	20		/* lm_lists */
15056deab07SRod Evans #define	AL_CNT_LMNOW	8		/* lm_now */
15156deab07SRod Evans #define	AL_CNT_RELBIND	20		/* relocation binding */
15256deab07SRod Evans #define	AL_CNT_ACTAUDIT	2		/* lm_actaudit */
15356deab07SRod Evans #define	AL_CNT_MOVES	10		/* move_data */
15456deab07SRod Evans #define	AL_CNT_MPOBJS	4		/* elf_obj_file() */
15556deab07SRod Evans #define	AL_CNT_TEXTREL	2		/* text relocation segment */
15656deab07SRod Evans #define	AL_CNT_NEEDED	1		/* dependency path */
15756deab07SRod Evans #define	AL_CNT_SEARCH	4		/* search path */
15856deab07SRod Evans #define	AL_CNT_FILTEES	2		/* filtee path */
15956deab07SRod Evans #define	AL_CNT_HANDLES	1		/* hdl_list[] */
160a4bc8592SRod Evans #define	AL_CNT_FREELIST	80		/* free_alp */
16108278a5eSRod Evans #define	AL_CNT_CAP	10		/* capabilities candidate */
16256deab07SRod Evans #define	AL_CNT_SPATH	4		/* search path */
16357ef7aa9SRod Evans #define	AL_CNT_DYNLIST	2		/* dynlm_list */
16457ef7aa9SRod Evans #define	AL_CNT_PENDING	2		/* pending tsort list (INITFIRST) */
16557ef7aa9SRod Evans #define	AL_CNT_PLTPAD	10		/* plt padding */
16657ef7aa9SRod Evans #define	AL_CNT_AUDITORS	2		/* auditing list */
1671c1abfbcSRod Evans #define	AL_CNT_ENVIRON	20		/* environment list (enough for ldd) */
1682020b2b6SRod Evans #define	AL_CNT_COOKIES	2		/* head link-map list cookies */
1707c478bd9Sstevel@tonic-gate /*
1717c478bd9Sstevel@tonic-gate  * Size of buffer for building error messages.
1727c478bd9Sstevel@tonic-gate  */
1737c478bd9Sstevel@tonic-gate #define	ERRSIZE		2048		/* MAXPATHLEN * 2 */
1757c478bd9Sstevel@tonic-gate /*
1767c478bd9Sstevel@tonic-gate  * Configuration file information.
1777c478bd9Sstevel@tonic-gate  */
1787c478bd9Sstevel@tonic-gate typedef struct config {
1797c478bd9Sstevel@tonic-gate 	const char	*c_name;
1807c478bd9Sstevel@tonic-gate 	Addr		c_bgn;
1817c478bd9Sstevel@tonic-gate 	Addr		c_end;
1827c478bd9Sstevel@tonic-gate 	Word		*c_hashtbl;
1837c478bd9Sstevel@tonic-gate 	Word		*c_hashchain;
1847c478bd9Sstevel@tonic-gate 	const char	*c_strtbl;
1857c478bd9Sstevel@tonic-gate 	Rtc_obj		*c_objtbl;
1867c478bd9Sstevel@tonic-gate 	Rtc_fltr	*c_fltr;
1877c478bd9Sstevel@tonic-gate 	Rtc_flte	*c_flte;
1887c478bd9Sstevel@tonic-gate } Config;
1907c478bd9Sstevel@tonic-gate /*
1917c478bd9Sstevel@tonic-gate  * Register symbol list.
1927c478bd9Sstevel@tonic-gate  */
1937c478bd9Sstevel@tonic-gate typedef struct reglist {
1947c478bd9Sstevel@tonic-gate 	Rt_map		*rl_lmp;	/* defining object */
1957c478bd9Sstevel@tonic-gate 	Sym		*rl_sym;	/* regsym */
1967c478bd9Sstevel@tonic-gate 	struct reglist	*rl_next;	/* next entry */
1977c478bd9Sstevel@tonic-gate } Reglist;
1997c478bd9Sstevel@tonic-gate /*
2007c478bd9Sstevel@tonic-gate  * Data structure to hold interpreter information.
2017c478bd9Sstevel@tonic-gate  */
2027c478bd9Sstevel@tonic-gate typedef struct interp {
2037c478bd9Sstevel@tonic-gate 	char		*i_name;	/* interpreter name */
2047c478bd9Sstevel@tonic-gate 	caddr_t		i_faddr;	/* address interpreter is mapped at */
2057c478bd9Sstevel@tonic-gate } Interp;
2077c478bd9Sstevel@tonic-gate /*
2087c478bd9Sstevel@tonic-gate  * Data structure used to keep track of copy relocations.  These relocations
2097c478bd9Sstevel@tonic-gate  * are collected during initial relocation processing and maintained on the
2107c478bd9Sstevel@tonic-gate  * COPY(lmp) list of the defining object.  Each copy list is also added to the
2117c478bd9Sstevel@tonic-gate  * COPY(lmp) of the head object (normally the application dynamic executable)
2127c478bd9Sstevel@tonic-gate  * from which they will be processed after all relocations are done.
2137c478bd9Sstevel@tonic-gate  *
2147c478bd9Sstevel@tonic-gate  * The use of RTLD_GROUP will also reference individual objects COPY(lmp) lists
2157c478bd9Sstevel@tonic-gate  * in case a bound symbol must be assigned to it actual copy relocation.
2167c478bd9Sstevel@tonic-gate  */
2177c478bd9Sstevel@tonic-gate typedef struct {
2187c478bd9Sstevel@tonic-gate 	const char	*r_name;	/* symbol name */
2197c478bd9Sstevel@tonic-gate 	Sym		*r_rsym;	/* reference symbol table entry */
2207c478bd9Sstevel@tonic-gate 	Rt_map		*r_rlmp;	/* reference link map */
2217c478bd9Sstevel@tonic-gate 	Rt_map		*r_dlmp;	/* definition link map */
2227c478bd9Sstevel@tonic-gate 	Sym		*r_dsym;	/* definition symbol table entry */
2237c478bd9Sstevel@tonic-gate 	void		*r_radd;	/* copy to address */
2247c478bd9Sstevel@tonic-gate 	const void	*r_dadd;	/* copy from address */
2257c478bd9Sstevel@tonic-gate 	ulong_t		r_size;		/* copy size bytes */
2267c478bd9Sstevel@tonic-gate } Rel_copy;
2287c478bd9Sstevel@tonic-gate /*
2297c478bd9Sstevel@tonic-gate  * Define a file descriptor, which maintains information regarding a pathname
2307c478bd9Sstevel@tonic-gate  * that has been opened and minimally inspected.
2317c478bd9Sstevel@tonic-gate  */
23256deab07SRod Evans struct fdesc {
2337c478bd9Sstevel@tonic-gate 	Rt_map		*fd_lmp;	/* existing link-map pointer */
2341c1abfbcSRod Evans 	Lm_list		*fd_lml;	/* callers link-map list */
2357c478bd9Sstevel@tonic-gate 	Fct		*fd_ftp;	/* file functions pointer */
2367c478bd9Sstevel@tonic-gate 	const char	*fd_oname;	/* original file name */
2377c478bd9Sstevel@tonic-gate 	const char	*fd_odir;	/* original directory name */
2387c478bd9Sstevel@tonic-gate 	const char	*fd_nname;	/* new file (expanded) name */
2397c478bd9Sstevel@tonic-gate 	const char	*fd_pname;	/* new path (resolved) name */
2407c478bd9Sstevel@tonic-gate 	dev_t		fd_dev;		/* file device number */
241cb511613SAli Bahrami 	rtld_ino_t	fd_ino;		/* file inode number */
2427c478bd9Sstevel@tonic-gate 	avl_index_t	fd_avlwhere;	/* avl tree insertion index */
24308278a5eSRod Evans 	Syscapset	fd_scapset;	/* capabilities */
24456deab07SRod Evans 	mmapobj_result_t *fd_mapp;	/* mapping pointer */
24556deab07SRod Evans 	uint_t		fd_mapn;	/* mapping number */
2461c1abfbcSRod Evans 	uint_t		fd_flags;
24756deab07SRod Evans };
24956deab07SRod Evans #define	FLG_FD_ALTER	0x0001		/* file is an alternate */
25056deab07SRod Evans #define	FLG_FD_SLASH	0x0002		/* file contains a "/" */
25156deab07SRod Evans #define	FLG_FD_RESOLVED	0x0004		/* fd_nname has been resolved */
25208278a5eSRod Evans #define	FLG_FD_ALTCHECK	0x0008		/* alternative system capabilities */
25308278a5eSRod Evans 					/*	checked */
25408278a5eSRod Evans #define	FLG_FD_ALTCAP	0x0010		/* alternative system capabilities */
25508278a5eSRod Evans 					/*	should be used */
2561c1abfbcSRod Evans #define	FLG_FD_IGNORE	0x0020		/* descriptor should be ignored */
2587c478bd9Sstevel@tonic-gate /*
2597c478bd9Sstevel@tonic-gate  * File descriptor availability flag.
2607c478bd9Sstevel@tonic-gate  */
2617c478bd9Sstevel@tonic-gate #define	FD_UNAVAIL	-1
2637c478bd9Sstevel@tonic-gate /*
2647c478bd9Sstevel@tonic-gate  * Disabled filter flag.  Filter objects are referenced using their .dynamic
2657c478bd9Sstevel@tonic-gate  * index (DT_FILTER or DT_AUXILIARY).  This index is saved and used to lookup
2667c478bd9Sstevel@tonic-gate  * the required filter.  Note that 0 is a valid .dynamic index.  The caller's
2677c478bd9Sstevel@tonic-gate  * OBJFLTRNDX() element is initialized using the following flag, and should
2687c478bd9Sstevel@tonic-gate  * the filter's initialization fail, is reset to this value to indicate the
2697c478bd9Sstevel@tonic-gate  * filter is disabled.  UINT_MAX provides a convenient invalid .dynamic index.
2707c478bd9Sstevel@tonic-gate  */
2717c478bd9Sstevel@tonic-gate #define	FLTR_DISABLED	UINT_MAX
2737c478bd9Sstevel@tonic-gate /*
2747c478bd9Sstevel@tonic-gate  * Status flags for rtld_flags
2757c478bd9Sstevel@tonic-gate  */
2767c478bd9Sstevel@tonic-gate #define	RT_FL_THREADS	0x00000001	/* threads are enabled */
2777c478bd9Sstevel@tonic-gate #define	RT_FL_WARNFLTR	0x00000002	/* warn of missing filtees (ldd) */
2787c478bd9Sstevel@tonic-gate #define	RT_FL_DBNOTIF	0x00000004	/* binding activity going on */
279f441771bSRod Evans #define	RT_FL_DEFERRED	0x00000008	/* load deferred dependencies (ldd) */
2807c478bd9Sstevel@tonic-gate #define	RT_FL_NOBIND	0x00000010	/* don't carry out plt binding */
2817c478bd9Sstevel@tonic-gate #define	RT_FL_NOVERSION	0x00000020	/* disable version checking */
2827c478bd9Sstevel@tonic-gate #define	RT_FL_SECURE	0x00000040	/* setuid/segid flag */
2832020b2b6SRod Evans #define	RT_FL_APPLIC	0x00000080	/* executing application code */
2841c1abfbcSRod Evans #define	RT_FL_NOENVIRON	0x00000100	/* don't process environment */
2851c1abfbcSRod Evans 					/*	variables (ld.so.1 -e) */
2867c478bd9Sstevel@tonic-gate #define	RT_FL_CONFGEN	0x00000200	/* don't relocate initiating object */
2871c1abfbcSRod Evans 					/*	set by crle(1) */
2887c478bd9Sstevel@tonic-gate #define	RT_FL_CONFAPP	0x00000400	/* application specific configuration */
2897c478bd9Sstevel@tonic-gate 					/*	cache required */
2907c478bd9Sstevel@tonic-gate #define	RT_FL_DEBUGGER	0x00000800	/* a debugger is monitoring us */
2919aa23310Srie #define	RT_FL_OPERATION	0x00001000	/* start recording operations */
2927c478bd9Sstevel@tonic-gate #define	RT_FL_NEWLOCALE	0x00002000	/* message locale has changed */
2937c478bd9Sstevel@tonic-gate #define	RT_FL_NOBAPLT	0x00004000	/* sparc: don't use ba plt's */
2947c478bd9Sstevel@tonic-gate #define	RT_FL_NOAUXFLTR	0x00008000	/* disable auxiliary filters */
29556deab07SRod Evans 
2967c478bd9Sstevel@tonic-gate #define	RT_FL_NOAUDIT	0x00020000	/* disable auditing */
2977c478bd9Sstevel@tonic-gate #define	RT_FL_ATEXIT	0x00040000	/* we're shutting down */
2987c478bd9Sstevel@tonic-gate #define	RT_FL_SILENCERR	0x00080000	/* silence error messages */
29956deab07SRod Evans 
3007c478bd9Sstevel@tonic-gate #define	RT_FL_INITFIRST	0x00200000	/* processing a DT_INITFIRST object */
30156deab07SRod Evans 
3027c478bd9Sstevel@tonic-gate #define	RT_FL_DEMANGLE	0x01000000	/* demangle C++ symbol names */
3037c478bd9Sstevel@tonic-gate #define	RT_FL_NOCFG	0x02000000	/* disable config file use */
3047c478bd9Sstevel@tonic-gate #define	RT_FL_NODIRCFG	0x04000000	/* disable directory config use */
3057c478bd9Sstevel@tonic-gate #define	RT_FL_NOOBJALT	0x08000000	/* disable object alternative use */
3067c478bd9Sstevel@tonic-gate #define	RT_FL_NOENVCFG	0x10000000	/* disable config envars use */
3077c478bd9Sstevel@tonic-gate #define	RT_FL_DIRCFG	0x20000000	/* directory config info available */
3087c478bd9Sstevel@tonic-gate #define	RT_FL_OBJALT	0x40000000	/* object alternatives are available */
3097c478bd9Sstevel@tonic-gate #define	RT_FL_MEMRESV	0x80000000	/* memory reservation established */
3117c478bd9Sstevel@tonic-gate /*
3127c478bd9Sstevel@tonic-gate  * Status flags for rtld_flags2
3137c478bd9Sstevel@tonic-gate  */
3145aefb655Srie #define	RT_FL2_HASAUDIT	0x00000001	/* auditing lm_list is present */
3157c478bd9Sstevel@tonic-gate #define	RT_FL2_RTLDSEEN	0x00000002	/* rtldinfo has been set */
3165aefb655Srie #define	RT_FL2_UNIFPROC	0x00000004	/* libc/libthread unified environment */
31756deab07SRod Evans 
3187c478bd9Sstevel@tonic-gate #define	RT_FL2_NOFLTCFG	0x00000010	/* disable config filter use */
3197c478bd9Sstevel@tonic-gate #define	RT_FL2_FLTCFG	0x00000020	/* filter config info available */
3207c478bd9Sstevel@tonic-gate #define	RT_FL2_HWCAP	0x00000040	/* hardware capabilities available */
3217c478bd9Sstevel@tonic-gate #define	RT_FL2_FTL2WARN	0x00000080	/* convert fatal to warning messages */
3227c478bd9Sstevel@tonic-gate #define	RT_FL2_BINDNOW	0x00000100	/* LD_BIND_NOW in effect */
323dffec89cSrie #define	RT_FL2_BINDLAZY	0x00000200	/* disable RTLD_NOW (and LD_BIND_NOW) */
32410a4fa49Srie #define	RT_FL2_PLMSETUP	0x00000400	/* primary link-map set up complete */
3259aa23310Srie #define	RT_FL2_BRANDED	0x00000800	/* process is branded */
3269aa23310Srie #define	RT_FL2_NOPLM	0x00001000	/* process has no primary link map */
3273dbfc803SRod Evans #define	RT_FL2_SETUID	0x00002000	/* ld.so.1 is setuid root */
328bebb829dSRod Evans #define	RT_FL2_ADDR32	0x00004000	/* 32-bit address space requirement */
3307c478bd9Sstevel@tonic-gate /*
3317c478bd9Sstevel@tonic-gate  * Information flags for env_info.
3327c478bd9Sstevel@tonic-gate  */
3337c478bd9Sstevel@tonic-gate #define	ENV_INF_PATHCFG	0x00000001	/* replaceable LD_LIBRARY_PATH */
3347c478bd9Sstevel@tonic-gate 					/*	originates from configuration */
3357c478bd9Sstevel@tonic-gate 					/*	file */
3367c478bd9Sstevel@tonic-gate #define	ENV_INF_FLAGCFG	0x00000002	/* replaceable LD_FLAGS originates */
3377c478bd9Sstevel@tonic-gate 					/*	from configuration file */
3397c478bd9Sstevel@tonic-gate /*
34010a4fa49Srie  * RTLDINFO descriptor.
34110a4fa49Srie  */
34210a4fa49Srie typedef struct {
34310a4fa49Srie 	Rt_map		*rti_lmp;	/* RTLDINFO provider */
34410a4fa49Srie 	Lc_interface	*rti_info;	/* RTLDINFO data */
34510a4fa49Srie } Rti_desc;
34710a4fa49Srie /*
34856deab07SRod Evans  * Binding flags for the rt_bind_guard()/rt_bind_clear() routines.
3498cd45542Sraf  * These are defined in usr/src/lib/libc/inc/libc_int.h in the
3508cd45542Sraf  * latest version of the libc/rtld runtime interface (CI_V_FIVE).
3517c478bd9Sstevel@tonic-gate  */
3528cd45542Sraf #if !defined(CI_V_FIVE)
35356deab07SRod Evans #define	THR_FLG_RTLD	0x00000001	/* rtldlock bind guard flag */
3548cd45542Sraf #define	THR_FLG_NOLOCK	0x00000000	/* no-op before CI_V_FIVE */
3558cd45542Sraf #define	THR_FLG_REENTER	0x00000000	/* no-op before CI_V_FIVE */
3568cd45542Sraf #endif
3589aa23310Srie #define	ROUND(x, a)	(((int)(x) + ((int)(a) - 1)) & ~((int)(a) - 1))
3607c478bd9Sstevel@tonic-gate /*
3617c478bd9Sstevel@tonic-gate  * Print buffer.
3627c478bd9Sstevel@tonic-gate  */
3637c478bd9Sstevel@tonic-gate typedef struct {
3647c478bd9Sstevel@tonic-gate 	char	*pr_buf;	/* pointer to beginning of buffer */
3657c478bd9Sstevel@tonic-gate 	char	*pr_cur;	/* pointer to next free char in buffer */
3667c478bd9Sstevel@tonic-gate 	size_t	pr_len;		/* buffer size */
3677c478bd9Sstevel@tonic-gate 	int	pr_fd;		/* output fd */
3687c478bd9Sstevel@tonic-gate } Prfbuf;
3707c478bd9Sstevel@tonic-gate /*
37156deab07SRod Evans  * Path name descriptor.  Used to construct various path names such as search
37256deab07SRod Evans  * paths, dependency paths, filter paths etc.  The pd_info element can be used
37356deab07SRod Evans  * to hold various pointers, like Grp_hdl, Rtc_obj, etc.
3747c478bd9Sstevel@tonic-gate  */
37556deab07SRod Evans struct pdesc {
37656deab07SRod Evans 	const char	*pd_pname;	/* path name - may be expanded */
37756deab07SRod Evans 	const char	*pd_oname;	/* original name - unexpanded */
37856deab07SRod Evans 	void		*pd_info;	/* possible auxiliary information */
37956deab07SRod Evans 	size_t		pd_plen;	/* path name length */
38056deab07SRod Evans 	uint_t		pd_flags;	/* descriptor specific flags */
38156deab07SRod Evans };
3837c478bd9Sstevel@tonic-gate /*
38456deab07SRod Evans  * Path name descriptors are passed to expand_path() and expand().  These
38556deab07SRod Evans  * routines break down possible multiple path strings (separated with ":"),
38656deab07SRod Evans  * and perform any reserved token expansion.  These routines are passed
38756deab07SRod Evans  * information that indicates the use of the path, for example, search paths,
38856deab07SRod Evans  * i.e., LD_LIBRARY_PATH, RPATHS, etc. are defined using la_objsearch()
38956deab07SRod Evans  * information (see LA_SER flags in link.h).  This information is recorded in
39056deab07SRod Evans  * the pd_flags field for later use.
39156deab07SRod Evans  *
39256deab07SRod Evans  * Define expansion path tokens.  These are used to prevent various expansions
39356deab07SRod Evans  * from occurring, and record those expansions that do.  Any expansion
39456deab07SRod Evans  * information is also recorded in the pd_flags field, and thus is or'd
39556deab07SRod Evans  * together with any LA_SER flags.
39656deab07SRod Evans  */
39756deab07SRod Evans #define	PD_TKN_ORIGIN	0x00001000	/* $ORIGIN expansion has occurred */
39856deab07SRod Evans #define	PD_TKN_PLATFORM	0x00002000	/* $PLATFORM expansion has occurred */
39956deab07SRod Evans #define	PD_TKN_OSNAME	0x00004000	/* $OSNAME expansion has occurred */
40056deab07SRod Evans #define	PD_TKN_OSREL	0x00008000	/* $OSREL expansion has occurred */
40156deab07SRod Evans #define	PD_TKN_ISALIST	0x00010000	/* $ISALIST expansion has occurred */
40208278a5eSRod Evans #define	PD_TKN_CAP	0x00020000	/* $CAPABILITY/$HWCAP expansion has */
40308278a5eSRod Evans 					/*	occurred */
40408278a5eSRod Evans #define	PD_TKN_MACHINE	0x00040000	/* $MACHINE expansion has occurred */
40508278a5eSRod Evans #define	PD_TKN_RESOLVED	0x00080000	/* resolvepath() expansion has */
40656deab07SRod Evans 					/*	occurred */
40756deab07SRod Evans #define	PD_MSK_EXPAND	0x000ff000	/* mask for all expansions */
40856deab07SRod Evans 
40956deab07SRod Evans /*
41056deab07SRod Evans  * Define additional path information.  These definitions extend the path
41156deab07SRod Evans  * information, and may be passed into expand_path(), or set internally, or
41256deab07SRod Evans  * inherited from expand().  These definitions are or'd together with any
41356deab07SRod Evans  * LA_SER_ flags and PD_TKN_ flags.
41456deab07SRod Evans  */
41556deab07SRod Evans #define	PD_FLG_PNSLASH	0x00100000	/* pd_pname contains a slash */
41656deab07SRod Evans #define	PD_FLG_DUPLICAT	0x00200000	/* path is a duplicate */
41756deab07SRod Evans #define	PD_FLG_EXTLOAD	0x00400000	/* path defines extra loaded objects */
4187c478bd9Sstevel@tonic-gate 					/*	(preload, audit etc.) */
41956deab07SRod Evans #define	PD_FLG_UNIQUE	0x00800000	/* ensure path is unique */
42056deab07SRod Evans #define	PD_FLG_USED	0x01000000	/* indicate that path is used */
42156deab07SRod Evans #define	PD_FLG_FULLPATH	0x02000000	/* ensure path is a full path */
42356deab07SRod Evans #define	PD_MSK_INHERIT	0x0ffff000	/* mask for pd_flags incorporation */
4257c478bd9Sstevel@tonic-gate /*
42656deab07SRod Evans  * Additional token expansion information.  Although these flags may be set
42756deab07SRod Evans  * within a token data item return from expand(), they are masked off with
42856deab07SRod Evans  * PD_MSK_INHERIT prior to any expansion information being recorded in a path
42956deab07SRod Evans  * name descriptor for later diagnostics.
43056deab07SRod Evans  */
43156deab07SRod Evans #define	TKN_NONE	0x00000001	/* no token expansion has occurred */
43256deab07SRod Evans #define	TKN_DOTSLASH	0x00000002	/* path contains a "./" */
43356deab07SRod Evans 
43456deab07SRod Evans /*
43556deab07SRod Evans  * dlopen() handle list size.
4367c478bd9Sstevel@tonic-gate  */
43756deab07SRod Evans #define	HDLIST_SZ	101	/* prime no. for hashing */
43856deab07SRod Evans #define	HDLIST_ORP	102	/* orphan handle list */
44056deab07SRod Evans /*
44156deab07SRod Evans  * Define a path name search descriptor.  This "cookie" maintains state as
44256deab07SRod Evans  * search paths are processed with get_next_dir().  Note, the path list is an
44356deab07SRod Evans  * indirect pointer, as search paths can be reevaluated for secure applications
44456deab07SRod Evans  * to provide better error diagnostics.
44556deab07SRod Evans  */
44656deab07SRod Evans typedef struct {
44756deab07SRod Evans 	uchar_t		*sp_rule;	/* present search rule */
44856deab07SRod Evans 	Alist		**sp_dalpp;	/* present path list within rule */
44956deab07SRod Evans 	Aliste		sp_idx;		/* present index within path list */
45056deab07SRod Evans } Spath_desc;
4529aa23310Srie /*
45356deab07SRod Evans  * Define a path name definition descriptor.  Used to maintain initial ELF and
45456deab07SRod Evans  * AOUT path name definitions.
4559aa23310Srie  */
45656deab07SRod Evans typedef struct {
45756deab07SRod Evans 	const char	*sd_name;	/* path name */
45856deab07SRod Evans 	size_t		sd_len;		/* path name size */
45956deab07SRod Evans } Spath_defn;
4617c478bd9Sstevel@tonic-gate /*
4627c478bd9Sstevel@tonic-gate  * Define _caller flags.
4637c478bd9Sstevel@tonic-gate  */
4647c478bd9Sstevel@tonic-gate #define	CL_NONE		0
4657c478bd9Sstevel@tonic-gate #define	CL_EXECDEF	1		/* supply the executable as a default */
4667c478bd9Sstevel@tonic-gate 					/* if the caller can't be determined */
4687c478bd9Sstevel@tonic-gate /*
46937ffaf83SRod Evans  * Binding information flags.  These flags are passed up from low level binding
47037ffaf83SRod Evans  * routines to indicate "additional" information, such as why a binding has been
47137ffaf83SRod Evans  * rejected.  These flags use the same data element as is used to record any
47237ffaf83SRod Evans  * DBG_BINFO flags.  The DBG_BINFO flags are used to define the final bindings
47337ffaf83SRod Evans  * information and are used to provide better binding diagnostics.
4747c478bd9Sstevel@tonic-gate  */
47537ffaf83SRod Evans #define	BINFO_REJDIRECT		0x010000	/* reject a direct binding */
47637ffaf83SRod Evans #define	BINFO_REJSINGLE		0x100000	/* reject a singleton binding */
47737ffaf83SRod Evans #define	BINFO_REJGROUP		0x200000	/* reject a group binding */
47837ffaf83SRod Evans 
47937ffaf83SRod Evans #define	BINFO_MSK_TRYAGAIN	0xf00000	/* a mask of bindings that */
48037ffaf83SRod Evans 						/*    should be retried */
48137ffaf83SRod Evans #define	BINFO_MSK_REJECTED	0xff0000	/* a mask of bindings that */
48237ffaf83SRod Evans 						/*    have been rejected */
483cb511613SAli Bahrami 
484cb511613SAli Bahrami /*
485cb511613SAli Bahrami  * The 32-bit version of rtld uses special stat() wrapper functions
486cb511613SAli Bahrami  * that preserve the non-largefile semantics of stat()/fstat() while
487cb511613SAli Bahrami  * allowing for large inode values. The 64-bit rtld uses stat() directly.
488cb511613SAli Bahrami  */
489cb511613SAli Bahrami #ifdef _LP64
490cb511613SAli Bahrami #define	rtld_fstat	fstat
491cb511613SAli Bahrami #define	rtld_stat	stat
492cb511613SAli Bahrami typedef	struct stat	rtld_stat_t;
493cb511613SAli Bahrami #else
494cb511613SAli Bahrami typedef struct {
495cb511613SAli Bahrami 	dev_t		st_dev;
496cb511613SAli Bahrami 	rtld_ino_t	st_ino;
497cb511613SAli Bahrami 	mode_t		st_mode;
498cb511613SAli Bahrami 	uid_t		st_uid;
499cb511613SAli Bahrami 	off_t		st_size;
500cb511613SAli Bahrami 	timestruc_t	st_mtim;
501cb511613SAli Bahrami #ifdef sparc
502cb511613SAli Bahrami 	blksize_t	st_blksize;
503cb511613SAli Bahrami #endif
504cb511613SAli Bahrami } rtld_stat_t;
505cb511613SAli Bahrami #endif
506cb511613SAli Bahrami 
5074e12d685SRod Evans /*
5084e12d685SRod Evans  * Some capabilities aux vector definitions have been removed over time.
5094e12d685SRod Evans  * However, existing objects may define these capabilities.  Establish
5104e12d685SRod Evans  * capability masks that provide for deleting any removed capabilities, so
5114e12d685SRod Evans  * that these capabilities are not used to validate the associated object.
5124e12d685SRod Evans  *
5134e12d685SRod Evans  * These masks are tightly coupled to the aux vector definitions in auxv_386.h
5144e12d685SRod Evans  * and auxv_SPARC.h, however they are maintained here, as only ld.so.1 needs
5154e12d685SRod Evans  * to remove these capabilities.  These definitions also describe where the
5164e12d685SRod Evans  * flags are associated and allow for providing multi-architecture definitions
5174e12d685SRod Evans  * should they become necessary, without having to pollute global header files.
5184e12d685SRod Evans  */
5194e12d685SRod Evans #if	defined(__x86)
5204e12d685SRod Evans #define	AV_HW1_IGNORE	(0x8000 | 0x2000)	/* withdrawn MON and PAUSE */
5214e12d685SRod Evans #else						/*    auxv_386.h flags */
5224e12d685SRod Evans #define	AV_HW1_IGNORE	0
5234e12d685SRod Evans #endif
524cb511613SAli Bahrami 
5252020b2b6SRod Evans /*
5262020b2b6SRod Evans  * Error messages generated by ld.so.1 can be written to two different places.
5272020b2b6SRod Evans  * During initial startup, messages are flushed to the stderr.  Once ld.so.1
5282020b2b6SRod Evans  * has jumped to the application, messages are stored in an internal buffer for
5292020b2b6SRod Evans  * retrieval by dlerror().  Between these two conditions, events such as libc's
5302020b2b6SRod Evans  * callbacks, and calls to auditors, are effectively jumping to application
5312020b2b6SRod Evans  * code.  These transitions from application code to ld.so.1 code are guarded by
5322020b2b6SRod Evans  * the following macros to ensure any error messages are directed to the
5332020b2b6SRod Evans  * appropriate output.  The single argument, "f", is a local variable that
5342020b2b6SRod Evans  * can retain, and reinstate, the RT_FL_APPLIC flag of the global rtld_flags
5352020b2b6SRod Evans  * variable.
5362020b2b6SRod Evans  */
5372020b2b6SRod Evans #define	APPLICATION_ENTER(f) \
5382020b2b6SRod Evans 	f = (rtld_flags & RT_FL_APPLIC) ? 0 : RT_FL_APPLIC; \
5392020b2b6SRod Evans 	rtld_flags |= f;
5402020b2b6SRod Evans #define	APPLICATION_RETURN(f) \
5412020b2b6SRod Evans 	rtld_flags &= ~f;
5422020b2b6SRod Evans 
5437c478bd9Sstevel@tonic-gate /*
5447c478bd9Sstevel@tonic-gate  * Data declarations.
5457c478bd9Sstevel@tonic-gate  */
54610a4fa49Srie extern Lc_desc		glcs[];		/* global external interfaces */
5488cd45542Sraf extern	Rt_lock		rtldlock;	/* rtld lock */
5498cd45542Sraf extern	int		thr_flg_nolock;
5508cd45542Sraf extern	int		thr_flg_reenter;
55257ef7aa9SRod Evans extern APlist		*dynlm_list;	/* dynamic list of link-maps */
5537c478bd9Sstevel@tonic-gate extern char		**environ;	/* environ pointer */
5557c478bd9Sstevel@tonic-gate extern int		dyn_plt_ent_size; /* Size of dynamic plt's */
5567c478bd9Sstevel@tonic-gate extern ulong_t		at_flags;	/* machine specific file flags */
55741072f3cSrie extern const char	*procname;	/* file name of executing process */
5587c478bd9Sstevel@tonic-gate extern Rtld_db_priv	r_debug;	/* debugging information */
5597c478bd9Sstevel@tonic-gate extern char		*lasterr;	/* string describing last error */
5607c478bd9Sstevel@tonic-gate extern Interp		*interp;	/* ELF executable interpreter info */
56141072f3cSrie extern const char	*rtldname;	/* name of the dynamic linker */
56256deab07SRod Evans extern APlist		*hdl_alp[];	/* dlopen() handle list */
5637c478bd9Sstevel@tonic-gate extern size_t		syspagsz;	/* system page size */
5647c478bd9Sstevel@tonic-gate extern Isa_desc		*isa;		/* isalist descriptor */
5657c478bd9Sstevel@tonic-gate extern Uts_desc		*uts;		/* utsname descriptor */
5667c478bd9Sstevel@tonic-gate extern uint_t		rtld_flags;	/* status flags for RTLD */
5677c478bd9Sstevel@tonic-gate extern uint_t		rtld_flags2;	/* additional status flags for RTLD */
5687c478bd9Sstevel@tonic-gate extern uint32_t		pltcnt21d;	/* cnt of 21d PLTs */
5697c478bd9Sstevel@tonic-gate extern uint32_t		pltcnt24d;	/* cnt of 24d PLTs */
5707c478bd9Sstevel@tonic-gate extern uint32_t		pltcntu32;	/* cnt of u32 PLTs */
5717c478bd9Sstevel@tonic-gate extern uint32_t		pltcntu44;	/* cnt of u44 PLTs */
5727c478bd9Sstevel@tonic-gate extern uint32_t		pltcntfull;	/* cnt of full PLTs */
5737c478bd9Sstevel@tonic-gate extern uint32_t		pltcntfar;	/* cnt of far PLTs */
5747c478bd9Sstevel@tonic-gate extern uchar_t		search_rules[];	/* dependency search rules */
5767c478bd9Sstevel@tonic-gate extern Fct		elf_fct;	/* ELF file class dependent data */
57802ca3e02Srie #if	defined(__sparc) && !defined(__sparcv9)
5797c478bd9Sstevel@tonic-gate extern Fct		aout_fct;	/* a.out (4.x) file class dependent */
5807c478bd9Sstevel@tonic-gate 					/*	data */
5817c478bd9Sstevel@tonic-gate #endif
5837c478bd9Sstevel@tonic-gate extern Config		*config;		/* configuration structure */
5847c478bd9Sstevel@tonic-gate extern const char	*locale;		/* locale environment setting */
5867c478bd9Sstevel@tonic-gate extern const char	*rpl_audit;	/* replaceable LD_AUDIT string */
5877c478bd9Sstevel@tonic-gate extern const char	*rpl_debug;	/* replaceable LD_DEBUG string */
5887c478bd9Sstevel@tonic-gate extern const char	*rpl_ldflags;	/* replaceable LD_FLAGS string */
5897c478bd9Sstevel@tonic-gate extern const char	*rpl_libpath;	/* replaceable LD_LIBRARY string */
59056deab07SRod Evans extern Alist		*rpl_libdirs;	/*	and its associated Pdesc list */
5917c478bd9Sstevel@tonic-gate extern const char	*rpl_preload;	/* replaceable LD_PRELOAD string */
5937c478bd9Sstevel@tonic-gate extern const char	*prm_audit;	/* permanent LD_AUDIT string */
5947c478bd9Sstevel@tonic-gate extern const char	*prm_debug;	/* permanent LD_DEBUG string */
5957c478bd9Sstevel@tonic-gate extern const char	*prm_ldflags;	/* permanent LD_FLAGS string */
5967c478bd9Sstevel@tonic-gate extern const char	*prm_libpath;	/* permanent LD_LIBRARY string */
59756deab07SRod Evans extern Alist		*prm_libdirs;	/*	and its associated Pdesc list */
5987c478bd9Sstevel@tonic-gate extern const char	*prm_preload;	/* permanent LD_PRELOAD string */
60056deab07SRod Evans extern Alist		*elf_def_dirs;	/* ELF default directory seach paths */
60156deab07SRod Evans extern Alist		*elf_sec_dirs;	/* ELF secure directory seach paths */
60256deab07SRod Evans extern Alist		*aout_def_dirs;	/* AOUT default directory seach paths */
60356deab07SRod Evans extern Alist		*aout_sec_dirs;	/* AOUT secure directory seach paths */
60456deab07SRod Evans 
6057c478bd9Sstevel@tonic-gate extern uint_t		env_info;	/* information regarding environment */
6067c478bd9Sstevel@tonic-gate 					/*	variables */
6077c478bd9Sstevel@tonic-gate extern int		killsig;	/* signal sent on fatal exit */
60856deab07SRod Evans extern APlist		*free_alp;	/* defragmentation list */
6107c478bd9Sstevel@tonic-gate extern uint_t		audit_argcnt;	/* no. of stack args to copy */
6117c478bd9Sstevel@tonic-gate extern Audit_desc	*auditors;	/* global auditors */
6122020b2b6SRod Evans extern APlist		*aud_preinit;	/* list of objects defining local */
6132020b2b6SRod Evans extern APlist		*aud_activity;	/*    preinit and activity auditors */
6152017c965SRod Evans extern char		**_environ;	/* environ reference for libc */
6177c478bd9Sstevel@tonic-gate extern const char	*dbg_file;	/* debugging directed to a file */
6197c478bd9Sstevel@tonic-gate extern Reglist		*reglist;	/* list of register symbols */
6217c478bd9Sstevel@tonic-gate extern const Msg	err_reject[];	/* rejection error message tables */
6227c478bd9Sstevel@tonic-gate extern const Msg	ldd_reject[];
62308278a5eSRod Evans extern const Msg	ldd_warn[];
6257c478bd9Sstevel@tonic-gate extern const char	*profile_name;	/* object being profiled */
6267c478bd9Sstevel@tonic-gate extern const char	*profile_out;	/* profile output file */
6277c478bd9Sstevel@tonic-gate extern const char	*profile_lib;	/* audit library to perform profile */
62941072f3cSrie extern Dl_argsinfo	argsinfo;	/* process argument, environment and */
63041072f3cSrie 					/*	auxv information */
63243d7826aSRod Evans extern const char	*err_strs[ERR_NUM];
63343d7826aSRod Evans 					/* diagnostic error string headers */
6347c478bd9Sstevel@tonic-gate extern const char	*nosym_str;	/* MSG_GEN_NOSYM message cache */
63608278a5eSRod Evans extern Syscapset	*org_scapset;	/* original system capabilities */
63708278a5eSRod Evans extern Syscapset	*alt_scapset;	/* alternative system capabilities */
63808278a5eSRod Evans 
63908278a5eSRod Evans extern const char	*rpl_hwcap;	/* replaceable hwcap str */
64008278a5eSRod Evans extern const char	*rpl_sfcap;	/* replaceable sfcap str */
64108278a5eSRod Evans extern const char	*rpl_machcap;	/* replaceable machcap str */
64208278a5eSRod Evans extern const char	*rpl_platcap;	/* replaceable platcap str */
64308278a5eSRod Evans extern const char	*rpl_cap_files;	/* associated files */
64408278a5eSRod Evans 
64508278a5eSRod Evans extern const char	*prm_hwcap;	/* permanent hwcap str */
64608278a5eSRod Evans extern const char	*prm_sfcap;	/* permanent sfcap str */
64708278a5eSRod Evans extern const char	*prm_machcap;	/* permanent machcap str */
64808278a5eSRod Evans extern const char	*prm_platcap;	/* permanent platcap str */
64908278a5eSRod Evans extern const char	*prm_cap_files;	/* associated files */
65108278a5eSRod Evans extern avl_tree_t	*capavl;	/* capabilities files */
65208278a5eSRod Evans extern avl_tree_t	*nfavl;		/* not-found path names */
65308278a5eSRod Evans extern avl_tree_t	*spavl;		/* secure path names */
65520272c2eSAli Bahrami extern u_longlong_t	cnt_map;	/* Incr. for each object mapped */
65620272c2eSAli Bahrami extern u_longlong_t	cnt_unmap;	/* Incr. for each object unmapped */
65720272c2eSAli Bahrami 
6587c478bd9Sstevel@tonic-gate /*
6597c478bd9Sstevel@tonic-gate  * Function declarations.
6607c478bd9Sstevel@tonic-gate  */
6617c478bd9Sstevel@tonic-gate extern void		addfree(void *, size_t);
6627c478bd9Sstevel@tonic-gate extern int		append_alias(Rt_map *, const char *, int *);
6632020b2b6SRod Evans extern Rt_map		*analyze_lmc(Lm_list *, Aliste, Rt_map *, Rt_map *,
6642020b2b6SRod Evans 			    int *);
6657c478bd9Sstevel@tonic-gate extern void		atexit_fini(void);
6667c478bd9Sstevel@tonic-gate extern int		bind_one(Rt_map *, Rt_map *, uint_t);
6677c478bd9Sstevel@tonic-gate extern int		bufprint(Prfbuf *, const char *, ...);
6685aefb655Srie extern void		call_array(Addr *, uint_t, Rt_map *, Word);
6692020b2b6SRod Evans extern void		call_fini(Lm_list *, Rt_map **, Rt_map *);
6707c478bd9Sstevel@tonic-gate extern void		call_init(Rt_map **, int);
67160758829Srie extern int		callable(Rt_map *, Rt_map *, Grp_hdl *, uint_t);
6727c478bd9Sstevel@tonic-gate extern Rt_map		*_caller(caddr_t, int);
6737c478bd9Sstevel@tonic-gate extern caddr_t		caller(void);
6747c478bd9Sstevel@tonic-gate extern void		*calloc(size_t, size_t);
67508278a5eSRod Evans extern int		cap_alternative(void);
67608278a5eSRod Evans extern int		cap_check_fdesc(Fdesc *, Cap *, char *, Rej_desc *);
67708278a5eSRod Evans extern int		cap_check_lmp(Rt_map *, Rej_desc *);
67808278a5eSRod Evans extern int 		cap_filtees(Alist **, Aliste, const char *, Aliste,
6792020b2b6SRod Evans 			    Rt_map *, Rt_map *, const char *, int, uint_t,
6802020b2b6SRod Evans 			    int *);
68108278a5eSRod Evans extern int		cap_match(Sresult *, uint_t, Sym *, char *);
6825aefb655Srie extern const char	*_conv_reloc_type(uint_t rel);
683dde769a2SRod Evans extern Aliste		create_cntl(Lm_list *, int);
68456deab07SRod Evans extern void		defrag(void);
685e23c41c9SAli Bahrami extern int		dbg_setup(const char *, Dbg_desc *);
6867c478bd9Sstevel@tonic-gate extern const char	*demangle(const char *);
6877c478bd9Sstevel@tonic-gate extern int		dlclose_intn(Grp_hdl *, Rt_map *);
68802ca3e02Srie extern int		dlclose_core(Grp_hdl *, Rt_map *, Lm_list *);
68908278a5eSRod Evans extern int		dlsym_handle(Grp_hdl *, Slookup *, Sresult *, uint_t *,
69008278a5eSRod Evans 			    int *);
6917c478bd9Sstevel@tonic-gate extern void		*dlsym_intn(void *, const char *, Rt_map *, Rt_map **);
6927c478bd9Sstevel@tonic-gate extern Grp_hdl		*dlmopen_intn(Lm_list *, const char *, int, Rt_map *,
6939aa23310Srie 			    uint_t, uint_t);
6947c478bd9Sstevel@tonic-gate extern size_t		doprf(const char *, va_list, Prfbuf *);
6957c478bd9Sstevel@tonic-gate extern int		dowrite(Prfbuf *);
69656deab07SRod Evans extern void		*dz_map(Lm_list *, caddr_t, size_t, int, int);
6978cd45542Sraf extern int		enter(int);
6987c478bd9Sstevel@tonic-gate extern uint_t		expand(char **, size_t *, char **, uint_t, uint_t,
6997c478bd9Sstevel@tonic-gate 			    Rt_map *);
70056deab07SRod Evans extern int		expand_paths(Rt_map *, const char *, Alist **, Aliste,
70156deab07SRod Evans 			    uint_t, uint_t);
7022017c965SRod Evans extern void		free_hdl(Grp_hdl *);
7037c478bd9Sstevel@tonic-gate extern void		file_notfound(Lm_list *, const char *, Rt_map *,
7047c478bd9Sstevel@tonic-gate 			    uint_t, Rej_desc *);
70556deab07SRod Evans extern int		find_path(Lm_list *, Rt_map *, uint_t, Fdesc *,
70656deab07SRod Evans 			    Rej_desc *, int *);
7077c478bd9Sstevel@tonic-gate extern int		fpavl_insert(Lm_list *, Rt_map *, const char *,
7087c478bd9Sstevel@tonic-gate 			    avl_index_t);
70956deab07SRod Evans extern Rt_map		*fpavl_recorded(Lm_list *, const char *, uint_t,
71056deab07SRod Evans 			    avl_index_t *);
7117c478bd9Sstevel@tonic-gate extern void		fpavl_remove(Rt_map *);
71256deab07SRod Evans extern size_t		fullpath(Rt_map *, Fdesc *);
7137c478bd9Sstevel@tonic-gate extern Lmid_t		get_linkmap_id(Lm_list *);
71456deab07SRod Evans extern Pdesc		*get_next_dir(Spath_desc *, Rt_map *, uint_t);
7152017c965SRod Evans extern Grp_desc		*hdl_add(Grp_hdl *, Rt_map *, uint_t, int *);
7168af2c5b9Srie extern Grp_hdl		*hdl_create(Lm_list *, Rt_map *, Rt_map *, uint_t,
7178af2c5b9Srie 			    uint_t, uint_t);
71802ca3e02Srie extern int		hdl_initialize(Grp_hdl *, Rt_map *, int, int);
71908278a5eSRod Evans extern int		hwcap1_check(Syscapset *, Xword, Rej_desc *);
72008278a5eSRod Evans extern int		hwcap2_check(Syscapset *, Xword, Rej_desc *);
7219a411307Srie extern void		is_dep_init(Rt_map *, Rt_map *);
722466e2a62Srie extern int		is_move_data(caddr_t);
723247b82a1SRod Evans extern int		is_path_secure(char *, Rt_map *, uint_t, uint_t);
7243dbfc803SRod Evans extern int		is_rtld_setuid();
7259a411307Srie extern int		is_sym_interposer(Rt_map *, Sym *);
7269a411307Srie extern void		ldso_plt_init(Rt_map *);
7278cd45542Sraf extern void		leave(Lm_list *, int);
7287c478bd9Sstevel@tonic-gate extern void		lm_append(Lm_list *, Aliste, Rt_map *);
7292020b2b6SRod Evans extern void		lm_delete(Lm_list *, Rt_map *, Rt_map *);
7307c478bd9Sstevel@tonic-gate extern void		lm_move(Lm_list *, Aliste, Aliste, Lm_cntl *,
7317c478bd9Sstevel@tonic-gate 			    Lm_cntl *);
73208278a5eSRod Evans extern Rt_map 		*load_cap(Lm_list *, Aliste, const char *, Rt_map *,
73308278a5eSRod Evans 			    uint_t, uint_t, Grp_hdl **, Rej_desc *, int *);
7347247f888Srie extern void		load_completion(Rt_map *);
7352020b2b6SRod Evans extern Rt_map		*load_file(Lm_list *, Aliste, Rt_map *, Fdesc *, int *);
73656deab07SRod Evans extern Rt_map		*load_path(Lm_list *, Aliste, Rt_map *, int, uint_t,
73756deab07SRod Evans 			    Grp_hdl **, Fdesc *, Rej_desc *, int *);
73856deab07SRod Evans extern Rt_map		*load_one(Lm_list *, Aliste, Alist *, Rt_map *, int,
7399aa23310Srie 			    uint_t, Grp_hdl **, int *);
74056deab07SRod Evans extern const char	*load_trace(Lm_list *, Pdesc *, Rt_map *, Fdesc *);
7419aa23310Srie extern void		nfavl_insert(const char *, avl_index_t);
74256deab07SRod Evans extern void		*nu_map(Lm_list *, caddr_t, size_t, int, int);
74356deab07SRod Evans extern Fct		*map_obj(Lm_list *, Fdesc *, size_t, const char *, int,
74456deab07SRod Evans 			    Rej_desc *);
7457c478bd9Sstevel@tonic-gate extern void		*malloc(size_t);
74608278a5eSRod Evans extern int		machcap_check(Syscapset *, const char *, Rej_desc *);
74708278a5eSRod Evans extern void		machine_name(Syscapset *);
74856deab07SRod Evans extern int		move_data(Rt_map *, APlist **);
74908278a5eSRod Evans extern int		platcap_check(Syscapset *, const char *, Rej_desc *);
75008278a5eSRod Evans extern void		platform_name(Syscapset *);
75108278a5eSRod Evans extern int		pnavl_recorded(avl_tree_t **, const char *, uint_t,
75208278a5eSRod Evans 			    avl_index_t *);
7531c1abfbcSRod Evans extern int		procenv_user(APlist *, Word *, Word *, int);
7547c478bd9Sstevel@tonic-gate extern void		rd_event(Lm_list *, rd_event_e, r_state_e);
7551c1abfbcSRod Evans extern int		readenv_user(const char **, APlist **);
7567c478bd9Sstevel@tonic-gate extern int		readenv_config(Rtc_env *, Addr, int);
75731fdd7caSab extern void		rejection_inherit(Rej_desc *, Rej_desc *);
7589aa23310Srie extern int		relocate_lmc(Lm_list *, Aliste, Rt_map *, Rt_map *,
7599aa23310Srie 			    int *);
76056deab07SRod Evans extern int		relocate_finish(Rt_map *, APlist *, int);
7612020b2b6SRod Evans extern void		remove_alist(Alist **, int);
7627c478bd9Sstevel@tonic-gate extern void		remove_cntl(Lm_list *, Aliste);
7637c478bd9Sstevel@tonic-gate extern int		remove_hdl(Grp_hdl *, Rt_map *, int *);
764481bba9eSRod Evans extern void		remove_lmc(Lm_list *, Rt_map *, Aliste, const char *);
7657c478bd9Sstevel@tonic-gate extern void		remove_lml(Lm_list *);
7662020b2b6SRod Evans extern void		remove_so(Lm_list *, Rt_map *, Rt_map *);
7672a8d6ebaSRod Evans extern int		rt_critical(void);
7687c478bd9Sstevel@tonic-gate extern int		rt_bind_guard(int);
7697c478bd9Sstevel@tonic-gate extern int		rt_bind_clear(int);
77010a4fa49Srie extern int		rt_get_extern(Lm_list *, Rt_map *);
7717c478bd9Sstevel@tonic-gate extern int		rt_mutex_lock(Rt_lock *);
7727c478bd9Sstevel@tonic-gate extern int		rt_mutex_unlock(Rt_lock *);
77310a4fa49Srie extern void		rt_thr_init(Lm_list *);
7747c478bd9Sstevel@tonic-gate extern thread_t		rt_thr_self(void);
7755aefb655Srie extern void		rtld_db_dlactivity(Lm_list *);
7765aefb655Srie extern void		rtld_db_preinit(Lm_list *);
7775aefb655Srie extern void		rtld_db_postinit(Lm_list *);
7787c478bd9Sstevel@tonic-gate extern void		rtldexit(Lm_list *, int);
779cb511613SAli Bahrami #ifndef _LP64
780cb511613SAli Bahrami extern int		rtld_fstat(int, rtld_stat_t *restrict);
781cb511613SAli Bahrami extern int		rtld_stat(const char *restrict, rtld_stat_t *restrict);
782cb511613SAli Bahrami #endif
78341072f3cSrie extern int		rtld_getopt(char **, char ***, auxv_t **, Word *,
78441072f3cSrie 			    Word *, int);
7857c478bd9Sstevel@tonic-gate extern void		security(uid_t, uid_t, gid_t, gid_t, int);
7867c478bd9Sstevel@tonic-gate extern void		set_environ(Lm_list *);
78756deab07SRod Evans extern void		set_dirs(Alist **, Spath_defn *, uint_t);
78856deab07SRod Evans extern int		set_prot(Rt_map *, mmapobj_result_t *, int);
78941072f3cSrie extern Rt_map		*setup(char **, auxv_t *, Word, char *, int, char *,
79056deab07SRod Evans 			    ulong_t, ulong_t, int fd, Phdr *, char *, char **,
791*ebb8ac07SRobert Mustacchi 			    uid_t, uid_t, gid_t, gid_t, void *, int, uint_t *);
79256deab07SRod Evans extern const char	*stravl_insert(const char *, uint_t, size_t, int);
7933dbfc803SRod Evans extern void		spavl_insert(const char *);
79408278a5eSRod Evans extern int		sfcap1_check(Syscapset *, Xword, Rej_desc *);
795d326b23bSrie extern int		tls_assign(Lm_list *, Rt_map *, Phdr *);
79610a4fa49Srie extern void		tls_modaddrem(Rt_map *, uint_t);
79710a4fa49Srie extern int		tls_statmod(Lm_list *, Rt_map *);
7987c478bd9Sstevel@tonic-gate extern Rt_map		**tsort(Rt_map *, int, int);
7997c478bd9Sstevel@tonic-gate extern void		unused(Lm_list *);
80056deab07SRod Evans extern void		unmap_obj(mmapobj_result_t *, uint_t);
8017c478bd9Sstevel@tonic-gate extern int		update_mode(Rt_map *, int, int);
8027c478bd9Sstevel@tonic-gate extern void		zero(caddr_t, size_t);
80402ca3e02Srie #if	defined(__sparc)
8057c478bd9Sstevel@tonic-gate /*
8067c478bd9Sstevel@tonic-gate  * SPARC Register symbol support.
8077c478bd9Sstevel@tonic-gate  */
8087c478bd9Sstevel@tonic-gate extern int		elf_regsyms(Rt_map *);
8097c478bd9Sstevel@tonic-gate extern void		set_sparc_g1(ulong_t);
8107c478bd9Sstevel@tonic-gate extern void		set_sparc_g2(ulong_t);
8117c478bd9Sstevel@tonic-gate extern void		set_sparc_g3(ulong_t);
8127c478bd9Sstevel@tonic-gate extern void		set_sparc_g4(ulong_t);
8137c478bd9Sstevel@tonic-gate extern void		set_sparc_g5(ulong_t);
8147c478bd9Sstevel@tonic-gate extern void		set_sparc_g6(ulong_t);
8157c478bd9Sstevel@tonic-gate extern void		set_sparc_g7(ulong_t);
81602ca3e02Srie #endif
8187c478bd9Sstevel@tonic-gate extern long		_sysconfig(int);
8207c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
8217c478bd9Sstevel@tonic-gate }
8227c478bd9Sstevel@tonic-gate #endif
8247c478bd9Sstevel@tonic-gate #endif /* __RTLD_H */