[PATCH] Use a stub replacement and disable dss when sbrk is not supported

Mike Hommey mh+jemalloc at glandium.org
Thu Apr 12 01:13:03 PDT 2012


From: Mike Hommey <mh at glandium.org>

---
 configure.ac                        |    8 ++++++++
 include/jemalloc/jemalloc_defs.h.in |    3 +++
 src/chunk_dss.c                     |    7 +++++++
 3 files changed, 18 insertions(+)

diff --git a/configure.ac b/configure.ac
index 15a3f06..204e6e5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -692,6 +692,14 @@ fi
 ],
 [enable_dss="0"]
 )
+dnl Check whether the BSD/SUSv1 sbrk() exists. If not, disable DSS support.
+AC_CHECK_FUNC([sbrk], [have_sbrk="1"], [have_sbrk="0"])
+if test "x$have_sbrk" = "x1" ; then
+  AC_DEFINE([JEMALLOC_HAVE_SBRK], [ ])
+else
+  enable_dss="0"
+fi
+
 if test "x$enable_dss" = "x1" ; then
   AC_DEFINE([JEMALLOC_DSS], [ ])
 fi
diff --git a/include/jemalloc/jemalloc_defs.h.in b/include/jemalloc/jemalloc_defs.h.in
index 32efedb..0a0a60c 100644
--- a/include/jemalloc/jemalloc_defs.h.in
+++ b/include/jemalloc/jemalloc_defs.h.in
@@ -108,6 +108,9 @@
 #  define JEMALLOC_ATTR(s) JEMALLOC_CATTR(s,)
 #endif
 
+/* Defined if sbrk() is supported. */
+#undef JEMALLOC_HAVE_SBRK
+
 /* Non-empty if the tls_model attribute is supported. */
 #undef JEMALLOC_TLS_MODEL
 
diff --git a/src/chunk_dss.c b/src/chunk_dss.c
index 7c03409..c718e4c 100644
--- a/src/chunk_dss.c
+++ b/src/chunk_dss.c
@@ -3,6 +3,13 @@
 /******************************************************************************/
 /* Data. */
 
+#ifndef JEMALLOC_HAVE_SBRK
+void *sbrk(intptr_t increment)
+{
+  not_implemented();
+  return NULL;
+}
+#endif
 /*
  * Protects sbrk() calls.  This avoids malloc races among threads, though it
  * does not protect against races with threads that call sbrk() directly.
-- 
1.7.9.5




More information about the jemalloc-discuss mailing list