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.
This commit is contained in:
Mike Hommey 2012-03-27 14:48:58 +02:00 committed by Jason Evans
parent e77fa59ece
commit 1a0e777024
2 changed files with 13 additions and 0 deletions

View File

@ -1,6 +1,9 @@
#include <sys/mman.h> #include <sys/mman.h>
#include <sys/param.h> #include <sys/param.h>
#include <sys/syscall.h> #include <sys/syscall.h>
#if !defined(SYS_write) && defined(__NR_write)
#define SYS_write __NR_write
#endif
#include <sys/time.h> #include <sys/time.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/uio.h> #include <sys/uio.h>

View File

@ -44,7 +44,17 @@ JEMALLOC_CATTR(visibility("hidden"), static)
void void
wrtmessage(void *cbopaque, const char *s) 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)); 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) void (*je_malloc_message)(void *, const char *s)