]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/kern/printf.c
xnu-3248.30.4.tar.gz
[apple/xnu.git] / osfmk / kern / printf.c
index fd04f883a2c1a27cd4f2ab8afaf0c4729a872a04..82ad32bb90acdcca8ea57016053e627bdcab0689 100644 (file)
  */
 
 #include <debug.h>
-#include <mach_kdb.h>
 #include <mach_kdp.h>
-#include <platforms.h>
 #include <mach/boolean.h>
 #include <kern/cpu_number.h>
-#include <kern/lock.h>
 #include <kern/thread.h>
 #include <kern/sched_prim.h>
 #include <kern/misc_protos.h>
 #endif
 #include <console/serial_protos.h>
 
-#ifdef __ppc__
-#include <ppc/Firmware.h>
-#endif
-
 #define isdigit(d) ((d) >= '0' && (d) <= '9')
 #define Ctod(c) ((c) - '0')
 
 #define MAXBUF (sizeof(long long int) * 8)     /* enough for binary */
 static char digs[] = "0123456789abcdef";
 
-
 #if CONFIG_NO_PRINTF_STRINGS
 /* Prevent CPP from breaking the definition below */
 #undef printf
@@ -222,6 +214,12 @@ printnum(
 
 boolean_t      _doprnt_truncates = FALSE;
 
+#if (DEVELOPMENT || DEBUG) 
+boolean_t      doprnt_hide_pointers = FALSE;
+#else
+boolean_t      doprnt_hide_pointers = TRUE;
+#endif
+
 int
 __doprnt(
        const char      *fmt,
@@ -229,7 +227,8 @@ __doprnt(
                                                /* character output routine */
        void                    (*putc)(int, void *arg),
        void                    *arg,
-       int                     radix)          /* default radix - for '%r' */
+       int                     radix,          /* default radix - for '%r' */
+       int                     is_log)
 {
        int             length;
        int             prec;
@@ -574,6 +573,21 @@ __doprnt(
 
                    if (truncate) u = (long long)((int)(u));
 
+                   if (doprnt_hide_pointers && is_log) {
+                       const char str[] = "<ptr>";
+                       const char* strp = str;
+                       int strl = sizeof(str) - 1;
+
+                       if (u >= VM_MIN_KERNEL_AND_KEXT_ADDRESS && u <= VM_MAX_KERNEL_ADDRESS) {
+                           while(*strp != '\0') {
+                               (*putc)(*strp, arg);
+                               strp++;
+                           }
+                           nprinted += strl;
+                           break;
+                       }
+                   }
+
                    if (u != 0 && altfmt) {
                        if (base == 8)
                            prefix = "0";
@@ -661,7 +675,18 @@ _doprnt(
        void                    (*putc)(char),
        int                     radix)          /* default radix - for '%r' */
 {
-    __doprnt(fmt, *argp, dummy_putc, putc, radix);
+    __doprnt(fmt, *argp, dummy_putc, putc, radix, FALSE);
+}
+
+void 
+_doprnt_log(
+       register const char     *fmt,
+       va_list                 *argp,
+                                               /* character output routine */
+       void                    (*putc)(char),
+       int                     radix)          /* default radix - for '%r' */
+{
+    __doprnt(fmt, *argp, dummy_putc, putc, radix, TRUE);
 }
 
 #if    MP_PRINTF 
@@ -762,22 +787,12 @@ conslog_putc(
 #endif
 }
 
-#if    MACH_KDB
-extern void db_putchar(char c);
-#endif
-
 void
-dbugprintf(__unused const char *fmt, ...)
+cons_putc_locked(
+       char c)
 {
-
-#if    MACH_KDB
-       va_list listp;
-
-       va_start(listp, fmt);
-       _doprnt(fmt, &listp, db_putchar, 16);
-       va_end(listp);
-#endif
-       return;
+       if ((debug_mode && !disable_debug_output) || !disableConsoleOutput)
+               cnputc(c);
 }
 
 int
@@ -788,7 +803,7 @@ printf(const char *fmt, ...)
        if (fmt) {
                disable_preemption();
                va_start(listp, fmt);
-               _doprnt(fmt, &listp, conslog_putc, 16);
+               _doprnt_log(fmt, &listp, conslog_putc, 16);
                va_end(listp);
                enable_preemption();
        }
@@ -833,7 +848,7 @@ kdb_printf(const char *fmt, ...)
        va_list listp;
 
        va_start(listp, fmt);
-       _doprnt(fmt, &listp, consdebug_putc, 16);
+       _doprnt_log(fmt, &listp, consdebug_putc, 16);
        va_end(listp);
        return 0;
 }
@@ -860,6 +875,7 @@ kdb_printf_unbuffered(const char *fmt, ...)
        return 0;
 }
 
+
 static void
 copybyte(int c, void *arg)
 {
@@ -886,7 +902,7 @@ sprintf(char *buf, const char *fmt, ...)
 
         va_start(listp, fmt);
         copybyte_str = buf;
-        __doprnt(fmt, listp, copybyte, &copybyte_str, 16);
+        __doprnt(fmt, listp, copybyte, &copybyte_str, 16, FALSE);
         va_end(listp);
        *copybyte_str = '\0';
         return (int)strlen(buf);