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 #include <sys/types.h>
28 #include <sys/param.h>
29 #include <sys/user.h>
30 #include <sys/buf.h>
31 #include <sys/systm.h>
32 #include <sys/vm.h>
33 #include <sys/uio.h>
34 #include <vm/seg.h>
35 #include <sys/stat.h>
36
37 #include <sys/time.h>
38 #include <sys/varargs.h>
39
40 #include <sys/rsm/rsm.h>
41
42 /* lint -w2 */
43
44 extern char *vsprintf_len(size_t, char *, const char *, va_list);
45 extern char *sprintf(char *buf, const char *fmt, ...);
46
47 /*
48 * From kmdb, read printfs using : *rsmka_dbg/s
49 */
50 #define RSMKA_BUFSIZE 0x10000
51
52 char rsmka_buf[RSMKA_BUFSIZE];
53 char *rsmka_dbg = rsmka_buf;
54 char *rsmka_buf_end = rsmka_buf;
55 char *rsmka_buf_top = rsmka_buf + RSMKA_BUFSIZE - 256;
56 kmutex_t rsmka_buf_lock;
57
58 int rsmdbg_category = RSM_KERNEL_ALL;
59 #ifdef DEBUG
60 int rsmdbg_level = RSM_DEBUG_VERBOSE;
61 #else
62 int rsmdbg_level = RSM_NOTICE;
63 #endif
64
dbprintf(char * fmt,...)65 void dbprintf(char *fmt, ...) {
66 va_list ap;
67 /* lint -save -e40 */
68 va_start(ap, fmt);
69 /* lint -restore */
70 mutex_enter(&rsmka_buf_lock);
71 (void) vsprintf_len(255, rsmka_buf_end, fmt, ap);
72 rsmka_buf_end += strlen(rsmka_buf_end);
73 if (rsmka_buf_end > rsmka_buf_top) {
74 rsmka_buf_end = rsmka_buf;
75 }
76 va_end(ap);
77 mutex_exit(&rsmka_buf_lock);
78 }
79
80 void
dbg_printf(int msg_category,int msg_level,char * fmt,...)81 dbg_printf(int msg_category, int msg_level, char *fmt, ...)
82 {
83 if ((msg_category & rsmdbg_category) &&
84 (msg_level <= rsmdbg_level)) {
85 va_list ap;
86 va_start(ap, fmt);
87 mutex_enter(&rsmka_buf_lock);
88 (void) sprintf(rsmka_buf_end, "%16" PRIx64 ":",
89 curthread->t_did);
90 rsmka_buf_end += 17;
91 (void) vsprintf_len(255, rsmka_buf_end, fmt, ap);
92 rsmka_buf_end += strlen(rsmka_buf_end);
93 if (rsmka_buf_end > rsmka_buf_top) {
94 rsmka_buf_end = rsmka_buf;
95 }
96 mutex_exit(&rsmka_buf_lock);
97 va_end(ap);
98 }
99 }
100