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