From 1a0e7770243e0539fa8fef7bb1512f784f93389f Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Tue, 27 Mar 2012 14:48:58 +0200 Subject: [PATCH] Add a SYS_write definition on systems where it is not defined in headers Namely, in the Android NDK headers, SYS_write is not defined; but __NR_write is. --- include/jemalloc/internal/jemalloc_internal.h.in | 3 +++ src/util.c | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/include/jemalloc/internal/jemalloc_internal.h.in b/include/jemalloc/internal/jemalloc_internal.h.in index 4f557794..b7b8df8b 100644 --- a/include/jemalloc/internal/jemalloc_internal.h.in +++ b/include/jemalloc/internal/jemalloc_internal.h.in @@ -1,6 +1,9 @@ #include #include #include +#if !defined(SYS_write) && defined(__NR_write) +#define SYS_write __NR_write +#endif #include #include #include diff --git a/src/util.c b/src/util.c index 090e1f06..895aa198 100644 --- a/src/util.c +++ b/src/util.c @@ -44,7 +44,17 @@ JEMALLOC_CATTR(visibility("hidden"), static) void wrtmessage(void *cbopaque, const char *s) { + +#ifdef SYS_write + /* + * Use syscall(2) rather than write(2) when possible in order to avoid + * the possibility of memory allocation within libc. This is necessary + * on FreeBSD; most operating systems do not have this problem though. + */ UNUSED int result = syscall(SYS_write, STDERR_FILENO, s, strlen(s)); +#else + UNUSED int result = write(STDERR_FILENO, s, strlen(s)); +#endif } void (*je_malloc_message)(void *, const char *s)