xref: /illumos-gate/usr/src/common/sgsrtcid/sgsrtcid.h (revision c40a6cd785e883b3f052b122c332e21174fc1871)
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	_SGSRTCID_H
27 #define	_SGSRTCID_H
28 
29 #ifdef	__cplusplus
30 extern "C" {
31 #endif
32 
33 
34 /*
35  * This file defines the Rtc_id structure that is found at the beginning
36  * of linker configuration files. It resides at this level so that
37  * it can be accessed by file(1) as well as by crle(1) and the
38  * runtime linker (ld.so.1). The rest of the data structures for
39  * config files are found in usr/src/cmd/sgs/include/rtc.h
40  *
41  * The use of sizeof(char) data (no byte order issue) and explicit
42  * padding in the definition of Rtc_id ensures that it will have
43  * exactly the same layout on all systems, and will have a
44  * size of 16 bytes. The same layout means all systems can read it.
45  * the same size means that any data can be safely placed immediately
46  * following it, without the need for alignment.
47  */
48 
49 /*
50  * Identification header.
51  */
52 typedef struct {
53 	uchar_t	id_magic0;	/* RTC_ID_MAG0 */
54 	uchar_t	id_magic1;	/* RTC_ID_MAG1 */
55 	uchar_t	id_magic2;	/* RTC_ID_MAG2 */
56 	uchar_t	id_magic3;	/* RTC_ID_MAG0 */
57 	uchar_t	id_class;	/* File class/capacity (ELFCLASS constant) */
58 	uchar_t	id_data;	/* Data encoding (ELFDATA constant) */
59 	uchar_t	id_machine;	/* Architecture (ELF EM_ constant) */
60 	uchar_t	id_pad[9];	/* Ensure size is 16 bytes */
61 } Rtc_id;
62 
63 #define	RTC_ID_MAG0 '\077'	/* ? */
64 #define	RTC_ID_MAG1 'R'		/* Runtime */
65 #define	RTC_ID_MAG2 'L'		/* Linker */
66 #define	RTC_ID_MAG3 'C'		/* Configuration */
67 
68 /*
69  * Ensure that the largest machine constant will not grow beyond
70  * maximum value representable by an unsigned byte without our
71  * being alerted to it.
72  */
73 #if EM_NUM > 256
74 #error "Maximum machine constant size exceeded. Format requires revision."
75 #endif
76 
77 /*
78  * Check the 4 bytes starting at the given address to see if
79  * they contain the Rtc_id magic number. The type of the address
80  * is unimportant as long as it is valid, because RTC_ID_TEST()
81  * will cast it to (uchar_t *).
82  */
83 #define	RTC_ID_TEST(addr) \
84 	((RTC_ID_MAG0 == *((uchar_t *)addr)) && \
85 	(RTC_ID_MAG1 == *(((uchar_t *)addr) + 1)) && \
86 	(RTC_ID_MAG2 == *(((uchar_t *)addr) + 2)) && \
87 	(RTC_ID_MAG3 == *(((uchar_t *)addr) + 3)))
88 
89 #ifdef	__cplusplus
90 }
91 #endif
92 
93 #endif	/* _SGSRTCID_H */
94