42 Commits

Author SHA1 Message Date
Paul Floyd
50bded71b2 Bug 436413 - Warn about realloc of size zero
Adds a new warning to memcheck when realloc is used with a size of 0.
For a long time this has been "implementation defined" and so
non-portable. With C23 it will become UB.

Also adds a switch to turn off the error generation and a
second switch to select between the most common
"implementation" behaviours. The defaults for this second
switch are baked in at build time.
2023-03-10 21:55:14 +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
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
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
5cf51ca2f6 And here is the updated expected for FreeBSD scalar x86 mknodat 2023-02-25 16:12:14 +01:00
Paul Floyd
615336329b Small update to FreeBSD x86 scalar expected 2023-02-25 16:08:40 +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
1cea0e151b Cleanup of warnings, mostly -Wno-unused-but-set-variable 2023-01-08 17:51:37 +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
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
7289e2639c Remove alignment warning from a FreeBSD regtest 2022-06-01 21:54:19 +02:00
Paul Floyd
c10e4e864f Add filter for size of stat structure 2022-05-19 21:28:35 +02:00
Paul Floyd
6b7cd3b4e4 Update FreeBSD (f)stat tests for FreeBSD 13.1
Somewhat annoyingly, libc is using tail call optimization
which alters our callstacks.

FreeBSD 13 and earlier had something like

{compatibility API check}
  1372e0:       48 8d 95 08 fe ff ff    lea    -0x1f8(%rbp),%rdx
  1372e7:       bf 8d 01 00 00          mov    $0x18d,%edi
  1372ec:       44 89 f6                mov    %r14d,%esi
  1372ef:       31 c0                   xor    %eax,%eax
  1372f1:       e8 8a c5 09 00          call   1d3880 <syscall@plt>

{compatibility API check}
  1342b9:       3d 9f 4f 12 00          cmp    $0x124f9f,%eax
  1342be:       7c 25                   jl     1342e5 <_fstatfs+0x55>
  1342c0:       49 8b 07                mov    (%r15),%rax
  1342c3:       48 3b 45 e0             cmp    -0x20(%rbp),%rax
  1342c7:       0f 85 51 01 00 00       jne    13441e <_fstatfs+0x18e>

{compatibility not needed}
  1342cd:       44 89 f7                mov    %r14d,%edi
  1342d0:       48 89 de                mov    %rbx,%rsi
  1342d3:       48 81 c4 e8 01 00 00    add    $0x1e8,%rsp
  1342da:       5b                      pop    %rbx
  1342db:       41 5e                   pop    %r14
  1342dd:       41 5f                   pop    %r15
  1342df:       5d                      pop    %rbp

{tail call optimization}

  1342e0:       e9 bb a0 09 00          jmp    1ce3a0 <__sys_fstatfs@plt>

{compatibility API call}

So I've updated the expecteds and added a filter for 13.0 and older.
2022-05-19 19:52:57 +02:00
Paul Floyd
f6316d1b68 Fix memcheck/tests/freebsd/fexecve
This contained a stupid mistake, and had been working by luck.
2022-05-19 10:10:32 +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
277f10d523 Try again for FreeBSD errno_aligned_allocs on x86
Harder than I thought to trigger ENOMEM on x86, so just fake it.
2022-05-10 21:01:01 +02:00
Paul Floyd
d7944c09f5 Update FreeBSD memcheck/tests/freebsd/errno_aligned_allocs.c for x86
Size to force an ENOMEM on 64bit too big for 32bit.
2022-05-10 20:23:27 +02:00
Paul Floyd
978eb7f1ab Bug 446754 Improve error codes from alloc functions under memcheck
I've made these changes only for FreeBSD and Solaris for the moment.

I don't know what should be done on Linux for aligned_alloc/memalign.
The current Valgrind code refects the glibc implementation, but not
what the documentation says.
2022-05-09 22:57:06 +02:00
Paul Floyd
35fcf875c6 FreeBSD shm_open2 also accepts first argument as SHM_ANON
Add an extra test to scalar
2022-05-09 21:27:36 +02:00
Paul Floyd
d99b369c09 FreeBSD shm_open2 arg5 seems to be optional
This syscall doesn't have a libc interface and manpage so
the documentation is skimpy.
2022-05-09 11:58:45 +02:00
Paul Floyd
3a883a6c1d Add FreeBSD shm_open2 syscall wrapper 2022-05-09 11:05:49 +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
Paul Floyd
6c51e110a2 Update FreeBSD scalar for x86
Missed one execve diff.
2022-04-13 22:59:09 +02:00
Paul Floyd
19584a93d1 Update FreeBSD [f]execve expecteds
As requested by Mark, for https://bugs.kde.org/show_bug.cgi?id=450437
2022-04-07 07:56:27 +02:00
Paul Floyd
4dd849e4ec Second go at memcheck/tests/freebsd/relapathat
Missed adding the argument to the C file
Needs more filtering
2022-04-03 22:28:26 +02:00
Paul Floyd
e816f4c44f Fixes for memcheck/tests/freebsd/realpathat
The syscall to realpathat was missing the buffer size argument.
By luck, no problem on amd64 but this failed on x86.
This adds the argument and a filter for the errors (size_t can be 4 or 8 bytes)
2022-04-03 22:00:09 +02:00
Paul Floyd
d6cdc6e523 Add filter to memcheck/tests/freebsd/fexecve for the size
Different size on x86 was causing a failure
2022-04-03 21:28:24 +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
Paul Floyd
536520cc1d Forgot to remove FreeBSD 13 i386 scalar expected 2021-12-11 16:20:58 +01:00
Paul Floyd
6db18baedb FreeBSD syswrap and scalar corrections for i386 and FreeBSD 12.2
There are still size/offset diffs on i386 for fexecve and realpathat.
2021-12-11 16:08:08 +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
d83f4c43e1 One more FreeBSD scalar fix
Using a 64 bit mask for an int argument was causing an
extra Conditional jump error
2021-12-10 22:11:16 +01:00
Paul Floyd
a56881fd7d FreeBSD scalar - filter didn't account for padding
Also forgot to remove deleted expected from EXTRA_DIST
2021-12-10 21:34:02 +01:00
Paul Floyd
0fe2799262 Correct some FreeBSD syswrap typos and simplify scalar
One typo affected scalar. Also add some more filtering
so that an extra expected is not needed for FreeBSD 13
2021-12-10 21:18:05 +01:00
Paul Floyd
de368522b8 Update FreeBSD 12 scalar 2021-12-10 21:04:25 +01:00
Paul Floyd
01048e33df FreeBSD sigreturn arg names again
Also make drd/tests/shared_timed_mutex more robust
Already not great using time delays, but the test seems
to fail intermittently due to spurious wakeups. So instead
of railing straight away, make it "three strikes and you're out".
2021-12-09 22:54:23 +01:00
Paul Floyd
f13667b1ef Bug 445607 Unhandled amd64-freebsd syscall: 247
I can't find much in the way of documentation for this.
Added to scalar, but no specific tests.
2021-11-17 23:15:23 +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
Mark Wielaard
a0ee664023 Add scalar.stderr.exp-freebsd130-x86 to EXTRA_DIST 2021-11-10 09:05:20 +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
Paul Floyd
7c5d720a2b FreeBSD support, patch 10
memcheck
No code changes. A few modified tests. Adds new FreeBSD specific tests.
2021-10-09 12:37:17 +02:00
Paul Floyd
e2583c02a5 FreeBSD support, patch 2
Files in the root directory
Several Makefile.am files that have dependencies on FreeBSD autoconf
variables. Included a few new filter files to act as placeholders
to create new freebsd subdirectories.

Updated NEWS with the FreeBSD bugzilla items plus a couple of other
items fixed indirectly.
2021-10-07 08:18:47 +02:00