diff --git a/src/configure.in b/src/configure.in
index b79824a331971e82d7ebb0cc22da557382bb87ca..3c942c489bfbfe64631cea9ce73c0bb9fde87d30 100644
--- a/src/configure.in
+++ b/src/configure.in
@@ -1,4 +1,4 @@
-AC_REVISION("$Id: configure.in,v 1.993 2006/08/09 17:00:50 grubba Exp $")
+AC_REVISION("$Id: configure.in,v 1.994 2006/08/09 18:52:05 mast Exp $")
 AC_INIT(interpret.c)
 AC_CONFIG_HEADER(machine.h)
 
@@ -2295,7 +2295,7 @@ if test "x$PIKE_PATH_TRANSLATE" = "x"; then
     # MinGW system.
     cat <<\EOF
 #!/bin/sh
-# Automatically generated by $Id: configure.in,v 1.993 2006/08/09 17:00:50 grubba Exp $.
+# Automatically generated by $Id: configure.in,v 1.994 2006/08/09 18:52:05 mast Exp $.
 # MinGW-version. Do NOT edit.
 posix_name="`cat`"
 posix_prefix="/"
@@ -2333,7 +2333,7 @@ EOF
     # Native POSIX system.
   cat <<\EOF
 #!/bin/sh
-# Automatically generated by $Id: configure.in,v 1.993 2006/08/09 17:00:50 grubba Exp $.
+# Automatically generated by $Id: configure.in,v 1.994 2006/08/09 18:52:05 mast Exp $.
 # POSIX-version. Do NOT edit.
 cat
 EOF
@@ -2342,7 +2342,7 @@ else
   # rntcl-style
   cat <<\EOF
 #!/bin/sh
-# Automatically generated by $Id: configure.in,v 1.993 2006/08/09 17:00:50 grubba Exp $.
+# Automatically generated by $Id: configure.in,v 1.994 2006/08/09 18:52:05 mast Exp $.
 # RNTCL-version. Do NOT edit.
 sed -e "$PIKE_PATH_TRANSLATE"
 EOF
@@ -4459,6 +4459,26 @@ AC_MSG_RESULT($pike_cv_has_struct_sockaddr_in6)
 
 #############################################################################
 
+if test $ac_cv_header_malloc_h = yes; then
+  AC_MSG_CHECKING(struct mallinfo in malloc.h)
+  AC_CACHE_VAL(pike_cv_struct_mallinfo, [
+    AC_TRY_LINK([
+#ifdef HAVE_MALLOC_H
+#include <malloc.h>
+#endif
+    ], [
+      struct mallinfo foo;
+    ], pike_cv_struct_mallinfo=yes, pike_cv_struct_mallinfo=no)
+  ])
+  if test $pike_cv_struct_mallinfo = yes; then
+    AC_DEFINE(HAVE_STRUCT_MALLINFO, 1,
+	      [Defined if malloc.h contains a struct mallinfo.])
+  fi
+  AC_MSG_RESULT($pike_cv_struct_mallinfo)
+fi
+
+#############################################################################
+
 if test "x$ac_cv_func_strtol" = "xyes"; then
   AC_MSG_CHECKING(if strtol works for large hexadecimal constants)
   AC_CACHE_VAL(pike_cv_func_strtol_works, [
diff --git a/src/malloc.c b/src/malloc.c
index 43a1dd4d115332b8ced3adb675fc49402d99aaa7..034e644204d1b84825b451713d56d79f8d7693a2 100644
--- a/src/malloc.c
+++ b/src/malloc.c
@@ -4,8 +4,7 @@
 #include "global.h"
 #define USE_LOCKS 1
 #define USE_DL_PREFIX 1
-#define NO_MALLINFO 1
-/* Further pike changes below: PMOD_EXPORT */
+/* Further pike changes below: PMOD_EXPORTs and lines marked "PIKE". */
 /* End pike preamble */
 
 /*
@@ -589,9 +588,15 @@ DEFAULT_MMAP_THRESHOLD       default: 256K
   malloc does support the following options.
 */
 
+#ifndef M_TRIM_THRESHOLD	/* PIKE change */
 #define M_TRIM_THRESHOLD     (-1)
+#endif				/* PIKE change */
+#ifndef M_GRANULARITY		/* PIKE change */
 #define M_GRANULARITY        (-2)
+#endif				/* PIKE change */
+#ifndef M_MMAP_THRESHOLD	/* PIKE change */
 #define M_MMAP_THRESHOLD     (-3)
+#endif				/* PIKE change */
 
 /* ------------------------ Mallinfo declarations ------------------------ */
 
@@ -622,6 +627,12 @@ DEFAULT_MMAP_THRESHOLD       default: 256K
 
 #ifdef HAVE_USR_INCLUDE_MALLOC_H
 #include "/usr/include/malloc.h"
+
+/* PIKE change start */
+#elif defined (HAVE_MALLOC_H) && defined (HAVE_STRUCT_MALLINFO)
+#include <malloc.h>
+/* PIKE change end */
+
 #else /* HAVE_USR_INCLUDE_MALLOC_H */
 
 struct mallinfo {