>From f80a8246bef0e3aa756282625fe69ac69dd0c177 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 19 Apr 2019 17:37:35 -0700 Subject: [PATCH 2/2] Remove --enable-checking=xmallocoverrun MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It doesn’t work anymore, and these days ‘gcc -fsanitize=address’ does a better job anyway. * configure.ac: Remove the option. * configure.ac (ac_xmalloc_overrun, XMALLOC_OVERRUN_CHECK): * src/alloc.c (XMALLOC_OVERRUN_CHECK_OVERHEAD) (XMALLOC_OVERRUN_CHECK_SIZE, XMALLOC_OVERRUN_SIZE_SIZE) (xmalloc_overrun_check_header, xmalloc_overrun_check_trailer) (xmalloc_put_size, xmalloc_get_size, overrun_check_malloc) (overrun_check_realloc, overrun_check_free): Remove. All uses removed. * etc/NEWS: Mention this. --- configure.ac | 9 +-- etc/NEWS | 7 ++- src/alloc.c | 169 +-------------------------------------------------- 3 files changed, 6 insertions(+), 179 deletions(-) diff --git a/configure.ac b/configure.ac index b7bdce66ae..32b8ce5019 100644 --- a/configure.ac +++ b/configure.ac @@ -545,7 +545,7 @@ AC_DEFUN enable only specific categories of checks. Categories are: all,yes,no. Flags are: stringbytes, stringoverrun, stringfreelist, - structs, xmallocoverrun, glyphs])], + structs, glyphs])], [ac_checking_flags="${enableval}"],[]) IFS="${IFS= }"; ac_save_IFS="$IFS"; IFS="$IFS," CHECK_STRUCTS=false @@ -559,21 +559,18 @@ AC_DEFUN ac_gc_check_stringbytes= ; ac_gc_check_string_overrun= ; ac_gc_check_string_free_list= ; - ac_xmalloc_overrun= ; ac_glyphs_debug= ;; all) ac_enable_checking=1 ; CHECK_STRUCTS=true ac_gc_check_stringbytes=1 ; ac_gc_check_string_overrun=1 ; ac_gc_check_string_free_list=1 ; - ac_xmalloc_overrun=1 ; ac_glyphs_debug=1 ;; # these enable particular checks stringbytes) ac_gc_check_stringbytes=1 ;; stringoverrun) ac_gc_check_string_overrun=1 ;; stringfreelist) ac_gc_check_string_free_list=1 ;; structs) CHECK_STRUCTS=true ;; - xmallocoverrun) ac_xmalloc_overrun=1 ;; glyphs) ac_glyphs_debug=1 ;; *) AC_MSG_ERROR(unknown check category $check) ;; esac @@ -607,10 +604,6 @@ AC_DEFUN AC_DEFINE(GC_CHECK_STRING_FREE_LIST, 1, [Define this to check the string free list.]) fi -if test x$ac_xmalloc_overrun != x ; then - AC_DEFINE(XMALLOC_OVERRUN_CHECK, 1, -[Define this to check for malloc buffer overrun.]) -fi if test x$ac_glyphs_debug != x ; then AC_DEFINE(GLYPH_DEBUG, 1, [Define this to enable glyphs debugging code.]) diff --git a/etc/NEWS b/etc/NEWS index f991dbaf97..051063171e 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -90,9 +90,10 @@ check that the portable dumper code has been updated to match the last change to one of the data structures that it relies on. +++ -** The configure option '--enable-checking=conslist' has been withdrawn. -It made Emacs irredeemably slow, and is no longer useful with modern -debugging tools. +** The configure options '--enable-checking=conslist' and +'--enable-checking=xmallocoverrun' have been withdrawn. The former +made Emacs irredeemably slow, and the latter made it crash. Neither +option was useful with modern debugging tools. --- ** Emacs now requires GTK 2.24 and GTK 3.10 for the GTK 2 and GTK 3 diff --git a/src/alloc.c b/src/alloc.c index b51c205fa9..35751faed8 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -151,9 +151,7 @@ malloc_initialize_hook (void) if (malloc_set_state (malloc_state_ptr) != 0) emacs_abort (); -# ifndef XMALLOC_OVERRUN_CHECK alloc_unexec_post (); -# endif } } @@ -681,171 +679,6 @@ verify (LISP_ALIGNMENT % GCALIGNMENT == 0); it never does anything that requires an alignment of 16. */ enum { MALLOC_IS_LISP_ALIGNED = alignof (max_align_t) % LISP_ALIGNMENT == 0 }; -#ifndef XMALLOC_OVERRUN_CHECK -#define XMALLOC_OVERRUN_CHECK_OVERHEAD 0 -#else - -/* Check for overrun in malloc'ed buffers by wrapping a header and trailer - around each block. - - The header consists of XMALLOC_OVERRUN_CHECK_SIZE fixed bytes - followed by XMALLOC_OVERRUN_SIZE_SIZE bytes containing the original - block size in little-endian order. The trailer consists of - XMALLOC_OVERRUN_CHECK_SIZE fixed bytes. - - The header is used to detect whether this block has been allocated - through these functions, as some low-level libc functions may - bypass the malloc hooks. */ - -#define XMALLOC_OVERRUN_CHECK_SIZE 16 -#define XMALLOC_OVERRUN_CHECK_OVERHEAD \ - (2 * XMALLOC_OVERRUN_CHECK_SIZE + XMALLOC_OVERRUN_SIZE_SIZE) - -/* Define XMALLOC_OVERRUN_SIZE_SIZE so that (1) it's large enough to - hold a size_t value and (2) the header size is a multiple of the - alignment that Emacs needs for C types and for USE_LSB_TAG. */ -#define XMALLOC_OVERRUN_SIZE_SIZE \ - (((XMALLOC_OVERRUN_CHECK_SIZE + sizeof (size_t) \ - + LISP_ALIGNMENT - 1) \ - / LISP_ALIGNMENT * LISP_ALIGNMENT) \ - - XMALLOC_OVERRUN_CHECK_SIZE) - -static char const xmalloc_overrun_check_header[XMALLOC_OVERRUN_CHECK_SIZE] = - { '\x9a', '\x9b', '\xae', '\xaf', - '\xbf', '\xbe', '\xce', '\xcf', - '\xea', '\xeb', '\xec', '\xed', - '\xdf', '\xde', '\x9c', '\x9d' }; - -static char const xmalloc_overrun_check_trailer[XMALLOC_OVERRUN_CHECK_SIZE] = - { '\xaa', '\xab', '\xac', '\xad', - '\xba', '\xbb', '\xbc', '\xbd', - '\xca', '\xcb', '\xcc', '\xcd', - '\xda', '\xdb', '\xdc', '\xdd' }; - -/* Insert and extract the block size in the header. */ - -static void -xmalloc_put_size (unsigned char *ptr, size_t size) -{ - int i; - for (i = 0; i < XMALLOC_OVERRUN_SIZE_SIZE; i++) - { - *--ptr = size & ((1 << CHAR_BIT) - 1); - size >>= CHAR_BIT; - } -} - -static size_t -xmalloc_get_size (unsigned char *ptr) -{ - size_t size = 0; - int i; - ptr -= XMALLOC_OVERRUN_SIZE_SIZE; - for (i = 0; i < XMALLOC_OVERRUN_SIZE_SIZE; i++) - { - size <<= CHAR_BIT; - size += *ptr++; - } - return size; -} - - -/* Like malloc, but wraps allocated block with header and trailer. */ - -static void * -overrun_check_malloc (size_t size) -{ - register unsigned char *val; - if (SIZE_MAX - XMALLOC_OVERRUN_CHECK_OVERHEAD < size) - emacs_abort (); - - val = malloc (size + XMALLOC_OVERRUN_CHECK_OVERHEAD); - if (val) - { - memcpy (val, xmalloc_overrun_check_header, XMALLOC_OVERRUN_CHECK_SIZE); - val += XMALLOC_OVERRUN_CHECK_SIZE + XMALLOC_OVERRUN_SIZE_SIZE; - xmalloc_put_size (val, size); - memcpy (val + size, xmalloc_overrun_check_trailer, - XMALLOC_OVERRUN_CHECK_SIZE); - } - return val; -} - - -/* Like realloc, but checks old block for overrun, and wraps new block - with header and trailer. */ - -static void * -overrun_check_realloc (void *block, size_t size) -{ - register unsigned char *val = (unsigned char *) block; - if (SIZE_MAX - XMALLOC_OVERRUN_CHECK_OVERHEAD < size) - emacs_abort (); - - if (val - && memcmp (xmalloc_overrun_check_header, - val - XMALLOC_OVERRUN_CHECK_SIZE - XMALLOC_OVERRUN_SIZE_SIZE, - XMALLOC_OVERRUN_CHECK_SIZE) == 0) - { - size_t osize = xmalloc_get_size (val); - if (memcmp (xmalloc_overrun_check_trailer, val + osize, - XMALLOC_OVERRUN_CHECK_SIZE)) - emacs_abort (); - memset (val + osize, 0, XMALLOC_OVERRUN_CHECK_SIZE); - val -= XMALLOC_OVERRUN_CHECK_SIZE + XMALLOC_OVERRUN_SIZE_SIZE; - memset (val, 0, XMALLOC_OVERRUN_CHECK_SIZE + XMALLOC_OVERRUN_SIZE_SIZE); - } - - val = realloc (val, size + XMALLOC_OVERRUN_CHECK_OVERHEAD); - - if (val) - { - memcpy (val, xmalloc_overrun_check_header, XMALLOC_OVERRUN_CHECK_SIZE); - val += XMALLOC_OVERRUN_CHECK_SIZE + XMALLOC_OVERRUN_SIZE_SIZE; - xmalloc_put_size (val, size); - memcpy (val + size, xmalloc_overrun_check_trailer, - XMALLOC_OVERRUN_CHECK_SIZE); - } - return val; -} - -/* Like free, but checks block for overrun. */ - -static void -overrun_check_free (void *block) -{ - unsigned char *val = (unsigned char *) block; - - if (val - && memcmp (xmalloc_overrun_check_header, - val - XMALLOC_OVERRUN_CHECK_SIZE - XMALLOC_OVERRUN_SIZE_SIZE, - XMALLOC_OVERRUN_CHECK_SIZE) == 0) - { - size_t osize = xmalloc_get_size (val); - if (memcmp (xmalloc_overrun_check_trailer, val + osize, - XMALLOC_OVERRUN_CHECK_SIZE)) - emacs_abort (); -#ifdef XMALLOC_CLEAR_FREE_MEMORY - val -= XMALLOC_OVERRUN_CHECK_SIZE + XMALLOC_OVERRUN_SIZE_SIZE; - memset (val, 0xff, osize + XMALLOC_OVERRUN_CHECK_OVERHEAD); -#else - memset (val + osize, 0, XMALLOC_OVERRUN_CHECK_SIZE); - val -= XMALLOC_OVERRUN_CHECK_SIZE + XMALLOC_OVERRUN_SIZE_SIZE; - memset (val, 0, XMALLOC_OVERRUN_CHECK_SIZE + XMALLOC_OVERRUN_SIZE_SIZE); -#endif - } - - free (val); -} - -#undef malloc -#undef realloc -#undef free -#define malloc overrun_check_malloc -#define realloc overrun_check_realloc -#define free overrun_check_free -#endif - /* If compiled with XMALLOC_BLOCK_INPUT_CHECK, define a symbol BLOCK_INPUT_IN_MEMORY_ALLOCATORS that is visible to the debugger. If that variable is set, block input while in one of Emacs's memory @@ -1820,7 +1653,7 @@ static char const string_overrun_cookie[GC_STRING_OVERRUN_COOKIE_SIZE] = calculating a value to be passed to malloc. */ static ptrdiff_t const STRING_BYTES_MAX = min (STRING_BYTES_BOUND, - ((SIZE_MAX - XMALLOC_OVERRUN_CHECK_OVERHEAD + ((SIZE_MAX - GC_STRING_EXTRA - offsetof (struct sblock, data) - SDATA_DATA_OFFSET) -- 2.20.1