diff options
| author | Paul Eggert | 2011-09-29 20:25:46 -0700 |
|---|---|---|
| committer | Paul Eggert | 2011-09-29 20:25:46 -0700 |
| commit | cb993c584c8ef91f5352ec9aa97d26fd76cfd643 (patch) | |
| tree | 923b3bcb5b390d9b3d5f34e941b29f4d80f13477 /src/lisp.h | |
| parent | 5f91c1e5303017cad6ed7d7d903440b3328fe7ff (diff) | |
| download | emacs-cb993c584c8ef91f5352ec9aa97d26fd76cfd643.tar.gz emacs-cb993c584c8ef91f5352ec9aa97d26fd76cfd643.zip | |
Port --enable-checking=all to Fedora 14 x86.
* alloc.c (XMALLOC_OVERRUN_CHECK_OVERHEAD, XMALLOC_OVERRUN_CHECK_SIZE):
Move to lisp.h.
(xmalloc_put_size, xmalloc_get_size, overrun_check_malloc)
(overrun_check_realloc, overrun_check_free):
Use XMALLOC_OVERRUN_SIZE_SIZE, not sizeof (size_t).
That way, xmalloc returns a properly-aligned pointer even if
XMALLOC_OVERRUN_CHECK is defined. The old debugging code happened
to align OK on typical 64-bit hosts, but not on Fedora 14 x86.
* charset.c (syms_of_charset): Take XMALLOC_OVERRUN_CHECK_OVERHEAD
into account when calculating the initial malloc maximum.
* lisp.h (XMALLOC_OVERRUN_CHECK_OVERHEAD, XMALLOC_OVERRUN_CHECK_SIZE):
Move here from alloc.c, so that charset.c can use it too.
Properly align; the old code wasn't right for common 32-bit hosts
when configured with --enable-checking=all.
(XMALLOC_BASE_ALIGNMENT, COMMON_MULTIPLE, XMALLOC_HEADER_ALIGNMENT)
(XMALLOC_OVERRUN_SIZE_SIZE): New macros.
Diffstat (limited to 'src/lisp.h')
| -rw-r--r-- | src/lisp.h | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/lisp.h b/src/lisp.h index e9a525a32b5..7aba299f162 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -3568,6 +3568,54 @@ extern int initialized; | |||
| 3568 | 3568 | ||
| 3569 | extern int immediate_quit; /* Nonzero means ^G can quit instantly */ | 3569 | extern int immediate_quit; /* Nonzero means ^G can quit instantly */ |
| 3570 | 3570 | ||
| 3571 | /* Overhead for overrun check in malloc'ed buffers. The check | ||
| 3572 | operates by wrapping a header and trailer around each block. | ||
| 3573 | |||
| 3574 | The header consists of XMALLOC_OVERRUN_CHECK_SIZE fixed bytes | ||
| 3575 | followed by XMALLOC_OVERRUN_SIZE_SIZE bytes containing the original | ||
| 3576 | block size in little-endian order. The trailer consists of | ||
| 3577 | XMALLOC_OVERRUN_CHECK_SIZE fixed bytes. | ||
| 3578 | |||
| 3579 | The header is used to detect whether this block has been allocated | ||
| 3580 | through these functions, as some low-level libc functions may | ||
| 3581 | bypass the malloc hooks. */ | ||
| 3582 | |||
| 3583 | #ifndef XMALLOC_OVERRUN_CHECK | ||
| 3584 | # define XMALLOC_OVERRUN_CHECK_OVERHEAD 0 | ||
| 3585 | #else | ||
| 3586 | |||
| 3587 | # define XMALLOC_OVERRUN_CHECK_SIZE 16 | ||
| 3588 | # define XMALLOC_OVERRUN_CHECK_OVERHEAD \ | ||
| 3589 | (2 * XMALLOC_OVERRUN_CHECK_SIZE + XMALLOC_OVERRUN_SIZE_SIZE) | ||
| 3590 | |||
| 3591 | /* Define XMALLOC_OVERRUN_SIZE_SIZE so that (1) it's large enough to | ||
| 3592 | hold a size_t value and (2) the header size is a multiple of the | ||
| 3593 | alignment that Emacs needs for C types and for USE_LSB_TAG. */ | ||
| 3594 | # define XMALLOC_BASE_ALIGNMENT \ | ||
| 3595 | offsetof ( \ | ||
| 3596 | struct { \ | ||
| 3597 | union { long double d; intmax_t i; void *p; } u; \ | ||
| 3598 | char c; \ | ||
| 3599 | }, \ | ||
| 3600 | c) | ||
| 3601 | # ifdef USE_LSB_TAG | ||
| 3602 | /* A common multiple of the positive integers A and B. Ideally this | ||
| 3603 | would be the least common multiple, but there's no way to do that | ||
| 3604 | as a constant expression in C, so do the best that we can easily do. */ | ||
| 3605 | # define COMMON_MULTIPLE(a, b) \ | ||
| 3606 | ((a) % (b) == 0 ? (a) : (b) % (a) == 0 ? (b) : (a) * (b)) | ||
| 3607 | # define XMALLOC_HEADER_ALIGNMENT \ | ||
| 3608 | COMMON_MULTIPLE (1 << GCTYPEBITS, XMALLOC_BASE_ALIGNMENT) | ||
| 3609 | # else | ||
| 3610 | # define XMALLOC_HEADER_ALIGNMENT XMALLOC_BASE_ALIGNMENT | ||
| 3611 | # endif | ||
| 3612 | # define XMALLOC_OVERRUN_SIZE_SIZE \ | ||
| 3613 | (((XMALLOC_OVERRUN_CHECK_SIZE + sizeof (size_t) \ | ||
| 3614 | + XMALLOC_HEADER_ALIGNMENT - 1) \ | ||
| 3615 | / XMALLOC_HEADER_ALIGNMENT * XMALLOC_HEADER_ALIGNMENT) \ | ||
| 3616 | - XMALLOC_OVERRUN_CHECK_SIZE) | ||
| 3617 | #endif | ||
| 3618 | |||
| 3571 | extern POINTER_TYPE *xmalloc (size_t); | 3619 | extern POINTER_TYPE *xmalloc (size_t); |
| 3572 | extern POINTER_TYPE *xrealloc (POINTER_TYPE *, size_t); | 3620 | extern POINTER_TYPE *xrealloc (POINTER_TYPE *, size_t); |
| 3573 | extern void xfree (POINTER_TYPE *); | 3621 | extern void xfree (POINTER_TYPE *); |