Print this page
5218 posix definition of NULL
correct unistd.h and iso/stddef_iso.h
update gate source affected
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libumem/common/misc.c
+++ new/usr/src/lib/libumem/common/misc.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 27 #pragma ident "%Z%%M% %I% %E% SMI"
28 28
29 29 #include <unistd.h>
30 30 #include <dlfcn.h>
31 31 #include <signal.h>
32 32 #include <stdarg.h>
33 33 #include <stdio.h>
34 34 #include <string.h>
35 35
36 36 #include <sys/machelf.h>
37 37
38 38 #include <umem_impl.h>
39 39 #include "misc.h"
40 40
41 41 #define UMEM_ERRFD 2 /* goes to standard error */
42 42 #define UMEM_MAX_ERROR_SIZE 4096 /* error messages are truncated to this */
43 43
44 44 /*
45 45 * This is a circular buffer for holding error messages.
46 46 * umem_error_enter appends to the buffer, adding "..." to the beginning
47 47 * if data has been lost.
48 48 */
49 49
50 50 #define ERR_SIZE 8192 /* must be a power of 2 */
51 51
52 52 static mutex_t umem_error_lock = DEFAULTMUTEX;
53 53
54 54 static char umem_error_buffer[ERR_SIZE] = "";
55 55 static uint_t umem_error_begin = 0;
56 56 static uint_t umem_error_end = 0;
57 57
58 58 #define WRITE_AND_INC(var, value) { \
59 59 umem_error_buffer[(var)++] = (value); \
60 60 var = P2PHASE((var), ERR_SIZE); \
61 61 }
62 62
63 63 static void
64 64 umem_log_enter(const char *error_str)
65 65 {
66 66 int looped;
67 67 char c;
68 68
69 69 looped = 0;
70 70
71 71 (void) mutex_lock(&umem_error_lock);
72 72
73 73 while ((c = *error_str++) != '\0') {
74 74 WRITE_AND_INC(umem_error_end, c);
75 75 if (umem_error_end == umem_error_begin)
76 76 looped = 1;
77 77 }
78 78
79 79 umem_error_buffer[umem_error_end] = 0;
80 80
81 81 if (looped) {
82 82 uint_t idx;
83 83 umem_error_begin = P2PHASE(umem_error_end + 1, ERR_SIZE);
84 84
85 85 idx = umem_error_begin;
86 86 WRITE_AND_INC(idx, '.');
87 87 WRITE_AND_INC(idx, '.');
88 88 WRITE_AND_INC(idx, '.');
89 89 }
90 90
91 91 (void) mutex_unlock(&umem_error_lock);
92 92 }
93 93
94 94 void
95 95 umem_error_enter(const char *error_str)
96 96 {
97 97 #ifndef UMEM_STANDALONE
98 98 if (umem_output && !issetugid())
99 99 (void) write(UMEM_ERRFD, error_str, strlen(error_str));
100 100 #endif
101 101
102 102 umem_log_enter(error_str);
103 103 }
104 104
105 105 int
106 106 highbit(ulong_t i)
107 107 {
108 108 register int h = 1;
109 109
110 110 if (i == 0)
111 111 return (0);
112 112 #ifdef _LP64
113 113 if (i & 0xffffffff00000000ul) {
114 114 h += 32; i >>= 32;
115 115 }
116 116 #endif
117 117 if (i & 0xffff0000) {
118 118 h += 16; i >>= 16;
119 119 }
120 120 if (i & 0xff00) {
121 121 h += 8; i >>= 8;
122 122 }
123 123 if (i & 0xf0) {
124 124 h += 4; i >>= 4;
125 125 }
126 126 if (i & 0xc) {
127 127 h += 2; i >>= 2;
128 128 }
129 129 if (i & 0x2) {
130 130 h += 1;
131 131 }
132 132 return (h);
133 133 }
134 134
135 135 int
136 136 lowbit(ulong_t i)
137 137 {
138 138 register int h = 1;
139 139
140 140 if (i == 0)
141 141 return (0);
142 142 #ifdef _LP64
143 143 if (!(i & 0xffffffff)) {
144 144 h += 32; i >>= 32;
145 145 }
146 146 #endif
147 147 if (!(i & 0xffff)) {
148 148 h += 16; i >>= 16;
149 149 }
150 150 if (!(i & 0xff)) {
151 151 h += 8; i >>= 8;
152 152 }
153 153 if (!(i & 0xf)) {
154 154 h += 4; i >>= 4;
155 155 }
156 156 if (!(i & 0x3)) {
157 157 h += 2; i >>= 2;
158 158 }
159 159 if (!(i & 0x1)) {
160 160 h += 1;
161 161 }
162 162 return (h);
163 163 }
164 164
165 165 void
166 166 hrt2ts(hrtime_t hrt, timestruc_t *tsp)
167 167 {
168 168 tsp->tv_sec = hrt / NANOSEC;
169 169 tsp->tv_nsec = hrt % NANOSEC;
170 170 }
171 171
172 172 void
173 173 log_message(const char *format, ...)
174 174 {
175 175 char buf[UMEM_MAX_ERROR_SIZE] = "";
176 176
177 177 va_list va;
178 178
179 179 va_start(va, format);
180 180 (void) vsnprintf(buf, UMEM_MAX_ERROR_SIZE-1, format, va);
181 181 va_end(va);
182 182
183 183 #ifndef UMEM_STANDALONE
184 184 if (umem_output > 1)
185 185 (void) write(UMEM_ERRFD, buf, strlen(buf));
186 186 #endif
187 187
188 188 umem_log_enter(buf);
189 189 }
190 190
191 191 #ifndef UMEM_STANDALONE
192 192 void
193 193 debug_printf(const char *format, ...)
194 194 {
195 195 char buf[UMEM_MAX_ERROR_SIZE] = "";
196 196
197 197 va_list va;
198 198
199 199 va_start(va, format);
200 200 (void) vsnprintf(buf, UMEM_MAX_ERROR_SIZE-1, format, va);
201 201 va_end(va);
202 202
203 203 (void) write(UMEM_ERRFD, buf, strlen(buf));
204 204 }
205 205 #endif
206 206
207 207 void
208 208 umem_vprintf(const char *format, va_list va)
209 209 {
210 210 char buf[UMEM_MAX_ERROR_SIZE] = "";
211 211
212 212 (void) vsnprintf(buf, UMEM_MAX_ERROR_SIZE-1, format, va);
213 213
214 214 umem_error_enter(buf);
215 215 }
216 216
217 217 void
218 218 umem_printf(const char *format, ...)
219 219 {
220 220 va_list va;
221 221
222 222 va_start(va, format);
223 223 umem_vprintf(format, va);
224 224 va_end(va);
225 225 }
226 226
227 227 /*ARGSUSED*/
228 228 void
229 229 umem_printf_warn(void *ignored, const char *format, ...)
230 230 {
231 231 va_list va;
232 232
233 233 va_start(va, format);
234 234 umem_vprintf(format, va);
235 235 va_end(va);
236 236 }
↓ open down ↓ |
236 lines elided |
↑ open up ↑ |
237 237
238 238 /*
239 239 * print_sym tries to print out the symbol and offset of a pointer
240 240 */
241 241 int
242 242 print_sym(void *pointer)
243 243 {
244 244 int result;
245 245 Dl_info sym_info;
246 246
247 - uintptr_t end = NULL;
247 + uintptr_t end = (uintptr_t)NULL;
248 248
249 249 Sym *ext_info = NULL;
250 250
251 251 result = dladdr1(pointer, &sym_info, (void **)&ext_info,
252 252 RTLD_DL_SYMENT);
253 253
254 254 if (result != 0) {
255 255 const char *endpath;
256 256
257 257 end = (uintptr_t)sym_info.dli_saddr + ext_info->st_size;
258 258
259 259 endpath = strrchr(sym_info.dli_fname, '/');
260 260 if (endpath)
261 261 endpath++;
262 262 else
263 263 endpath = sym_info.dli_fname;
264 264 umem_printf("%s'", endpath);
265 265 }
266 266
267 267 if (result == 0 || (uintptr_t)pointer > end) {
268 268 umem_printf("?? (0x%p)", pointer);
269 269 return (0);
270 270 } else {
271 271 umem_printf("%s+0x%p", sym_info.dli_sname,
272 272 (char *)pointer - (char *)sym_info.dli_saddr);
273 273 return (1);
274 274 }
275 275 }
↓ open down ↓ |
18 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX