summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Evans <je@facebook.com>2010-09-20 23:05:41 (GMT)
committerJason Evans <je@facebook.com>2010-09-20 23:05:41 (GMT)
commita09f55c87d799e6e0e64972838ca6768027e9174 (patch)
treec62cf5b991d3aff066e0398d0a390c60f7ce5903
parent28177d466fbbfd10927b4d05655c2ec6711faa1b (diff)
downloadjemalloc-a09f55c87d799e6e0e64972838ca6768027e9174.zip
jemalloc-a09f55c87d799e6e0e64972838ca6768027e9174.tar.gz
jemalloc-a09f55c87d799e6e0e64972838ca6768027e9174.tar.bz2
Wrap strerror_r().
Create the buferror() function, which wraps strerror_r(). This is necessary because glibc provides a non-standard strerror_r().
-rw-r--r--jemalloc/include/jemalloc/internal/jemalloc_internal.h.in5
-rw-r--r--jemalloc/src/chunk_mmap.c11
-rw-r--r--jemalloc/src/chunk_swap.c7
-rw-r--r--jemalloc/src/jemalloc.c19
4 files changed, 32 insertions, 10 deletions
diff --git a/jemalloc/include/jemalloc/internal/jemalloc_internal.h.in b/jemalloc/include/jemalloc/internal/jemalloc_internal.h.in
index 04bc56f..514ef5c 100644
--- a/jemalloc/include/jemalloc/internal/jemalloc_internal.h.in
+++ b/jemalloc/include/jemalloc/internal/jemalloc_internal.h.in
@@ -101,8 +101,8 @@ extern void (*JEMALLOC_P(malloc_message))(void *wcbopaque, const char *s);
# define JEMALLOC_INLINE static inline
#endif
-/* Size of stack-allocated buffer passed to strerror_r(). */
-#define STRERROR_BUF 64
+/* Size of stack-allocated buffer passed to buferror(). */
+#define BUFERROR_BUF 64
/* Minimum alignment of allocations is 2^LG_QUANTUM bytes. */
#ifdef __i386__
@@ -289,6 +289,7 @@ extern unsigned narenas;
arena_t *arenas_extend(unsigned ind);
arena_t *choose_arena_hard(void);
+int buferror(int errnum, char *buf, size_t buflen);
void jemalloc_prefork(void);
void jemalloc_postfork(void);
diff --git a/jemalloc/src/chunk_mmap.c b/jemalloc/src/chunk_mmap.c
index a3d09e9..bc36755 100644
--- a/jemalloc/src/chunk_mmap.c
+++ b/jemalloc/src/chunk_mmap.c
@@ -28,7 +28,8 @@ static pthread_key_t mmap_unaligned_tsd;
static void *pages_map(void *addr, size_t size, bool noreserve);
static void pages_unmap(void *addr, size_t size);
-static void *chunk_alloc_mmap_slow(size_t size, bool unaligned, bool noreserve);
+static void *chunk_alloc_mmap_slow(size_t size, bool unaligned,
+ bool noreserve);
static void *chunk_alloc_mmap_internal(size_t size, bool noreserve);
/******************************************************************************/
@@ -57,9 +58,9 @@ pages_map(void *addr, size_t size, bool noreserve)
* We succeeded in mapping memory, but not in the right place.
*/
if (munmap(ret, size) == -1) {
- char buf[STRERROR_BUF];
+ char buf[BUFERROR_BUF];
- strerror_r(errno, buf, sizeof(buf));
+ buferror(errno, buf, sizeof(buf));
malloc_write("<jemalloc>: Error in munmap(): ");
malloc_write(buf);
malloc_write("\n");
@@ -79,9 +80,9 @@ pages_unmap(void *addr, size_t size)
{
if (munmap(addr, size) == -1) {
- char buf[STRERROR_BUF];
+ char buf[BUFERROR_BUF];
- strerror_r(errno, buf, sizeof(buf));
+ buferror(errno, buf, sizeof(buf));
malloc_write("<jemalloc>: Error in munmap(): ");
malloc_write(buf);
malloc_write("\n");
diff --git a/jemalloc/src/chunk_swap.c b/jemalloc/src/chunk_swap.c
index ed9e414..ee038ba 100644
--- a/jemalloc/src/chunk_swap.c
+++ b/jemalloc/src/chunk_swap.c
@@ -294,9 +294,10 @@ chunk_swap_enable(const int *fds, unsigned nfds, bool prezeroed)
void *addr = mmap((void *)((uintptr_t)vaddr + voff), sizes[i],
PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, fds[i], 0);
if (addr == MAP_FAILED) {
- char buf[STRERROR_BUF];
+ char buf[BUFERROR_BUF];
- strerror_r(errno, buf, sizeof(buf));
+
+ buferror(errno, buf, sizeof(buf));
malloc_write(
"<jemalloc>: Error in mmap(..., MAP_FIXED, ...): ");
malloc_write(buf);
@@ -304,7 +305,7 @@ chunk_swap_enable(const int *fds, unsigned nfds, bool prezeroed)
if (opt_abort)
abort();
if (munmap(vaddr, voff) == -1) {
- strerror_r(errno, buf, sizeof(buf));
+ buferror(errno, buf, sizeof(buf));
malloc_write("<jemalloc>: Error in munmap(): ");
malloc_write(buf);
malloc_write("\n");
diff --git a/jemalloc/src/jemalloc.c b/jemalloc/src/jemalloc.c
index 40c3a63..0b60ce6 100644
--- a/jemalloc/src/jemalloc.c
+++ b/jemalloc/src/jemalloc.c
@@ -139,6 +139,25 @@ choose_arena_hard(void)
return (ret);
}
+/*
+ * glibc provides a non-standard strerror_r() when _GNU_SOURCE is defined, so
+ * provide a wrapper.
+ */
+int
+buferror(int errnum, char *buf, size_t buflen)
+{
+#ifdef _GNU_SOURCE
+ char *b = strerror_r(errno, buf, buflen);
+ if (b != buf) {
+ strncpy(buf, b, buflen);
+ buf[buflen-1] = '\0';
+ }
+ return (0);
+#else
+ return (strerror_r(errno, buf, buflen));
+#endif
+}
+
static void
stats_print_atexit(void)
{