xref: /titanic_41/usr/src/lib/libbsm/common/adr.c (revision bb25c06cca41ca78e5fb87fbb8e81d55beb18c95)
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 #ifndef lint
23 static char sccsid[] = "%Z%%M%	%I%	%E% SMI";
24 #endif
25 
26 /*
27  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
28  * Use is subject to license terms.
29  */
30 
31 #pragma ident	"%Z%%M%	%I%	%E% SMI"
32 
33 /*
34  * Adr memory based encoding
35  */
36 
37 #include <sys/types.h>
38 #include <bsm/audit.h>
39 #include <bsm/libbsm.h>
40 #include <bsm/audit_record.h>
41 
42 void
43 #ifdef __STDC__
44 adr_start(adr_t *adr, char *p)
45 #else
46 adr_start(adr, p)
47 	adr_t *adr;
48 	char *p;
49 #endif
50 {
51 	adr->adr_stream = p;
52 	adr->adr_now = p;
53 }
54 
55 int
56 #ifdef __STDC__
57 adr_count(adr_t *adr)
58 #else
59 adr_count(adr)
60 	adr_t *adr;
61 #endif
62 {
63 	return (((intptr_t)adr->adr_now) - ((intptr_t)adr->adr_stream));
64 }
65 
66 
67 /*
68  * adr_char - pull out characters
69  */
70 void
71 #ifdef __STDC__
72 adr_char(adr_t *adr, char *cp, int count)
73 #else
74 adr_char(adr, cp, count)
75 	adr_t *adr;
76 	char *cp;
77 	int count;
78 #endif
79 {
80 	while (count-- > 0)
81 		*adr->adr_now++ = *cp++;
82 }
83 
84 /*
85  * adr_short - pull out shorts
86  */
87 void
88 #ifdef __STDC__
89 adr_short(adr_t *adr, short *sp, int count)
90 #else
91 adr_short(adr, sp, count)
92 	adr_t *adr;
93 	short *sp;
94 	int count;
95 #endif
96 {
97 
98 	for (; count-- > 0; sp++) {
99 		*adr->adr_now++ = (char)((*sp >> 8) & 0x00ff);
100 		*adr->adr_now++ = (char)(*sp & 0x00ff);
101 	}
102 }
103 
104 /*
105  * adr_int32 - pull out uint32
106  */
107 #pragma weak adr_long = adr_int32
108 #ifdef __STDC__
109 void adr_long(adr_t *adr, int32_t *lp, int count);
110 void
111 adr_int32(adr_t *adr, int32_t *lp, int count)
112 #else
113 void adr_long();
114 void
115 adr_int32(adr, lp, count)
116 	adr_t *adr;
117 	int32_t *lp;
118 	int count;
119 #endif
120 {
121 	int i;		/* index for counting */
122 	uint32_t l;		/* value for shifting */
123 
124 	for (; count-- > 0; lp++) {
125 		for (i = 0, l = *(uint32_t *)lp; i < 4; i++) {
126 			*adr->adr_now++ =
127 				(char)((uint32_t)(l & 0xff000000) >> 24);
128 			l <<= 8;
129 		}
130 	}
131 }
132 
133 /*
134  * adr_int64 - pull out uint64_t
135  */
136 void
137 #ifdef __STDC__
138 adr_int64(adr_t *adr, int64_t *lp, int count)
139 #else
140 adr_int64(adr, lp, count)
141 	adr_t *adr;
142 	int64_t *lp;
143 	int count;
144 #endif
145 {
146 	int i;		/* index for counting */
147 	uint64_t l;	/* value for shifting */
148 
149 	for (; count-- > 0; lp++) {
150 		for (i = 0, l = *(uint64_t *)lp; i < 8; i++) {
151 			*adr->adr_now++ = (char)
152 				((uint64_t)(l & 0xff00000000000000ULL) >> 56);
153 			l <<= 8;
154 		}
155 	}
156 }
157