summaryrefslogtreecommitdiffstats
path: root/libexec/rtld-elf/xmalloc.c
diff options
context:
space:
mode:
authorkib <kib@FreeBSD.org>2011-08-24 20:05:13 +0000
committerkib <kib@FreeBSD.org>2011-08-24 20:05:13 +0000
commit6a7906318730de9b42a49050eb3f9fa3b476812b (patch)
treecbf9abe0c68b62c518886f500059522babc1525d /libexec/rtld-elf/xmalloc.c
parenta3d2844ed5203016f1e0148e2a87c759bbf01954 (diff)
downloadFreeBSD-src-6a7906318730de9b42a49050eb3f9fa3b476812b.zip
FreeBSD-src-6a7906318730de9b42a49050eb3f9fa3b476812b.tar.gz
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)
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 7ee4c57..0d99225 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;
}
OpenPOWER on IntegriCloud