|
41 | 41 | * chunks as chunks. Anything "large" is passed off to malloc(). Change |
42 | 42 | * the number of freelists to change the small/large boundary. |
43 | 43 | * |
44 | | - * |
45 | | - * About CLOBBER_FREED_MEMORY: |
46 | | - * |
47 | | - * If this symbol is defined, all freed memory is overwritten with 0x7F's. |
48 | | - * This is useful for catching places that reference already-freed memory. |
49 | | - * |
50 | | - * About MEMORY_CONTEXT_CHECKING: |
51 | | - * |
52 | | - * Since we usually round request sizes up to the next power of 2, there |
53 | | - * is often some unused space immediately after a requested data area. |
54 | | - * Thus, if someone makes the common error of writing past what they've |
55 | | - * requested, the problem is likely to go unnoticed ... until the day when |
56 | | - * there *isn't* any wasted space, perhaps because of different memory |
57 | | - * alignment on a new platform, or some other effect. To catch this sort |
58 | | - * of problem, the MEMORY_CONTEXT_CHECKING option stores 0x7E just beyond |
59 | | - * the requested space whenever the request is less than the actual chunk |
60 | | - * size, and verifies that the byte is undamaged when the chunk is freed. |
61 | | - * |
62 | | - * |
63 | | - * About USE_VALGRIND and Valgrind client requests: |
64 | | - * |
65 | | - * Valgrind provides "client request" macros that exchange information with |
66 | | - * the host Valgrind (if any). Under !USE_VALGRIND, memdebug.h stubs out |
67 | | - * currently-used macros. |
68 | | - * |
69 | | - * When running under Valgrind, we want a NOACCESS memory region both before |
70 | | - * and after the allocation. The chunk header is tempting as the preceding |
71 | | - * region, but mcxt.c expects to able to examine the standard chunk header |
72 | | - * fields. Therefore, we use, when available, the requested_size field and |
73 | | - * any subsequent padding. requested_size is made NOACCESS before returning |
74 | | - * a chunk pointer to a caller. However, to reduce client request traffic, |
75 | | - * it is kept DEFINED in chunks on the free list. |
76 | | - * |
77 | | - * The rounded-up capacity of the chunk usually acts as a post-allocation |
78 | | - * NOACCESS region. If the request consumes precisely the entire chunk, |
79 | | - * there is no such region; another chunk header may immediately follow. In |
80 | | - * that case, Valgrind will not detect access beyond the end of the chunk. |
81 | | - * |
82 | | - * See also the cooperating Valgrind client requests in mcxt.c. |
83 | | - * |
84 | 44 | *------------------------------------------------------------------------- |
85 | 45 | */ |
86 | 46 |
|
@@ -296,10 +256,10 @@ static const unsigned char LogTable256[256] = |
296 | 256 | */ |
297 | 257 | #ifdef HAVE_ALLOCINFO |
298 | 258 | #define AllocFreeInfo(_cxt, _chunk) \ |
299 | | - fprintf(stderr, "AllocFree: %s: %p, %d\n", \ |
| 259 | + fprintf(stderr, "AllocFree: %s: %p, %zu\n", \ |
300 | 260 | (_cxt)->header.name, (_chunk), (_chunk)->size) |
301 | 261 | #define AllocAllocInfo(_cxt, _chunk) \ |
302 | | - fprintf(stderr, "AllocAlloc: %s: %p, %d\n", \ |
| 262 | + fprintf(stderr, "AllocAlloc: %s: %p, %zu\n", \ |
303 | 263 | (_cxt)->header.name, (_chunk), (_chunk)->size) |
304 | 264 | #else |
305 | 265 | #define AllocFreeInfo(_cxt, _chunk) |
@@ -345,77 +305,6 @@ AllocSetFreeIndex(Size size) |
345 | 305 | return idx; |
346 | 306 | } |
347 | 307 |
|
348 | | -#ifdef CLOBBER_FREED_MEMORY |
349 | | - |
350 | | -/* Wipe freed memory for debugging purposes */ |
351 | | -static void |
352 | | -wipe_mem(void *ptr, size_t size) |
353 | | -{ |
354 | | - VALGRIND_MAKE_MEM_UNDEFINED(ptr, size); |
355 | | - memset(ptr, 0x7F, size); |
356 | | - VALGRIND_MAKE_MEM_NOACCESS(ptr, size); |
357 | | -} |
358 | | -#endif |
359 | | - |
360 | | -#ifdef MEMORY_CONTEXT_CHECKING |
361 | | -static void |
362 | | -set_sentinel(void *base, Size offset) |
363 | | -{ |
364 | | - char *ptr = (char *) base + offset; |
365 | | - |
366 | | - VALGRIND_MAKE_MEM_UNDEFINED(ptr, 1); |
367 | | - *ptr = 0x7E; |
368 | | - VALGRIND_MAKE_MEM_NOACCESS(ptr, 1); |
369 | | -} |
370 | | - |
371 | | -static bool |
372 | | -sentinel_ok(const void *base, Size offset) |
373 | | -{ |
374 | | - const char *ptr = (const char *) base + offset; |
375 | | - bool ret; |
376 | | - |
377 | | - VALGRIND_MAKE_MEM_DEFINED(ptr, 1); |
378 | | - ret = *ptr == 0x7E; |
379 | | - VALGRIND_MAKE_MEM_NOACCESS(ptr, 1); |
380 | | - |
381 | | - return ret; |
382 | | -} |
383 | | -#endif |
384 | | - |
385 | | -#ifdef RANDOMIZE_ALLOCATED_MEMORY |
386 | | - |
387 | | -/* |
388 | | - * Fill a just-allocated piece of memory with "random" data. It's not really |
389 | | - * very random, just a repeating sequence with a length that's prime. What |
390 | | - * we mainly want out of it is to have a good probability that two palloc's |
391 | | - * of the same number of bytes start out containing different data. |
392 | | - * |
393 | | - * The region may be NOACCESS, so make it UNDEFINED first to avoid errors as |
394 | | - * we fill it. Filling the region makes it DEFINED, so make it UNDEFINED |
395 | | - * again afterward. Whether to finally make it UNDEFINED or NOACCESS is |
396 | | - * fairly arbitrary. UNDEFINED is more convenient for AllocSetRealloc(), and |
397 | | - * other callers have no preference. |
398 | | - */ |
399 | | -static void |
400 | | -randomize_mem(char *ptr, size_t size) |
401 | | -{ |
402 | | - static int save_ctr = 1; |
403 | | - size_t remaining = size; |
404 | | - int ctr; |
405 | | - |
406 | | - ctr = save_ctr; |
407 | | - VALGRIND_MAKE_MEM_UNDEFINED(ptr, size); |
408 | | - while (remaining-- > 0) |
409 | | - { |
410 | | - *ptr++ = ctr; |
411 | | - if (++ctr > 251) |
412 | | - ctr = 1; |
413 | | - } |
414 | | - VALGRIND_MAKE_MEM_UNDEFINED(ptr - size, size); |
415 | | - save_ctr = ctr; |
416 | | -} |
417 | | -#endif /* RANDOMIZE_ALLOCATED_MEMORY */ |
418 | | - |
419 | 308 |
|
420 | 309 | /* |
421 | 310 | * Public routines |
|
0 commit comments