5860 Commits

Author SHA1 Message Date
Paul Floyd
28e4efb2b1 Mised one aligned alloc wrapper on Linux
Need different expected for GCC / libstdc++

And I think that the 32bit expected will also need updating.
2023-03-10 08:40:40 +01:00
Paul Floyd
f6ee38b419 Malloc replacements: add some C++14/17 comments
Rearrange the code to group C++ 14 operator deeltes together.
2023-03-09 20:58:12 +01:00
Paul Floyd
d4affb0ab7 Make operator new aligned more like the standalone versions
If the alignment is not a power of two return nullptr for the
nothrow overload and bomb for the throwing overload.
2023-03-08 23:10:22 +01:00
Paul Floyd
18ca012c08 Fix compile failure on Linux
Use SizeT rather than size_t
Also make tests quieter with -q
2023-03-07 23:19:04 +01:00
Paul Floyd
114c528dab Add 32bit version of sized_aligned_new_delete_args expected
Asl add some parens to shut up clangd
2023-03-07 22:58:57 +01:00
Paul Floyd
ceee3e8922 Add checks to all new / delete overload arguments 2023-03-07 22:47:19 +01:00
Paul Floyd
e8d4d64e46 Bug 466104 - aligned_alloc problems, part 1
I think that these are all now done.
This commit refactors memalign and updates manual-core.xml
to say some behaviour of Valgrind depends on the build time
OS and libraries.
2023-03-06 21:50:01 +01:00
Paul Floyd
43880cb199 Linux musl: fix code refactor that missed one usage 2023-03-05 17:41:27 +01:00
Paul Floyd
0fecf3914d Darwin regtest: remove test that aligned_alloc fails with huge alignment
Needs more debugging.
2023-03-05 17:20:23 +01:00
Paul Floyd
15fdfa8464 Fix a compiler warning 2023-03-05 16:34:50 +01:00
Paul Floyd
dc8af61b5a Linux musl: alligned_alloc accepts alignment of zero 2023-03-05 16:30:44 +01:00
Paul Floyd
4ca2fa7b1f Solaris: bump alignment to next power of two for aligned_alloc
I'm not changing the Valgrind allocator to fit Solaris, too bad.
2023-03-05 16:13:09 +01:00
Paul Floyd
bf8d5b9a52 Solaris: copy paste error in alignment check for aligned_alloc 2023-03-05 16:01:23 +01:00
Paul Floyd
b723d03bb3 Solaris: adapt to aligned_alloc only enforcing a multiple of 4 2023-03-05 15:42:39 +01:00
Paul Floyd
fd20bb9c67 Make aligned_alloc behave more like the underlying platform aligned_alloc
This is the third part of
Bug 466104 aligned_alloc problems, part 1

Shouldn't affect Linux glibc.
2023-03-05 15:25:51 +01:00
Paul Floyd
cb7adf4a9e Bug 449309 - Missing loopback device ioctl(s)
Patch provided by:
    Faheem Sheikh <faheem.sheikh@bmw.de>

Note that the testcase provided with this report hasn't
been added as it requires privileges.
2023-03-05 08:42:42 +01:00
Paul Floyd
9fa27e001e Typo in comment 2023-02-28 23:27:22 +01:00
Paul Floyd
40c196b0ca Fix Darwin compilation
Removed memalign wrapper on Darwin, so valloc can't use it any more.
2023-02-28 22:58:14 +01:00
Paul Floyd
94a41e050c Bug 445743 - "The impossible happened: mutex is locked simultaneously by two threads" while using mutexes with priority inheritance and signals
Been using the same fix in FreeBSD for quite a while, so I think
it's safe to apply to Linux and close the bugzi item.
2023-02-28 22:17:25 +01:00
Paul Floyd
33ce1bf1cb Change behaviour of posix_memalign for Solaris
It returns NULL and 0 status whilst most other platforms
allocatae some undefined amount of memory (which is allowed
by posix).

Update the posix_memalign test as well.

Finally remove some clang warnings about alignment.
2023-02-28 21:21:05 +01:00
Paul Floyd
19dc72931b Put back Darwin zone memalign
I had another look at the XNU source and this does seem to exist.
The manpage says that it is the zone version of posix_memalign,
though that's probably more because Darwin has no memalign.
2023-02-28 19:56:52 +01:00
Paul Floyd
e862c6f3d2 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.
2023-02-28 13:46:08 +01:00
Paul Floyd
f6f7cae623 FreeBSD mknodat syscall dev arg is 64bits so the syscall needs splitting into amd64 and x86 versions 2023-02-25 16:09:41 +01:00
Paul Floyd
b861458d3d FreeBSD: make rfork() fail more gracefully
rfork() is barely used in base FreeBSD. The main use
is in posix_spawn(). If rfork() fails with EINVAL
then it falls back to using vfork(). This is preferable
to Valgrind bombing.

ksh93 uses posix_spawn. I tested bash and csh and they had
no problems.

Also add 'hello world" smoke tests for bash csh and ksh
2023-02-25 15:16:35 +01:00
Paul Floyd
e61a04babc bug465435 - m_libcfile.c:66 (vgPlain_safe_fd): Assertion 'newfd >= VG_(fd_hard_limit)' failed. 2023-02-24 21:32:08 +01:00
Paul Floyd
6e4eb0b674 Darwin: try to fix assert in DRD
The hard coded memory mapping trigger drd_start_using_mem_w_perms
which will lead to tl_assert(vg_tid != VG_INVALID_THREADID);

But vg_tid was just set to VG_INVALID_THREADID before the
hard coded memory map.
2023-02-08 22:54:57 +01:00
Paul Floyd
4c80a467a9 FreeBSD: fix internal sysctlbyname
I used the libc interface rather than the syscall interface.
The syscall also has the name length which libc adds.
2023-02-03 13:51:04 +01:00
Paul Floyd
7003f40be9 FreeBSD: improve internal syscallbyname
Post FreeBSD 12.2 this is a syscall that does everything
(rather than needing an undocumented syscall).
2023-02-02 22:06:38 +01:00
Mark Wielaard
e4c5c764e8 Add valgrind-monitor[-def].py to EXTRA_DIST
So as to make sure these get copied into the tarball.
Fixes make distcheck.
2023-02-01 23:53:17 +01:00
Paul Floyd
fd7daaa5e0 FreeBSD: cleanup launcher
cppcheck spotted a bug in the skipping of whitespace between shebang
and interpreter command. This could potentially cause the platform
to be misidentified (for x86 on amd64).
2023-02-01 21:45:46 +01:00
Paul Floyd
b1aba91160 FreeBSD: cleanup and refactor syscalls readlink and readlinkat
There was some code to handle /proc/curproc/file (a symlink to
the exe that wee need to bodge as it refers to the tool exe).
But it was neither tested nor working.

Can't use the same technique as Linux and Solaris which have more
complete /proc filesystems where each pid has symlinks for
each open file, which we use for the guest. Instead need to
copy the path ourselves. So move sys_readlink out of generic.

Simplify the handling of the resolved guest exe name - store it in
a global like VG_(args_the_exename).
2023-01-31 21:52:36 +01:00
Paul Floyd
82282a6676 Bug 464969 - D language demangling
Patch from witold.baryluk@gmail.com

(also added a testcase)
2023-01-29 22:07:52 +01:00
Paul Floyd
44a6e87492 Compiler warning expansion to defined
Clang doesn't like
m_debuginfo/tinfl.c:182:45: warning: macro expansion producing 'defined' has undefined behavior [-Wexpansion-to-defined]
2023-01-29 17:49:11 +01:00
Paul Floyd
ea733f262e macOS: Try to fix build, doesn't like .debug_gdb_scripts 2023-01-29 17:35:08 +01:00
Paul Floyd
5830ece5cd FreeBSD: update comment about __sysctlbyname and kern.proc.pathname 2023-01-25 08:31:09 +01:00
Paul Floyd
e56436d560 FreeBSD: fix build on older OSes
A bad copy-and-paste broke compilation on FreeBSD 12.
2023-01-24 21:54:09 +01:00
Paul Floyd
8dba06c771 FreeBSD: remove different reserved fds number
No idea where it originated. Causes no problems on
FreeBSD 13.1 amd64.
2023-01-24 21:03:48 +01:00
Paul Floyd
7886c072e1 FreeBSD: switch to FreeBSD 12 versions of syscalls for fstat etc
This was a change that enabled 64bit inodes (ino64).

Also a couple of typos in READMEs.
2023-01-24 20:41:15 +01:00
Paul Floyd
5a6f1c1322 Bug 435441 - valgrind fails to interpose malloc on musl 1.2.2 due to weak symbol name and no libc soname
Patch by Michael Forney <mforney@mforney.org>
2023-01-23 09:05:50 +01:00
Paul Floyd
c15993dcb4 FreeBSD: start adding more checks for /proc
Also add a couple of expecteds.
2023-01-22 21:48:51 +01:00
Paul Floyd
a526bbd051 FreeBSD: Fix auxv AT_EXECPATH
This was being copied from the host. Now it's synthesized for
the guest. Also improve the none/freebsd/auxv test to
print a few of the strings in auxv (but not the envp ones).
2023-01-21 20:49:30 +01:00
Paul Floyd
2b1c6db9c8 Two more debuginfo.c typos 2023-01-21 18:09:47 +01:00
Paul Floyd
5d38764204 Bug 464476 - Firefox fails to start under Valgrind
On FreeBSD, Firefox uses the kern.proc.pathname.PID sysctl
to get the binary path (where PID can be the actual pid
or -1). The user path is /usr/local/bin/firefox which is
a symlink to /usr/local/lib/firefox/firefox.

This was failing because we were not handling this MIB.
That meant that the sysctl returned the path for the
binary of the running tool (e.g.,
/home/paulf/scratch/valgrind/memcheck/memcheck-amd64-freebsd).
Firefox looks for files in the same directory.
Since it was the wrong directory it failed to find them and
exited.

I also noticed a lot of _umtx_op errors. On analysis they
are spurious. The wake ops take an "obj" argument, a pointer
to a variable. They only use the address as a key for
lookups and don't read the contents.
2023-01-21 17:55:09 +01:00
Paul Floyd
ded1adc432 FreeBSD: small change for pthread mutex types
It seems what is 'normal' and 'default' is not
portable.

And a bit more debuginfo mmap comment fixing
2023-01-21 13:51:50 +01:00
Paul Floyd
6d8ea1bd86 Cleanup mmap comments in debuginfo.c 2023-01-21 13:34:47 +01:00
Mark Wielaard
fdda0bece6 m_debuginfo: Suppress warning about not handling entry_value ops
The warning: evaluate_Dwarf3_Expr: unhandled DW_OP_ 0xf3 isn't
very helpful. This means we didn't handle DW_OP_GNU_entry_value.

DW_OP_GNU_entry_value (or DWARF5 DW_OP_entry_value) means interpreting
the given DWARF expression using register values as they were upon
entering the function. Which is non-trivial to implement.

We can fail the evaluation of the DWARF expression without warning
about it by default, since it isn't really needed for any current
valgrind functionality (and it is only done with --read-var-info=yes.
2023-01-15 14:24:31 +01:00
Paul Floyd
cae2118d95 FreeBSD: some _umtx_op corrections
mutex trylock doesn't user timer arguments
plain mutex lock doesn't need restart

still not sure about mutex trylock
2023-01-15 09:05:55 +01:00
Paul Floyd
30cdbfbb2c FreeBSD: some more clangd refactoring 2023-01-15 07:20:08 +01:00
Paul Floyd
8fcc813468 Bug 241072 List tools in --help output 2023-01-11 21:42:41 +01:00
Paul Floyd
d320fc123b FreeBSD: clang-tidy corrections 2023-01-08 17:52:48 +01:00