xref: /illumos-gate/usr/src/cmd/sgs/crle/common/_crle.h (revision fec047081731fd77caf46ec0471c501b2cb33894)
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 2009 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 #include <sys/types.h>
30 #include <gelf.h>
31 #include <sgs.h>
32 #include <rtc.h>
33 #include <machdep.h>
34 
35 #ifdef	__cplusplus
36 extern "C" {
37 #endif
38 
39 /*
40  * Hash table support routines.
41  */
42 typedef	struct hash_obj	Hash_obj;
43 typedef struct hash_ent Hash_ent;
44 typedef	struct hash_tbl	Hash_tbl;
45 
46 typedef enum {
47 	HASH_STR,
48 	HASH_INT
49 } Hash_type;
50 
51 /*
52  * Each unique object (identified by dev/inode pair) is maintained as a hash
53  * object.  This descriptor identifies the object (file or directory), whether
54  * it has an alternate, or represents a non-existent object.
55  */
56 struct hash_obj {
57 	Half		o_flags;		/* object identification */
58 	Hash_tbl	*o_tbl;			/* its dev/inode table */
59 	char		*o_alter;		/* any alternate path */
60 	Word		o_calter;		/*	and its conf offset */
61 	char		*o_path;		/* the objects real path */
62 	Lword		o_info;			/* information for cache */
63 						/*	consistency checks */
64 };
65 
66 /*
67  * Each element of a hash table is maintained as a hash entry.  Each element
68  * points to a unique hash object.  Many elements can point to the same hash
69  * object (as is the case with linked files).  Elements on the string table
70  * hash lists identify their directory id, either the directory itself, or the
71  * files that belong to the directory.  These directory and file entries are
72  * what will be converted into object descriptors in the final cache file.
73  */
74 struct hash_ent {
75 	Hash_ent	*e_next;		/* next hash item */
76 	Word		e_hash;			/* hash value (or inode no.) */
77 	Addr		e_key;			/* name (or inode no.) */
78 	int		e_off;			/* offset of file in dirname */
79 	Half		e_id;			/* directory identifier */
80 	Half		e_flags;		/* entry specific flags */
81 	Word		e_cnt;			/* no. of files in directory */
82 	Hash_ent	*e_dir;			/* files directory */
83 	Hash_ent	*e_path;		/* files full path entry */
84 	Hash_obj	*e_obj;			/* unique object */
85 	Rtc_obj		*e_cobj;		/* final configuration object */
86 };
87 
88 /*
89  * Each hash table is maintained as a hash table descriptor.  Each dev has a
90  * hash table of inodes, and all directory and file entries are also maintained
91  * on the string table hash table.
92  */
93 struct hash_tbl {
94 	ulong_t		t_ident;		/* dev no. for inode cache */
95 	int		t_size;			/* no. of buckets */
96 	Hash_type	t_type;			/* HASH_INT or HASH_STR */
97 	Hash_ent	**t_entry;		/* entries */
98 };
99 
100 #define	HASH_FND_ENT	0x01		/* search for existing hash entry */
101 #define	HASH_ADD_ENT	0x02		/* add hash entry */
102 
103 /*
104  * Environment variable support.
105  */
106 typedef struct {
107 	const char	*e_str;		/* complete environment string */
108 	size_t		e_varsz;	/* variable size, ie. the LD_XXX part */
109 	size_t		e_totsz;	/* total string size */
110 	uint_t		e_flags;
111 } Env_desc;
112 
113 /*
114  * Filter/filtee association support.  The filtees are a list of Hash_ent's.
115  */
116 typedef struct {
117 	Hash_ent	*f_fent;	/* filter */
118 	const char	*f_str;		/* filtee string and its associated */
119 	size_t		f_strsz;	/*	size */
120 	APlist		*f_filtee;	/* filtees */
121 } Flt_desc;
122 
123 /*
124  * Global data for final configuration files construction.
125  */
126 typedef	struct crle_desc {
127 	char		*c_name;		/* calling program */
128 	char		*c_tempname;	/* temporary file, file descriptor */
129 	int		c_tempfd;	/*	mmapped address and size */
130 	Addr		c_tempaddr;
131 	size_t		c_tempsize;
132 	Addr		c_tempheadaddr;	/* Ptr to Rtc_head within c_tempaddr */
133 	char		*c_confil;	/* configuration file */
134 	char		*c_objdir;	/* current object directory for */
135 					/*	dldump(3dl) */
136 	char		*c_audit;	/* audit library name */
137 	uint_t		c_flags;	/* state flags for crle processing */
138 	int		c_dlflags;	/* current dldump(3dl) flags */
139 	int		c_strbkts;	/* internal hash table initialization */
140 	int		c_inobkts;	/*	parameters */
141 	uint_t		c_dirnum;	/* no. of directories processed */
142 	uint_t		c_filenum;	/* no. of files processed */
143 	uint_t		c_hashstrnum;	/* no. of hashed strings to create */
144 	Hash_tbl	*c_strtbl;	/* string table and size */
145 	size_t		c_strsize;
146 	APlist		*c_inotbls;	/* list of inode tables */
147 	const char	*c_app;		/* specific application */
148 	char		*c_edlibpath;	/* ELF default library path */
149 	char		*c_eslibpath;	/* ELF secure library path */
150 	APlist		*c_env;		/* environment variables */
151 	uint_t		c_envnum;	/*	and associated number */
152 	APlist		*c_flt;		/* filter/filtee associations */
153 	uint_t		c_fltrnum;	/*	and associated filter number */
154 	uint_t		c_fltenum;	/*	and associated filtee number */
155 } Crle_desc;
156 
157 #define	CRLE_CREAT	0x0001		/* config file creation required */
158 #define	CRLE_ALTER	0x0002		/* alternative entries required */
159 #define	CRLE_DUMP	0x0004		/* alternative create by dldump(3dl) */
160 #define	CRLE_ADDID	0x0008		/* Add Rtc_id to head of new files */
161 #define	CRLE_VERBOSE	0x0010		/* verbose mode */
162 /* 0x20 was previously used for a.out support */
163 #define	CRLE_EXISTS	0x0040		/* config file already exists */
164 #define	CRLE_DIFFDEV	0x0080		/* config file and temporary exist on */
165 					/*	different filesystems */
166 #define	CRLE_CONFDEF	0x0100		/* configuration file is default */
167 #define	CRLE_UPDATE	0x0200		/* update existing configuration file */
168 #define	CRLE_RPLENV	0x0400		/* replaceable environment variable */
169 #define	CRLE_PRMENV	0x0800		/* permanent environment variable */
170 
171 #define	CRLE_EDLIB	0x1000		/* default elf search path supplied */
172 #define	CRLE_ESLIB	0x2000		/* default elf secure path supplied */
173 
174 #define	AL_CNT_CRLE	10
175 
176 /*
177  * Return type code returned by inspectconfig()
178  */
179 typedef enum {
180 	INSCFG_RET_OK = 0,		/* Config file is OK */
181 	INSCFG_RET_FAIL = 1,		/* Config file has a fatal problem */
182 	INSCFG_RET_NEED64 = 2,		/* 64-bit config seen by 32-bit crle */
183 } INSCFG_RET;
184 
185 /*
186  * Local functions.
187  */
188 extern int		addlib(Crle_desc *, char **, const char *);
189 extern int		addenv(Crle_desc *, const char *, uint_t);
190 extern int		depend(Crle_desc *, const char *, Half, GElf_Ehdr *);
191 extern int		dlflags(Crle_desc *, const char *);
192 extern int		dump(Crle_desc *);
193 extern int		genconfig(Crle_desc *);
194 extern Hash_ent		*get_hash(Hash_tbl *, Addr, Half, int);
195 extern int		inspect(Crle_desc *, const char *, Half);
196 extern Hash_tbl		*make_hash(int, Hash_type, ulong_t);
197 extern INSCFG_RET	inspectconfig(Crle_desc *, int);
198 extern int		updateconfig(Crle_desc *);
199 
200 #ifdef	__cplusplus
201 }
202 #endif
203 
204 #endif	/* __CRLE_H */
205