]> git.ipfire.org Git - thirdparty/valgrind.git/commit
Make memalign behave more like the underlying platform memalign
authorPaul Floyd <pjfloyd@wanadoo.fr>
Tue, 28 Feb 2023 12:17:24 +0000 (13:17 +0100)
committerPaul Floyd <pjfloyd@wanadoo.fr>
Tue, 28 Feb 2023 12:46:08 +0000 (13:46 +0100)
commite862c6f3d2374beebf78b52dfc8303ff33707001
treed3032728c93993bb5bf244cfe644a7abc5358dae
parent5cf51ca2f658a945f28853fd948a8f2f12fb8ffb
Make memalign behave more like the underlying platform memalign

This is the first part of
Bug 466104 aligned_alloc problems, part 1

The bulk of this change is try try to get memalign to be more
platform aware. Previously the Valgrind implementation only
reflected the glibc implementation. That meant non-power of
two alignment values would silently get bumped up to the
next largest power of two. Most other platforms return NULL
and set errno to EINVAL.

There are a few other changes. A couple of the other aligned alloc
functions like valloc were caling the Valgrind memalign. This meant
that there weould be an extra Valgrind memalign in any error
callstacks. Now these functions call the allocator directly.

The memcheck memalign2 testcase has been redone. The memalign
parts moved out to per-platform versions and the tescase
itdelf renamed to posix_memalign, since that is all that is left.
I also modified the testcase so that it checks that the
memalign calls check for non-NULL returns, and on platforms
that set errno that it is correctly set. Previously the
test only worked on non-glibc because NULL & alignment is
zero.  The platform versions have been tested on glibc,
MUSL, FreeBSD and OpenIndiana and should hopefully run OK
both under memcheck and standalone.

There is stil quite a lot that is NOT done

1. I'm not certain that implementations allocate more memory
   and/or use a wider alignment. It doesn't help that almost
   universally the memalign implementations are badly
   documented, undocumented or buggy.
2. We don't handle very large alignment requests well.
   Most implementations will fail and set EINVAL if the
   alignment is over half the memory space. Valgrind will
   core panic if an aligmnt of over 16Mbytes is requested.
3. We don't generate any memcheck errors for invalid values
   of alignment. That's planned in Part 2.
4. The code is static and fixed at compile time. That means that
   if you are using MUSL with a glibc-built Valgrind you
   will still get glibc memalign behaviour.
   I'll wait to see if there are any requests before trying
   to make the behaviour selectable at runtime.
34 files changed:
.gitignore
coregrind/m_mallocfree.c
coregrind/m_replacemalloc/vg_replace_malloc.c
memcheck/tests/Makefile.am
memcheck/tests/amd64/sh-mem-vec256-plo-no.stderr.exp
memcheck/tests/amd64/sh-mem-vec256-plo-yes.stderr.exp
memcheck/tests/common/sh-mem-vec128-plo-no.stderr.exp-32bit-le
memcheck/tests/common/sh-mem-vec128-plo-no.stderr.exp-64bit-le
memcheck/tests/common/sh-mem-vec128-plo-yes.stderr.exp-32bit-le
memcheck/tests/common/sh-mem-vec128-plo-yes.stderr.exp-64bit-le
memcheck/tests/freebsd/Makefile.am
memcheck/tests/freebsd/errno_aligned_allocs.c
memcheck/tests/freebsd/memalign.c [new file with mode: 0644]
memcheck/tests/freebsd/memalign.stderr.exp [moved from memcheck/tests/memalign2.stderr.exp with 100% similarity]
memcheck/tests/freebsd/memalign.vgtest [moved from memcheck/tests/memalign2.vgtest with 78% similarity]
memcheck/tests/linux/Makefile.am
memcheck/tests/linux/memalign.c [new file with mode: 0644]
memcheck/tests/linux/memalign.stderr.exp [new file with mode: 0644]
memcheck/tests/linux/memalign.vgtest [new file with mode: 0644]
memcheck/tests/memalign2.c [deleted file]
memcheck/tests/memalign_args.c [new file with mode: 0644]
memcheck/tests/memalign_args.stderr.exp [new file with mode: 0644]
memcheck/tests/memalign_args.stderr.exp-glibc [new file with mode: 0644]
memcheck/tests/memalign_args.vgtest [new file with mode: 0644]
memcheck/tests/memalign_test.stderr.exp
memcheck/tests/memalign_test.stderr.exp-freebsd-clang
memcheck/tests/posix_memalign.c [new file with mode: 0644]
memcheck/tests/posix_memalign.stderr.exp [new file with mode: 0644]
memcheck/tests/posix_memalign.vgtest [new file with mode: 0644]
memcheck/tests/solaris/Makefile.am
memcheck/tests/solaris/memalign.c [new file with mode: 0644]
memcheck/tests/solaris/memalign.stderr.exp [new file with mode: 0644]
memcheck/tests/solaris/memalign.vgtest [new file with mode: 0644]
memcheck/tests/test-plo-no.stderr.exp-le64-freebsd