Date: Thu, 28 Mar 2002 09:02:33 -0800 (PST) From: Brian Feldman <green@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 8572 for review Message-ID: <200203281702.g2SH2Xh33714@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://people.freebsd.org/~peter/p4db/chv.cgi?CH=8572 Change 8572 by green@green_laptop_2 on 2002/03/28 09:02:01 Re-add 0xdeadc0de-filling support to free(9). Affected files ... ... //depot/projects/trustedbsd/mac/sys/kern/kern_malloc.c#4 edit Differences ... ==== //depot/projects/trustedbsd/mac/sys/kern/kern_malloc.c#4 (text+ko) ==== @@ -116,6 +116,13 @@ {0, NULL}, }; +/* + * The WEIRD_ADDR is used as known text to copy into free objects so + * that modifications after frees can be detected. + */ +#define WEIRD_ADDR 0xdeadc0de +#define MAX_COPY 64 + static struct mtx malloc_mtx; u_int vm_kmem_size; @@ -198,6 +205,24 @@ } /* + * Copy in known text to make the memory look free. + */ +static __inline void +trash_mem(void *addr, size_t size) +{ +#ifdef INVARIANTS + uint32_t *ip; + + ip = (uint32_t *)addr; + size = size >= MAX_COPY ? MAX_COPY : size & ~sizeof(uint32_t); + while (size != 0) { + *ip++ = WEIRD_ADDR; + size -= sizeof(uint32_t); + } +#endif +} + +/* * free: * * Free a block of memory allocated by malloc. @@ -230,9 +255,11 @@ if (!(slab->us_flags & UMA_SLAB_MALLOC)) { size = slab->us_zone->uz_size; + trash_mem(addr, size); uma_zfree_arg(slab->us_zone, addr, slab); } else { size = slab->us_size; + trash_mem(addr, size); uma_large_free(slab); } /* mtx_lock(&malloc_mtx); XXX */ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe p4-projects" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200203281702.g2SH2Xh33714>