]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Partial implementation of mallinfo(). It still puts zero in all
authorNicholas Nethercote <njn@valgrind.org>
Wed, 17 Aug 2005 05:01:37 +0000 (05:01 +0000)
committerNicholas Nethercote <njn@valgrind.org>
Wed, 17 Aug 2005 05:01:37 +0000 (05:01 +0000)
the fields, but all the plumbing is now there so that m_mallocfree.c
can fill them in.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@4441

coregrind/m_mallocfree.c
coregrind/m_replacemalloc/vg_replace_malloc.c
coregrind/m_scheduler/scheduler.c
coregrind/pub_core_mallocfree.h
coregrind/pub_core_replacemalloc.h

index e21ed6290cb9b87b8dbbdce9bfd9278de0bf9edb..ae739193cf9dced464bb40fed5934d090fc6750a 100644 (file)
@@ -1204,6 +1204,14 @@ SizeT VG_(arena_payload_szB) ( ThreadId tid, ArenaId aid, void* ptr )
    return get_pszB(a, b);
 }
 
+// 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));
+}
 
 /*------------------------------------------------------------*/
 /*--- Services layered on top of malloc/free.              ---*/
index df5603ea8a9fdc3090f0d290797428c4117e484c..a86b0632818c80279dc79ecf39df6d49b67efea0 100644 (file)
@@ -429,36 +429,18 @@ PANIC(m_libc_dot_so_dot_6, malloc_trim);
 PANIC(m_libc_dot_so_dot_6, malloc_get_state);
 PANIC(m_libc_dot_so_dot_6, malloc_set_state);
 
-
-/* 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 Memcheck
+// 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 = (UChar*)(&mi); \
-      for (i = 0; i < sizeof(mi); i++) \
-         pmi[i] = 0; \
+      static struct vg_mallinfo mi; \
+      MALLOC_TRACE("mallinfo()"); \
+      if (!init_done) init(); \
+      (void)VALGRIND_NON_SIMD_CALL1( info.mallinfo, &mi ); \
       return mi; \
    }
 
index 4b0503624ffa55fd584018dc3d96dc2613c6f7a3..a941685f2817cad0c826b3578114ab54f576e01d 100644 (file)
@@ -1027,6 +1027,7 @@ void do_client_request ( ThreadId tid )
         info->tl___builtin_vec_delete = VG_(tdict).tool___builtin_vec_delete;
 
         info->arena_payload_szB       = VG_(arena_payload_szB);
+        info->mallinfo                = VG_(mallinfo);
         info->clo_trace_malloc        = VG_(clo_trace_malloc);
 
          SET_CLREQ_RETVAL( tid, 0 );     /* return value is meaningless */
index 94dcbc69c468ecd5339ef89a9f82615e5bb2b08f..51670427912f557dece27c9dd838a70713a80ce0 100644 (file)
@@ -68,6 +68,21 @@ typedef Int ArenaId;
 // greater than 8.
 #define VG_MIN_MALLOC_SZB        8
 
+/* 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, 
@@ -83,6 +98,8 @@ extern void  VG_(set_client_malloc_redzone_szB) ( SizeT rz_szB );
 
 extern SizeT VG_(arena_payload_szB) ( ThreadId tid, ArenaId aid, void* p );
 
+extern void  VG_(mallinfo) ( ThreadId tid, struct vg_mallinfo* mi );
+
 extern void  VG_(sanity_check_malloc_all) ( void );
 
 extern void  VG_(print_all_arena_stats) ( void );
index e50de51d7841bd11e778fe4bfd069f7eefc7c390..7f27ce09bf89f28f3652d0edaab1b88fc92f7a2f 100644 (file)
@@ -51,6 +51,7 @@ struct vg_mallocfunc_info {
    void* (*tl_realloc)             (ThreadId tid, void* p, SizeT size);
 
    SizeT (*arena_payload_szB)      (ThreadId tid, ArenaId aid, void* payload);
+   void  (*mallinfo)               (ThreadId tid, struct vg_mallinfo* mi);
    Bool        clo_trace_malloc;
 };