xref: /titanic_52/usr/src/cmd/sgs/crle/common/_crle.h (revision 1cb6af97c6f66f456d4f726ef056e1ebc0f73305)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	__CRLE_H
28 #define	__CRLE_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/types.h>
33 #include <gelf.h>
34 #include <sgs.h>
35 #include <rtc.h>
36 #include <machdep.h>
37 
38 #ifdef	__cplusplus
39 extern "C" {
40 #endif
41 
42 
43 /*
44  * Hash table support routines.
45  */
46 typedef	struct hash_obj	Hash_obj;
47 typedef struct hash_ent Hash_ent;
48 typedef	struct hash_tbl	Hash_tbl;
49 
50 typedef enum {
51 	HASH_STR,
52 	HASH_INT
53 } Hash_type;
54 
55 /*
56  * Each unique object (identified by dev/inode pair) is maintained as a hash
57  * object.  This descriptor identifies the object (file or directory), whether
58  * it has an alternate, or represents a non-existent object.
59  */
60 struct hash_obj {
61 	Half		o_flags;		/* object identification */
62 	Hash_tbl	*o_tbl;			/* its dev/inode table */
63 	char		*o_alter;		/* any alternate path */
64 	Word		o_calter;		/*	and its conf offset */
65 	char		*o_path;		/* the objects real path */
66 	Lword		o_info;			/* information for cache */
67 						/*	consistency checks */
68 };
69 
70 /*
71  * Each element of a hash table is maintained as a hash entry.  Each element
72  * points to a unique hash object.  Many elements can point to the same hash
73  * object (as is the case with linked files).  Elements on the string table
74  * hash lists identify their directory id, either the directory itself, or the
75  * files that belong to the directory.  These directory and file entries are
76  * what will be converted into object descriptors in the final cache file.
77  */
78 struct hash_ent {
79 	Hash_ent *	e_next;			/* next hash item */
80 	Word		e_hash;			/* hash value (or inode no.) */
81 	Addr		e_key;			/* name (or inode no.) */
82 	int		e_off;			/* offset of file in dirname */
83 	Half		e_id;			/* directory identifier */
84 	Half		e_flags;		/* entry specific flags */
85 	Word		e_cnt;			/* no. of files in directory */
86 	Hash_ent *	e_dir;			/* files directory */
87 	Hash_ent *	e_path;			/* files full path entry */
88 	Hash_obj *	e_obj;			/* unique object */
89 	Rtc_obj *	e_cobj;			/* final configuration object */
90 };
91 
92 /*
93  * Each hash table is maintained as a hash table descriptor.  Each dev has a
94  * hash table of inodes, and all directory and file entries are also maintained
95  * on the string table hash table.
96  */
97 struct hash_tbl {
98 	ulong_t		t_ident;		/* dev no. for inode cache */
99 	int 		t_size;			/* no. of buckets */
100 	Hash_type	t_type;			/* HASH_INT or HASH_STR */
101 	Hash_ent **	t_entry;		/* entries */
102 };
103 
104 #define	HASH_FND_ENT	0x01		/* search for existing hash entry */
105 #define	HASH_ADD_ENT	0x02		/* add hash entry */
106 
107 /*
108  * Environment variable support.
109  */
110 typedef struct {
111 	const char	*e_str;		/* complete environment string */
112 	size_t		e_varsz;	/* variable size, ie. the LD_XXX part */
113 	size_t		e_totsz;	/* total string size */
114 	uint_t		e_flags;
115 } Env_desc;
116 
117 /*
118  * Filter/filtee association support.  The filtees are a list of Hash_ent's.
119  */
120 typedef struct {
121 	Hash_ent *	f_fent;		/* filter */
122 	const char	*f_str;		/* filtee string and its associated */
123 	size_t		f_strsz;	/*	size */
124 	List		f_filtee;	/* filtees */
125 } Flt_desc;
126 
127 /*
128  * Global data for final configuration files construction.
129  */
130 typedef	struct crle_desc {
131 	char		*c_name;		/* calling program */
132 	char		*c_tempname;	/* temporary file, file descriptor */
133 	int		c_tempfd;	/*	mmapped address and size */
134 	Addr		c_tempaddr;
135 	size_t		c_tempsize;
136 	char		*c_confil;	/* configuration file */
137 	char		*c_objdir;	/* current object directory for */
138 					/*	dldump(3dl) */
139 	char		*c_audit;	/* audit library name */
140 	uint_t		c_flags;	/* state flags for crle processing */
141 	ushort_t	c_machine;	/* object machine type and class to */
142 	ushort_t	c_class;	/* 	operate on */
143 	int		c_dlflags;	/* current dldump(3dl) flags */
144 	int		c_strbkts;	/* internal hash table initialization */
145 	int		c_inobkts;	/*	parameters */
146 	uint_t		c_dirnum;	/* no. of directories processed */
147 	uint_t		c_filenum;	/* no. of files processed */
148 	uint_t		c_hashstrnum;	/* no. of hashed strings to create */
149 	Hash_tbl	*c_strtbl;	/* string table and size */
150 	size_t		c_strsize;
151 	List		c_inotbls;	/* list of inode tables */
152 	const char	*c_app;		/* specific application */
153 	char		*c_edlibpath;	/* ELF default library path */
154 	char		*c_adlibpath;	/* AOUT default library path */
155 	char		*c_eslibpath;	/* ELF secure library path */
156 	char		*c_aslibpath;	/* AOUT secure library path */
157 	List		c_env;		/* environment variables */
158 	uint_t		c_envnum;	/*	and associated number */
159 	List		c_flt;		/* filter/filtee associations */
160 	uint_t		c_fltrnum;	/*	and associated filter number */
161 	uint_t		c_fltenum;	/*	and associated filtee number */
162 } Crle_desc;
163 
164 #define	CRLE_CREAT	0x0001		/* config file creation required */
165 #define	CRLE_ALTER	0x0002		/* alternative entries required */
166 #define	CRLE_DUMP	0x0004		/* alternative create by dldump(3dl) */
167 #define	CRLE_VERBOSE	0x0010		/* verbose mode */
168 #define	CRLE_AOUT	0x0020		/* AOUT flag in effect */
169 #define	CRLE_EXISTS	0x0040		/* config file already exists */
170 #define	CRLE_DIFFDEV	0x0080		/* config file and temporary exist on */
171 					/*	different filesystems */
172 #define	CRLE_CONFDEF	0x0100		/* configuration file is default */
173 #define	CRLE_UPDATE	0x0200		/* update existing configuration file */
174 #define	CRLE_RPLENV	0x0400		/* replaceable environment variable */
175 #define	CRLE_PRMENV	0x0800		/* permanent environment variable */
176 
177 #define	CRLE_EDLIB	0x1000		/* default elf search path supplied */
178 #define	CRLE_ESLIB	0x2000		/* default elf secure path supplied */
179 #define	CRLE_ADLIB	0x4000		/* default AOUT search path supplied */
180 #define	CRLE_ASLIB	0x8000		/* default AOUT secure path supplied */
181 
182 /*
183  * Local functions.
184  */
185 extern int		addlib(Crle_desc *, char **, const char *);
186 extern int		addenv(Crle_desc *, const char *, uint_t);
187 extern int		depend(Crle_desc *, const char *, Half, GElf_Ehdr *);
188 extern int		dlflags(Crle_desc *, const char *);
189 extern int		dump(Crle_desc *);
190 extern int		genconfig(Crle_desc *);
191 extern Hash_ent *	get_hash(Hash_tbl *, Addr, Half, int);
192 extern int		inspect(Crle_desc *, const char *, Half);
193 extern Listnode *	list_append(List *, const void *);
194 extern Hash_tbl *	make_hash(int, Hash_type, ulong_t);
195 extern int		inspectconfig(Crle_desc *);
196 extern int		updateconfig(Crle_desc *);
197 
198 #ifdef	__cplusplus
199 }
200 #endif
201 
202 #endif	/* __CRLE_H */
203