From 6a7906318730de9b42a49050eb3f9fa3b476812b Mon Sep 17 00:00:00 2001 From: kib Date: Wed, 24 Aug 2011 20:05:13 +0000 Subject: Rtld links with the specially built pic static libc library to get some C runtime services, like printf(). Unfortunately, the multithread-safeness measures in the libc do not work in rtld environment. Rip the kernel printf() implementation and use it in the rtld instead of libc version. This printf does not require any shared global data and thus is mt-safe. Systematically use rtld_printf() and related functions, remove the calls to err(3). Note that stdio is still pulled from libc due to libmap implementaion using fopen(). This is safe but unoptimal, and can be changed later. Reported and tested by: pgj Diagnosed and reviewed by: kan (previous version) Approved by: re (bz) --- libexec/rtld-elf/xmalloc.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'libexec/rtld-elf/xmalloc.c') diff --git a/libexec/rtld-elf/xmalloc.c b/libexec/rtld-elf/xmalloc.c index 7ee4c57..0d99225 100644 --- a/libexec/rtld-elf/xmalloc.c +++ b/libexec/rtld-elf/xmalloc.c @@ -25,10 +25,12 @@ * $FreeBSD$ */ -#include #include #include #include +#include +#include "rtld.h" +#include "rtld_printf.h" void *xcalloc(size_t); void *xmalloc(size_t); @@ -44,8 +46,10 @@ void * xmalloc(size_t size) { void *p = malloc(size); - if (p == NULL) - err(1, "Out of memory"); + if (p == NULL) { + rtld_fdputstr(STDERR_FILENO, "Out of memory\n"); + _exit(1); + } return p; } @@ -53,7 +57,9 @@ char * xstrdup(const char *s) { char *p = strdup(s); - if (p == NULL) - err(1, "Out of memory"); + if (p == NULL) { + rtld_fdputstr(STDERR_FILENO, "Out of memory\n"); + _exit(1); + } return p; } -- cgit v1.1