1226 Commits

Author SHA1 Message Date
Mark Wielaard
89423f5d8b Intercept stpcpy also in ld.so for arm64
On other arches stpcpy () is intercepted for both libc.so and ld.so.
But not on arm64, where it is only intercepted for libc.so.

This can cause memcheck warnings about the use of stpcpy () in ld.so
when called through dlopen () because ld.so contains its own copy of
that functions.

Fix by introducing VG_Z_LD_LINUX_AARCH64_SO_1 (the encoded name of
ld.so on arm64) and using that in vg_replace_strmem.c to intercept
stpcpy.

https://bugs.kde.org/show_bug.cgi?id=407307
2019-05-07 21:20:04 +02:00
Julian Seward
88b9aad08a Advance the head to 3.16.0.GIT. 2019-04-18 06:38:36 +02:00
Julian Seward
9a8e749a7d Update __VALGRIND_MINOR__ for the upcoming 3.15 release. 2019-04-08 08:07:39 +02:00
Philippe Waroquiers
081c34ea47 Fix Bug 404638 - Add VG_(replaceIndexXA)
Based on a patch from Łukasz Marek.

Note that this function differs from:
   *(T*)VG_(indexXA)(arr, index) = new_value;
as the function will mark the array as unsorted.

Note that this function is currently unused in the current valgrind code basis,
but it is useful for tools outside of valgrind tree.
2019-03-16 12:11:39 +01:00
Nicholas Nethercote
441bfc5f51 Overhaul DHAT.
This commit thoroughly overhauls DHAT, moving it out of the
"experimental" ghetto. It makes moderate changes to DHAT itself,
including dumping profiling data to a JSON format output file. It also
implements a new data viewer (as a web app, in dhat/dh_view.html).

The main benefits over the old DHAT are as follows.

- The separation of data collection and presentation means you can run a
  program once under DHAT and then sort the data in various ways. Also,
  full data is in the output file, and the viewer chooses what to omit.

- The data can be sorted in more ways than previously. Some of these
  sorts involve useful filters such as "short-lived" and "zero reads or
  zero writes".

- The tree structure view avoids the need to choose stack trace depth.
  This avoids both the problem of not enough depth (when records that
  should be distinct are combined, and may not contain enough
  information to be actionable) and the problem of too much depth (when
  records that should be combined are separated, making them seem less
  important than they really are).

- Byte and block measures are shown with a percentage relative to the
  global count, which helps gauge relative significance of different
  parts of the profile.

- Byte and blocks measures are also shown with an allocation rate
  (bytes and blocks per million instructions), which enables comparisons
  across multiple profiles, even if those profiles represent different
  workloads.

- Both global and per-node measurements are taken at the global heap
  peak ("At t-gmax"), which gives Massif-like insight into the point of
  peak memory use.

- The final/liftimes stats are a bit more useful than the old deaths
  stats. (E.g. the old deaths stats didn't take into account lifetimes
  of unfreed blocks.)

- The handling of realloc() has changed. The sequence `p = malloc(100);
  realloc(p, 200);` now increases the total block count by 2 and the
  total byte count by 300. Previously it increased them by 1 and 200.
  The new handling is a more operational view that better reflects the
  effect of allocations on performance. It makes a significant
  difference in the results, giving paths involving reallocation (e.g.
  repeated pushing to a growing vector) more prominence.

Other things of note:

- There is now testing, both regression tests that run within the
  standard test suite, and viewer-specific tests that cannot run within
  the standard test suite. The latter are run by loading
  dh_view.html?test=1 in a web browser.

- The commit puts all tool lists in Makefiles (and similar files) in the
  following consistent order: memcheck, cachegrind, callgrind, helgrind,
  drd, massif, dhat, lackey, none; exp-sgcheck, exp-bbv.

- A lot of fields in dh_main.c have been given more descriptive names.
  Those names now match those used in dh_view.js.
2019-02-01 14:54:34 +11:00
Julian Seward
50bb127b1d Bug 402781 - Redo the cache used to process indirect branch targets.
[This commit contains an implementation for all targets except amd64-solaris
and x86-solaris, which will be completed shortly.]

In the baseline simulator, jumps to guest code addresses that are not known at
JIT time have to be looked up in a guest->host mapping table.  That means:
indirect branches, indirect calls and most commonly, returns.  Since there are
huge numbers of these (often 10+ million/second) the mapping mechanism needs
to be extremely cheap.

Currently, this is implemented using a direct-mapped cache, VG_(tt_fast), with
2^15 (guest_addr, host_addr) pairs.  This is queried in handwritten assembly
in VG_(disp_cp_xindir) in dispatch-<arch>-<os>.S.  If there is a miss in the
cache then we fall back out to C land, and do a slow lookup using
VG_(search_transtab).

Given that the size of the translation table(s) in recent years has expanded
significantly in order to keep pace with increasing application sizes, two bad
things have happened: (1) the cost of a miss in the fast cache has risen
significantly, and (2) the miss rate on the fast cache has also increased
significantly.  This means that large (~ one-million-basic-blocks-JITted)
applications that run for a long time end up spending a lot of time in
VG_(search_transtab).

The proposed fix is to increase associativity of the fast cache, from 1
(direct mapped) to 4.  Simulations of various cache configurations using
indirect-branch traces from a large application show that is the best of
various configurations.  In an extreme case with 5.7 billion indirect
branches:

* The increase of associativity from 1 way to 4 way, whilst keeping the
  overall cache size the same (32k guest/host pairs), reduces the miss rate by
  around a factor of 3, from 4.02% to 1.30%.

* The use of a slightly better hash function than merely slicing off the
  bottom 15 bits of the address, reduces the miss rate further, from 1.30% to
  0.53%.

Overall the VG_(tt_fast) miss rate is almost unchanged on small workloads, but
reduced by a factor of up to almost 8 on large workloads.

By implementing each (4-entry) cache set using a move-to-front scheme in the
case of hits in ways 1, 2 or 3, the vast majority of hits can be made to
happen in way 0.  Hence the cost of having this extra associativity is almost
zero in the case of a hit.  The improved hash function costs an extra 2 ALU
shots (a shift and an xor) but overall this seems performance neutral to a
win.
2019-01-25 09:14:56 +01:00
Philippe Waroquiers
d7d8231750 Fix false positive 'Conditional jump or move' on amd64 64 bits ptracing 32 bits.
PTRACE_GET_THREAD_AREA is not handled by amd64 linux syswrap, which leads
to false positive errors in 64 bits program ptrace-ing 32 bits processes.

For example, the below error was wrongly reported on GDB:
==25377== Conditional jump or move depends on uninitialised value(s)
==25377==    at 0x8A1D7EC: td_thr_get_info (td_thr_get_info.c:35)
==25377==    by 0x526819: thread_from_lwp(thread_info*, ptid_t) (linux-thread-db.c:417)
==25377==    by 0x5281D4: thread_db_notice_clone(ptid_t, ptid_t) (linux-thread-db.c:442)
==25377==    by 0x51773B: linux_handle_extended_wait(lwp_info*, int) (linux-nat.c:2027)
....
==25377==  Uninitialised value was created by a stack allocation
==25377==    at 0x69A360: x86_linux_get_thread_area(int, void*, unsigned int*) (x86-linux-nat.c:278)

Fix this by implementing PTRACE_GET|SET_THREAD_AREA on amd64.
2019-01-12 15:35:59 +01:00
Nicholas Nethercote
8b689c66d9 Implement VG_(apply_ExeContext)().
It's been declared for a long time, but was lacking a definition.
2018-10-19 16:30:42 +11:00
Mark Wielaard
4692f675b2 Hook up linux membarrier syscall for s390x-linux
Fixes none/tests/linux/membarrier on s390x-linux.
2018-09-22 11:02:08 +02:00
Mark Wielaard
5d41dadeb3 Update vg-entities.xml and valgrind.h for next version number. 2018-09-14 23:12:45 +02:00
Mark Wielaard
790f5f3018 Bug 397354 utimensat should ignore tv_sec if tv_nsec is UTIME_NOW/OMIT.
When code uses utimensat with UTIME_NOW or UTIME_OMIT valgrind memcheck
would generate a warning. But as the utimensat manpage says:

  If the tv_nsec field of one of the timespec structures has the  special
  value  UTIME_NOW,  then  the corresponding file timestamp is set to the
  current time.  If the tv_nsec field of one of the  timespec  structures
  has the special value UTIME_OMIT, then the corresponding file timestamp
  is left unchanged.  In both of these cases, the  value  of  the  corre‐
  sponding tv_sec field is ignored.

So ignore the timespec tv_sec when tv_nsec is set to UTIME_NOW or
UTIME_OMIT.
2018-09-03 11:54:38 +02:00
Rhys Kidd
2b0aa0a5b8 macos: Fix missing syscall ulock_wait (OS X 10.12). bz#379754
Based upon patch available at:
https://bugs.kde.org/attachment.cgi?id=105482
2018-08-19 15:00:45 -04:00
Tom Hughes
488a5b8bb6 Improve bpf wrapper to check arguments more carefully 2018-08-14 20:47:19 +01:00
Quentin Monnet
0097176525 Add file descriptor tracking in wrappers for bpf system call
Support for the bpf system call was added in a previous commit, but
did not include tracking for file descriptors handled by the call.

Add checks and tracking for file descriptors. Check in PRE() wrapper
that all file descriptors (pointing to object such as eBPF programs or
maps, cgroups, or raw tracepoints) used by the system call are valid,
then add tracking in POST() wrapper for newly produced file descriptors.

As the file descriptors are not always processed in the same way by the
bpf call, add to the header file some additional definitions from bpf.h
that are necessary to sort out under what conditions descriptors should
be checked in the PRE() helper.
2018-08-14 20:47:19 +01:00
Quentin Monnet
1d933b5a4a Add support for bpf system call
Fixes: 388786 - Support bpf syscall in amd64 Linux

Add support for bpf() Linux-specific system call on amd64 platform. The
bpf() syscall is used to handle eBPF objects (programs and maps), and
can be used for a number of operations. It takes three arguments:

- "cmd" is an integer encoding a subcommand to run. Available subcommand
  include loading a new program, creating a map or updating its entries,
  retrieving information about an eBPF object, and may others.
- "attr" is a pointer to an object of type union bpf_attr. This object
  converts to a struct related to selected subcommand, and embeds the
  various parameters used with this subcommand. Some of those parameters
  are read by the kernel (example for an eBPF map lookup: the key of the
  entry to lookup), others are written into (the value retrieved from
  the map lookup).
- "attr_size" is the size of the object pointed by "attr".

Since the action performed by the kernel, and the way "attr" attributes
are processed depends on the subcommand in use, the PRE() and POST()
wrappers need to make the distinction as well. For each subcommand, mark
the attributes that are read or written.

For some map operations, the only way to infer the size of the memory
areas used for read or write operations seems to involve reading
from /proc/<pid>/fdinfo/<fd> in order to retrieve the size of keys
and values for this map.

The definitions of union bpf_attr and of other eBPF-related elements
required for adequately performing the checks were added to the Linux
header file.

Processing related to file descriptors is added in a follow-up patch.
2018-08-14 20:47:19 +01:00
Philippe Waroquiers
8bc2b6fd26 Fix 392118 - unhandled amd64-linux syscall: 332 (statx)
Code patch provided by Mattias Andrée

Added a regression test to (somewhat) test stat and statx.

Tested on amd64 only.
2018-08-11 15:56:56 +02:00
Petar Jovanovic
f9606bc01c mips: add membarrier system call support
Fixes none/tests/linux/membarrier on MIPS platforms.
2018-08-07 14:09:43 +02:00
Mark Wielaard
fbbb696c5d Mask AT_HWCAPS on arm64 to those instructions VEX implements.
This patch makes sure that the process running under valgrind only sees
the AES, PMULL, SHA1, SHA2, CRC32, FP, and ASIMD features in auxv AT_HWCAPS.

https://bugs.kde.org/show_bug.cgi?id=381556
2018-06-21 08:17:11 +02:00
Petar Jovanovic
9a6cf7a41c mips64: add N32 ABI support
Adding MIPS N32 ABI support.

BZ issue - #345763.

Contributed and maintained by mulitple people over the years:
  Crestez Dan Leonard, Maran Pakkirisamy, Dimitrije Nikolic,
  Aleksandar Rikalo, Tamara Vlahovic.
2018-06-14 17:40:08 +00:00
Petar Jovanovic
ac58a6b857 mips64: use RegWord where appplicable
Use RegWord type in mips64.

Part of the changes required for MIPS N32 ABI support.
BZ issue - #345763.

Contributed by:
  Dimitrije Nikolic, Aleksandar Rikalo and Tamara Vlahovic.
2018-06-14 17:40:08 +00:00
Petar Jovanovic
06546d831d mips64: define _VKI_NSIG_BPW based on the size of long
Define _VKI_NSIG_BPW in a similar way to how _NSIG_BPW is defined in kernel.

This will be important for N32 ABI changes. (BZ #345763)
2018-06-14 17:38:20 +00:00
Rhys Kidd
92d6a53886 Fix missing kevent_qos syscall (macOS 10.11). bz#383723
Based upon patch from Alexandru Croitor.
2018-06-03 12:53:18 -04:00
Philippe Waroquiers
54145019b0 n-i-bz Fix possible stack trashing by semctl syscall wrapping
The modified test none/tests/sem crashes with a SEGV when valgrind is compiled
with lto on various amd64 platforms (debian/gcc 6.3, RHEL7/gcc 6.4,
Ubuntu/gcc 7.2)

The problem is that the vki_semid_ds buf is not what is expected by the kernel:
the kernel expects a bigger structure vki_semid64_ds (at least on
these platforms).
Getting the sem_nsems seems to work by chance, as sem_nsems is at
the same offset in both vki_semid_ds and vki_semid64_ds.
However, e.g. the ctime was not set properly after syscall return,
and 2 words after sem_nsems were set to 0 by the kernel, causing
the SEGV, as a spilled register became 0.

Fix consists in using the 64 bit version for __NR_semctl.
Tested on debian/amd64 and s390x.
2018-04-01 14:31:40 +02:00
Tom Hughes
12d162aabc Update linux system call numbers. 2018-03-21 12:28:31 +00:00
Bart Van Assche
a05d86e562 Linux: Add support for the zoned block device ioctls
Shingled magnetic recording drives support a command set called ZBC
(Zoned Block Commands). Two new ioctls have been added to the Linux
kernel to support such drives, namely VKI_BLKREPORTZONE and
VKI_BLKRESETZONE. Add support to Valgrind for these ioctls.
2018-03-12 10:46:15 -07:00
Bart Van Assche
ccd1e177ee Linux: Add support for the BLKFLSBUF ioctl 2018-03-12 10:46:01 -07:00
Rhys Kidd
dcb83cf846 macos: Fix unhandled syscall: mach:43 (mach_generate_activity_id). bz#385279
Based upon a patch provided by Louis Brunner <louis.brunner.fr@gmail.com> and
tested by:
  FX           <fxcoudert@gcc.gnu.org>
  Chris Wilson <chris+kde@qwirx.com>
2018-02-11 19:56:58 -05:00
Ivo Raisr
bd077baa71 Add a simple progress-reporting facility.
Fixes BZ#384633.
Patch by: Julian Seward <jseward@acm.org>
2018-01-20 19:56:02 +00:00
Julian Seward
cceed053ce Bug 79362 - Debug info is lost for .so files when they are dlclose'd. Majorly reworked by Philippe Waroquiers. 2018-01-11 19:40:12 +01:00
Philippe Waroquiers
619fb35df7 Fix 376257 - helgrind history full speed up using a cached stack
This patch implements the flag --delta-stacktrace=yes/no.
Yes indicates to calculate the full history stack traces by
changing just the last frame if no call/return instruction was
executed.
This can speed up helgrind by up to 25%.

This flags is currently set to yes only on linux x86 and amd64, as some
platform dependent validation of the used heuristics is needed before
setting the default to yes on a platform. See function check_cached_rcec_ok
in libhb_core.c for more details about how to validate/check the behaviour
on a new platform.
2017-11-02 21:33:35 +01:00
Rhys Kidd
1ce04c35c2 Preliminary support for Darwin 17.x (macOS 10.13) 2017-10-01 19:45:10 -04:00
Rhys Kidd
ed6ad13bc8 Fix missing workq_ops operations (macOS)
Related to discussion in bz#383723. Patch based upon one provided by
Andy Maloney.
2017-10-01 19:05:48 -04:00
Petar Jovanovic
c96148a2a1 mips: fix VKI_SIOCATMARK, VKI_SIOCSPGRP and VKI_SIOCGPGRP macros
Set correct values from Linux kernel.
See ./arch/mips/include/uapi/asm/sockios.h

This issue is covered by newly introduced memcheck test mips32/bad_sioc.
2017-09-27 16:04:31 +02:00
Rhys Kidd
55fe390c7a Fix missing pselect syscall (OS X 10.11). bz#379748
Based upon patch from Louis Brunner.
2017-09-03 12:55:52 -04:00
Ivo Raisr
ba17add79a Fix out-of-tree build on Solaris.
Simply #include config.h with no path at all.
Path by: Rob Boehne <robb@datalogics.com>
2017-08-17 22:38:18 +02:00
Mark Wielaard
33fa406cb1 Fix pub_tool_basics.h build issue with g++ 4.4.7.
g++ 4.4.7 doesn't accept union field initializers:
In file included from ../../include/pub_tool_vki.h:50,
                 from valgrind_cpp_test.cpp:13:
../../include/vki/vki-linux.h: In function ‘vki_cmsghdr* __vki_cmsg_nxthdr(void*, __vki_kernel_size_t, vki_cmsghdr*)’:
../../include/vki/vki-linux.h:673: error: expected primary-expression before ‘.’ token

Assign value after declaration which works for any g++ version.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16437
2017-06-06 09:03:03 +00:00
Julian Seward
fdd319ac66 Update version numbers for 3.13.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16431
2017-06-01 15:44:29 +00:00
Petar Jovanovic
81ba51146e mips: implement set/long_jmp instead of builtins
- VG_MINIMAL_SETJMP and VG_MINIMAL_LONGJMP for VGP_mips64_linux are defined.
- Implementation of VG_MINIMAL_SETJMP and VG_MINIMAL_LONGJMP for mips32 is
  improved by rescuing FP registers.

This should unbreak mips64/clang build.

Patch by Aleksandar Rikalo.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16378
2017-05-15 14:56:22 +00:00
Ivo Raisr
754487de4f Add Linux specific ioctl wrapper for CDROMREADMODE1
Fixes BZ#360429
Original patch by: Vasantha Ganesh K <vasanthaganesh.k@tuta.io>


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16358
2017-05-10 23:14:31 +00:00
Ivo Raisr
d73f2c748a Implement additional Xen hypercalls
Fixes BZ#373086
Patch by: Mihai DONȚU <mihai.dontu@gmail.com>


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16355
2017-05-10 18:04:17 +00:00
Ivo Raisr
4770c34059 Update Xen 4.6 domctl wrappers
Fixes BZ#377891
Patch by: Antony Saba <awsaba@gmail.com>



git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16354
2017-05-10 17:37:35 +00:00
Ivo Raisr
246bb0e25f Remove TileGX/Linux port.
Fixes BZ#379504.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16340
2017-05-08 17:21:59 +00:00
Ivo Raisr
d8f648486e Fix some spelling mistakes.
Fixes BZ#374719
Patch by: klemens <ka7@la-evento.com>


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16336
2017-05-05 22:13:20 +00:00
Ivo Raisr
38edd50c0e Update copyright end year to 2017 in preparation for 3.13 release.
n-i-bz



git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16333
2017-05-04 15:09:39 +00:00
Rhys Kidd
8226909643 macos: Fix unhandled syscall: mach:70 (host_create_mach_voucher_trap). bz#379390
Based upon a patch from Louis Brunner.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16326
2017-04-30 21:52:33 +00:00
Rhys Kidd
bc4ee3af41 macos: Block out a few more macOS / Darwin syscalls. n-i-bz.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16324
2017-04-30 01:59:33 +00:00
Rhys Kidd
254ca9753a macos: Add a no-op wrapper for a new-in-10.10 syscall: fstatat64
Patch from Louis Brunner.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16323
2017-04-30 00:34:59 +00:00
Rhys Kidd
fd128453ff macos: Add a no-op wrapper for a new-in-10.10 syscall: faccessat
Patch from Louis Brunner.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16322
2017-04-30 00:28:10 +00:00
Rhys Kidd
2cc6181ab4 macos: Add a no-op wrapper for a new-in-10.10 syscall: csrctl
Patch from Louis Brunner.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16321
2017-04-30 00:09:56 +00:00
Ivo Raisr
c356e1c01f Syscall wrapper for prctl(PR_SET_NAME) must not check more than 16 bytes.
Fixes BZ#379039.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16314
2017-04-26 19:27:14 +00:00