aboutsummaryrefslogtreecommitdiff
path: root/libexec/rtld-elf/xmalloc.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/xmalloc.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/xmalloc.c')
-rw-r--r--libexec/rtld-elf/xmalloc.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/libexec/rtld-elf/xmalloc.c b/libexec/rtld-elf/xmalloc.c
index 7ee4c570c6b8..0d992257b986 100644
--- a/libexec/rtld-elf/xmalloc.c
+++ b/libexec/rtld-elf/xmalloc.c
@@ -25,10 +25,12 @@
* $FreeBSD$
*/
-#include <err.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
+#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;
}