1570 Commits

Author SHA1 Message Date
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
7136cd9876 musl regtest : fix warnings and badly initialized struct msghdr 2023-02-21 23:05:22 +01:00
Paul Floyd
fe008c8739 regtest: remove compiler warnings with clang 2023-02-19 10:10:59 +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
f7e4bb4af2 Bug 382034 - Testcases build fixes for musl 2023-01-27 08:42:06 +01:00
Paul Floyd
e2eeebafa6 FreeBSD: fix compile of auxv on FreeBSD 12 2023-01-24 22:00:44 +01:00
Paul Floyd
f7983be3f2 FreeBSD: improve auxv filter
Didn't work id the clone directory isn't 'valgrind'
2023-01-22 09:41:49 +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
ed73978bdb Update wrong expecteds for Bug 241072 2023-01-12 08:00:27 +01:00
Paul Floyd
8fcc813468 Bug 241072 List tools in --help output 2023-01-11 21:42:41 +01:00
Andreas Arnez
4f4cd4b8d5 s390: Add z16 support to ecag testcase
The testcase 'none/tests/s390x/ecag' requires expected output from any
machine it runs on.  This is missing for z16, so add it.
2023-01-11 16:44:38 +01:00
Andreas Arnez
d6073d34d4 s390: Add test for short/extended vector float insns
Several issues with vector floating point instructions have gone unnoticed
due to a lack of test coverage in this area.  Add a test case that
improves the coverage, particuarly when dealing with short and extended
floating point formats.
2023-01-11 16:44:38 +01:00
Paul Floyd
99dfad28a5 Cleanup warnings
Now no warnings on Fedora 36
For a short while
2023-01-09 23:57:01 +01:00
Paul Floyd
8224cf37a9 Update none/tests/cmdline1 and 2 for non-linux 2022-12-31 10:13:19 +01:00
Philippe Waroquiers
c8bb6a62ca Add clo option -scheduling-quantum=<number> to control scheduler time slice.
This option can be useful when tracking race conditions which are sensitive
to thread scheduling.
2022-12-30 16:28:23 +01:00
Paul Floyd
1c61a442b1 FreeBSD: add a check that the mqueuefs kernel module is loaded for the none/tests/mq regtest 2022-12-22 09:09:52 +01:00
Mark Wielaard
0811a612dd Implicit int in none/tests/faultstatus.c
There is a definition in faultstatus.c that is not accepted by
C99 compilers (implicit ints were removed in that language revision).

https://bugs.kde.org/show_bug.cgi?id=462007
2022-11-18 20:12:06 +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
f2550057e1 Bug 170510 - Don't warn about ioctl of size 0 without direction hint
Apply this to generic and update the message on all platforms.
2022-11-10 22:31:07 +01:00
Mark Wielaard
6a5a689fd9 Add none/tests/freebsd/auxv.stderr.exp-freebsd14 to EXTRA_DIST 2022-10-20 00:34:15 +02:00
Paul Floyd
12d2a3c85d Auxv user stack for FreeBSD, last part
Clean up, didn't need an extra func for user stack limit.
2022-10-19 00:51:05 +02:00
Paul Floyd
802f2d21d9 Auxv user stack for FreeBSD, part 2
Try to set the stack limit.
2022-10-18 22:11:32 +02:00
Paul Floyd
e5b069f2e8 Add abexit to non-Linux expecteds for gdb atexit events 2022-09-18 16:57:04 +02:00
Philippe Waroquiers
e489f31974 Add abexit in --vgdb-stopat. fix 459031 --error-exitcode doc. Add lwpid in thread_wrapper tracing.
Note that this modifies files on darwin/solaris/bsd but I only did a linux
build so possibly this commit might cause a compilation error, that should
then be trivial to fix.

Also added memmem test in the list of ignored files.
2022-09-17 22:54:05 +02:00
Paul Floyd
5d058e6332 Backout synthesizing AT_BSDFLAGS auxv entry
This was causing a crash on several FreeBSD 13.1 testcases
(but not 13.0). Probably related to "sig fastblock".
2022-07-03 21:28:57 +02:00
Paul Floyd
b29a1e1cf5 Improve FreeBSD sysctl kern.usrstack
This was handled by sysctl but not sysctlbyname.
The value returned was wrong.
Added a regtest.
2022-07-03 15:12:20 +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
3ce7673720 Add syscall wrappers for FreeBSD funlinkat and copy_file_range
Aslo add a smoketest for /bin/cp, which uses copy_file_range
2022-06-06 22:37:47 +02:00
Paul Floyd
a4151207a2 Add small sleep to none/tests/pth_2sig to help prevent hanging
On FreeBSD 13.0 x86 this testcase was hanging on some systems.
It seems like the SIGTERM signals were not being recieved
before the child exited, which left the parent hanging in the
pause() waiting to be killed.

Reported, patch provided and tested by Nick Briggs.
2022-05-23 21:27:58 +02:00
Paul Floyd
14df01dc4e Add expecteds to EXTRA_DIST 2022-05-20 22:13:16 +02:00
Mark Wielaard
2dad922aba Add cmdline{1,2}.stdout.exp-non-linux files
The new --enable-debuginfod=<yes|no> command line flag is only
available on GNU/Linux systems. Add new exp file for other systems.
2022-05-20 14:58:45 +02:00
Aaron Merey
8d4eb6be20 Add --enabled-debuginfod command line option
Currently debuginfod is enabled in Valgrind when the $DEBUGINFOD_URLS
environment variable is set and disabled when it isn't set.

This patch adds an --enable-debuginfod=<yes|no> command line option
to provide another level of control over whether Valgrind attempts
to download debuginfo. "yes" is the default value.

$DEBUGINFOD_URLS must still contain debuginfod server URLs in order
for this feature to work when --enable-debuginfod=yes.

https://bugs.kde.org/show_bug.cgi?id=453602
2022-05-20 02:48:53 +02:00
Paul Floyd
ed78405cd6 Make testcase myrandom() noinline.
With clang 13 none/tests/amd64/amd64locked fails because of what
looks like a clang optimization error. do_bt_G_E_tests is the
point of failure, and one factor is that clang 13 is inlining
myrandom().
2022-05-18 23:41:43 +02:00
Paul Floyd
7e5073f853 Changes to auxv for FreeBSD 13.1 2022-05-14 16:24:22 +02:00
Paul Floyd
8187a60ac3 Add a configure test for -ansi and use it for none/tests/ansi 2022-04-19 22:21:37 +02:00
Paul Floyd
d6bcd3ba29 Some more auxv extensions for FreeBSD 14
New entries added to testcase and documented in initimg.
May need more work
2022-04-14 00:01:49 +02:00
Paul Floyd
d5b782056d Fix typo in EXTRA_DIST 2022-04-12 23:55:46 +02:00
Paul Floyd
3e7774ea5a Bug 452274 memcheck crashes with Assertion 'sci->status.what == SsIdle' failed
FreeBSD (and Darwin) use the carry flag for syscall syscall status.
That means that in the assembler for do_syscall_for_client_WRK
they have a call to LibVEX_GuestAMD64_put_rflag_c (amd64) or
LibVEX_GuestX86_put_eflag_c (x86). These also call WRK functions.

The problem is that do_syscall_for_client_WRK has carefully crafted
labels correspinding to IP addresses. If a signal interrupts
processdings, IP can be compared to these addresses so that
VG_(fixup_guest_state_after_syscall_interrupted) can work
out how to resume the syscall. But if IP is in the save
carry flag functions, the address is not recognized and
VG_(fixup_guest_state_after_syscall_interrupted) fails.

The crash in the title happens because the interrupted
syscall does not reset its status, and on the next syscall
it is expected that the status be idle.

To fix this I added global variables that get set to 1
just before calling the save carry flag functions, and cleared
just after. VG_(fixup_guest_state_after_syscall_interrupted)
can then check this and work out which section we are in
and resume the syscall correctly.

Also:

Start a new NEWS section for 3.20

Add a regtest for this and also a similar one for Bug 445032
(x86-freebsd only, new subdir).

I saw that this problem also probably exists with macOS, so I made
the same changes there (not yet tested)
2022-04-12 23:50:48 +02:00
Mark Wielaard
8eb547054a Warn for execve syscall with argv or argv[0] being NULL.
For execve valgrind would silently fail when argv was NULL or
unadressable. Make sure that this produces a warning under memcheck.

The linux kernel accepts argv[0] being NULL, but most other kernels
don't since posix says it should be non-NULL and it causes argc to
be zero which is unexpected and might cause security issues.

This adjusts some testcases so they don't rely on execve succeeding
when argv is NULL and expect warnings about argv or argv[0] being
NULL or unaddressable.

https://bugs.kde.org/show_bug.cgi?id=450437
2022-04-06 22:48:45 +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
df214356db none/tests/amd64/avx_estimate_insn.vgtest fails on AMD processors
commit ef9ac3aa0fd3ed41d74707ffe49abe9ad2797ddd
"fix avx-1 amd64 test" split off the estimate instructions
into their own testcase avx_estimate_insn.

The commit message suggested that two .exp files would be
added, one for the intel and one for the amd cases.

It seems the .exp-amd variant was forgotten. This commit
adds it.

https://bugs.kde.org/show_bug.cgi?id=413330
2022-02-16 23:26:16 +01:00
Carl Love
ab740a1741 Powerpc test_isa_3_1_VRT fix
The vcmpequq, vcmpgtsq, vcmpgtuq test cases for the dotted versions of the
instructions were issuing the non-dotted instruction.

This patch fixes the issues and updates the expected output.

Note, the issue exposed a bug in the VEX/priv/guest_ppc_toIR.c handling of
the instructions.  That fix is in a separate patch.
2022-02-02 00:52:31 +00:00
Paul Floyd
49fe0dc74a Anticipate testcase problems with GCC 12
There will be a lot more to come.

On amd64 Linux
In faultstatus was seeing the division by zero and emitting a ud2 opcode.
In wrap3 a pair of mutually recursive functions were being inlined.
When forced not to be inlined GCC merged them into a single function.
It cannot see that the client requests have diffeent behaviour.
2021-11-23 23:37:02 +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
Julian Seward
0d38ca5dd6 Bug 444399 - disInstr(arm64): unhandled instruction 0xC87F2D89 (LD{,A}XP and ST{,L}XP). FOLLOWUP FIX.
This is an attempt to un-break 'make dist', as broken by the main commit for
this bug, which was 530df882b8f60ecacaf2b9b8a719f7ea1c1d1650.
2021-11-12 13:08:45 +01:00
Julian Seward
530df882b8 Bug 444399 - disInstr(arm64): unhandled instruction 0xC87F2D89 (LD{,A}XP and ST{,L}XP).
This is unfortunately a big and complex patch, to implement LD{,A}XP and
ST{,L}XP.  These were omitted from the original AArch64 v8.0 implementation
for unknown reasons.

(Background) the patch is made significantly more complex because for AArch64
we actually have two implementations of the underlying
Load-Linked/Store-Conditional (LL/SC) machinery: a "primary" implementation,
which translates LL/SC more or less directly into IR and re-emits them at the
back end, and a "fallback" implementation that implements LL/SC "manually", by
taking advantage of the fact that V serialises thread execution, so we can
"implement" LL/SC by simulating a reservation using fields LLSC_* in the guest
state, and invalidating the reservation at every thread switch.

(Background) the fallback scheme is needed because the primary scheme is in
violation of the ARMv8 semantics in that it can (easily) introduce extra
memory references between the LL and SC, hence on some hardware causing the
reservation to always fail and so the simulated program to wind up looping
forever.

For these instructions, big picture:

* for the primary implementation, we take advantage of the fact that
  IRStmt_LLSC allows I128 bit transactions to be represented.  Hence we bundle
  up the two 64-bit data elements into an I128 (or vice versa) and present a
  single I128-typed IRStmt_LLSC in the IR.  In the backend, those are
  re-emitted as LDXP/STXP respectively.  For LL/SC on 32-bit register pairs,
  that bundling produces a single 64-bit item, and so the existing LL/SC
  backend machinery handles it.  The effect is that a doubleword 32-bit LL/SC
  in the front end translates into a single 64-bit LL/SC in the back end.
  Overall, though, the implementation is straightforward.

* for the fallback implementation, it is necessary to extend the guest state
  field `guest_LLSC_DATA` to represent a 128-bit transaction, by splitting it
  into _DATA_LO64 and DATA_HI64.  Then, the implementation is an exact
  analogue of the fallback implementation for single-word LL/SC.  It takes
  advantage of the fact that the backend already supports 128-bit CAS, as
  fixed in bug 445354.  As with the primary implementation, doubleword 32-bit
  LL/SC is bundled into a single 64-bit transaction.

Detailed changes:

* new arm64 guest state fields LLSC_DATA_LO64/LLSC_DATA_LO64 to replace
  guest_LLSC_DATA

* (ridealong fix) arm64 front end: a fix to a minor and harmless decoding bug
  for the single-word LDX/STX case.

* arm64 front end: IR generation for LD{,A}XP/ST{,L}XP: tedious and
  longwinded, but per comments above, an exact(ish) analogue of the singleword
  case

* arm64 backend: new insns ARM64Instr_LdrEXP / ARM64Instr_StrEXP to wrap up 2
  x 64 exclusive loads/stores.  Per comments above, there's no need to handle
  the 2 x 32 case.

* arm64 isel: translate I128-typed IRStmt_LLSC into the above two insns

* arm64 isel: some auxiliary bits and pieces needed to handle I128 values;
  this is standard doubleword isel stuff

* arm64 isel: (ridealong fix): Ist_CAS: check for endianness of the CAS!

* arm64 isel: (ridealong) a couple of formatting fixes

* IR infrastructure: add support for I128 constants, done the same as V128
  constants

* memcheck: handle shadow loads and stores for I128 values

* testcase: memcheck/tests/atomic_incs.c: on arm64, also test 128-bit atomic
  addition, to check we really have atomicity right

* testcase: new test none/tests/arm64/ldxp_stxp.c, tests operation but not
  atomicity.  (Smoke test).
2021-11-12 12:13:45 +01:00
Carl Love
3950c5d661 Valgrind Add powerpc R=1 tests
Contributed by Will Schmidt <will_schmidt@vnet.ibm.com>

This includes updates and adjustments as suggested by Carl.

Add tests that exercise PCRelative instructions.
These instructions are encoded with R==1, which indicate that
the memory accessed by the instruction is at a location
relative to the currently executing instruction.

These tests are built using -Wl,-text and -Wl,-bss
options to ensure the location of the target array is at a
location with a specific offset from the currently
executing instruction.

The write instructions are aimed at a large buffer in
the bss section; which is checked for updates at the
completion of each test.

In order to ensure consistent output across assorted
systems, the tests have been padded with ori, nop instructions
and align directives.

Detailed changes:
 * Makefile.am: Add test_isa_3_1_R1_RT and test_isa_3_1_R1_XT tests.
 * isa_3_1_helpers.h: Add identify_instruction_by_func_name() helper function
   to indicate if the test is for R==1.
   Add helpers to initialize and print changes to the pcrelative_write_target
   array.
   Add #define to help pad code with a series of eyecatcher ORI instructions.
     * test_isa_3_1_R1_RT.c: New test.
     * test_isa_3_1_R1_XT.c: New test.
     * test_isa_3_1_R1_XT.stdout.exp: New expected output.
     * test_isa_3_1_R1_XT.stdout.exp: New expected output.
     * test_isa_3_1_R1_RT.stderr.exp: New expected output.
     * test_isa_3_1_R1_RT.stderr.exp: New expected output.

     * test_isa_3_1_R1_RT.vgtest: New test handler.
     * test_isa_3_1_R1_XT.vgtest: New test handler.

     * test_isa_3_1_common.c: Add indicators (updates_byte,updates_halfword,
       updates_word) indicators to control the output from the R==1 tests.
       Add helper check for "_R1" to indicate if instruction is coded with R==1.
       Add init and print helpers for the pcrelative_write_target array.
2021-11-02 11:07:37 -05:00
Andreas Arnez
b77dbefe72 Bug 444242 - s390x: Sign-extend "relative long" offset in EXRL
In s390_irgen_EXRL, the offset is zero-extended instead of sign-extended,
typically causing Valgrind to crash when a negative offset occurs.

Fix this with a new helper function that calculates a "relative long"
address from a 32-bit offset.  Replace other calculations of "relative
long" addresses by invocations of this function as well.  And for
consistency, do the same with "relative" (short) addresses.
2021-10-28 15:08:20 +02:00
Paul Floyd
8c0f72667e Fix the ramaining easily fixable warnings with clang
There's one remaining
memalign2.c:29:9: warning: unused variable 'piece' [-Wunused-variable]
because of a block of #if FreeBSD for memalign that looks unnecessary

Otherwise all that is left is a few like

warning: unknown warning option '-Wno-alloc-size-larger-than'; did you mean '-Wno-frame-larger-than='? [-Wunknown-warning-option]

because there is no standard for compiler arguments.
2021-10-10 21:56:49 +02:00
Paul Floyd
03f1c090f6 Remove a couple more warnings
suffix rule with dependency generates a warning
https://www.gnu.org/software/make/manual/html_node/Error-Messages.html
(bottom of page)

the other is a short initialized with an int literal that wraps to
a negative short value
2021-10-10 20:32:44 +02:00