summaryrefslogtreecommitdiffstats
path: root/src/dnmalloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dnmalloc.c')
-rw-r--r--src/dnmalloc.c97
1 files changed, 50 insertions, 47 deletions
diff --git a/src/dnmalloc.c b/src/dnmalloc.c
index 4ab3b9a..9f7bacc 100644
--- a/src/dnmalloc.c
+++ b/src/dnmalloc.c
@@ -164,7 +164,7 @@
*
* HAVE_SYS_PARAM_H Define to #include <sys/param.h> (for pagesize)
*
- * HAVE_MALLOC_H Define to #include <malloc.h> (for struct mallinfo)
+ * HAVE_MALLOC_H Define to #include <malloc.h> (for struct mallinfo2)
*
* HAVE_FCNTL_H Define to #include <fcntl.h>
*
@@ -530,7 +530,7 @@ assert_handler_tp *dnmalloc_set_handler(assert_handler_tp *new)
#define rEALLOc public_rEALLOc
#define vALLOc public_vALLOc
#define pVALLOc public_pVALLOc
-#define mALLINFo public_mALLINFo
+#define mALLINFo2 public_mALLINFo2
#define mALLOPt public_mALLOPt
#define mTRIm public_mTRIm
#define mSTATs public_mSTATs
@@ -546,7 +546,7 @@ assert_handler_tp *dnmalloc_set_handler(assert_handler_tp *new)
#define public_rEALLOc dlrealloc
#define public_vALLOc dlvalloc
#define public_pVALLOc dlpvalloc
-#define public_mALLINFo dlmallinfo
+#define public_mALLINFo2 dlmallinfo2
#define public_mALLOPt dlmallopt
#define public_mTRIm dlmalloc_trim
#define public_mSTATs dlmalloc_stats
@@ -560,7 +560,7 @@ assert_handler_tp *dnmalloc_set_handler(assert_handler_tp *new)
#define public_rEALLOc realloc
#define public_vALLOc valloc
#define public_pVALLOc pvalloc
-#define public_mALLINFo mallinfo
+#define public_mALLINFo2 mallinfo2
#define public_mALLOPt mallopt
#define public_mTRIm malloc_trim
#define public_mSTATs malloc_stats
@@ -790,27 +790,27 @@ extern Void_t* sbrk();
#endif
/*
- This version of malloc supports the standard SVID/XPG mallinfo
+ This version of malloc supports the standard SVID/XPG mallinfo2
routine that returns a struct containing usage properties and
statistics. It should work on any SVID/XPG compliant system that has
- a /usr/include/malloc.h defining struct mallinfo. (If you'd like to
+ a /usr/include/malloc.h defining struct mallinfo2. (If you'd like to
install such a thing yourself, cut out the preliminary declarations
as described above and below and save them in a malloc.h file. But
there's no compelling reason to bother to do this.)
- The main declaration needed is the mallinfo struct that is returned
- (by-copy) by mallinfo(). The SVID/XPG malloinfo struct contains a
+ The main declaration needed is the mallinfo2 struct that is returned
+ (by-copy) by mallinfo2(). The SVID/XPG malloinfo2 struct contains a
bunch of fields that are not even meaningful in this version of
- malloc. These fields are are instead filled by mallinfo() with
+ malloc. These fields are are instead filled by mallinfo2() with
other numbers that might be of interest.
HAVE_MALLOC_H should be set if you have a
/usr/include/malloc.h file that includes a declaration of struct
- mallinfo. If so, it is included; else an SVID2/XPG2 compliant
+ mallinfo2. If so, it is included; else an SVID2/XPG2 compliant
version is declared below. These must be precisely the same for
- mallinfo() to work. The original SVID version of this struct,
- defined on most systems with mallinfo, declares all fields as
- ints. But some others define as unsigned long. If your system
+ mallinfo2() to work. The original SVID version of this struct,
+ defined on most systems with mallinfo2, declares all fields as
+ size_2. But some others define as unsigned long. If your system
defines the fields using a type of different width than listed here,
you must #include your system version and #define
HAVE_MALLOC_H.
@@ -821,23 +821,23 @@ extern Void_t* sbrk();
/* On *BSD, malloc.h is deprecated, and on some *BSD including
* it may actually raise an error.
*/
-#if defined(HAVE_MALLOC_H) && !defined(__OpenBSD__) && !defined(__FreeBSD__) && !defined(__NetBSD__)
+#if defined(HAVE_MALLOC_H) && !defined(__OpenBSD__) && !defined(__FreeBSD__) && !defined(__NetBSD__) && defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 33)
#include <malloc.h>
#else
-/* SVID2/XPG mallinfo structure */
-
-struct mallinfo {
- int arena; /* non-mmapped space allocated from system */
- int ordblks; /* number of free chunks */
- int smblks; /* number of fastbin blocks */
- int hblks; /* number of mmapped regions */
- int hblkhd; /* space in mmapped regions */
- int usmblks; /* maximum total allocated space */
- int fsmblks; /* space available in freed fastbin blocks */
- int uordblks; /* total allocated space */
- int fordblks; /* total free space */
- int keepcost; /* top-most, releasable (via malloc_trim) space */
+/* SVID2/XPG mallinfo2 structure */
+
+struct mallinfo2 {
+ size_t arena; /* non-mmapped space allocated from system */
+ size_t ordblks; /* number of free chunks */
+ size_t smblks; /* number of fastbin blocks */
+ size_t hblks; /* number of mmapped regions */
+ size_t hblkhd; /* space in mmapped regions */
+ size_t usmblks; /* maximum total allocated space */
+ size_t fsmblks; /* space available in freed fastbin blocks */
+ size_t uordblks; /* total allocated space */
+ size_t fordblks; /* total free space */
+ size_t keepcost; /* top-most, releasable (via malloc_trim) space */
};
/*
@@ -1007,7 +1007,7 @@ int public_mALLOPt();
/*
- mallinfo()
+ mallinfo2()
Returns (by copy) a struct containing various summary statistics:
arena: current total non-mmapped bytes allocated from system
@@ -1030,9 +1030,9 @@ int public_mALLOPt();
thus be inaccurate.
*/
#if __STD_C
-struct mallinfo public_mALLINFo(void);
+struct mallinfo2 public_mALLINFo2(void);
#else
-struct mallinfo public_mALLINFo();
+struct mallinfo2 public_mALLINFo2();
#endif
/*
@@ -1114,7 +1114,7 @@ size_t public_mUSABLe();
(normally sbrk) outside of malloc.
malloc_stats prints only the most commonly interesting statistics.
- More information can be obtained by calling mallinfo.
+ More information can be obtained by calling mallinfo2.
*/
#if __STD_C
@@ -1365,7 +1365,7 @@ static int mTRIm(size_t);
static size_t mUSABLe(Void_t*);
static void mSTATs();
static int mALLOPt(int, int);
-static struct mallinfo mALLINFo(void);
+static struct mallinfo2 mALLINFo2(void);
#else
static Void_t* mALLOc();
static void fREe();
@@ -1379,7 +1379,7 @@ static int mTRIm();
static size_t mUSABLe();
static void mSTATs();
static int mALLOPt();
-static struct mallinfo mALLINFo();
+static struct mallinfo2 mALLINFo2();
#endif
/*
@@ -1686,14 +1686,14 @@ void public_mSTATs() {
}
}
-struct mallinfo public_mALLINFo() {
- struct mallinfo m;
+struct mallinfo2 public_mALLINFo2() {
+ struct mallinfo2 m;
if (MALLOC_PREACTION == 0) {
- m = mALLINFo();
+ m = mALLINFo2();
(void) MALLOC_POSTACTION;
return m;
} else {
- struct mallinfo nm = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+ struct mallinfo2 nm = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
return nm;
}
}
@@ -5292,10 +5292,10 @@ DL_STATIC size_t mUSABLe(mem) Void_t* mem;
------------------------------ mallinfo ------------------------------
*/
-DL_STATIC struct mallinfo mALLINFo()
+DL_STATIC struct mallinfo2 mALLINFo2()
{
mstate av = get_malloc_state();
- struct mallinfo mi;
+ static struct mallinfo2 mi;
unsigned int i;
mbinptr b;
chunkinfoptr p;
@@ -5311,6 +5311,10 @@ DL_STATIC struct mallinfo mALLINFo()
}
check_malloc_state();
+ if (!av || av->top == 0) {
+ return mi;
+ }
+
/* Account for top */
avail = chunksize(av->top);
nblocks = 1; /* top always exists */
@@ -5356,19 +5360,18 @@ DL_STATIC struct mallinfo mALLINFo()
DL_STATIC void mSTATs()
{
- struct mallinfo mi = mALLINFo();
+ struct mallinfo2 mi = mALLINFo2();
fprintf(stderr, "hashtable = %10lu MB\n",
(CHUNK_SIZE_T)(HASHTABLESIZE / (1024*1024)));
fprintf(stderr, "max system bytes = %10lu\n",
- (CHUNK_SIZE_T)(mi.usmblks));
+ (CHUNK_SIZE_T)(mi.usmblks));
fprintf(stderr, "system bytes = %10lu (%10lu sbrked, %10lu mmaped)\n",
- (CHUNK_SIZE_T)(mi.arena + mi.hblkhd),
- (CHUNK_SIZE_T)(mi.arena),
- (CHUNK_SIZE_T)(mi.hblkhd));
+ (CHUNK_SIZE_T)(mi.arena + mi.hblkhd),
+ (CHUNK_SIZE_T)(mi.arena),
+ (CHUNK_SIZE_T)(mi.hblkhd));
fprintf(stderr, "in use bytes = %10lu\n",
- (CHUNK_SIZE_T)(mi.uordblks + mi.hblkhd));
-
+ (CHUNK_SIZE_T)(mi.uordblks + mi.hblkhd));
}
@@ -5521,7 +5524,7 @@ arc4_stir(void)
struct {
struct timeval tv1;
struct timeval tv2;
- u_int rnd[(128 - 2*sizeof(struct timeval)) / sizeof(u_int)];
+ unsigned char rnd[(128 - 2*sizeof(struct timeval)) / sizeof(unsigned char)];
} rdat;
#if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__)
ssize_t sz = 0;