kern_malloc.c (42408) | kern_malloc.c (42453) |
---|---|
1/* 2 * Copyright (c) 1987, 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)kern_malloc.c 8.3 (Berkeley) 1/4/94 | 1/* 2 * Copyright (c) 1987, 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)kern_malloc.c 8.3 (Berkeley) 1/4/94 |
34 * $Id: kern_malloc.c,v 1.49 1998/11/10 08:46:24 peter Exp $ | 34 * $Id: kern_malloc.c,v 1.50 1999/01/08 17:31:09 eivind Exp $ |
35 */ 36 37#include "opt_vm.h" 38 39#include <sys/param.h> 40#include <sys/systm.h> 41#include <sys/kernel.h> 42#define MALLOC_INSTANTIATE --- 16 unchanged lines hidden (view full) --- 59 60static struct malloc_type *kmemstatistics; 61static struct kmembuckets bucket[MINBUCKET + 16]; 62static struct kmemusage *kmemusage; 63static char *kmembase; 64static char *kmemlimit; 65static int vm_kmem_size; 66 | 35 */ 36 37#include "opt_vm.h" 38 39#include <sys/param.h> 40#include <sys/systm.h> 41#include <sys/kernel.h> 42#define MALLOC_INSTANTIATE --- 16 unchanged lines hidden (view full) --- 59 60static struct malloc_type *kmemstatistics; 61static struct kmembuckets bucket[MINBUCKET + 16]; 62static struct kmemusage *kmemusage; 63static char *kmembase; 64static char *kmemlimit; 65static int vm_kmem_size; 66 |
67#if defined(INVARIANTS) | 67#ifdef INVARIANTS |
68/* 69 * This structure provides a set of masks to catch unaligned frees. 70 */ 71static long addrmask[] = { 0, 72 0x00000001, 0x00000003, 0x00000007, 0x0000000f, 73 0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff, 74 0x000001ff, 0x000003ff, 0x000007ff, 0x00000fff, 75 0x00001fff, 0x00003fff, 0x00007fff, 0x0000ffff, --- 180 unchanged lines hidden (view full) --- 256 long *end, *lp, alloc, copysize; 257#endif 258 register struct malloc_type *ksp = type; 259 260 if (!type->ks_next) 261 panic("freeing with unknown type (%s)", type->ks_shortdesc); 262 263 KASSERT(kmembase <= (char *)addr && (char *)addr < kmemlimit, | 68/* 69 * This structure provides a set of masks to catch unaligned frees. 70 */ 71static long addrmask[] = { 0, 72 0x00000001, 0x00000003, 0x00000007, 0x0000000f, 73 0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff, 74 0x000001ff, 0x000003ff, 0x000007ff, 0x00000fff, 75 0x00001fff, 0x00003fff, 0x00007fff, 0x0000ffff, --- 180 unchanged lines hidden (view full) --- 256 long *end, *lp, alloc, copysize; 257#endif 258 register struct malloc_type *ksp = type; 259 260 if (!type->ks_next) 261 panic("freeing with unknown type (%s)", type->ks_shortdesc); 262 263 KASSERT(kmembase <= (char *)addr && (char *)addr < kmemlimit, |
264 ("free: address %p out of range", (void *)addr)); | 264 ("free: address %p out of range", (void *)addr)); |
265 kup = btokup(addr); 266 size = 1 << kup->ku_indx; 267 kbp = &bucket[kup->ku_indx]; 268 s = splmem(); 269#ifdef INVARIANTS 270 /* 271 * Check for returns of data that do not point to the 272 * beginning of the allocation. --- 24 unchanged lines hidden (view full) --- 297#ifdef INVARIANTS 298 /* 299 * Check for multiple frees. Use a quick check to see if 300 * it looks free before laboriously searching the freelist. 301 */ 302 if (freep->spare0 == WEIRD_ADDR) { 303 fp = (struct freelist *)kbp->kb_next; 304 while (fp) { | 265 kup = btokup(addr); 266 size = 1 << kup->ku_indx; 267 kbp = &bucket[kup->ku_indx]; 268 s = splmem(); 269#ifdef INVARIANTS 270 /* 271 * Check for returns of data that do not point to the 272 * beginning of the allocation. --- 24 unchanged lines hidden (view full) --- 297#ifdef INVARIANTS 298 /* 299 * Check for multiple frees. Use a quick check to see if 300 * it looks free before laboriously searching the freelist. 301 */ 302 if (freep->spare0 == WEIRD_ADDR) { 303 fp = (struct freelist *)kbp->kb_next; 304 while (fp) { |
305 if (fp->spare0 != WEIRD_ADDR) { | 305 if (fp->spare0 != WEIRD_ADDR) |
306 panic("free: free item %p modified", fp); | 306 panic("free: free item %p modified", fp); |
307 } else if (addr == (caddr_t)fp) { | 307 else if (addr == (caddr_t)fp) |
308 panic("free: multiple freed item %p", addr); | 308 panic("free: multiple freed item %p", addr); |
309 } | |
310 fp = (struct freelist *)fp->next; 311 } 312 } 313 /* 314 * Copy in known text to detect modification after freeing 315 * and to make it look free. Also, save the type being freed 316 * so we can list likely culprit if modification is detected 317 * when the object is reallocated. --- 159 unchanged lines hidden --- | 309 fp = (struct freelist *)fp->next; 310 } 311 } 312 /* 313 * Copy in known text to detect modification after freeing 314 * and to make it look free. Also, save the type being freed 315 * so we can list likely culprit if modification is detected 316 * when the object is reallocated. --- 159 unchanged lines hidden --- |