|
From: <sv...@va...> - 2005-08-17 05:01:40
|
Author: njn
Date: 2005-08-17 06:01:37 +0100 (Wed, 17 Aug 2005)
New Revision: 4441
Log:
Partial implementation of mallinfo(). It still puts zero in all
the fields, but all the plumbing is now there so that m_mallocfree.c
can fill them in.
Modified:
trunk/coregrind/m_mallocfree.c
trunk/coregrind/m_replacemalloc/vg_replace_malloc.c
trunk/coregrind/m_scheduler/scheduler.c
trunk/coregrind/pub_core_mallocfree.h
trunk/coregrind/pub_core_replacemalloc.h
Modified: trunk/coregrind/m_mallocfree.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_mallocfree.c 2005-08-17 04:34:05 UTC (rev 4440)
+++ trunk/coregrind/m_mallocfree.c 2005-08-17 05:01:37 UTC (rev 4441)
@@ -1204,6 +1204,14 @@
return get_pszB(a, b);
}
=20
+// We cannot return the whole struct as the library function does,
+// because this is called by a client request. So instead we use
+// a pointer to do call by reference.
+void VG_(mallinfo) ( ThreadId tid, struct vg_mallinfo* mi )
+{
+ // Should do better than this...
+ VG_(memset)(mi, 0x0, sizeof(struct vg_mallinfo));
+}
=20
/*------------------------------------------------------------*/
/*--- Services layered on top of malloc/free. ---*/
Modified: trunk/coregrind/m_replacemalloc/vg_replace_malloc.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_replacemalloc/vg_replace_malloc.c 2005-08-17 04:34:=
05 UTC (rev 4440)
+++ trunk/coregrind/m_replacemalloc/vg_replace_malloc.c 2005-08-17 05:01:=
37 UTC (rev 4441)
@@ -429,36 +429,18 @@
PANIC(m_libc_dot_so_dot_6, malloc_get_state);
PANIC(m_libc_dot_so_dot_6, malloc_set_state);
=20
-
-/* Yet another ugly hack. Cannot include <malloc.h> because we
- implement functions implemented there with different signatures.
- This struct definition MUST match the system one. */
-
-/* SVID2/XPG mallinfo structure */
-struct mallinfo {
- int arena; /* total space allocated from system */
- int ordblks; /* number of non-inuse chunks */
- int smblks; /* unused -- always zero */
- int hblks; /* number of mmapped regions */
- int hblkhd; /* total space in mmapped regions */
- int usmblks; /* unused -- always zero */
- int fsmblks; /* unused -- always zero */
- int uordblks; /* total allocated space */
- int fordblks; /* total non-inuse space */
- int keepcost; /* top-most, releasable (via malloc_trim) space */
-};
-
+// mi must be static; if it is auto then Memcheck thinks it is
+// uninitialised when used by the caller of this function, because Memch=
eck
+// doesn't know that the call to mallinfo fills in mi.
#define MALLINFO(soname, fnname) \
\
- struct mallinfo VG_REPLACE_FUNCTION(soname, fnname) ( void ); \
- struct mallinfo VG_REPLACE_FUNCTION(soname, fnname) ( void ) \
+ struct vg_mallinfo VG_REPLACE_FUNCTION(soname, fnname) ( void ); \
+ struct vg_mallinfo VG_REPLACE_FUNCTION(soname, fnname) ( void ) \
{ \
- /* Should really try to return something a bit more meaningful */ =
\
- UInt i; \
- struct mallinfo mi; \
- UChar* pmi =3D (UChar*)(&mi); \
- for (i =3D 0; i < sizeof(mi); i++) \
- pmi[i] =3D 0; \
+ static struct vg_mallinfo mi; \
+ MALLOC_TRACE("mallinfo()"); \
+ if (!init_done) init(); \
+ (void)VALGRIND_NON_SIMD_CALL1( info.mallinfo, &mi ); \
return mi; \
}
=20
Modified: trunk/coregrind/m_scheduler/scheduler.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_scheduler/scheduler.c 2005-08-17 04:34:05 UTC (rev =
4440)
+++ trunk/coregrind/m_scheduler/scheduler.c 2005-08-17 05:01:37 UTC (rev =
4441)
@@ -1027,6 +1027,7 @@
info->tl___builtin_vec_delete =3D VG_(tdict).tool___builtin_vec_delete=
;
=20
info->arena_payload_szB =3D VG_(arena_payload_szB);
+ info->mallinfo =3D VG_(mallinfo);
info->clo_trace_malloc =3D VG_(clo_trace_malloc);
=20
SET_CLREQ_RETVAL( tid, 0 ); /* return value is meaningless =
*/
Modified: trunk/coregrind/pub_core_mallocfree.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/pub_core_mallocfree.h 2005-08-17 04:34:05 UTC (rev 44=
40)
+++ trunk/coregrind/pub_core_mallocfree.h 2005-08-17 05:01:37 UTC (rev 44=
41)
@@ -68,6 +68,21 @@
// greater than 8.
#define VG_MIN_MALLOC_SZB 8
=20
+/* This struct definition MUST match the system one. */
+/* SVID2/XPG mallinfo structure */
+struct vg_mallinfo {
+ int arena; /* total space allocated from system */
+ int ordblks; /* number of non-inuse chunks */
+ int smblks; /* unused -- always zero */
+ int hblks; /* number of mmapped regions */
+ int hblkhd; /* total space in mmapped regions */
+ int usmblks; /* unused -- always zero */
+ int fsmblks; /* unused -- always zero */
+ int uordblks; /* total allocated space */
+ int fordblks; /* total non-inuse space */
+ int keepcost; /* top-most, releasable (via malloc_trim) space */
+};
+
extern void* VG_(arena_malloc) ( ArenaId arena, SizeT nbytes );
extern void VG_(arena_free) ( ArenaId arena, void* ptr );
extern void* VG_(arena_calloc) ( ArenaId arena,=20
@@ -83,6 +98,8 @@
=20
extern SizeT VG_(arena_payload_szB) ( ThreadId tid, ArenaId aid, void* p=
);
=20
+extern void VG_(mallinfo) ( ThreadId tid, struct vg_mallinfo* mi );
+
extern void VG_(sanity_check_malloc_all) ( void );
=20
extern void VG_(print_all_arena_stats) ( void );
Modified: trunk/coregrind/pub_core_replacemalloc.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/pub_core_replacemalloc.h 2005-08-17 04:34:05 UTC (rev=
4440)
+++ trunk/coregrind/pub_core_replacemalloc.h 2005-08-17 05:01:37 UTC (rev=
4441)
@@ -51,6 +51,7 @@
void* (*tl_realloc) (ThreadId tid, void* p, SizeT size);
=20
SizeT (*arena_payload_szB) (ThreadId tid, ArenaId aid, void* pay=
load);
+ void (*mallinfo) (ThreadId tid, struct vg_mallinfo* mi=
);
Bool clo_trace_malloc;
};
=20
|