1/*- 2 * Copyright (c) 2002, 2003, 2004, 2005 Jeffrey Roberson <jeff@FreeBSD.org> 3 * Copyright (c) 2004, 2005 Bosko Milekic <bmilekic@FreeBSD.org> 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 17 unchanged lines hidden (view full) --- 26 */ 27 28/* 29 * uma_dbg.c Debugging features for UMA users 30 * 31 */ 32 33#include <sys/cdefs.h> |
34__FBSDID("$FreeBSD: head/sys/vm/uma_dbg.c 249313 2013-04-09 17:43:48Z glebius $"); |
35 36#include <sys/param.h> 37#include <sys/systm.h> 38#include <sys/kernel.h> 39#include <sys/types.h> 40#include <sys/queue.h> 41#include <sys/lock.h> 42#include <sys/mutex.h> 43#include <sys/malloc.h> 44 45#include <vm/vm.h> 46#include <vm/vm_object.h> 47#include <vm/vm_page.h> 48#include <vm/uma.h> 49#include <vm/uma_int.h> 50#include <vm/uma_dbg.h> 51 |
52static const uint32_t uma_junk = 0xdeadc0de; |
53 54/* 55 * Checks an item to make sure it hasn't been overwritten since it was freed, 56 * prior to subsequent reallocation. 57 * 58 * Complies with standard ctor arg/return 59 * 60 */ 61int 62trash_ctor(void *mem, int size, void *arg, int flags) 63{ 64 int cnt; |
65 uint32_t *p; |
66 67 cnt = size / sizeof(uma_junk); 68 69 for (p = mem; cnt > 0; cnt--, p++) 70 if (*p != uma_junk) { 71 printf("Memory modified after free %p(%d) val=%x @ %p\n", 72 mem, size, *p, p); 73 return (0); --- 6 unchanged lines hidden (view full) --- 80 * 81 * Complies with standard dtor arg/return 82 * 83 */ 84void 85trash_dtor(void *mem, int size, void *arg) 86{ 87 int cnt; |
88 uint32_t *p; |
89 90 cnt = size / sizeof(uma_junk); 91 92 for (p = mem; cnt > 0; cnt--, p++) 93 *p = uma_junk; 94} 95 96/* --- 20 unchanged lines hidden (view full) --- 117{ 118 (void)trash_ctor(mem, size, NULL, 0); 119} 120 121int 122mtrash_ctor(void *mem, int size, void *arg, int flags) 123{ 124 struct malloc_type **ksp; |
125 uint32_t *p = mem; |
126 int cnt; 127 128 size -= sizeof(struct malloc_type *); 129 ksp = (struct malloc_type **)mem; 130 ksp += size / sizeof(struct malloc_type *); 131 cnt = size / sizeof(uma_junk); 132 133 for (p = mem; cnt > 0; cnt--, p++) --- 11 unchanged lines hidden (view full) --- 145 * 146 * Complies with standard dtor arg/return 147 * 148 */ 149void 150mtrash_dtor(void *mem, int size, void *arg) 151{ 152 int cnt; |
153 uint32_t *p; |
154 155 size -= sizeof(struct malloc_type *); 156 cnt = size / sizeof(uma_junk); 157 158 for (p = mem; cnt > 0; cnt--, p++) 159 *p = uma_junk; 160} 161 --- 29 unchanged lines hidden (view full) --- 191 (void)mtrash_ctor(mem, size, NULL, 0); 192} 193 194static uma_slab_t 195uma_dbg_getslab(uma_zone_t zone, void *item) 196{ 197 uma_slab_t slab; 198 uma_keg_t keg; |
199 uint8_t *mem; |
200 |
201 mem = (uint8_t *)((unsigned long)item & (~UMA_SLAB_MASK)); |
202 if (zone->uz_flags & UMA_ZONE_VTOSLAB) { 203 slab = vtoslab((vm_offset_t)mem); 204 } else { 205 keg = LIST_FIRST(&zone->uz_kegs)->kl_keg; 206 if (keg->uk_flags & UMA_ZONE_HASH) 207 slab = hash_sfind(&keg->uk_hash, mem); 208 else 209 slab = (uma_slab_t)(mem + keg->uk_pgoff); --- 104 unchanged lines hidden --- |