Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 6 Sep 2011 10:21:33 +0000 (UTC)
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r225417 - head/libexec/rtld-elf
Message-ID:  <201109061021.p86ALXBF078723@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kib
Date: Tue Sep  6 10:21:33 2011
New Revision: 225417
URL: http://svn.freebsd.org/changeset/base/225417

Log:
  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)

Modified:
  head/libexec/rtld-elf/rtld_printf.c

Modified: head/libexec/rtld-elf/rtld_printf.c
==============================================================================
--- head/libexec/rtld-elf/rtld_printf.c	Tue Sep  6 10:19:01 2011	(r225416)
+++ head/libexec/rtld-elf/rtld_printf.c	Tue Sep  6 10:21:33 2011	(r225417)
@@ -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;
@@ -55,16 +59,6 @@ struct snprintf_arg {
 };
 
 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 
 }
 
 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
 	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, 
 	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);
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201109061021.p86ALXBF078723>