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