1301 Commits

Author SHA1 Message Date
Paul Floyd
227fa1d53b Cleanup for clangd, mostly FreeBSD
Consistently use braces. Make some bitwise expressions use unsigned.
Use some named variables for magic numbers.
2022-12-25 18:36:20 +01:00
Paul Floyd
5b52408406 Bug 462830 - WARNING: unhandled amd64-freebsd syscall: 474
Add syscall wrappers for sctp_generic_recvmsg and sctp_generic_sendmsg
on FreeBSD.
2022-12-22 23:08:45 +01:00
Paul Floyd
ac6d9faf4b Bug 351857 - confusing error message about valid command line option
Added code to handle missing "=something".
2022-11-12 21:02:07 +01:00
Paul Floyd
aed1e501c8 FreeBSD: fix a typo in my previous commit for VKI_AT_USRSTACKLIM define. 2022-10-28 17:04:26 +02:00
Paul Floyd
4ff2185f45 FreeBSD: remove dependency on elf header and make VKI_ copies of AT defines
Also prepare NEWS and configure.ac for 3.21.0
2022-10-28 16:52:50 +02:00
Paul Floyd
b31ff3321e Improve FreeBSD handling of W^X setting.
FreeBSD has a sysctl that prevents mmapping regions
that are both Write and Exec. This setting prevents
Valgrind from workig correctly.

This change uses ELF tags to turn off W^X control,
and also removes a sysctl check for the same flag.

Patch contributor:
0a3a794143
2022-10-16 18:58:52 +02:00
Paul Floyd
9f27d8fbc7 Bug-456171 [PATCH] FreeBSD: Don't record address errors when accessing the 'kern.ps_strings' sysctl struct
There is quite a lot of stuff here.

The problem is that setproctitle and kern.ps_strings were using the Valgrind host auxv
rather than the guest. The proposed patch would have just ignored those memory ranges.

I've gone a fair bit further than that
1. refactored the initimg code for building the client auxv. Previously we were
   simply ignoring any non-scalar entries. Now we copy most of thse as well.
   That means that 'strtab' built on the client stack no longet only contains
   strings, at can also now contain binary structures. Note I was a bit
   concerned that there may be some alignment issues, but I haven't seen any
   problems so far.
2. Added intercepts to sysctl and sysctlbyname for kern.ps_strings, then find
   AT_PS_STRINGS from the client auxv that is now usable from step 1.
3. Some refactoring of sysctl and sysctlbyname syscall wrappers. More to do
   there!
4. Added a setproctitle testcase (that also tests the sysctls).
5. Updated the auxv testcase now that more AT_* entries are handled.
2022-07-03 13:05:54 +02:00
Paul Floyd
a108669a18 Implement vgdb invoker on FreeBSD
This is a translation of the Linux vgdb-invoker-ptrace.c
to the FreeBSD ptrace dialect. It seems to be basically
functional (3 out of 4 of the regression tests pass,
and for the 4th one it seems to be a limitation of
ptrace on FreeBSD that it can cause syscalls to be
interrupted).
2022-06-14 22:39:31 +02:00
Paul Floyd
2b370744e5 Indent and add more comments for FreeBSD syscall code
After working on an issue that turns out to seem to be with the
FreeBSD kernel sched_uler I played a lot with the Valgrind
syscall and scheduler code. I've kept the comments and the
reformatting.
2022-05-30 22:57:34 +02:00
Paul Floyd
6cb8e52c34 More changes for FreeBSD 13.1
These concern auxv, swapoff and fcntl F_KINFO

I wanted to use the new fcntl K_INFO to replace the existing
horrible implementation of resolve_filename, but it seems to
have change the behaviour for redirected files. Several
fdleak regtests fail because stdout resolves to an empty
string.
2022-05-14 16:46:03 +02:00
Paul Floyd
295ce0e643 Update FreeBSD struct vki_kinfo_vmentry 2022-05-07 17:28:08 +02:00
Di Chen
fca4a3d8e5 Support new memfd_secret linux syscall (447)
memfd_secret is a new syscall in linux 5.14. memfd_secret() is
disabled by default and a command-line option needs to be added to
enable it at boot time.

$ cat /proc/cmdline
[...] secretmem.enable=y

https://bugs.kde.org/451878
https://lwn.net/Articles/865256/
2022-04-19 11:59:36 +02:00
Paul Floyd
60dd674e71 Missing defines for FreeBSD 14 swapoff
+1 typo
2022-04-13 23:32:55 +02:00
Paul Floyd
cdd98111c7 Updates to FreeBSD syscalls for FreeBSD 14
3 new syscalls, and swapoff has a COMPAT13 version.
2022-04-13 23:00:44 +02:00
Mark Wielaard
a1bb40171a Move ht_sigchld_ignore and ht_ignore_node to pub_tool_signals.h
ht_sigchld_ignore and ht_ignore_node were defined in pub_core_signals.h
which cannot include any other tool header.

...checking header files and include directives
*** File coregrind/pub_core_signals.h must not include pub_tool_hashtable.h

So move the definition and type to pub_tool_signals.h
2022-04-08 09:42:18 +02:00
Aaron Merey
2ad9335044 Bug 445011: SIGCHLD is sent when valgrind uses debuginfod-find
Valgrind fork+execs debuginfod-find in order to perform debuginfod
queries. Any SIGCHLD debuginfod-find sends upon termination can
mistakenly be delivered to the client running under valgrind.

To prevent this, record in a hash table the PID of each process
valgrind forks for internal use. Do not send SIGCHLD to the client
if it is from a PID in this hash table.

https://bugs.kde.org/show_bug.cgi?id=445011
2022-04-07 22:09:57 +02:00
Paul Floyd
6c91d2d4ee Extend FreeBSD procctl
4 new types added in FreeBSD 13.1
2022-04-03 18:27:17 +02:00
Paul Floyd
bbc3bcab0a Bug 451843 - valgrind fails to start on a FreeBSD system which enforces W^X
Also add FreeBSD 13.1 to configure.ac
2022-04-03 15:50:38 +02:00
Mark Wielaard
1024237358 Implement linux rseq syscall as ENOSYS
This implements rseq for amd64, arm, arm64, ppc32, ppc64,
s390x and x86 linux as ENOSYS (without warning).

glibc will start using rseq to accelerate sched_getcpu, if
available. This would cause a warning from valgrind every
time a new thread is started.

Real rseq (restartable sequences) support is pretty hard, so
for now just explicitly return ENOSYS (just like we do for clone3).

https://sourceware.org/pipermail/libc-alpha/2021-December/133656.html
2021-12-15 12:15:06 +01:00
Paul Floyd
bb178889c7 Bug 446823 FreeBSD - missing syscalls when using libzm4
Adds syscall wrappers for __specialfd and __realpathat.
Also remove kernel dependency on COMPAT_FREEBSD10.

This change also reorganizes somewhat the scalar test
and adds configure time checks for the FreeBSD version,
allowing regression tests to be compiled depending on the
FreeBSD release.

From now on, scalar.c will contain syscalls for FreeBSD 11 and 12
and subsequent releases will get their own scalar, starting with
scalar_13_plus.c.
2021-12-11 12:32:08 +01:00
Paul Floyd
49d6d73c25 Add missing syscall wrapper on Solaris
I tried to test drd/tests/pth_mutex_signal on Solaris
(you never know) but encountered a missing syscall
wrapper. So this adds a very basic wrapper for lwp_mutex_unlock.

Also update a Solaris expected that I missed amongst the FreeBSD changes.
2021-11-22 04:12:16 +01:00
Paul Floyd
83dda2b71a Bug 444925 fexecve syscall wrapper not properly implemented
Implement fexecve and a few testcases on FreeBSD.
2021-11-14 22:06:14 +01:00
Paul Floyd
d1d74d7985 Some FreeBSD cleaning
Add a scalar expected for FreeBSD 13 i386
Add SIGLIBRT define
2021-11-09 23:19:19 +01:00
Mark Wielaard
5aca524f5a Set version once in configure.ac, use in valgrind.h andvg-entities.xml
Currently the version is updated in 3 places, configure.ac,
include/valgrind.h and docs/xml/vg-entities.xml. This goes wrong from
time to time. So only define the version (and release date) once in
configure.ac and update both other places at configure time.
2021-10-17 23:14:50 +02:00
Mark Wielaard
95468b34f1 Remove executable bits from source files (drd_main.c, pub_tool_machine.h) 2021-10-15 18:02:25 +02:00
Mark Wielaard
42b08ed5bd -> 3.18.1 final
Now with __VALGRIND_MINOR__ set to 18 in include/valgrind.h
2021-10-15 14:23:59 +02:00
Mark Wielaard
ef95220dda Implement BPF_MAP_LOOKUP_AND_DELETE_ELEM and BPF_MAP_FREEZE
Implement BPF_MAP_LOOKUP_AND_DELETE_ELEM (command 21) and
BPF_MAP_FREEZE (command 22) and produce a WARNING instead of a fatal
error for unrecognized BPF commands.

https://bugs.kde.org/show_bug.cgi?id=426148
2021-10-12 23:15:41 +02:00
Lubomir Rintel
a21e890f82 Add close_range(2) support
This is a system call introduced in Linux 5.9.

It's typically used to bulk-close file descriptors that a process inherited
without having desired so and doesn't want to pass them to its offspring
for security reasons. For this reason the sensible upper limit value tends
to be unknown and the users prefer to stay on the safe side by setting it
high.

This is a bit peculiar because, if unfiltered, the syscall could end up
closing descriptors Valgrind uses for its purposes, ending in no end of
mayhem and suffering.

This patch adjusts the upper bounds to a safe value and then skips over
the descriptor Valgrind uses by potentially calling the real system call
with sub-ranges that are safe to close.

The call can fail on negative ranges and bad flags -- we're dealing with
the first condition ourselves while letting the real call fail on bad
flags.

https://bugs.kde.org/show_bug.cgi?id=439090
2021-10-12 22:58:45 +02:00
Paul Floyd
68bb7c063f FreeBSD support, patch 12
coregrind modified files
2021-10-09 15:01:08 +02:00
Paul Floyd
3c53eea626 Add copyright statements to added FreeBSD headers 2021-10-08 22:08:12 +02:00
Paul Floyd
7774acbc9c FreeBSD support, patch 3
include directory
New FreeBSD specific headers
SONAMES for FreeBSD libraries
2021-10-06 21:24:17 +02:00
Andreas Arnez
565bae9c70 s390x: Mark arch13 features as supported
Make the STFLE instruction report the miscellaneous-instruction-extensions
facility 3 and the vector-enhancements facility 2 as supported.  Indicate
support for the latter in the HWCAP vector as well.
2021-09-01 14:44:16 +02:00
Mark Wielaard
52ed51fc35 Generate a ENOSYS (sys_ni_syscall) for clone3 on all linux arches
glibc 2.34 will try to use clone3 first before falling back to
the clone syscall. So implement clone3 as sys_ni_syscall which
simply return ENOSYS without producing a warning.

https://bugs.kde.org/show_bug.cgi?id=439590
2021-07-21 19:53:21 +02:00
Andreas Arnez
484b7dd1e8 Bug 430429 - s390x: Fix clang compile error in valgrind.h
It has been observed that clang emits an error in valgrind.h for the macro
VALGRIND_DO_CLIENT_REQUEST_EXPR:

 "[...] unsupported inline asm: input with type 'int' matching output with
 type 'volatile unsigned long'"

Fix this with an explicit cast of the input to 'unsigned long int.'

The patch has been suggested by Jonathan Albrecht.
2021-03-09 17:36:12 +01:00
Paul Floyd
e42badd060 Bug 388787 - Support for C++17 new/delete
These over-aligned new and delete operators were added in C++ 17.
2021-03-02 13:32:22 +01:00
Allison Karlitskaya
dec3050653 Linux: Add wrapper for fcntl(F_{GET,ADD}_SEALS)
Add also a testcase to memcheck/tests/linux, enabled according to a new
check for memfd_create() in configure.ac.

https://bugs.kde.org/show_bug.cgi?id=361770
2021-02-20 21:04:12 +01:00
Bart Van Assche
dc29ef72df core: Pass stack change user requests on to tools
Since DRD tracks the lowest and highest stack address that has been used,
it needs to know about stack registration events. Hence pass on stack
registration events to tools.
2021-02-20 08:43:23 -08:00
Carl Love
10f16e8d9e PPC64: Fix for VG_MAX_INSTR_SZB, max instruction size is now 8bytes for prefix inst
The ISA 3.1 support has both word instructions of length 4-bytes and prefixed
instruction of length 8-bytes.  The following fix is needed when Valgrind
is compiled using an ISA 3.1 compiler.
2021-01-11 15:28:09 -06:00
Laurent Bonnans
1c49351424 Fix 397605 - Add support for Linux FICLONE ioctl 2020-12-20 20:00:57 +01:00
Andreas Arnez
159f132289 Bug 404076 - s390x: Implement z14 vector instructions
Implement the new instructions/features that were added to z/Architecture
with the vector-enhancements facility 1.  Also cover the instructions from
the vector-packed-decimal facility that are defined outside the chapter
"Vector Decimal Instructions", but not the ones from that chapter itself.

For a detailed list of newly supported instructions see the updates to
`docs/internals/s390-opcodes.csv'.

Since the miscellaneous instruction extensions facility 2 was already
addressed by Bug 404406, this completes the support necessary to run
general programs built with `--march=z14' under Valgrind.  The
vector-packed-decimal facility is currently not exploited by the standard
toolchain and libraries.
2020-12-08 19:37:39 +01:00
Nicholas Nethercote
8c08253b89 Add support for copy and ad hoc profiling to DHAT. 2020-12-07 19:57:56 +11:00
Paul Floyd
d2d54dbcc7 Bug 428909 - helgrind: need to intercept duplicate libc definitions for Fedora 33 2020-12-04 10:11:55 +01:00
Mark Wielaard
fe4b349df3 Support new faccessat2 linux syscall (439)
faccessat2 is a new syscall in linux 5.8 and will be used by glibc 2.33.
faccessat2 is simply faccessat with a new flag argument. It has
a common number across all linux arches.

https://bugs.kde.org/427787
2020-10-16 02:55:06 +02:00
Mark Wielaard
6323fd5bfd Handle linux syscalls sched_getattr and sched_setattr
The only "special" thing about these syscalls is that the given
struct sched_attr determines its own size for future expansion.

Original fix by "ISHIKAWA,chiaki" <ishikawa@yk.rim.or.jp>

https://bugs.kde.org/show_bug.cgi?id=369029
2020-08-01 15:34:48 +02:00
Mark Wielaard
0a69a8f5bd Add execveat for arm[64], [nano]mips[32|64], ppc[32|64], s390x and x86.
https://bugs.kde.org/show_bug.cgi?id=345077
2020-06-09 09:03:02 +02:00
Mark Wielaard
09e7482024 Advance the head to 3.17.0.GIT. 2020-06-08 21:12:39 +02:00
Alexandra Hájková
6f6ff49ffa Add support for execveat syscall
Refactor the code to be reusable between execve and
execveat syscalls.

https://bugs.kde.org/show_bug.cgi?id=345077
2020-06-08 20:58:09 +02:00
Petar Jovanovic
4a889e881b mips: remove rt-rk email that is no longer in use
Email mips-valgrind@rt-rk.com is no longer in use.
2020-05-20 13:18:55 +00:00
Michal Privoznik
60a7ebedc0 Add support for setns syscall
I've tested this on amd64 and arm but I'm enabling it on all
arches since the syscall should work identically on all of them.

This was requested by users for a long time (almost 5 years) and
in fact, some programs (like libvirt) use namespaces and fork off
to enter other namespaces. Lack of implementation means valgrind
can't be used with these programs (or their configuration must be
changed to not use namespaces, which defeats the purpose).

Without knowing it, I've converged to same patch as mentioned in
bugs below.

https://bugs.kde.org/show_bug.cgi?id=343099
https://bugs.kde.org/show_bug.cgi?id=368923
https://bugs.kde.org/show_bug.cgi?id=369031

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2020-04-28 17:36:20 +02:00
Martin Storsjö
7359c5fd9f mingw: Fix arch detection ifdefs for non-x86 mingw platforms
Don't assume that __MINGW32__ implies x86; Windows runs on ARM/ARM64
as well, and there are mingw toolchains that target those architectures.

This mirrors how the MSVC parts of the same expressions are written,
as (defined(_WIN32) && defined(_M_IX86)) and
(defined(_WIN64) && defined(_M_X64)) - not relying on _WIN32/_WIN64
or __MINGW32__/__MINGW64__ alone to indicate architecture.

Change the __MINGW64__ and _WIN64 ifdefs into plain __MINGW32__
and _WIN32 as well, for clarity - these defines mostly imply
platform.
2020-04-27 11:51:02 -07:00