libthr: Add vprintf variant of _thread_printf, formatted PANIC()

No ABI change.

Reviewed by:	kib
Sponsored by:	EMC / Isilon Storage Division
Differential Revision:	https://reviews.freebsd.org/D6672
This commit is contained in:
Conrad Meyer 2016-06-01 16:09:56 +00:00
parent 83e80fe84a
commit 3a7d122f96
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=301134
3 changed files with 36 additions and 13 deletions

View File

@ -35,6 +35,7 @@ __FBSDID("$FreeBSD$");
#ifdef _PTHREAD_FORCED_UNWIND
#include <dlfcn.h>
#endif
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
@ -171,16 +172,29 @@ thread_unwind(void)
#endif
void
_thread_exitf(const char *fname, int lineno, const char *fmt, ...)
{
va_list ap;
/* Write an error message to the standard error file descriptor: */
_thread_printf(STDERR_FILENO, "Fatal error '");
va_start(ap, fmt);
_thread_vprintf(STDERR_FILENO, fmt, ap);
va_end(ap);
_thread_printf(STDERR_FILENO, "' at line %d in file %s (errno = %d)\n",
lineno, fname, errno);
abort();
}
void
_thread_exit(const char *fname, int lineno, const char *msg)
{
/* Write an error message to the standard error file descriptor: */
_thread_printf(2,
"Fatal error '%s' at line %d in file %s (errno = %d)\n",
msg, lineno, fname, errno);
abort();
_thread_exitf(fname, lineno, "%s", msg);
}
void

View File

@ -51,9 +51,18 @@ static void pstr(int fd, const char *s);
*/
void
_thread_printf(int fd, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
_thread_vprintf(fd, fmt, ap);
va_end(ap);
}
void
_thread_vprintf(int fd, const char *fmt, va_list ap)
{
static const char digits[16] = "0123456789abcdef";
va_list ap;
char buf[20];
char *s;
unsigned long r, u;
@ -61,13 +70,12 @@ _thread_printf(int fd, const char *fmt, ...)
long d;
int islong;
va_start(ap, fmt);
while ((c = *fmt++)) {
islong = 0;
if (c == '%') {
next: c = *fmt++;
if (c == '\0')
goto out;
return;
switch (c) {
case 'c':
pchar(fd, va_arg(ap, int));
@ -111,8 +119,6 @@ next: c = *fmt++;
}
pchar(fd, c);
}
out:
va_end(ap);
}
/*

View File

@ -86,7 +86,7 @@ TAILQ_HEAD(mutex_queue, pthread_mutex);
/*
* Kernel fatal error handler macro.
*/
#define PANIC(string) _thread_exit(__FILE__,__LINE__,string)
#define PANIC(args...) _thread_exitf(__FILE__, __LINE__, ##args)
/* Output debug messages like this: */
#define stdout_debug(args...) _thread_printf(STDOUT_FILENO, ##args)
@ -778,6 +778,8 @@ void _mutex_leave_robust(struct pthread *curthread, struct pthread_mutex *m)
void _libpthread_init(struct pthread *) __hidden;
struct pthread *_thr_alloc(struct pthread *) __hidden;
void _thread_exit(const char *, int, const char *) __hidden __dead2;
void _thread_exitf(const char *, int, const char *, ...) __hidden __dead2
__printflike(3, 4);
int _thr_ref_add(struct pthread *, struct pthread *, int) __hidden;
void _thr_ref_delete(struct pthread *, struct pthread *) __hidden;
void _thr_ref_delete_unlocked(struct pthread *, struct pthread *) __hidden;
@ -789,7 +791,8 @@ void _thr_stack_free(struct pthread_attr *) __hidden;
void _thr_free(struct pthread *, struct pthread *) __hidden;
void _thr_gc(struct pthread *) __hidden;
void _thread_cleanupspecific(void) __hidden;
void _thread_printf(int, const char *, ...) __hidden;
void _thread_printf(int, const char *, ...) __hidden __printflike(2, 3);
void _thread_vprintf(int, const char *, va_list) __hidden;
void _thr_spinlock_init(void) __hidden;
void _thr_cancel_enter(struct pthread *) __hidden;
void _thr_cancel_enter2(struct pthread *, int) __hidden;