xref: /onnv-gate/usr/src/cmd/sgs/crle/common/_crle.h (revision 9131:d7741cc87056)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51976Sab196087  * Common Development and Distribution License (the "License").
61976Sab196087  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*9131SRod.Evans@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #ifndef	__CRLE_H
270Sstevel@tonic-gate #define	__CRLE_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #include <sys/types.h>
300Sstevel@tonic-gate #include <gelf.h>
310Sstevel@tonic-gate #include <sgs.h>
320Sstevel@tonic-gate #include <rtc.h>
330Sstevel@tonic-gate #include <machdep.h>
340Sstevel@tonic-gate 
350Sstevel@tonic-gate #ifdef	__cplusplus
360Sstevel@tonic-gate extern "C" {
370Sstevel@tonic-gate #endif
380Sstevel@tonic-gate 
390Sstevel@tonic-gate /*
400Sstevel@tonic-gate  * Hash table support routines.
410Sstevel@tonic-gate  */
420Sstevel@tonic-gate typedef	struct hash_obj	Hash_obj;
430Sstevel@tonic-gate typedef struct hash_ent Hash_ent;
440Sstevel@tonic-gate typedef	struct hash_tbl	Hash_tbl;
450Sstevel@tonic-gate 
460Sstevel@tonic-gate typedef enum {
470Sstevel@tonic-gate 	HASH_STR,
480Sstevel@tonic-gate 	HASH_INT
490Sstevel@tonic-gate } Hash_type;
500Sstevel@tonic-gate 
510Sstevel@tonic-gate /*
520Sstevel@tonic-gate  * Each unique object (identified by dev/inode pair) is maintained as a hash
530Sstevel@tonic-gate  * object.  This descriptor identifies the object (file or directory), whether
540Sstevel@tonic-gate  * it has an alternate, or represents a non-existent object.
550Sstevel@tonic-gate  */
560Sstevel@tonic-gate struct hash_obj {
570Sstevel@tonic-gate 	Half		o_flags;		/* object identification */
580Sstevel@tonic-gate 	Hash_tbl	*o_tbl;			/* its dev/inode table */
590Sstevel@tonic-gate 	char		*o_alter;		/* any alternate path */
600Sstevel@tonic-gate 	Word		o_calter;		/*	and its conf offset */
610Sstevel@tonic-gate 	char		*o_path;		/* the objects real path */
620Sstevel@tonic-gate 	Lword		o_info;			/* information for cache */
630Sstevel@tonic-gate 						/*	consistency checks */
640Sstevel@tonic-gate };
650Sstevel@tonic-gate 
660Sstevel@tonic-gate /*
670Sstevel@tonic-gate  * Each element of a hash table is maintained as a hash entry.  Each element
680Sstevel@tonic-gate  * points to a unique hash object.  Many elements can point to the same hash
690Sstevel@tonic-gate  * object (as is the case with linked files).  Elements on the string table
700Sstevel@tonic-gate  * hash lists identify their directory id, either the directory itself, or the
710Sstevel@tonic-gate  * files that belong to the directory.  These directory and file entries are
720Sstevel@tonic-gate  * what will be converted into object descriptors in the final cache file.
730Sstevel@tonic-gate  */
740Sstevel@tonic-gate struct hash_ent {
75*9131SRod.Evans@Sun.COM 	Hash_ent	*e_next;		/* next hash item */
760Sstevel@tonic-gate 	Word		e_hash;			/* hash value (or inode no.) */
770Sstevel@tonic-gate 	Addr		e_key;			/* name (or inode no.) */
780Sstevel@tonic-gate 	int		e_off;			/* offset of file in dirname */
790Sstevel@tonic-gate 	Half		e_id;			/* directory identifier */
800Sstevel@tonic-gate 	Half		e_flags;		/* entry specific flags */
810Sstevel@tonic-gate 	Word		e_cnt;			/* no. of files in directory */
82*9131SRod.Evans@Sun.COM 	Hash_ent	*e_dir;			/* files directory */
83*9131SRod.Evans@Sun.COM 	Hash_ent	*e_path;		/* files full path entry */
84*9131SRod.Evans@Sun.COM 	Hash_obj	*e_obj;			/* unique object */
85*9131SRod.Evans@Sun.COM 	Rtc_obj		*e_cobj;		/* final configuration object */
860Sstevel@tonic-gate };
870Sstevel@tonic-gate 
880Sstevel@tonic-gate /*
890Sstevel@tonic-gate  * Each hash table is maintained as a hash table descriptor.  Each dev has a
900Sstevel@tonic-gate  * hash table of inodes, and all directory and file entries are also maintained
910Sstevel@tonic-gate  * on the string table hash table.
920Sstevel@tonic-gate  */
930Sstevel@tonic-gate struct hash_tbl {
940Sstevel@tonic-gate 	ulong_t		t_ident;		/* dev no. for inode cache */
950Sstevel@tonic-gate 	int 		t_size;			/* no. of buckets */
960Sstevel@tonic-gate 	Hash_type	t_type;			/* HASH_INT or HASH_STR */
97*9131SRod.Evans@Sun.COM 	Hash_ent	**t_entry;		/* entries */
980Sstevel@tonic-gate };
990Sstevel@tonic-gate 
1000Sstevel@tonic-gate #define	HASH_FND_ENT	0x01		/* search for existing hash entry */
1010Sstevel@tonic-gate #define	HASH_ADD_ENT	0x02		/* add hash entry */
1020Sstevel@tonic-gate 
1030Sstevel@tonic-gate /*
1040Sstevel@tonic-gate  * Environment variable support.
1050Sstevel@tonic-gate  */
1060Sstevel@tonic-gate typedef struct {
1070Sstevel@tonic-gate 	const char	*e_str;		/* complete environment string */
1080Sstevel@tonic-gate 	size_t		e_varsz;	/* variable size, ie. the LD_XXX part */
1090Sstevel@tonic-gate 	size_t		e_totsz;	/* total string size */
1100Sstevel@tonic-gate 	uint_t		e_flags;
1110Sstevel@tonic-gate } Env_desc;
1120Sstevel@tonic-gate 
1130Sstevel@tonic-gate /*
1140Sstevel@tonic-gate  * Filter/filtee association support.  The filtees are a list of Hash_ent's.
1150Sstevel@tonic-gate  */
1160Sstevel@tonic-gate typedef struct {
117*9131SRod.Evans@Sun.COM 	Hash_ent	*f_fent;	/* filter */
1180Sstevel@tonic-gate 	const char	*f_str;		/* filtee string and its associated */
1190Sstevel@tonic-gate 	size_t		f_strsz;	/*	size */
120*9131SRod.Evans@Sun.COM 	APlist		*f_filtee;	/* filtees */
1210Sstevel@tonic-gate } Flt_desc;
1220Sstevel@tonic-gate 
1230Sstevel@tonic-gate /*
1240Sstevel@tonic-gate  * Global data for final configuration files construction.
1250Sstevel@tonic-gate  */
1260Sstevel@tonic-gate typedef	struct crle_desc {
1270Sstevel@tonic-gate 	char		*c_name;		/* calling program */
1280Sstevel@tonic-gate 	char		*c_tempname;	/* temporary file, file descriptor */
1290Sstevel@tonic-gate 	int		c_tempfd;	/*	mmapped address and size */
1300Sstevel@tonic-gate 	Addr		c_tempaddr;
1310Sstevel@tonic-gate 	size_t		c_tempsize;
1321976Sab196087 	Addr		c_tempheadaddr;	/* Ptr to Rtc_head within c_tempaddr */
1330Sstevel@tonic-gate 	char		*c_confil;	/* configuration file */
1340Sstevel@tonic-gate 	char		*c_objdir;	/* current object directory for */
1350Sstevel@tonic-gate 					/*	dldump(3dl) */
1360Sstevel@tonic-gate 	char		*c_audit;	/* audit library name */
1370Sstevel@tonic-gate 	uint_t		c_flags;	/* state flags for crle processing */
1380Sstevel@tonic-gate 	int		c_dlflags;	/* current dldump(3dl) flags */
1390Sstevel@tonic-gate 	int		c_strbkts;	/* internal hash table initialization */
1400Sstevel@tonic-gate 	int		c_inobkts;	/*	parameters */
1410Sstevel@tonic-gate 	uint_t		c_dirnum;	/* no. of directories processed */
1420Sstevel@tonic-gate 	uint_t		c_filenum;	/* no. of files processed */
1430Sstevel@tonic-gate 	uint_t		c_hashstrnum;	/* no. of hashed strings to create */
1440Sstevel@tonic-gate 	Hash_tbl	*c_strtbl;	/* string table and size */
1450Sstevel@tonic-gate 	size_t		c_strsize;
146*9131SRod.Evans@Sun.COM 	APlist		*c_inotbls;	/* list of inode tables */
1470Sstevel@tonic-gate 	const char	*c_app;		/* specific application */
1480Sstevel@tonic-gate 	char		*c_edlibpath;	/* ELF default library path */
1490Sstevel@tonic-gate 	char		*c_adlibpath;	/* AOUT default library path */
1500Sstevel@tonic-gate 	char		*c_eslibpath;	/* ELF secure library path */
1510Sstevel@tonic-gate 	char		*c_aslibpath;	/* AOUT secure library path */
152*9131SRod.Evans@Sun.COM 	APlist		*c_env;		/* environment variables */
1530Sstevel@tonic-gate 	uint_t		c_envnum;	/*	and associated number */
154*9131SRod.Evans@Sun.COM 	APlist		*c_flt;		/* filter/filtee associations */
1550Sstevel@tonic-gate 	uint_t		c_fltrnum;	/*	and associated filter number */
1560Sstevel@tonic-gate 	uint_t		c_fltenum;	/*	and associated filtee number */
1570Sstevel@tonic-gate } Crle_desc;
1580Sstevel@tonic-gate 
1590Sstevel@tonic-gate #define	CRLE_CREAT	0x0001		/* config file creation required */
1600Sstevel@tonic-gate #define	CRLE_ALTER	0x0002		/* alternative entries required */
1610Sstevel@tonic-gate #define	CRLE_DUMP	0x0004		/* alternative create by dldump(3dl) */
1621976Sab196087 #define	CRLE_ADDID	0x0008		/* Add Rtc_id to head of new files */
1630Sstevel@tonic-gate #define	CRLE_VERBOSE	0x0010		/* verbose mode */
1640Sstevel@tonic-gate #define	CRLE_AOUT	0x0020		/* AOUT flag in effect */
1650Sstevel@tonic-gate #define	CRLE_EXISTS	0x0040		/* config file already exists */
1660Sstevel@tonic-gate #define	CRLE_DIFFDEV	0x0080		/* config file and temporary exist on */
1670Sstevel@tonic-gate 					/*	different filesystems */
1680Sstevel@tonic-gate #define	CRLE_CONFDEF	0x0100		/* configuration file is default */
1690Sstevel@tonic-gate #define	CRLE_UPDATE	0x0200		/* update existing configuration file */
1700Sstevel@tonic-gate #define	CRLE_RPLENV	0x0400		/* replaceable environment variable */
1710Sstevel@tonic-gate #define	CRLE_PRMENV	0x0800		/* permanent environment variable */
1720Sstevel@tonic-gate 
1730Sstevel@tonic-gate #define	CRLE_EDLIB	0x1000		/* default elf search path supplied */
1740Sstevel@tonic-gate #define	CRLE_ESLIB	0x2000		/* default elf secure path supplied */
1750Sstevel@tonic-gate #define	CRLE_ADLIB	0x4000		/* default AOUT search path supplied */
1760Sstevel@tonic-gate #define	CRLE_ASLIB	0x8000		/* default AOUT secure path supplied */
1770Sstevel@tonic-gate 
178*9131SRod.Evans@Sun.COM #define	AL_CNT_CRLE	10
179*9131SRod.Evans@Sun.COM 
1800Sstevel@tonic-gate /*
1811976Sab196087  * Return type code returned by inspectconfig()
1821976Sab196087  */
1831976Sab196087 typedef enum {
1841976Sab196087 	INSCFG_RET_OK = 0,		/* Config file is OK */
1851976Sab196087 	INSCFG_RET_FAIL = 1,		/* Config file has a fatal problem */
1861976Sab196087 	INSCFG_RET_NEED64 = 2,		/* 64-bit config seen by 32-bit crle */
1871976Sab196087 } INSCFG_RET;
1881976Sab196087 
1891976Sab196087 /*
1900Sstevel@tonic-gate  * Local functions.
1910Sstevel@tonic-gate  */
1920Sstevel@tonic-gate extern int		addlib(Crle_desc *, char **, const char *);
1930Sstevel@tonic-gate extern int		addenv(Crle_desc *, const char *, uint_t);
1940Sstevel@tonic-gate extern int		depend(Crle_desc *, const char *, Half, GElf_Ehdr *);
1950Sstevel@tonic-gate extern int		dlflags(Crle_desc *, const char *);
1960Sstevel@tonic-gate extern int		dump(Crle_desc *);
1970Sstevel@tonic-gate extern int		genconfig(Crle_desc *);
198*9131SRod.Evans@Sun.COM extern Hash_ent		*get_hash(Hash_tbl *, Addr, Half, int);
1990Sstevel@tonic-gate extern int		inspect(Crle_desc *, const char *, Half);
200*9131SRod.Evans@Sun.COM extern Hash_tbl		*make_hash(int, Hash_type, ulong_t);
2012056Sab196087 extern INSCFG_RET	inspectconfig(Crle_desc *, int);
2020Sstevel@tonic-gate extern int		updateconfig(Crle_desc *);
2030Sstevel@tonic-gate 
2040Sstevel@tonic-gate #ifdef	__cplusplus
2050Sstevel@tonic-gate }
2060Sstevel@tonic-gate #endif
2070Sstevel@tonic-gate 
2080Sstevel@tonic-gate #endif	/* __CRLE_H */
209