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