#include <os/log_private.h>
/* for vaddlog(): the following are implemented in osfmk/kern/printf.c */
-extern void bsd_log_lock(void);
+extern bool bsd_log_lock(bool);
extern void bsd_log_unlock(void);
+uint32_t vaddlog_msgcount = 0;
+uint32_t vaddlog_msgcount_dropped = 0;
+
/* Keep this around only because it's exported */
void _printf(int, struct tty *, const char *, ...);
extern const char *debugger_panic_str;
extern void cnputc(char); /* standard console putc */
-void (*v_putc)(char) = cnputc; /* routine to putc on virtual console */
extern struct tty cons; /* standard console tty */
extern struct tty *constty; /* pointer to console "window" tty */
struct putchar_args {
int flags;
struct tty *tty;
+ bool last_char_was_cr;
};
static void putchar(int c, void *arg);
tty_unlock(tp);
}
- pca.flags = TOLOG;
- pca.tty = TTY_NULL;
- va_start(ap, fmt);
- __doprnt(fmt, ap, putchar, &pca, 10, TRUE);
- va_end(ap);
-
- logwakeup(msgbufp);
-
va_start(ap, fmt);
os_log_with_args(OS_LOG_DEFAULT, OS_LOG_TYPE_DEFAULT, fmt, ap, __builtin_return_address(0));
va_end(ap);
void
logtime(time_t secs)
{
- printf("Time %ld Message ", secs);
+ printf("Time 0x%lx Message ", secs);
}
static void
struct putchar_args *pca = arg;
if ((pca->flags & TOLOGLOCKED) && c != '\0' && c != '\r' && c != 0177) {
- log_putc_locked(aslbufp, c);
+ log_putc_locked(aslbufp, (char)c);
}
putchar(c, arg);
}
int
vaddlog(const char *fmt, va_list ap)
{
+ if (!bsd_log_lock(oslog_is_safe())) {
+ os_atomic_inc(&vaddlog_msgcount_dropped, relaxed);
+ return 1;
+ }
+
struct putchar_args pca = {
.flags = TOLOGLOCKED,
.tty = NULL,
};
- bsd_log_lock();
__doprnt(fmt, ap, putchar_asl, &pca, 10, TRUE);
bsd_log_unlock();
logwakeup(NULL);
+ os_atomic_inc(&vaddlog_msgcount, relaxed);
return 0;
}
constty = 0;
}
if ((pca->flags & TOLOG) && c != '\0' && c != '\r' && c != 0177) {
- log_putc(c);
+ log_putc((char)c);
}
if ((pca->flags & TOLOGLOCKED) && c != '\0' && c != '\r' && c != 0177) {
- log_putc_locked(msgbufp, c);
+ log_putc_locked(msgbufp, (char)c);
}
if ((pca->flags & TOCONS) && constty == 0 && c != '\0') {
- (*v_putc)(c);
+ cnputc((char)c);
}
if (pca->flags & TOSTR) {
- **sp = c;
+ **sp = (char)c;
(*sp)++;
}
+
+ pca->last_char_was_cr = ('\n' == c);
}
-int
-vprintf_log_locked(const char *fmt, va_list ap)
+bool
+printf_log_locked(bool addcr, const char *fmt, ...)
+{
+ bool retval;
+ va_list args;
+
+ va_start(args, fmt);
+ retval = vprintf_log_locked(fmt, args, addcr);
+ va_end(args);
+
+ return retval;
+}
+
+bool
+vprintf_log_locked(const char *fmt, va_list ap, bool addcr)
{
struct putchar_args pca;
pca.flags = TOLOGLOCKED;
pca.tty = NULL;
+ pca.last_char_was_cr = false;
__doprnt(fmt, ap, putchar, &pca, 10, TRUE);
- return 0;
+ if (addcr) {
+ putchar('\n', &pca);
+ }
+ return pca.last_char_was_cr;
}
-#if !CONFIG_EMBEDDED
-
+#if CONFIG_VSPRINTF
/*
* Scaled down version of vsprintf(3).
*
}
return 0;
}
-#endif /* !CONFIG_EMBEDDED */
+#endif /* CONFIG_VSPRINTF */
/*
* Scaled down version of snprintf(3).
return retval;
}
+int
+vscnprintf(char *buf, size_t size, const char *fmt, va_list args)
+{
+ ssize_t ssize = size;
+ int i;
+
+ i = vsnprintf(buf, size, fmt, args);
+
+ return (i >= ssize) ? (int)(ssize - 1) : i;
+}
+
+int
+scnprintf(char *buf, size_t size, const char *fmt, ...)
+{
+ va_list args;
+ int i;
+
+ va_start(args, fmt);
+ i = vscnprintf(buf, size, fmt, args);
+ va_end(args);
+
+ return i;
+}
+
static void
snprintf_func(int ch, void *arg)
{
struct snprintf_arg *const info = arg;
if (info->remain >= 2) {
- *info->str++ = ch;
+ *info->str++ = (char)ch;
info->remain--;
}
}