2 * Copyright (c) 1986, 1988, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * @(#)subr_prf.c 8.3 (Berkeley) 1/21/94
35 * $FreeBSD: src/sys/kern/subr_prf.c,v 1.61.2.5 2002/08/31 18:22:08 dwmalone Exp $
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/kernel.h>
43 #include <sys/msgbuf.h>
44 #include <sys/malloc.h>
48 #include <sys/tprintf.h>
49 #include <sys/stdint.h>
50 #include <sys/syslog.h>
53 #include <sys/sysctl.h>
55 #include <sys/ctype.h>
56 #include <sys/eventhandler.h>
57 #include <sys/kthread.h>
58 #include <sys/cpu_topology.h>
60 #include <sys/thread2.h>
61 #include <sys/spinlock2.h>
68 * Note that stdarg.h and the ANSI style va_start macro is used for both
69 * ANSI and traditional C compilers. We use the __ machine version to stay
70 * within the kernel header file set.
72 #include <machine/stdarg.h>
78 #define TONOSPIN 0x10 /* avoid serialization */
80 /* Max number conversion buffer length: a u_quad_t in base 2, plus NUL byte. */
81 #define MAXNBUF (sizeof(intmax_t) * NBBY + 1)
96 struct tty *constty; /* pointer to console "window" tty */
98 static void msglogchar(int c, int pri);
99 static void msgaddchar(int c, void *dummy);
100 static void kputchar (int ch, void *arg);
101 static char *ksprintn (char *nbuf, uintmax_t num, int base, int *lenp,
103 static void snprintf_func (int ch, void *arg);
105 static int consintr = 1; /* Ok to handle console interrupts? */
106 static int msgbufmapped; /* Set when safe to use msgbuf */
107 static struct spinlock cons_spin = SPINLOCK_INITIALIZER(cons_spin, "cons_spin");
108 static thread_t constty_td = NULL;
112 static int log_console_output = 1;
113 TUNABLE_INT("kern.log_console_output", &log_console_output);
114 SYSCTL_INT(_kern, OID_AUTO, log_console_output, CTLFLAG_RW,
115 &log_console_output, 0, "Duplicate console output to the syslog");
116 static int kprintf_logging = TOLOG | TOCONS;
117 TUNABLE_INT("kern.kprintf_logging", &kprintf_logging);
118 SYSCTL_INT(_kern, OID_AUTO, kprintf_logging, CTLFLAG_RW,
119 &kprintf_logging, 0, "kprintf() target bitmask: 0x1=console 0x4=dmesg");
121 static int ptr_restrict = 0;
122 TUNABLE_INT("security.ptr_restrict", &ptr_restrict);
123 SYSCTL_INT(_security, OID_AUTO, ptr_restrict, CTLFLAG_RW, &ptr_restrict, 0,
124 "Prevent leaking the kernel pointers back to userland");
126 static int unprivileged_read_msgbuf = 1;
127 TUNABLE_INT("security.unprivileged_read_msgbuf", &unprivileged_read_msgbuf);
128 SYSCTL_INT(_security, OID_AUTO, unprivileged_read_msgbuf, CTLFLAG_RW,
129 &unprivileged_read_msgbuf, 0,
130 "Unprivileged processes may read the kernel message buffer");
133 * Warn that a system table is full.
136 tablefull(const char *tab)
139 log(LOG_ERR, "%s: table is full\n", tab);
143 * Uprintf prints to the controlling terminal for the current process.
146 uprintf(const char *fmt, ...)
148 struct proc *p = curproc;
150 struct putchar_arg pca;
153 if (p && (p->p_flags & P_CONTROLT) && p->p_session->s_ttyvp) {
155 pca.tty = p->p_session->s_ttyp;
158 retval = kvcprintf(fmt, kputchar, &pca, ap);
165 tprintf_open(struct proc *p)
167 if ((p->p_flags & P_CONTROLT) && p->p_session->s_ttyvp) {
168 sess_hold(p->p_session);
169 return ((tpr_t) p->p_session);
175 tprintf_close(tpr_t sess)
178 sess_rele((struct session *) sess);
182 * tprintf prints on the controlling terminal associated
183 * with the given session.
186 tprintf(tpr_t tpr, const char *fmt, ...)
188 struct session *sess = (struct session *)tpr;
189 struct tty *tp = NULL;
192 struct putchar_arg pca;
195 if (sess && sess->s_ttyvp && ttycheckoutq(sess->s_ttyp, 0)) {
203 retval = kvcprintf(fmt, kputchar, &pca, ap);
210 * Ttyprintf displays a message on a tty; it should be used only by
211 * the tty driver, or anything that knows the underlying tty will not
212 * be revoke(2)'d away. Other callers should use tprintf.
215 ttyprintf(struct tty *tp, const char *fmt, ...)
218 struct putchar_arg pca;
224 retval = kvcprintf(fmt, kputchar, &pca, ap);
230 * Log writes to the log buffer, and guarantees not to sleep (so can be
231 * called by interrupt routines). If there is no process reading the
232 * log yet, it writes to the console also.
235 log(int level, const char *fmt, ...)
239 struct putchar_arg pca;
243 if ((kprintf_logging & TOCONS) == 0 || log_open)
249 retval = kvcprintf(fmt, kputchar, &pca, ap);
256 #define CONSCHUNK 128
259 log_console(struct uio *uio)
261 int c, i, error, iovlen, nl;
263 struct iovec *miov = NULL;
267 if (!log_console_output)
270 pri = LOG_INFO | LOG_CONSOLE;
272 iovlen = uio->uio_iovcnt * sizeof (struct iovec);
273 miov = kmalloc(iovlen, M_TEMP, M_WAITOK);
274 consbuffer = kmalloc(CONSCHUNK, M_TEMP, M_WAITOK);
275 bcopy((caddr_t)muio.uio_iov, (caddr_t)miov, iovlen);
280 while (uio->uio_resid > 0) {
281 c = (int)szmin(uio->uio_resid, CONSCHUNK);
282 error = uiomove(consbuffer, (size_t)c, uio);
285 for (i = 0; i < c; i++) {
286 msglogchar(consbuffer[i], pri);
287 if (consbuffer[i] == '\n')
294 msglogchar('\n', pri);
297 kfree(consbuffer, M_TEMP);
302 * Output to the console.
305 kprintf(const char *fmt, ...)
309 struct putchar_arg pca;
312 savintr = consintr; /* disable interrupts */
316 pca.flags = kprintf_logging & ~TOTTY;
318 retval = kvcprintf(fmt, kputchar, &pca, ap);
322 consintr = savintr; /* reenable interrupts */
327 kvprintf(const char *fmt, __va_list ap)
330 struct putchar_arg pca;
333 savintr = consintr; /* disable interrupts */
336 pca.flags = kprintf_logging & ~TOTTY;
338 retval = kvcprintf(fmt, kputchar, &pca, ap);
341 consintr = savintr; /* reenable interrupts */
346 * Limited rate kprintf. The passed rate structure must be initialized
347 * with the desired reporting frequency. A frequency of 0 will result in
350 * count may be initialized to a negative number to allow an initial
353 * Returns 0 if it did not issue the printf, non-zero if it did.
356 krateprintf(struct krate *rate, const char *fmt, ...)
361 if (rate->ticks != (int)time_uptime) {
362 rate->ticks = (int)time_uptime;
366 if (rate->count < rate->freq) {
379 * Print a character to the dmesg log, the console, and/or the user's
382 * NOTE: TOTTY does not require nonblocking operation, but TOCONS
383 * and TOLOG do. When we have a constty we still output to
384 * the real console but we have a monitoring thread which
385 * we wakeup which tracks the log.
388 kputchar(int c, void *arg)
390 struct putchar_arg *ap = (struct putchar_arg*) arg;
391 int flags = ap->flags;
392 struct tty *tp = ap->tty;
396 if ((flags & TOCONS) && tp == NULL && constty)
397 flags |= TOLOG | TOWAKEUP;
398 if ((flags & TOTTY) && tputchar(c, tp) < 0)
401 msglogchar(c, ap->pri);
402 if ((flags & TOCONS) && c)
404 if (flags & TOWAKEUP)
409 * Scaled down version of sprintf(3).
412 ksprintf(char *buf, const char *cfmt, ...)
417 __va_start(ap, cfmt);
418 retval = kvcprintf(cfmt, NULL, buf, ap);
425 * Scaled down version of vsprintf(3).
428 kvsprintf(char *buf, const char *cfmt, __va_list ap)
432 retval = kvcprintf(cfmt, NULL, buf, ap);
438 * Scaled down version of snprintf(3).
441 ksnprintf(char *str, size_t size, const char *format, ...)
446 __va_start(ap, format);
447 retval = kvsnprintf(str, size, format, ap);
453 * Scaled down version of vsnprintf(3).
456 kvsnprintf(char *str, size_t size, const char *format, __va_list ap)
458 struct snprintf_arg info;
463 retval = kvcprintf(format, snprintf_func, &info, ap);
464 if (info.remain >= 1)
470 kvasnprintf(char **strp, size_t size, const char *format, __va_list ap)
472 struct snprintf_arg info;
475 *strp = kmalloc(size, M_TEMP, M_WAITOK);
478 retval = kvcprintf(format, snprintf_func, &info, ap);
479 if (info.remain >= 1)
485 kvasfree(char **strp)
488 kfree(*strp, M_TEMP);
494 snprintf_func(int ch, void *arg)
496 struct snprintf_arg *const info = arg;
498 if (info->remain >= 2) {
505 * Put a NUL-terminated ASCII number (base <= 36) in a buffer in reverse
506 * order; return an optional length and a pointer to the last character
507 * written in the buffer (i.e., the first character of the string).
508 * The buffer pointed to by `nbuf' must have length >= MAXNBUF.
511 ksprintn(char *nbuf, uintmax_t num, int base, int *lenp, int upper)
518 c = hex2ascii(num % base);
519 *++p = upper ? toupper(c) : c;
520 } while (num /= base);
527 * Scaled down version of printf(3).
529 * Two additional formats:
531 * The format %pb%i is supported to decode error registers.
534 * kprintf("reg=%pb%i\n", "<base><arg>*", regval);
536 * where <base> is the output base expressed as a control character, e.g.
537 * \10 gives octal; \20 gives hex. Each arg is a sequence of characters,
538 * the first of which gives the bit number to be inspected (origin 1), and
539 * the next characters (up to a control character, i.e. a character <= 32),
540 * give the name of the register. Thus:
542 * kvcprintf("reg=%pb%i\n", "\10\2BITTWO\1BITONE\n", 3);
544 * would produce output:
546 * reg=3<BITTWO,BITONE>
549 #define PCHAR(c) {int cc=(c); if(func) (*func)(cc,arg); else *d++=cc; retval++;}
552 kvcprintf(char const *fmt, void (*func)(int, void*), void *arg, __va_list ap)
556 const char *p, *percent, *q;
559 int base, tmp, width, ladjust, sharpflag, spaceflag, neg, sign, dot;
560 int cflag, hflag, jflag, lflag, qflag, tflag, zflag;
563 int retval = 0, stop = 0;
568 * Make a supreme effort to avoid reentrant panics or deadlocks.
570 * NOTE! Do nothing that would access mycpu/gd/fs unless the
571 * function is the normal kputchar(), which allows us to
572 * use this function for very early debugging with a special
575 if (func == kputchar) {
576 if (mycpu->gd_flags & GDF_KPRINTF)
578 atomic_set_long(&mycpu->gd_flags, GDF_KPRINTF);
582 ddb_active = db_active;
594 fmt = "(fmt null)\n";
596 usespin = (func == kputchar &&
597 (kprintf_logging & TONOSPIN) == 0 &&
598 panic_cpu_gd != mycpu &&
599 (((struct putchar_arg *)arg)->flags & TOTTY) == 0);
602 spin_lock(&cons_spin);
608 while ((ch = (u_char)*fmt++) != '%' || stop) {
614 dot = dwidth = ladjust = neg = sharpflag = sign = upper = 0;
616 cflag = hflag = jflag = lflag = qflag = tflag = zflag = 0;
619 switch (ch = (u_char)*fmt++) {
640 width = __va_arg(ap, int);
646 dwidth = __va_arg(ap, int);
654 case '1': case '2': case '3': case '4':
655 case '5': case '6': case '7': case '8': case '9':
656 for (n = 0;; ++fmt) {
657 n = n * 10 + ch - '0';
659 if (ch < '0' || ch > '9')
668 PCHAR(__va_arg(ap, int));
694 *(__va_arg(ap, char *)) = retval;
696 *(__va_arg(ap, short *)) = retval;
698 *(__va_arg(ap, intmax_t *)) = retval;
700 *(__va_arg(ap, long *)) = retval;
702 *(__va_arg(ap, quad_t *)) = retval;
704 *(__va_arg(ap, int *)) = retval;
710 /* peek if this is a /b/ hiding as /p/ or not */
711 if (fmt[0] == 'b' && fmt[1] == '%' && fmt[2] == 'i') {
712 fmt += 3; /* consume "b%i" */
713 p = __va_arg(ap, char *);
714 num = (u_int)__va_arg(ap, int);
715 for (q = ksprintn(nbuf, num, *p++, NULL, 0);*q;)
723 if (num & (1 << (n - 1))) {
724 PCHAR(tmp ? ',' : '<');
725 for (; (n = *p) > ' '; ++p)
729 for (; *p > ' '; ++p)
738 sharpflag = (width == 0);
740 num = (uintptr_t)__va_arg(ap, void *);
741 if (ptr_restrict && fmt[0] != 'x' &&
742 !(panicstr || dumping || ddb_active)) {
743 if (ptr_restrict == 1) {
744 /* zero out upper bits */
755 p = __va_arg(ap, char *);
761 for (n = 0; n < dwidth && p[n]; n++)
766 if (!ladjust && width > 0)
771 if (ladjust && width > 0)
793 num = (u_char)__va_arg(ap, int);
795 num = (u_short)__va_arg(ap, int);
797 num = __va_arg(ap, uintmax_t);
799 num = __va_arg(ap, u_long);
801 num = __va_arg(ap, u_quad_t);
803 num = __va_arg(ap, ptrdiff_t);
805 num = __va_arg(ap, size_t);
807 num = __va_arg(ap, u_int);
811 num = (char)__va_arg(ap, int);
813 num = (short)__va_arg(ap, int);
815 num = __va_arg(ap, intmax_t);
817 num = __va_arg(ap, long);
819 num = __va_arg(ap, quad_t);
821 num = __va_arg(ap, ptrdiff_t);
823 num = __va_arg(ap, ssize_t);
825 num = __va_arg(ap, int);
827 if (sign && (intmax_t)num < 0) {
829 num = -(intmax_t)num;
831 p = ksprintn(nbuf, num, base, &n, upper);
833 if (sharpflag && num != 0) {
839 if (neg || (sign && spaceflag))
842 if (!ladjust && padc == '0')
843 dwidth = width - tmp;
844 width -= tmp + imax(dwidth, n);
851 } else if (sign && spaceflag) {
854 if (sharpflag && num != 0) {
857 } else if (base == 16) {
874 while (percent < fmt)
877 * Since we ignore an formatting argument it is no
878 * longer safe to obey the remaining formatting
879 * arguments as the arguments will no longer match
888 * Cleanup reentrancy issues.
890 if (func == kputchar)
891 atomic_clear_long(&mycpu->gd_flags, GDF_KPRINTF);
893 spin_unlock(&cons_spin);
902 * Called from the panic code to try to get the console working
903 * again in case we paniced inside a kprintf().
908 spin_init(&cons_spin, "kvcre");
909 atomic_clear_long(&mycpu->gd_flags, GDF_KPRINTF);
913 * Console support thread for constty intercepts. This is needed because
914 * console tty intercepts can block. Instead of having kputchar() attempt
915 * to directly write to the console intercept we just force it to log
916 * and wakeup this baby to track and dump the log to constty.
927 EVENTHANDLER_REGISTER(shutdown_pre_sync, shutdown_kproc,
928 constty_td, SHUTDOWN_PRI_FIRST);
929 constty_td->td_flags |= TDF_SYSTHREAD;
932 rindex = mbp->msg_bufr; /* persistent loop variable */
933 xindex = mbp->msg_bufx - 1; /* anything different than bufx */
937 kproc_suspend_loop();
942 if (xindex == mbp->msg_bufx ||
945 tsleep(constty_td, 0, "waiting", hz*60);
952 * Get message buf FIFO indices. rindex is tracking.
954 xindex = mbp->msg_bufx;
956 if ((tp = constty) == NULL) {
962 * Check if the calculated bytes has rolled the whole
966 if (n > mbp->msg_size - 1024) {
967 rindex = xindex - mbp->msg_size + 2048;
972 * And dump it. If constty gets stuck will give up.
974 while (rindex != xindex) {
975 u_int ri = rindex % mbp->msg_size;
976 if (tputchar((uint8_t)mbp->msg_ptr[ri], tp) < 0) {
981 if (tp->t_outq.c_cc >= tp->t_ohiwat) {
982 tsleep(constty_daemon, 0, "blocked", hz / 10);
983 if (tp->t_outq.c_cc >= tp->t_ohiwat) {
993 static struct kproc_desc constty_kp = {
998 SYSINIT(bufdaemon, SI_SUB_KTHREAD_UPDATE, SI_ORDER_ANY,
999 kproc_start, &constty_kp);
1002 * Put character in log buffer with a particular priority.
1007 msglogchar(int c, int pri)
1009 static int lastpri = -1;
1010 static int dangling;
1016 if (c == '\0' || c == '\r')
1018 if (pri != -1 && pri != lastpri) {
1020 msgaddchar('\n', NULL);
1023 msgaddchar('<', NULL);
1024 for (p = ksprintn(nbuf, (uintmax_t)pri, 10, NULL, 0); *p;)
1025 msgaddchar(*p--, NULL);
1026 msgaddchar('>', NULL);
1029 msgaddchar(c, NULL);
1039 * Put char in log buffer. Make sure nothing blows up beyond repair if
1040 * we have an MP race.
1045 msgaddchar(int c, void *dummy)
1056 lindex = mbp->msg_bufl;
1057 rindex = mbp->msg_bufr;
1058 xindex = mbp->msg_bufx++; /* Allow SMP race */
1061 mbp->msg_ptr[xindex % mbp->msg_size] = c;
1062 n = xindex - lindex;
1063 if (n > mbp->msg_size - 1024) {
1064 lindex = xindex - mbp->msg_size + 2048;
1066 mbp->msg_bufl = lindex;
1068 n = xindex - rindex;
1069 if (n > mbp->msg_size - 1024) {
1070 rindex = xindex - mbp->msg_size + 2048;
1072 mbp->msg_bufr = rindex;
1077 msgbufcopy(struct msgbuf *oldp)
1083 rindex = oldp->msg_bufr;
1084 xindex = oldp->msg_bufx;
1087 n = xindex - rindex;
1088 if (n > oldp->msg_size - 1024)
1089 rindex = xindex - oldp->msg_size + 2048;
1090 while (rindex != xindex) {
1091 msglogchar(oldp->msg_ptr[rindex % oldp->msg_size], -1);
1097 msgbufinit(void *ptr, size_t size)
1100 static struct msgbuf *oldp = NULL;
1102 size -= sizeof(*msgbufp);
1104 msgbufp = (struct msgbuf *) (cp + size);
1105 if (msgbufp->msg_magic != MSG_MAGIC || msgbufp->msg_size != size) {
1107 bzero(msgbufp, sizeof(*msgbufp));
1108 msgbufp->msg_magic = MSG_MAGIC;
1109 msgbufp->msg_size = (char *)msgbufp - cp;
1111 msgbufp->msg_ptr = cp;
1112 if (msgbufmapped && oldp != msgbufp)
1119 /* Sysctls for accessing/clearing the msgbuf */
1122 sysctl_kern_msgbuf(SYSCTL_HANDLER_ARGS)
1127 u_int rindex_modulo;
1128 u_int xindex_modulo;
1134 * Only wheel or root can access the message log.
1136 if (unprivileged_read_msgbuf == 0) {
1137 KKASSERT(req->td->td_proc);
1138 cred = req->td->td_proc->p_ucred;
1140 if ((cred->cr_prison || groupmember(0, cred) == 0) &&
1141 priv_check(req->td, PRIV_ROOT) != 0
1148 * Unwind the buffer, so that it's linear (possibly starting with
1149 * some initial nulls).
1151 * We don't push the entire buffer like we did before because
1152 * bufr (and bufl) now advance in chunks when the fifo is full,
1153 * rather than one character.
1156 rindex = mbp->msg_bufr;
1157 xindex = mbp->msg_bufx;
1158 n = xindex - rindex;
1159 if (n > mbp->msg_size - 1024) {
1160 rindex = xindex - mbp->msg_size + 2048;
1161 n = xindex - rindex;
1163 rindex_modulo = rindex % mbp->msg_size;
1164 xindex_modulo = xindex % mbp->msg_size;
1166 if (rindex_modulo < xindex_modulo) {
1168 * Can handle in one linear section.
1170 error = sysctl_handle_opaque(oidp,
1171 mbp->msg_ptr + rindex_modulo,
1172 xindex_modulo - rindex_modulo,
1174 } else if (rindex_modulo == xindex_modulo) {
1176 * Empty buffer, just return a single newline
1178 error = sysctl_handle_opaque(oidp, "\n", 1, req);
1179 } else if (n <= mbp->msg_size - rindex_modulo) {
1181 * Can handle in one linear section.
1183 error = sysctl_handle_opaque(oidp,
1184 mbp->msg_ptr + rindex_modulo,
1189 * Glue together two linear sections into one contiguous
1192 error = sysctl_handle_opaque(oidp,
1193 mbp->msg_ptr + rindex_modulo,
1194 mbp->msg_size - rindex_modulo,
1196 n -= mbp->msg_size - rindex_modulo;
1198 error = sysctl_handle_opaque(oidp, mbp->msg_ptr,
1204 SYSCTL_PROC(_kern, OID_AUTO, msgbuf, CTLTYPE_STRING | CTLFLAG_RD,
1205 0, 0, sysctl_kern_msgbuf, "A", "Contents of kernel message buffer");
1207 static int msgbuf_clear;
1210 sysctl_kern_msgbuf_clear(SYSCTL_HANDLER_ARGS)
1213 error = sysctl_handle_int(oidp, oidp->oid_arg1, oidp->oid_arg2, req);
1214 if (!error && req->newptr) {
1215 /* Clear the buffer and reset write pointer */
1216 msgbufp->msg_bufr = msgbufp->msg_bufx;
1217 msgbufp->msg_bufl = msgbufp->msg_bufx;
1218 bzero(msgbufp->msg_ptr, msgbufp->msg_size);
1224 SYSCTL_PROC(_kern, OID_AUTO, msgbuf_clear,
1225 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_SECURE, &msgbuf_clear, 0,
1226 sysctl_kern_msgbuf_clear, "I", "Clear kernel message buffer");
1230 DB_SHOW_COMMAND(msgbuf, db_show_msgbuf)
1236 if (!msgbufmapped) {
1237 db_printf("msgbuf not mapped yet\n");
1240 db_printf("msgbufp = %p\n", msgbufp);
1241 db_printf("magic = %x, size = %d, r= %d, w = %d, ptr = %p\n",
1242 msgbufp->msg_magic, msgbufp->msg_size,
1243 msgbufp->msg_bufr % msgbufp->msg_size,
1244 msgbufp->msg_bufx % msgbufp->msg_size,
1247 rindex = msgbufp->msg_bufr;
1248 for (i = 0; i < msgbufp->msg_size; i++) {
1249 j = (i + rindex) % msgbufp->msg_size;
1250 db_printf("%c", msgbufp->msg_ptr[j]);
1259 hexdump(const void *ptr, int length, const char *hdr, int flags)
1263 const unsigned char *cp;
1266 if ((flags & HD_DELIM_MASK) != 0)
1267 delim = (flags & HD_DELIM_MASK) >> 8;
1271 if ((flags & HD_COLUMN_MASK) != 0)
1272 cols = flags & HD_COLUMN_MASK;
1277 for (i = 0; i < length; i+= cols) {
1281 if ((flags & HD_OMIT_COUNT) == 0)
1282 kprintf("%04x ", i);
1284 if ((flags & HD_OMIT_HEX) == 0) {
1285 for (j = 0; j < cols; j++) {
1288 kprintf("%c%02x", delim, cp[k]);
1294 if ((flags & HD_OMIT_CHARS) == 0) {
1296 for (j = 0; j < cols; j++) {
1300 else if (cp[k] >= ' ' && cp[k] <= '~')
1301 kprintf("%c", cp[k]);
1312 kprint_cpuset(cpumask_t *mask)
1320 CPUSET_FOREACH(i, *mask) {
1335 kprintf("%d-%d", b, e - 1);
1347 kprintf("%d-%d", b, e - 1);