From owner-p4-projects Thu Mar 28 9: 2:41 2002 Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 7F4B437B404; Thu, 28 Mar 2002 09:02:34 -0800 (PST) Delivered-To: perforce@freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id 8C64337B405 for ; Thu, 28 Mar 2002 09:02:33 -0800 (PST) Received: (from perforce@localhost) by freefall.freebsd.org (8.11.6/8.11.6) id g2SH2Xh33714 for perforce@freebsd.org; Thu, 28 Mar 2002 09:02:33 -0800 (PST) (envelope-from green@freebsd.org) Date: Thu, 28 Mar 2002 09:02:33 -0800 (PST) Message-Id: <200203281702.g2SH2Xh33714@freefall.freebsd.org> X-Authentication-Warning: freefall.freebsd.org: perforce set sender to green@freebsd.org using -f From: Brian Feldman Subject: PERFORCE change 8572 for review To: Perforce Change Reviews Sender: owner-p4-projects@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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