about summary refs log tree commit diff
path: root/malloc/hooks.c
Commit message (Collapse)AuthorAgeFilesLines
* Update copyright dates with scripts/update-copyrights.Joseph Myers2019-01-011-1/+1
| | | | | | | * All files with FSF copyright notices: Update copyright dates using scripts/update-copyrights. * locale/programs/charmap-kw.h: Regenerated. * locale/programs/locfile-kw.h: Likewise.
* malloc: Update heap dumping/undumping comments [BZ #23351]Florian Weimer2018-06-291-36/+6
| | | | | | Also remove a few now-unused declarations and definitions. Reviewed-by: Carlos O'Donell <carlos@redhat.com>
* Update copyright dates with scripts/update-copyrights.Joseph Myers2018-01-011-1/+1
| | | | | | | * All files with FSF copyright notices: Update copyright dates using scripts/update-copyrights. * locale/programs/charmap-kw.h: Regenerated. * locale/programs/locfile-kw.h: Likewise.
* Silence -O3 -Wall warning in malloc/hooks.c with GCC 7 [BZ #22052]H.J. Lu2017-10-151-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | realloc_check has unsigned char *magic_p; ... __libc_lock_lock (main_arena.mutex); const mchunkptr oldp = mem2chunk_check (oldmem, &magic_p); __libc_lock_unlock (main_arena.mutex); if (!oldp) malloc_printerr ("realloc(): invalid pointer"); ... if (newmem == NULL) *magic_p ^= 0xFF; with static void malloc_printerr(const char *str) __attribute__ ((noreturn)); GCC 7 -O3 warns hooks.c: In function ‘realloc_check’: hooks.c:352:14: error: ‘magic_p’ may be used uninitialized in this function [-Werror=maybe-uninitialized] *magic_p ^= 0xFF; due to the GCC bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82090 This patch silences GCC 7 by using DIAG_IGNORE_NEEDS_COMMENT. [BZ #22052] * malloc/hooks.c (realloc_check): Use DIAG_IGNORE_NEEDS_COMMENT to silence -O3 -Wall warning with GCC 7.
* malloc: Remove the internal_function attributeFlorian Weimer2017-08-311-2/+0
|
* malloc: Change top_check return type to voidFlorian Weimer2017-08-311-14/+12
| | | | | | After commit ec2c1fcefb200c6cb7e09553f3c6af8815013d83, (malloc: Abort on heap corruption, without a backtrace), the function always returns 0.
* malloc: Remove check_action variable [BZ #21754]Florian Weimer2017-08-301-50/+5
| | | | | | | | | | | Clean up calls to malloc_printerr and trim its argument list. This also removes a few bits of work done before calling malloc_printerr (such as unlocking operations). The tunable/environment variable still enables the lightweight additional malloc checking, but mallopt (M_CHECK_ACTION) no longer has any effect.
* Update copyright dates with scripts/update-copyrights.Joseph Myers2017-01-011-1/+1
|
* malloc: Use accessors for chunk metadata accessFlorian Weimer2016-10-281-4/+4
| | | | | This change allows us to change the encoding of these struct members in a centralized fashion.
* malloc: Remove malloc_get_state, malloc_set_state [BZ #19473]Florian Weimer2016-10-261-49/+14
| | | | | | | | | | | | After the removal of __malloc_initialize_hook, newly compiled Emacs binaries are no longer able to use these interfaces. malloc_get_state is only used during the Emacs build process, so we provide a stub implementation only. Existing Emacs binaries will not call this stub function, but still reference the symbol. The rewritten tst-mallocstate test constructs a dumped heap which should approximates what existing Emacs binaries pass to glibc malloc.
* malloc: Automated part of conversion to __libc_lockFlorian Weimer2016-09-061-14/+14
|
* malloc: Correct malloc alignment on 32-bit architectures [BZ #6527]Florian Weimer2016-05-241-1/+1
| | | | | | | | | | | | | | | | After the heap rewriting added in commit 4cf6c72fd2a482e7499c29162349810029632c3f (malloc: Rewrite dumped heap for compatibility in __malloc_set_state), we can change malloc alignment for new allocations because the alignment of old allocations no longer matters. We need to increase the malloc state version number, so that binaries containing dumped heaps of the new layout will not try to run on previous versions of glibc, resulting in obscure crashes. This commit addresses a failure of tst-malloc-thread-fail on the affected architectures (32-bit ppc and mips) because the test checks pointer alignment.
* malloc: Rewrite dumped heap for compatibility in __malloc_set_stateFlorian Weimer2016-05-131-100/+50
| | | | | | | | | | | | | | | | | This will allow us to change many aspects of the malloc implementation while preserving compatibility with existing Emacs binaries. As a result, existing Emacs binaries will have a larger RSS, and Emacs needs a few more milliseconds to start. This overhead is specific to Emacs (and will go away once Emacs switches to its internal malloc). The new checks to make free and realloc compatible with the dumped heap are confined to the mmap paths, which are already quite slow due to the munmap overhead. This commit weakens some security checks, but only for heap pointers in the dumped main arena. By default, this area is empty, so those checks are as effective as before.
* malloc: Remove max_total_mem member form struct malloc_parFlorian Weimer2016-02-191-1/+1
| | | | | Also note that sumblks in struct mallinfo is always 0. No functional change.
* Update copyright dates with scripts/update-copyrights.Joseph Myers2016-01-041-1/+1
|
* Fix for test "malloc_usable_size: expected 7 but got 11"James Lemke2015-05-191-24/+38
| | | | | | [BZ #17581] The checking chain of unused chunks was terminated by a hash of the block pointer, which was sometimes confused with the chunk length byte. We now avoid using a length byte equal to the magic byte.
* Avoid deadlock in malloc on backtrace (BZ #16159)Siddhesh Poyarekar2015-05-191-4/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When the malloc subsystem detects some kind of memory corruption, depending on the configuration it prints the error, a backtrace, a memory map and then aborts the process. In this process, the backtrace() call may result in a call to malloc, resulting in various kinds of problematic behavior. In one case, the malloc it calls may detect a corruption and call backtrace again, and a stack overflow may result due to the infinite recursion. In another case, the malloc it calls may deadlock on an arena lock with the malloc (or free, realloc, etc.) that detected the corruption. In yet another case, if the program is linked with pthreads, backtrace may do a pthread_once initialization, which deadlocks on itself. In all these cases, the program exit is not as intended. This is avoidable by marking the arena that malloc detected a corruption on, as unusable. The following patch does that. Features of this patch are as follows: - A flag is added to the mstate struct of the arena to indicate if the arena is corrupt. - The flag is checked whenever malloc functions try to get a lock on an arena. If the arena is unusable, a NULL is returned, causing the malloc to use mmap or try the next arena. - malloc_printerr sets the corrupt flag on the arena when it detects a corruption - free does not concern itself with the flag at all. It is not important since the backtrace workflow does not need free. A free in a parallel thread may cause another corruption, but that's not new - The flag check and set are not atomic and may race. This is fine since we don't care about contention during the flag check. We want to make sure that the malloc call in the backtrace does not trip on itself and all that action happens in the same thread and not across threads. I verified that the test case does not show any regressions due to this patch. I also ran the malloc benchmarks and found an insignificant difference in timings (< 2%). * malloc/Makefile (tests): New test case tst-malloc-backtrace. * malloc/arena.c (arena_lock): Check if arena is corrupt. (reused_arena): Find a non-corrupt arena. (heap_trim): Pass arena to unlink. * malloc/hooks.c (malloc_check_get_size): Pass arena to malloc_printerr. (top_check): Likewise. (free_check): Likewise. (realloc_check): Likewise. * malloc/malloc.c (malloc_printerr): Add arena argument. (unlink): Likewise. (munmap_chunk): Adjust. (ARENA_CORRUPTION_BIT): New macro. (arena_is_corrupt): Likewise. (set_arena_corrupt): Likewise. (sysmalloc): Use mmap if there are no usable arenas. (_int_malloc): Likewise. (__libc_malloc): Don't fail if arena_get returns NULL. (_mid_memalign): Likewise. (__libc_calloc): Likewise. (__libc_realloc): Adjust for additional argument to malloc_printerr. (_int_free): Likewise. (malloc_consolidate): Likewise. (_int_realloc): Likewise. (_int_memalign): Don't touch corrupt arenas. * malloc/tst-malloc-backtrace.c: New test case.
* Update copyright dates with scripts/update-copyrights.Joseph Myers2015-01-021-1/+1
|
* Fix for test "malloc_usable_size: expected 7 but got 11"James Lemke2014-12-111-44/+35
| | | | [BZ #17581] Revert this fix while investigating a problem.
* Fix for test "malloc_usable_size: expected 7 but got 11"James Lemke2014-12-011-35/+44
| | | | | | [BZ #17581] The checking chain of unused chunks was terminated by a hash of the block pointer, which was sometimes confused with the chunk length byte. The chain is now terminated by a NULL byte.
* Reformat malloc to gnu style.Ondřej Bílka2014-01-021-294/+354
|
* Update copyright notices with scripts/update-copyrightsAllan McRae2014-01-011-1/+1
|
* Expand MALLOC_COPY and MALLOC_ZERO to memcpy and memset.Ondřej Bílka2013-12-101-1/+1
|
* Drop PER_THREAD conditionals from malloc.Ondřej Bílka2013-12-101-4/+0
|
* Replace malloc force_reg by atomic_forced_read.Ondřej Bílka2013-12-091-1/+1
|
* Consolidate valloc/pvalloc code.Ondřej Bílka2013-11-201-0/+7
| | | | | To make malloc code more maintainable we make malloc and pvalloc share logic with memalign.
* malloc: Fix for infinite loop in memalign/posix_memalign.Will Newton2013-10-301-0/+8
| | | | | | | | | | | | | | | | | | | A very large alignment argument passed to mealign/posix_memalign causes _int_memalign to enter an infinite loop. Limit the maximum alignment value to the maximum representable power of two to prevent this from happening. Changelog: 2013-10-30 Will Newton <will.newton@linaro.org> [BZ #16038] * malloc/hooks.c (memalign_check): Limit alignment to the maximum representable power of two. * malloc/malloc.c (__libc_memalign): Likewise. * malloc/tst-memalign.c (do_test): Add test for very large alignment values. * malloc/tst-posix_memalign.c (do_test): Likewise.
* malloc/hooks.c: Correct check for overflow in memalign_check.Will Newton2013-10-101-4/+7
| | | | | | | | | | | | | A large value of bytes passed to memalign_check can cause an integer overflow in _int_memalign and heap corruption. This issue can be exposed by running tst-memalign with MALLOC_CHECK_=3. ChangeLog: 2013-10-10 Will Newton <will.newton@linaro.org> * malloc/hooks.c (memalign_check): Ensure the value of bytes passed to _int_memalign does not overflow.
* Use (void) in no-arguments function definitions.Joseph Myers2013-06-081-1/+1
|
* Remove __malloc_ptr_t.Joseph Myers2013-03-081-3/+3
|
* Update copyright notices with scripts/update-copyrights.Joseph Myers2013-01-021-1/+1
|
* Return requested size for malloc_usable_size when MALLOC_CHECK_ > 0Siddhesh Poyarekar2012-09-051-1/+30
| | | | | | | | | | | [BZ #1349] malloc_usable_size returns the usable size in an allocated chunk, which may be >= the requested size. In the case of MALLOC_CHECK_ being exported to > 0 however, only the requested size is usable, since a magic value is written at the end of the request size to trap writes beyond request bounds. Hence, when MALLOC_CHECK_ is exported to > 0, malloc_usable_size() should return the request size.
* Replace FSF snail mail address with URLs.Paul Eggert2012-02-091-3/+2
|
* Cleanups of mallocUlrich Drepper2012-01-311-6/+6
| | | | Remove ugly names and unnecessary wrappers.
* Minor cleanups of malloc codeUlrich Drepper2012-01-161-3/+3
|
* Remove MALLOC_FAILURE_ACTION use in mallocUlrich Drepper2011-09-101-4/+4
|
* Simplify malloc initializationUlrich Drepper2011-09-101-2/+2
| | | | | | Singificantly reduce the code needed at malloc initialization. In the process getpagesize is simplified by always initializing GLRO(dl_pagesize).
* Simplify malloc codeUlrich Drepper2011-09-101-169/+21
| | | | Remove all kinds of unused configuration options and dead code.
* Remove support for !USE___THREADUlrich Drepper2011-09-101-1/+1
|
* (memalign_check): No need to use checked_request2size.Ulrich Drepper2011-07-081-3/+1
|
* Restore locking in free_check.Ulrich Drepper2009-11-011-17/+20
| | | | | | This code is only used when MALLOC_CHECK_ is used. Then some bogus crashes and/or assert could result from the locking changes. The code ain't fast.
* (top_check): Force hook value into register.Ulrich Drepper2009-04-171-1/+1
|
* [BZ #9957]Ulrich Drepper2009-04-161-6/+7
| | | | | | | | | | | | | | | | | | | | | | | | 2009-04-16 Ulrich Drepper <drepper@redhat.com> [BZ #9957] * malloc/malloc.c (force_reg): Define. (sYSMALLOc): Load hook variable into variable before test and force into register. (sYSTRIm): Likewise. (public_mALLOc): Force hook value into register. (public_fREe): Likewise. (public_rEALLOc): Likewise. (public_mEMALIGn): Likewise. (public_vALLOc): Likewise. (public_pVALLOc): Likewise. (public_cALLOc): Likewise. (__posix_memalign): Likewise. * malloc/arena.c (ptmalloc_init): Load hook variable into variable before test and force into register. * malloc/hooks.c (top_check): Likewise. (public_s_ET_STATe): Pretty printing. * resolv/res_send.c (send_dg): Don't just ignore the result we got in case we only receive one reply in single-request mode.
* * malloc/malloc.c (_int_realloc): Add parameter with old blockUlrich Drepper2009-04-081-3/+23
| | | | | | size. Remove duplicated test. Don't handle mmap'ed blocks here. Adjust all callers. * malloc/hooks.c (realloc_check): Adjust _int_realloc call.
* * config.h.in (USE_MULTIARCH): Define.Ulrich Drepper2009-03-131-5/+10
| | | | | | | | | | | | | | | | | | | | | | | | * configure.in: Handle --enable-multi-arch. * elf/dl-runtime.c (_dl_fixup): Handle STT_GNU_IFUNC. (_dl_fixup_profile): Likewise. * elf/do-lookup.c (dl_lookup_x): Likewise. * sysdeps/x86_64/dl-machine.h: Handle STT_GNU_IFUNC. * elf/elf.h (STT_GNU_IFUNC): Define. * include/libc-symbols.h (libc_ifunc): Define. * sysdeps/x86_64/cacheinfo.c: If USE_MULTIARCH is defined, use the framework in init-arch.h to get CPUID values. * sysdeps/x86_64/multiarch/Makefile: New file. * sysdeps/x86_64/multiarch/init-arch.c: New file. * sysdeps/x86_64/multiarch/init-arch.h: New file. * sysdeps/x86_64/multiarch/sched_cpucount.c: New file. * config.make.in (experimental-malloc): Define. * configure.in: Handle --enable-experimental-malloc. * malloc/Makefile: Handle experimental-malloc flag. * malloc/malloc.c: Implement PER_THREAD and ATOMIC_FASTBINS features. * malloc/arena.c: Likewise. * malloc/hooks.c: Likewise. * malloc/malloc.h: Define M_ARENA_TEST and M_ARENA_MAX.
* (_int_realloc): Likewise. Third argument is now padded sizeUlrich Drepper2009-02-071-2/+5
|
* * malloc/malloc.c (_int_free): Second argument is now mchunkptr.Ulrich Drepper2009-02-071-8/+7
| | | | | | | | | | Change all callers. (_int_realloc): Likewise. All _int_* functions are now static. * malloc/hooks.c: Change all callers to _int_free and _int_realloc. * malloc/arena.c: Likewise. * include/malloc.h: Remove now unnecessary declarations of the _int_* functions.
* (__malloc_check_init): Remove printf.Ulrich Drepper2008-07-151-3/+1
|
* * malloc/hooks.c (MALLOC_STATE_VERSION): Bump.Ulrich Drepper2007-05-211-12/+15
| | | | | | | | | | | | | | | | (public_sET_STATe): If ms->version < 3, put all chunks into unsorted chunks and clear {fd,bk}_nextsize fields of largebin chunks. * malloc/malloc.c [MALLOC_DEBUG]: Revert 2007-05-13 changes. * malloc/hooks.c: Likewise. * malloc/arena.c: Likewise. * malloc/malloc.c (do_check_malloc_state): Don't assert n_mmaps is not greater than n_mmaps_max. This removes the need for the previous change. * malloc/Makefile (CFLAGS-malloc.c): Revert accidental 2007-05-07 commit.
* [MALLOC_DEBUG]: Keep track of current maximum number of mmaps. n_mmaps_max ↵Ulrich Drepper2007-05-131-1/+10
| | | | is the target.