Commit Graph

226 Commits

Author SHA1 Message Date
Philippe Waroquiers
f2e1687cb8 Fix misplaced closing parenthesis in various VG_(....) calls
At many places, we have:
   VG_(fun(a,b,c))
instead of
   VG_(fun)(a,b,c)
So, fix these cases, found using:
grep -n -i -e 'VG_([a-z][a-z0-9_]*[^a-z0-9_)]' *.c */*.c */*/*.c



git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15776
2016-01-27 22:35:14 +00:00
Florian Krohm
45e3d3012d In ML_(am_allocate_segname) do not set the reference count of the
slot to 1. Rather do that in add_segment which is where the segment
refering to that name actually comes into existence.
Properly handle the case in add_segment where the to-be-added segment
and one (or more) of the segments it replaces have the same name
This may occur when doing a mremap.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15761
2016-01-16 21:44:31 +00:00
Florian Krohm
f44db9afb3 Remove code that has no effect. Looks like a leftover from early
debugging days.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15760
2016-01-16 21:12:57 +00:00
Philippe Waroquiers
647642d093 fix n-i-bz false positive leaks due to aspacemgr merging non heap segments with heap segments.
aspace mgr provides VG_(am_mmap_client_heap) that mmaps memory and
marks it as being client heap memory. Marking superblock segments used
for malloc/free as heap is critical for correct leak search: segments
mmap-ed for malloc/free cannot be considered as part of the root set.
On the other hand, other mmap-ed segments cannot be marked as client
heap, otherwise these segments will not be part of the root set, and
will not be scanned.

aspacemgr merges adjacent segments when they have the same characteristics
e.g. kind, RWX and isCH (is client heap) must be the same (see function
maybe_merge_nsegments).

However, VG_(am_mmap_client_heap) has a bug:
  * it first mmaps a normal segment (not marked as heap) using
     VG_(am_mmap_anon_float_client)
  * it then searches the segment that contains the just mmap-ed address and
    marks it as heap.
    
The problem is that VG_(am_mmap_anon_float_client) has already
possibly merged the new segment with a neighbour segment, without
taking the to be marked isCH into account, as the newly allocated memory
has not yet been marked as Client Heap.  So, this results in some memory being
marked as client heap, while it in fact is not client heap. This
memory will then not be scanned by the leak search.

The fix consists in having VG_(am_mmap_anon_float_client) and
VG_(am_mmap_client_heap) calling a new function
am_mmap_anon_float_client, which will mark (or not) the new segment as
client heap *before* trying to merge it with neighbouring segments.
Then the new (heap) segment will only be merged with neighbours that are also
client heap segments.



git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15759
2016-01-14 20:23:11 +00:00
Florian Krohm
1dc171f490 Strange segments in /proc/self/maps have been observed in the field.
Namely those with a file name and an inode number but without major
and minor device numbers. See for instance https://bugs.kde.org/124528#c11
This patch also recognises segments with a file name as FileV segments
(which is what valgrind used to do prior to r5818).


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15632
2015-09-05 21:27:58 +00:00
Ivo Raisr
7a4cc7d5fd Add support for ldsoexec on Solaris.
Solaris runtime linker allows to run dynamically linked programs indirectly, as:
    ld.so.1 <dynamic_executable>
This is now possible under Valgrind as well.

Fixes BZ#351858.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15607
2015-08-31 21:31:09 +00:00
Julian Seward
adc2dafee9 Update copyright dates, to include 2015. No functional change.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15577
2015-08-21 11:32:26 +00:00
Florian Krohm
e56a4a50df Fix printf format inconsistencies as pointed out by gcc -Wformat-signedness.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15499
2015-08-05 21:16:09 +00:00
Julian Seward
ac60633d65 Bug 345248 - add support for Solaris OS in valgrind
Authors of this port:
    Petr Pavlu         setup@dagobah.cz
    Ivo Raisr          ivosh@ivosh.net
    Theo Schlossnagle  theo@omniti.com
            


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15426
2015-07-21 14:44:28 +00:00
Florian Krohm
20efd87659 Revert an accidental change to the address space manager that sneaked
in in r15394.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15396
2015-07-06 20:22:16 +00:00
Florian Krohm
7a474c9455 Fix typos in source code. Patch by Dmitriy (olshevskiy87@bk.ru).
Fixes BZ #349874


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15394
2015-07-05 21:53:33 +00:00
Florian Krohm
0b6735e2ed Fix a comment.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15355
2015-06-25 21:12:44 +00:00
Florian Krohm
4eeecae9b7 fbit_mask needs to be unsigned because it sometimes shifts a '1'
into the MSB. Found by ubsan.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15346
2015-06-19 12:01:07 +00:00
Florian Krohm
b5ae4edaaf Wraparounds are never allowed -- not evern for MAny requests.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15292
2015-05-26 17:59:50 +00:00
Florian Krohm
50465bca95 Comment only change.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15270
2015-05-22 09:17:28 +00:00
Florian Krohm
31536d92a1 Remove an incorrect assertion. Need to consider SkShmC segments as well.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15269
2015-05-21 22:41:39 +00:00
Florian Krohm
e197c8e00d Changes for tilegx: Use VKI_AT_FDCWD not AT_FDCWD.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15227
2015-05-13 21:26:46 +00:00
Florian Krohm
463aa75635 In functions VG_(am_relocate_nooverlap_client) and VG_(am_extend_map_client)
need to allow SkShmC segments, too.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15221
2015-05-12 21:52:08 +00:00
Florian Krohm
7548da2acb Simplify is_valid_for taking advantage of the fact that SegKinds
are one-hot encoded.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15201
2015-05-10 11:07:06 +00:00
Rhys Kidd
9fe1f89425 Fix aspacem segment mismatch: seen with none/tests/bigcode
bz#345824

Tested on OS X 10.9 and OS X 10.10.

Before:

== 595 tests, 237 stderr failures, 23 stdout failures, 0 stderrB failures, 0 stdoutB failures, 31 post failures ==

After:

== 595 tests, 236 stderr failures, 22 stdout failures, 0 stderrB failures, 0 stdoutB failures, 31 post failures ==


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15171
2015-05-01 06:29:51 +00:00
Florian Krohm
307f73e22b Fix the namespace of the functions dealing with segment names.
As those are private to the address space manager they should
be ML_ not VG_ prefixed.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15165
2015-04-30 17:34:04 +00:00
Florian Krohm
2d01f78684 Rename VG_(am_is_bogus_client_stack_pointer) to
VG_(am_addr_is_in_extensible_client_stack).


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15132
2015-04-22 14:16:11 +00:00
Florian Krohm
3e50adbd1c Fix a silly bug.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15131
2015-04-22 13:50:13 +00:00
Julian Seward
082f9298a1 Add a port to Linux/TileGx. Zhi-Gang Liu (zliu@tilera.com)
Valgrind aspects, to match vex r3124.

See bug 339778 - Linux/TileGx platform support to Valgrind



git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15080
2015-04-10 12:30:09 +00:00
Florian Krohm
acc090b03a Certain kernels on s390 provide extra read permissions on executable
segments. See discussion here: https://bugs.kde.org/show_bug.cgi?id=345824#c4
Making sure that rx and x compare equal.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15075
2015-04-07 20:43:55 +00:00
Florian Krohm
0f10b973f1 Followup to r14898 which changes the storage of segment names by
putting them into a string table.
This patch adds reference counting to segment names and frees them
when they are no longer used. The so freed memory can be reclaimed to
store future segment names.
New file coregrind/m_aspacemgr/aspacemgr-segnames.c which has all the
code dealing with segment names. Carved out of aspacemgr-linux.c
Detailled comments in the code.
Fixes BZ 344559.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15073
2015-04-06 21:34:30 +00:00
Florian Krohm
b8c19b3f67 Change the minimum allowable value of aspacem_minAddr to
be VKI_PAGE_SIZE. That follows from the requirement that
the address ought to be page aligned and > 0. 


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15042
2015-03-27 08:47:22 +00:00
Florian Krohm
913972366f Add function VG_(am_is_valid_for_aspacem_minAddr) so that the parser
for command line options does not need to know what addresses are valid
for aspacem_minAddr.
That information should be hidden in the address space manager.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15040
2015-03-26 21:55:00 +00:00
Florian Krohm
e7674cfdbb Add VG_(am_is_bogus_client_stack_pointer)(Addr).
The function is used in VG_(client_syscall) to avoid extending the stack
when it is clear that the current value of the stack pointer does not
point into a segment that looks like a stack segment.
See the comments in the code there.
As a side effect of this we can now revert r15018 which increased
the stack size of the alternate stack in memcheck/tests/sigaltstack.c.
The reason is that the belief at the time: "alternate stack is too small"
was not correct. What instead happened was that VG_(client_syscall) called
VG_(extend_stack) without need (the syscall was tgkill) and the new stack
pointer happened to be in a file segment. 
In other words: the current stack pointer was still within the alternate
stack, i.e. the alternate stack was (barely) large enough.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15034
2015-03-23 17:13:04 +00:00
Philippe Waroquiers
4b70c77ad7 Fix non portability spotted by Florian:
An array must have at least 1 element.
0 element is accepted by gcc but is not portable.



git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15006
2015-03-12 22:46:58 +00:00
Philippe Waroquiers
826502e89a Implement command line option --valgrind-stacksize=<number>
This allows to decrease memory usage when using many threads,
if no big stacksize is needed by Valgrind.
If needed (e.g. for demangling big c++ symbols), the V stacksize
can be increased.



git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15004
2015-03-12 20:43:46 +00:00
Florian Krohm
a016e927bb New function VG_(am_mmap_client_heap) which swallows
VG_(am_set_segment_isCH_if_SkAnonC).
Rename VG_(am_set_segment_hasT_if_client_segment) to
VG_(am_set_segment_hasT) passing in an address (because that function
cannot possible take a pointer to a *const* segment). Also assert that
the segment containing the address is a client segment. Everything else
is a bug.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14993
2015-03-07 23:01:14 +00:00
Florian Krohm
1f8ced27c3 Produce a user message in case of stack overflow.
Change VG_(extend_stack) and VG_(am_extend_into_adjacent_reservation_client)
accordingly. 
Remove some redundant checking.
Add testcase.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14974
2015-03-03 14:56:17 +00:00
Florian Krohm
f8a625781c Change the prototype of VG_(am_extend_into_adjacent_reservation_client)
to match VG_(am_extend_map_client) for consistency.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14965
2015-02-26 16:07:12 +00:00
Florian Krohm
d59ebddc38 Change VG_(am_extend_map_client) as follows:
- Tighten up on asserts
- Simplify; as the function grows memory into a free segment, there
  cannot possibly be any translations to be discarded. Free segments
  do not have translations. sane_NSegment will make sure.
- Change the prototype to take in the start address of the mapping and
  return a pointer to the resized segment. Previously, the code 

   ok = VG_(am_extend_map_client)( &d, old_seg, needL );
   if (!ok)
      goto eNOMEM;
   VG_TRACK( new_mem_mmap, needA, needL, 
                           old_seg->hasR, old_seg->hasW, old_seg->hasX,

  was examining old_seg->hasR etc even though VG_(am_extend_map_client)
  stated that *old_seg was invalid after the function returned.
  That wasn't exactly a problem, but clearly looked wrong.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14963
2015-02-25 10:06:06 +00:00
Florian Krohm
e1b0a8e30d Fix an off-by-one error - this time, do it right.
A segment with start == end is not empty.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14957
2015-02-24 11:23:51 +00:00
Florian Krohm
7bd3d1e798 Revert r14954. If the end of a segment is 0xfffff.....fffff
then end + 1 == 0 and any start address will be >= end.
Think some more.....


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14956
2015-02-23 21:56:16 +00:00
Florian Krohm
8d088fa71e Fix an off-by-one error. A segment with start == end is not
empty.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14954
2015-02-23 19:57:12 +00:00
Florian Krohm
00ffec50e5 Pass in a mask of segment kinds to VG_(get_segment_starts)
and VG_(am_get_segment_starts) to indicate which segments
should be collected. That should solve the following problem:
in m_main.c we used to:

      seg_starts = VG_(get_segment_starts)( &n_seg_starts );

      for (i = 0; i < n_seg_starts; i++) {
         Word j, n;
         NSegment const* seg 
            = VG_(am_find_nsegment)( seg_starts[i] );
         vg_assert(seg);
         if (seg->kind == SkFileC || seg->kind == SkAnonC) {

         ...
         // ... dynamic memory allocation for valgrind
         ...
      }

This caused the vassert(seg) to fire because the dynamic memory
allocation further down the loop changed segments such that a 
valgrind segment which used to be non-SkFree suddenly became 
SkFree and hence VG_(am_find_nsegment) returned NULL. Whoom.

With this revision we only collect the segments we're really
interested in. For the example above that is all client segments.
So if V allocates memory -- fine. That will not change the layout
of client segments.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14949
2015-02-20 14:00:23 +00:00
Florian Krohm
22d7bf79ad Update a comment.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14941
2015-02-17 21:51:53 +00:00
Florian Krohm
09b7e14ba9 Update comment for VG_(am_find_nsegment) to match the code.
Likewise for VG_(am_next_nsegment). Also make the code similar to
VG_(am_find_nsegment) for easier comprehension.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14937
2015-02-16 23:04:53 +00:00
Florian Krohm
798e5a7707 Translations are allowed from all client segments. Update comments
and rename VG_(am_set_segment_hasT_if_SkFileC_or_SkAnonC) to 
VG_(am_set_segment_hasT_if_client_segment). Change it so it handles
all client segments.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14936
2015-02-16 22:58:30 +00:00
Florian Krohm
797f339875 Misc tweaks in segAddr_to_index:
(1) It is always invalid for the incoming segment pointer to be
    out of range. Assert that.
(2) Let the compiler do the address arithmetic. They're good at that
    and therefore:
(3) No asserts needed to check the result.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14933
2015-02-14 21:17:46 +00:00
Philippe Waroquiers
e352ffcafe Fix debug output of aspacemgr
The list of segnames was shown with a seq nr,
while each segment was referencing its segname with an offset.
The patch ensures that at all places, both the seq nr and the
offset is output



git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14911
2015-02-05 22:30:57 +00:00
Florian Krohm
aa74d46212 Replace the SegName array with a simple string table.
The validity of this change follows from the following observations:

(1) There is a single source for allocating and storing segment names,
    namely allocate_segname.
(2) For all invocations of allocate_segname the returned value (which
    represents the segmant name) is assigned to NSegment::fnIdx.
(3) All but one assignments to NSegment::fnIdx assign allocate_segname.
    The single exception assigns -1 in init_nsegment. That function is
    called whenever a new segment (named or unnamed) is allocated.

For a segment name to become unused there must be an assignment to
NSegment::fnIdx which was previously assigned a return value from 
allocate_segname. There is no such assignment.
It follows that all segment names are in use at all times, hence
SegName::inUse == True for all SegNames. So we can constant fold it
and don't need to represent it.
Pass 3 in preen_nsegments is obsolete as there are no segment names to
garbage collect.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14898
2015-01-31 00:29:50 +00:00
Florian Krohm
e882a1a485 Remove confusing function attribute. The function is always used (on all platforms).
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14897
2015-01-30 22:21:16 +00:00
Florian Krohm
2a38d9d56a Fix an incorrect comment. Add asserts.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14896
2015-01-29 23:01:14 +00:00
Florian Krohm
cb3b3b58b1 Remove unused field from NSegment structure.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14891
2015-01-27 20:46:19 +00:00
Florian Krohm
e70cb7b851 VG_(am_get_filename) returns a pointer to memory that belongs to the
address space manager. Callers should neither modify the string nor
free it (as the string resides is statically allocated memory). That
calls for a   const HChar *
The type change exposed two bugs. One in m_addrinfo.c and one in 
m_debuginfo.c. In both cases the returned string could possibly be freed later
on. So we need to strdup it first. Now fixed.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14886
2015-01-24 00:02:19 +00:00
Florian Krohm
d12d0b2bd9 Add function attributes.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14884
2015-01-23 16:53:06 +00:00