X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/2d21ac55c334faf3a56e5634905ed6987fc787d4..bd504ef0e0b883cdd7917b73b3574eb9ce669905:/osfmk/kern/printf.c diff --git a/osfmk/kern/printf.c b/osfmk/kern/printf.c index 6faceb7aa..88813d844 100644 --- a/osfmk/kern/printf.c +++ b/osfmk/kern/printf.c @@ -94,9 +94,7 @@ * %0m.n zero-padding * %*.* width and precision taken from arguments * - * This version does not implement %f, %e, or %g. It accepts, but - * ignores, an `l' as in %ld, %lo, %lx, and %lu, and therefore will not - * work correctly on machines for which sizeof(long) != sizeof(int). + * This version does not implement %f, %e, or %g. * * As mentioned, this version does not return any reasonable value. * @@ -157,7 +155,6 @@ */ #include -#include #include #include #include @@ -174,21 +171,25 @@ #endif #include -#ifdef __ppc__ -#include -#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 -#undef printf(x, ...) +/* Prevent CPP from breaking the definition below */ +#undef printf #endif +int _consume_printf_args(int a __unused, ...) +{ + return 0; +} +void _consume_kprintf_args(int a __unused, ...) +{ +} + static int printnum( unsigned long long int u, /* number to print */ @@ -218,7 +219,7 @@ boolean_t _doprnt_truncates = FALSE; int __doprnt( const char *fmt, - va_list *argp, + va_list argp, /* character output routine */ void (*putc)(int, void *arg), void *arg, @@ -290,7 +291,7 @@ __doprnt( } } else if (c == '*') { - length = va_arg(*argp, int); + length = va_arg(argp, int); c = *++fmt; if (length < 0) { ladjust = !ladjust; @@ -308,13 +309,15 @@ __doprnt( } } else if (c == '*') { - prec = va_arg(*argp, int); + prec = va_arg(argp, int); c = *++fmt; } } if (c == 'l') { c = *++fmt; /* need it if sizeof(int) < sizeof(long) */ + if (sizeof(int) prec || (length > 0 && n > length)) - break; - - (*putc)(*p++, arg); - nprinted++; + while ((n < prec) && (!(length > 0 && n >= length))) { + if (*p == '\0') { + break; + } + (*putc)(*p++, arg); + nprinted++; + n++; } if (n < length && ladjust) { @@ -464,8 +468,8 @@ __doprnt( unsigned char *up; char *q, *p; - up = (unsigned char *)va_arg(*argp, unsigned char *); - p = (char *)va_arg(*argp, char *); + up = (unsigned char *)va_arg(argp, unsigned char *); + p = (char *)va_arg(argp, char *); if (length == -1) length = 16; while(length--) { @@ -496,6 +500,9 @@ __doprnt( case 'p': altfmt = TRUE; + if (sizeof(int)= 0) { u = n; @@ -546,9 +553,9 @@ __doprnt( print_unsigned: if (long_long) { - u = va_arg(*argp, unsigned long long); + u = va_arg(argp, unsigned long long); } else { - u = va_arg(*argp, unsigned long); + u = va_arg(argp, unsigned int); } goto print_num; @@ -574,11 +581,11 @@ __doprnt( u /= base; } while (u != 0); - length -= (&buf[MAXBUF-1] - p); + length -= (int)(&buf[MAXBUF-1] - p); if (sign_char) length--; if (prefix) - length -= strlen(prefix); + length -= (int)strlen(prefix); if (padc == ' ' && !ladjust) { /* blank padding goes before prefix */ @@ -648,7 +655,7 @@ _doprnt( void (*putc)(char), int radix) /* default radix - for '%r' */ { - __doprnt(fmt, argp, dummy_putc, putc, radix); + __doprnt(fmt, *argp, dummy_putc, putc, radix); } #if MP_PRINTF @@ -744,26 +751,17 @@ conslog_putc( cnputc(c); #ifdef MACH_BSD - log_putc(c); + if (debug_mode == 0) + log_putc(c); #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 @@ -794,6 +792,25 @@ consdebug_putc(char c) PE_kputc(c); } +void +consdebug_putc_unbuffered(char c) +{ + if ((debug_mode && !disable_debug_output) || !disableConsoleOutput) + cnputc_unbuffered(c); + + debug_putc(c); + + if (!console_is_serial()) + if (!disable_serial_output) + PE_kputc(c); +} + +void +consdebug_log(char c) +{ + debug_putc(c); +} + int kdb_printf(const char *fmt, ...) { @@ -805,6 +822,30 @@ kdb_printf(const char *fmt, ...) return 0; } +int +kdb_log(const char *fmt, ...) +{ + va_list listp; + + va_start(listp, fmt); + _doprnt(fmt, &listp, consdebug_log, 16); + va_end(listp); + return 0; +} + +int +kdb_printf_unbuffered(const char *fmt, ...) +{ + va_list listp; + + va_start(listp, fmt); + _doprnt(fmt, &listp, consdebug_putc_unbuffered, 16); + va_end(listp); + return 0; +} + +#if !CONFIG_EMBEDDED + static void copybyte(int c, void *arg) { @@ -831,8 +872,9 @@ sprintf(char *buf, const char *fmt, ...) va_start(listp, fmt); copybyte_str = buf; - __doprnt(fmt, &listp, copybyte, ©byte_str, 16); + __doprnt(fmt, listp, copybyte, ©byte_str, 16); va_end(listp); *copybyte_str = '\0'; - return strlen(buf); + return (int)strlen(buf); } +#endif /* !CONFIG_EMBEDDED */