xref: /titanic_51/usr/src/lib/libbsm/common/adrm.c (revision 355b4669e025ff377602b6fc7caaf30dbc218371)
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 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /*
30  * Adr memory based translations
31  */
32 
33 #include <stdio.h>
34 #include <sys/types.h>
35 #include <bsm/audit.h>
36 #include <bsm/audit_record.h>
37 
38 void
39 adrm_start(adr_t *adr, char *p)
40 {
41 	adr->adr_stream = p;
42 	adr->adr_now = p;
43 }
44 
45 /*
46  * adrm_char - pull out characters
47  */
48 void
49 adrm_char(adr_t *adr, char *cp, int count)
50 {
51 	while (count--)
52 		*cp++ = *adr->adr_now++;
53 }
54 
55 /*
56  * adrm_short - pull out shorts
57  */
58 void
59 adrm_short(adr_t *adr, short *sp, int count)
60 {
61 
62 	while (count--) {
63 		*sp = *adr->adr_now++ << 8;
64 		*sp++ += ((short)*adr->adr_now++) & 0x00ff;
65 	}
66 }
67 
68 /*
69  * adrm_int32 - pull out int
70  */
71 void adrm_int(adr_t *adr, int32_t *lp, int count);
72 void adrm_long(adr_t *adr, int32_t *lp, int count);
73 #pragma weak adrm_int = adrm_int32
74 #pragma weak adrm_long = adrm_int32
75 
76 void
77 adrm_int32(adr_t *adr, int32_t *lp, int count)
78 {
79 	int i;
80 
81 	for (; count--; lp++) {
82 		*lp = 0;
83 		for (i = 0; i < 4; i++) {
84 			*lp <<= 8;
85 			*lp += ((int32_t)*adr->adr_now++) & 0x000000ff;
86 		}
87 	}
88 }
89 
90 void
91 adrm_int64(adr_t *adr, int64_t *lp, int count)
92 {
93 	int i;
94 
95 	for (; count--; lp++) {
96 		*lp = 0;
97 		for (i = 0; i < 8; i++) {
98 			*lp <<= 8;
99 			*lp += ((int64_t)*adr->adr_now++) & 0x00000000000000ff;
100 		}
101 	}
102 }
103 
104 void adrm_u_int(adr_t *adr, uint32_t *cp, int count);
105 void adrm_u_long(adr_t *adr, uint32_t *cp, int count);
106 #pragma weak adrm_u_int = adrm_u_int32
107 #pragma weak adrm_u_long = adrm_u_int32
108 
109 void
110 adrm_u_int32(adr_t *adr, uint32_t *cp, int count)
111 {
112 	adrm_int32(adr, (int32_t *)cp, count);
113 }
114 
115 void
116 adrm_u_char(adr_t *adr, uchar_t *cp, int count)
117 {
118 	adrm_char(adr, (char *)cp, count);
119 }
120 
121 void
122 adrm_u_int64(adr_t *adr, uint64_t *lp, int count)
123 {
124 	adrm_int64(adr, (int64_t *)lp, count);
125 }
126 
127 void
128 adrm_u_short(adr_t *adr, ushort_t *sp, int count)
129 {
130 	adrm_short(adr, (short *)sp, count);
131 }
132 
133 /*
134  * adrm_putint32 - pack in int32
135  */
136 #pragma weak adrm_putint = adrm_putint32
137 #pragma weak adrm_putlong = adrm_putint32
138 void
139 adrm_putint32(adr_t *adr, int32_t *lp, int count)
140 {
141 	int i;		/* index for counting */
142 	int32_t l;	/* value for shifting */
143 
144 	for (; count-- > 0; lp++) {
145 		for (i = 0, l = *lp; i < 4; i++) {
146 			*adr->adr_now++ = (char)((l & (int32_t)0xff000000) >>
147 				(int)24);
148 			l <<= (int)8;
149 		}
150 	}
151 }
152