xref: /illumos-gate/usr/src/cmd/sgs/include/rtc.h (revision 028c45646327b08802a29b76d1abea8907a57f17)
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	_RTC_H
27 #define	_RTC_H
28 
29 /*
30  * Global include file for the runtime configuration support.
31  */
32 #include <time.h>
33 #include <machdep.h>
34 
35 #ifdef	__cplusplus
36 extern "C" {
37 #endif
38 
39 /*
40  * Linker configuration files are designed to be mapped into memory
41  * and accessed directly. Hence, the layout of the data must follow
42  * byte order and alignment rules for the program examining it.
43  *
44  * From its initial design through the release of Solaris 10, runtime
45  * linker configuration files started with a configuration header (Rtc_head).
46  * The role of Rtc_head is to provide a table of contents to the remainder
47  * of the file. It tells what information is contained in the file,
48  * and the offset (relative to the base of the Rtc_head structure)
49  * within the file at which each item can be found. These offsets are
50  * 32-bit values. Linker configuration files are 32-bit limited, even
51  * for 64-bit platforms.
52  *
53  * It should be noted that Rtc_head contains no information that can be
54  * used to identify the type of program that created the file (byte order,
55  * elf class, and machine architecture). This leads to some difficulties:
56  *	- Interpreting a config file using a program with the opposite
57  *	  byte order can crash the program.
58  *	- Structure layout differences can cause a 64-bit version of the
59  *	  program to fail to read a 32-bit config file correctly, or
60  *	  vice versa. This was not an issue on sparc (both 32 and 64-bit
61  *	  happen to lay out the same way). However, 32 and 64-bit X86
62  *	  have differing alignment rules.
63  *	- The file command cannot easily identify a linker configuration
64  *	  file, and simply reports them as "data".
65  * Initially, the design of of these files assumed that a given file
66  * would be readable by any system. Experience shows that this is wrong.
67  * A linker config file is ABI specific, much like an object file. It should
68  * only be interpreted by a compatible program.
69  *
70  * Linker configuration files now start with an Rtc_id structure, followed
71  * immediately by Rtc_head. Rtc_id provides the information necessary to
72  * detect the type of program that wrote the file, in a manner that allows
73  * backwards compatibility with pre-existing config files:
74  *	- We can detect an old config file, because they do not start
75  *	  with the characters "\077RLC". In this case, we assume the
76  *	  file is compatible with the program interpreting it, and that
77  *	  Rtc_head is the first thing in the file.
78  *	- Solaris 10 and older will refuse to handle a config
79  *	  file that has an Rtc_id, because they will interpret
80  *	  the "\077RLC" signature as the ch_version field of Rtc_head,
81  *	  and will reject the version as being invalid.
82  *	- Rtc_id is specified such that its size will be 16 bytes
83  *	  on all systems, sufficient to align Rtc_head on any system, and
84  *	  to provide future expansion room.
85  *	- Offsets to data in the file continue to be specified relative
86  *	  to the Rtc_head address, meaning that existing software will
87  *	  continue to work with little or no modification.
88  */
89 
90 /*
91  * Identification header.
92  *
93  * This is defined in usr/src/common/sgsrtcid/sgsrtcid.h
94  * so that file(1) can also access it.
95  */
96 #include <sgsrtcid.h>
97 
98 /*
99  * Configuration header.
100  */
101 typedef struct {
102 	Word	ch_version;		/* version of config file */
103 	Word	ch_cnflags;		/* configuration flags */
104 	Word	ch_dlflags;		/* dldump() flags used */
105 	Word	ch_app;			/* application that this config file */
106 					/*	is specific to */
107 	Word	ch_hash;		/* hash table offset */
108 	Word	ch_obj;			/* object table offset */
109 	Word	ch_str;			/* string table offset */
110 	Word	ch_file;		/* file entries */
111 	Word	ch_dir;			/* directory entries */
112 	Word	ch_edlibpath;		/* ELF default library path offset */
113 	Word	ch_adlibpath;		/* AOUT default library path offset */
114 	Word	ch_eslibpath;		/* ELF secure library path offset */
115 	Word	ch_aslibpath;		/* AOUT secure library path offset */
116 	Lword	ch_resbgn;		/* memory reservation required to map */
117 	Lword	ch_resend;		/*	alternative objects defined */
118 					/*	by the configuration info */
119 	Word	ch_env;			/* environment variables */
120 	Word	ch_fltr;		/* filter table entries */
121 	Word	ch_flte;		/* filtee table entries */
122 } Rtc_head;
123 
124 #define	RTC_HDR_IGNORE	0x0001		/* ignore config information */
125 #define	RTC_HDR_ALTER	0x0002		/* alternative objects are defined - */
126 					/*	these may exist without a */
127 					/*	memory reservation (see -a) */
128 #define	RTC_HDR_64	0x0004		/* 64-bit objects used */
129 #define	RTC_HDR_UPM	0x0008		/* includes unified process model */
130 
131 /*
132  * Object descriptor.
133  */
134 typedef struct {
135 	Lword	co_info;		/* validation information */
136 	Word	co_name;		/* object name (directory or file) */
137 	Word	co_hash;		/* name hash value */
138 	Half	co_id;			/* directory identifier */
139 	Half	co_flags;		/* various flags */
140 	Word	co_alter;		/* alternative object file */
141 } Rtc_obj;
142 
143 #define	RTC_OBJ_DIRENT	0x0001		/* object defines a directory */
144 #define	RTC_OBJ_ALLENTS	0x0002		/* directory was scanned for all */
145 					/*	containing objects */
146 #define	RTC_OBJ_NOEXIST	0x0004		/* object does not exist */
147 #define	RTC_OBJ_EXEC	0x0008		/* object identifies executable */
148 #define	RTC_OBJ_ALTER	0x0010		/* object has an alternate */
149 #define	RTC_OBJ_DUMP	0x0020		/* alternate created by dldump(3C) */
150 #define	RTC_OBJ_REALPTH	0x0040		/* object identifies real path */
151 #define	RTC_OBJ_NOALTER	0x0080		/* object can't have an alternate */
152 #define	RTC_OBJ_GROUP	0x0100		/* object was expanded as a group */
153 #define	RTC_OBJ_APP	0x0200		/* object indicates app which makes */
154 					/*	configuration file specific */
155 #define	RTC_OBJ_CMDLINE	0x0400		/* object specified from command line */
156 #define	RTC_OBJ_FILTER	0x0800		/* object identifies a filter */
157 #define	RTC_OBJ_FILTEE	0x1000		/* object identifies a filtee */
158 #define	RTC_OBJ_OPTINAL	0x2000		/* object alternative is optional */
159 
160 /*
161  * Directory and file descriptors.  The configuration cache (cd_dir) points to
162  * an array of directory descriptors, this in turn point to their associated
163  * arrays of file descriptors.  Both of these provide sequential access for
164  * configuration file validation (directory, and possible file stat()'s).
165  */
166 typedef struct {
167 	Word	cd_obj;			/* index to Rtc_obj */
168 	Word	cd_file;		/* index to Rtc_file[] */
169 } Rtc_dir;
170 
171 typedef	struct {
172 	Word	cf_obj;			/* index to Rtc_obj */
173 } Rtc_file;
174 
175 
176 #define	RTC_VER_NONE	0
177 #define	RTC_VER_ONE	1		/* original version */
178 #define	RTC_VER_TWO	2		/* updated for -u use */
179 #define	RTC_VER_THREE	3		/* updated for -e/-E use */
180 #define	RTC_VER_FOUR	4		/* updated for filter/filtees */
181 #define	RTC_VER_CURRENT RTC_VER_FOUR
182 #define	RTC_VER_NUM	5
183 
184 /*
185  * Environment variable descriptor.  The configuration cache (ch_env) points to
186  * an array of these descriptors.
187  */
188 typedef struct {
189 	Word	env_str;		/* index into string table */
190 	Word	env_flags;		/* various flags */
191 } Rtc_env;
192 
193 #define	RTC_ENV_REPLACE	0x0001		/* replaceable string definition */
194 #define	RTC_ENV_PERMANT	0x0002		/* permanent string definition */
195 #define	RTC_ENV_CONFIG	0x1000		/* string originates from config file */
196 
197 /*
198  * Filter descriptor.  The configuration cache (ch_flt) points to an array of
199  * these descriptors.
200  */
201 typedef struct {
202 	Word	fr_filter;		/* filter name, and filtee string */
203 	Word	fr_string;		/*	as indexs into string table */
204 	Word	fr_filtee;		/* index into filtee array */
205 } Rtc_fltr;
206 
207 typedef struct {
208 	Word	fe_filtee;
209 } Rtc_flte;
210 
211 #ifdef	__cplusplus
212 }
213 #endif
214 
215 #endif	/* _RTC_H */
216