uma_dbg.c (e0f86251a7591d5449f2b108a9a9eb74bf21a6fd) uma_dbg.c (099a0e588cbe1bbc56a565bf57d722621b47a866)
1/*
2 * Copyright (c) 2002, Jeffrey Roberson <jeff@freebsd.org>
3 * 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

--- 178 unchanged lines hidden (view full) ---

187{
188 mtrash_ctor(mem, size, NULL);
189}
190
191static uma_slab_t
192uma_dbg_getslab(uma_zone_t zone, void *item)
193{
194 uma_slab_t slab;
1/*
2 * Copyright (c) 2002, Jeffrey Roberson <jeff@freebsd.org>
3 * 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

--- 178 unchanged lines hidden (view full) ---

187{
188 mtrash_ctor(mem, size, NULL);
189}
190
191static uma_slab_t
192uma_dbg_getslab(uma_zone_t zone, void *item)
193{
194 uma_slab_t slab;
195 uma_keg_t keg;
195 u_int8_t *mem;
196
196 u_int8_t *mem;
197
198 keg = zone->uz_keg;
197 mem = (u_int8_t *)((unsigned long)item & (~UMA_SLAB_MASK));
199 mem = (u_int8_t *)((unsigned long)item & (~UMA_SLAB_MASK));
198 if (zone->uz_flags & UMA_ZONE_MALLOC) {
200 if (keg->uk_flags & UMA_ZONE_MALLOC) {
199 slab = vtoslab((vm_offset_t)mem);
201 slab = vtoslab((vm_offset_t)mem);
200 } else if (zone->uz_flags & UMA_ZONE_HASH) {
201 slab = hash_sfind(&zone->uz_hash, mem);
202 } else if (keg->uk_flags & UMA_ZONE_HASH) {
203 slab = hash_sfind(&keg->uk_hash, mem);
202 } else {
204 } else {
203 mem += zone->uz_pgoff;
205 mem += keg->uk_pgoff;
204 slab = (uma_slab_t)mem;
205 }
206
207 return (slab);
208}
209
210/*
211 * Set up the slab's freei data such that uma_dbg_free can function.
212 *
213 */
214
215void
216uma_dbg_alloc(uma_zone_t zone, uma_slab_t slab, void *item)
217{
206 slab = (uma_slab_t)mem;
207 }
208
209 return (slab);
210}
211
212/*
213 * Set up the slab's freei data such that uma_dbg_free can function.
214 *
215 */
216
217void
218uma_dbg_alloc(uma_zone_t zone, uma_slab_t slab, void *item)
219{
220 uma_keg_t keg;
218 int freei;
219
221 int freei;
222
223 keg = zone->uz_keg;
220 if (slab == NULL) {
221 slab = uma_dbg_getslab(zone, item);
222 if (slab == NULL)
223 panic("uma: item %p did not belong to zone %s\n",
224 item, zone->uz_name);
225 }
226
227 freei = ((unsigned long)item - (unsigned long)slab->us_data)
224 if (slab == NULL) {
225 slab = uma_dbg_getslab(zone, item);
226 if (slab == NULL)
227 panic("uma: item %p did not belong to zone %s\n",
228 item, zone->uz_name);
229 }
230
231 freei = ((unsigned long)item - (unsigned long)slab->us_data)
228 / zone->uz_rsize;
232 / keg->uk_rsize;
229
233
230 slab->us_freelist[freei] = 255;
234 slab->us_freelist[freei].us_item = 255;
231
232 return;
233}
234
235/*
236 * Verifies freed addresses. Checks for alignment, valid slab membership
237 * and duplicate frees.
238 *
239 */
240
241void
242uma_dbg_free(uma_zone_t zone, uma_slab_t slab, void *item)
243{
235
236 return;
237}
238
239/*
240 * Verifies freed addresses. Checks for alignment, valid slab membership
241 * and duplicate frees.
242 *
243 */
244
245void
246uma_dbg_free(uma_zone_t zone, uma_slab_t slab, void *item)
247{
248 uma_keg_t keg;
244 int freei;
245
249 int freei;
250
251 keg = zone->uz_keg;
246 if (slab == NULL) {
247 slab = uma_dbg_getslab(zone, item);
248 if (slab == NULL)
249 panic("uma: Freed item %p did not belong to zone %s\n",
250 item, zone->uz_name);
251 }
252
253 freei = ((unsigned long)item - (unsigned long)slab->us_data)
252 if (slab == NULL) {
253 slab = uma_dbg_getslab(zone, item);
254 if (slab == NULL)
255 panic("uma: Freed item %p did not belong to zone %s\n",
256 item, zone->uz_name);
257 }
258
259 freei = ((unsigned long)item - (unsigned long)slab->us_data)
254 / zone->uz_rsize;
260 / keg->uk_rsize;
255
261
256 if (freei >= zone->uz_ipers)
262 if (freei >= keg->uk_ipers)
257 panic("zone: %s(%p) slab %p freelist %d out of range 0-%d\n",
263 panic("zone: %s(%p) slab %p freelist %d out of range 0-%d\n",
258 zone->uz_name, zone, slab, freei, zone->uz_ipers-1);
264 zone->uz_name, zone, slab, freei, keg->uk_ipers-1);
259
265
260 if (((freei * zone->uz_rsize) + slab->us_data) != item) {
266 if (((freei * keg->uk_rsize) + slab->us_data) != item) {
261 printf("zone: %s(%p) slab %p freed address %p unaligned.\n",
262 zone->uz_name, zone, slab, item);
263 panic("should be %p\n",
267 printf("zone: %s(%p) slab %p freed address %p unaligned.\n",
268 zone->uz_name, zone, slab, item);
269 panic("should be %p\n",
264 (freei * zone->uz_rsize) + slab->us_data);
270 (freei * keg->uk_rsize) + slab->us_data);
265 }
266
271 }
272
267 if (slab->us_freelist[freei] != 255) {
273 if (slab->us_freelist[freei].us_item != 255) {
268 printf("Slab at %p, freei %d = %d.\n",
274 printf("Slab at %p, freei %d = %d.\n",
269 slab, freei, slab->us_freelist[freei]);
275 slab, freei, slab->us_freelist[freei].us_item);
270 panic("Duplicate free of item %p from zone %p(%s)\n",
271 item, zone, zone->uz_name);
272 }
273
274 /*
275 * When this is actually linked into the slab this will change.
276 * Until then the count of valid slabs will make sure we don't
277 * accidentally follow this and assume it's a valid index.
278 */
276 panic("Duplicate free of item %p from zone %p(%s)\n",
277 item, zone, zone->uz_name);
278 }
279
280 /*
281 * When this is actually linked into the slab this will change.
282 * Until then the count of valid slabs will make sure we don't
283 * accidentally follow this and assume it's a valid index.
284 */
279 slab->us_freelist[freei] = 0;
285 slab->us_freelist[freei].us_item = 0;
280}
286}