Author: jmg
Date: Thu Jun 25 20:44:46 2015
New Revision: 284861
URL: https://svnweb.freebsd.org/changeset/base/284861

Log:
  If INVARIANTS is specified, add ctor/dtor to junk memory if they are
  unspecified...
  
  Submitted by: Suresh Gumpula at Netapp
  Differential Revision:        https://reviews.freebsd.org/D2725

Modified:
  head/sys/vm/uma_core.c
  head/sys/vm/uma_dbg.c

Modified: head/sys/vm/uma_core.c
==============================================================================
--- head/sys/vm/uma_core.c      Thu Jun 25 20:40:51 2015        (r284860)
+++ head/sys/vm/uma_core.c      Thu Jun 25 20:44:46 2015        (r284861)
@@ -1940,6 +1940,20 @@ uma_zcreate(const char *name, size_t siz
        args.dtor = dtor;
        args.uminit = uminit;
        args.fini = fini;
+#ifdef  INVARIANTS
+       /*
+        * If a zone is being created with an empty constructor and
+        * destructor, pass UMA constructor/destructor which checks for
+        * memory use after free.
+        */
+       if ((!(flags & UMA_ZONE_ZINIT)) && ctor == NULL && dtor == NULL &&
+           uminit == NULL && fini == NULL) {
+               args.ctor = trash_ctor;
+               args.dtor = trash_dtor;
+               args.uminit = trash_init;
+               args.fini = trash_fini;
+       }
+#endif
        args.align = align;
        args.flags = flags;
        args.keg = NULL;

Modified: head/sys/vm/uma_dbg.c
==============================================================================
--- head/sys/vm/uma_dbg.c       Thu Jun 25 20:40:51 2015        (r284860)
+++ head/sys/vm/uma_dbg.c       Thu Jun 25 20:44:46 2015        (r284861)
@@ -69,8 +69,13 @@ trash_ctor(void *mem, int size, void *ar
 
        for (p = mem; cnt > 0; cnt--, p++)
                if (*p != uma_junk) {
+#ifdef INVARIANTS
+                       panic("Memory modified after free %p(%d) val=%x @ %p\n",
+                           mem, size, *p, p);
+#else
                        printf("Memory modified after free %p(%d) val=%x @ 
%p\n",
                            mem, size, *p, p);
+#endif
                        return (0);
                }
        return (0);
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to