From a6bb123606f7afa6fb3342b35dad217c76951ee3 Mon Sep 17 00:00:00 2001 From: kib Date: Tue, 6 Sep 2011 10:21:33 +0000 Subject: [PATCH] Do not use the function pointers for the internal operation of rtld_printf() functions. The _rtld_error() function might be called early during the rtld bootstrap, in which case function pointers are not yet functional on ia64 due to required relocations not yet performed. Reported, reviewed and tested by: marcel Approved by: re (bz) --- libexec/rtld-elf/rtld_printf.c | 47 +++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/libexec/rtld-elf/rtld_printf.c b/libexec/rtld-elf/rtld_printf.c index a5ab130cb989..b9aadc3587b0 100644 --- a/libexec/rtld-elf/rtld_printf.c +++ b/libexec/rtld-elf/rtld_printf.c @@ -46,7 +46,11 @@ #define MAXNBUF (sizeof(intmax_t) * NBBY + 1) +#define PRINT_METHOD_SNPRINTF 1 +#define PRINT_METHOD_WRITE 2 + struct snprintf_arg { + int method; char *str; char *buf; size_t remain; @@ -54,16 +58,6 @@ struct snprintf_arg { int fd; }; -static void -snprintf_func(int ch, struct snprintf_arg *const info) -{ - - if (info->remain >= 2) { - *info->str++ = ch; - info->remain--; - } -} - static void printf_out(struct snprintf_arg *info) { @@ -76,14 +70,24 @@ printf_out(struct snprintf_arg *info) } static void -printf_func(int ch, struct snprintf_arg *const info) +snprintf_func(int ch, struct snprintf_arg *const info) { - if (info->remain > 0) { - *info->str++ = ch; - info->remain--; - } else - printf_out(info); + switch (info->method) { + case PRINT_METHOD_SNPRINTF: + if (info->remain >= 2) { + *info->str++ = ch; + info->remain--; + } + break; + case PRINT_METHOD_WRITE: + if (info->remain > 0) { + *info->str++ = ch; + info->remain--; + } else + printf_out(info); + break; + } } static char const hex2ascii_data[] = "0123456789abcdefghijklmnopqrstuvwxyz"; @@ -113,10 +117,9 @@ ksprintn(char *nbuf, uintmax_t num, int base, int *lenp, int upper) } static int -kvprintf(char const *fmt, void (*func)(int c, struct snprintf_arg *const arg), - struct snprintf_arg *arg, int radix, va_list ap) +kvprintf(char const *fmt, struct snprintf_arg *arg, int radix, va_list ap) { -#define PCHAR(c) func((c), arg) +#define PCHAR(c) snprintf_func((c), arg) char nbuf[MAXNBUF]; const char *p, *percent, *q; u_char *up; @@ -429,10 +432,11 @@ rtld_vsnprintf(char *buf, size_t bufsize, const char *fmt, va_list ap) struct snprintf_arg info; int retval; + info.method = PRINT_METHOD_SNPRINTF; info.buf = info.str = buf; info.buf_total = info.remain = bufsize; info.fd = -1; - retval = kvprintf(fmt, snprintf_func, &info, 10, ap); + retval = kvprintf(fmt, &info, 10, ap); if (info.remain >= 1) *info.str++ = '\0'; return (retval); @@ -445,10 +449,11 @@ rtld_vfdprintf(int fd, const char *fmt, va_list ap) struct snprintf_arg info; int retval; + info.method = PRINT_METHOD_WRITE; info.buf = info.str = buf; info.buf_total = info.remain = sizeof(buf); info.fd = fd; - retval = kvprintf(fmt, printf_func, &info, 10, ap); + retval = kvprintf(fmt, &info, 10, ap); printf_out(&info); return (retval); }