summaryrefslogtreecommitdiff
path: root/malloc/malloc-check.c
AgeCommit message (Collapse)Author
2026-03-12malloc: Remove lingering DIAG_POP_NEEDS_COMMENTAdhemerval Zanella
From 0ea9ebe48ad624919d579dbe651293975fb6a699.
2026-03-11malloc: Cleanup warningsWilco Dijkstra
Cleanup warnings - malloc builds with -Os and -Og without needing any complex warning avoidance defines. Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2026-01-01Update copyright dates with scripts/update-copyrightsPaul Eggert
2025-10-21Suppress -Wmaybe-uninitialized only for gccAdhemerval Zanella
The warning is not supported by clang. Reviewed-by: Sam James <sam@gentoo.org>
2025-10-03malloc: Cleanup macros, asserts and sysmalloc_mmap_fallbackWilliam Hunt
Refactor malloc.c to remove dead code, create macros to abstract duplicated code, and cleanup sysmalloc_mmap_fallback to remove logic not related to the mmap call. Change the return type of mmap_base to uintptr_t since this allows using operations on the return value, and avoids casting in both calls in mremap_chunk and munmap_chunk. Cleanup sysmalloc_mmap_fallback. Remove unused parameters nb, oldsize and av. Remove redundant overflow check and instead use size_t for all parameters except extra_flags to prevent overflows. Move logic not concerned with the mmap call itself outside the function after both calls to sysmalloc_mmap_fallback are made; this means move code for naming the VMA and marking the arena being extended as non-contiguous to the calling code to be handled in the case that the mmap is successful. Calculate the fallback size from nb to avoid modifying size after it has been set for MORECORE. Remove unused noncontiguous macro. Remove redundant assert for checking unreachable option for global_max_fast. Reviewed-by: Wilco Dijkstra  <Wilco.Dijkstra@arm.com>
2025-08-27malloc: Change mmap chunk layoutWilco Dijkstra
Change the mmap chunk layout to be identical to a normal chunk. This makes it safe for tcache to hold mmap chunks and simplifies size calculations in memsize and musable. Add mmap_base() and mmap_size() macros to simplify code. Reviewed-by: Cupertino Miranda <cupertino.miranda@oracle.com>
2025-08-04Revert "Change mmap representation"Wilco Dijkstra
This reverts commit 4b74591022e88639dcaefb8c4a2e405d301a59e2.
2025-08-04Change mmap representationWilco Dijkstra
2025-08-02malloc: Improve checked_request2sizeWilco Dijkstra
Change checked_request2size to return SIZE_MAX for huge inputs. This ensures large allocation requests stay large and can't be confused with a small allocation. As a result several existing checks against PTRDIFF_MAX become redundant. Reviewed-by: DJ Delorie <dj@redhat.com>
2025-06-26malloc: refactored aligned_OK and misaligned_chunkWilliam Hunt
Renamed aligned_OK to misaligned_mem as to be similar to misaligned_chunk, and reversed any assertions using the macro. Made misaligned_chunk call misaligned_mem after chunk2mem rather than bitmasking with the malloc alignment itself, since misaligned_chunk is meant to test the data chunk itself rather than the header, and the compiler will optimise the addition so the ternary operator is not needed. Reviewed-by: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
2025-05-12malloc: Improve malloc initializationWilco Dijkstra
Move malloc initialization to __libc_early_init. Use a hidden __ptmalloc_init for initialization and a weak call to avoid pulling in the system malloc in a static binary. All previous initialization checks can now be removed. Reviewed-by: Florian Weimer <fweimer@redhat.com>
2025-04-14malloc: Inline _int_freeWilco Dijkstra
Inline _int_free since it is a small function and only really used by __libc_free. Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-01-01Update copyright dates with scripts/update-copyrightsPaul Eggert
2024-11-25Silence most -Wzero-as-null-pointer-constant diagnosticsAlejandro Colomar
Replace 0 by NULL and {0} by {}. Omit a few cases that aren't so trivial to fix. Link: <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117059> Link: <https://software.codidact.com/posts/292718/292759#answer-292759> Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-01Update copyright dates with scripts/update-copyrightsPaul Eggert
2023-03-29Remove --enable-tunables configure optionAdhemerval Zanella Netto
And make always supported. The configure option was added on glibc 2.25 and some features require it (such as hwcap mask, huge pages support, and lock elisition tuning). It also simplifies the build permutations. Changes from v1: * Remove glibc.rtld.dynamic_sort changes, it is orthogonal and needs more discussion. * Cleanup more code. Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
2023-01-06Update copyright dates with scripts/update-copyrightsJoseph Myers
2022-07-05malloc: Simplify checked_request2size interfaceFlorian Weimer
In-band signaling avoids an uninitialized variable warning when building with -Og and GCC 12. Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
2022-01-01Update copyright dates with scripts/update-copyrightsPaul Eggert
I used these shell commands: ../glibc/scripts/update-copyrights $PWD/../gnulib/build-aux/update-copyright (cd ../glibc && git commit -am"[this commit message]") and then ignored the output, which consisted lines saying "FOO: warning: copyright statement not found" for each of 7061 files FOO. I then removed trailing white space from math/tgmath.h, support/tst-support-open-dev-null-range.c, and sysdeps/x86_64/multiarch/strlen-vec.S, to work around the following obscure pre-commit check failure diagnostics from Savannah. I don't know why I run into these diagnostics whereas others evidently do not. remote: *** 912-#endif remote: *** 913: remote: *** 914- remote: *** error: lines with trailing whitespace found ... remote: *** error: sysdeps/unix/sysv/linux/statx_cp.c: trailing lines
2021-09-03Remove "Contributed by" linesSiddhesh Poyarekar
We stopped adding "Contributed by" or similar lines in sources in 2012 in favour of git logs and keeping the Contributors section of the glibc manual up to date. Removing these lines makes the license header a bit more consistent across files and also removes the possibility of error in attribution when license blocks or files are copied across since the contributed-by lines don't actually reflect reality in those cases. Move all "Contributed by" and similar lines (Written by, Test by, etc.) into a new file CONTRIBUTED-BY to retain record of these contributions. These contributors are also mentioned in manual/contrib.texi, so we just maintain this additional record as a courtesy to the earlier developers. The following scripts were used to filter a list of files to edit in place and to clean up the CONTRIBUTED-BY file respectively. These were not added to the glibc sources because they're not expected to be of any use in future given that this is a one time task: https://gist.github.com/siddhesh/b5ecac94eabfd72ed2916d6d8157e7dc https://gist.github.com/siddhesh/15ea1f5e435ace9774f485030695ee02 Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2021-07-23Fix build and tests with --disable-tunablesSiddhesh Poyarekar
Remove unused code and declare __libc_mallopt when !IS_IN (libc) to allow the debug hook to build with --disable-tunables. Also, run tst-ifunc-isa-2* tests only when tunables are enabled since the result depends on it. Tested on x86_64. Reported-by: Matheus Castanho <msc@linux.ibm.com> Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2021-07-22glibc.malloc.check: Wean away from malloc hooksSiddhesh Poyarekar
The malloc-check debugging feature is tightly integrated into glibc malloc, so thanks to an idea from Florian Weimer, much of the malloc implementation has been moved into libc_malloc_debug.so to support malloc-check. Due to this, glibc malloc and malloc-check can no longer work together; they use altogether different (but identical) structures for heap management. This should not make a difference though since the malloc check hook is not disabled anywhere. malloc_set_state does, but it does so early enough that it shouldn't cause any problems. The malloc check tunable is now in the debug DSO and has no effect when the DSO is not preloaded. Reviewed-by: Carlos O'Donell <carlos@redhat.com> Tested-by: Carlos O'Donell <carlos@redhat.com>
2021-07-03Move glibc.malloc.check implementation into its own fileSiddhesh Poyarekar
Separate the malloc check implementation from the malloc hooks. They still use the hooks but are now maintained in a separate file. Reviewed-by: Carlos O'Donell <carlos@redhat.com>