aboutsummaryrefslogtreecommitdiff
path: root/libexec/rtld-elf/malloc.c
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2011-08-24 20:05:13 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2011-08-24 20:05:13 +0000
commit0e9a2605200b721fdfcf32d2c95f79a81fc84352 (patch)
treecbf9abe0c68b62c518886f500059522babc1525d /libexec/rtld-elf/malloc.c
parentf3fb16875ce6de5f348adb955caac61755e49879 (diff)
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)
Notes
svn path=/head/; revision=225152
Diffstat (limited to 'libexec/rtld-elf/malloc.c')
-rw-r--r--libexec/rtld-elf/malloc.c25
1 files changed, 5 insertions, 20 deletions
diff --git a/libexec/rtld-elf/malloc.c b/libexec/rtld-elf/malloc.c
index 38ae89af726e..95916598b53f 100644
--- a/libexec/rtld-elf/malloc.c
+++ b/libexec/rtld-elf/malloc.c
@@ -49,7 +49,6 @@ static char *rcsid = "$FreeBSD$";
#include <sys/types.h>
#include <sys/sysctl.h>
-#include <err.h>
#include <paths.h>
#include <stdarg.h>
#include <stddef.h>
@@ -59,6 +58,7 @@ static char *rcsid = "$FreeBSD$";
#include <unistd.h>
#include <sys/param.h>
#include <sys/mman.h>
+#include "rtld_printf.h"
#ifndef BSD
#define MAP_COPY MAP_PRIVATE
#define MAP_FILE 0
@@ -150,8 +150,7 @@ botch(s)
#endif
/* Debugging stuff */
-static void xprintf(const char *, ...);
-#define TRACE() xprintf("TRACE %s:%d\n", __FILE__, __LINE__)
+#define TRACE() rtld_printf("TRACE %s:%d\n", __FILE__, __LINE__)
extern int pagesize;
@@ -503,7 +502,8 @@ int n;
caddr_t addr = (caddr_t)
(((long)pagepool_start + pagesz - 1) & ~(pagesz - 1));
if (munmap(addr, pagepool_end - addr) != 0)
- warn("morepages: munmap %p", addr);
+ rtld_fdprintf(STDERR_FILENO, "morepages: munmap %p",
+ addr);
}
offset = (long)pagepool_start - ((long)pagepool_start & ~(pagesz - 1));
@@ -511,7 +511,7 @@ int n;
if ((pagepool_start = mmap(0, n * pagesz,
PROT_READ|PROT_WRITE,
MAP_ANON|MAP_COPY, fd, 0)) == (caddr_t)-1) {
- xprintf("Cannot map anonymous memory");
+ rtld_printf("Cannot map anonymous memory\n");
return 0;
}
pagepool_end = pagepool_start + n * pagesz;
@@ -522,18 +522,3 @@ int n;
#endif
return n;
}
-
-/*
- * Non-mallocing printf, for use by malloc itself.
- */
-static void
-xprintf(const char *fmt, ...)
-{
- char buf[256];
- va_list ap;
-
- va_start(ap, fmt);
- vsprintf(buf, fmt, ap);
- (void)write(STDOUT_FILENO, buf, strlen(buf));
- va_end(ap);
-}