Skip to content

Commit 00fb886

Browse files
author
florian
committedMar 7, 2015
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 a5019735-40e9-0310-863c-91ae7b9d1cf9
1 parent 4dbb7a3 commit 00fb886

File tree

4 files changed

+38
-56
lines changed

4 files changed

+38
-56
lines changed
 

‎coregrind/m_aspacemgr/aspacemgr-linux.c

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2568,6 +2568,23 @@ SysRes VG_(am_shared_mmap_file_float_valgrind)
25682568
fd, offset );
25692569
}
25702570

2571+
/* Convenience wrapper around VG_(am_mmap_anon_float_client) which also
2572+
marks the segment as containing the client heap. This is for the benefit
2573+
of the leak checker which needs to be able to identify such segments
2574+
so as not to use them as sources of roots during leak checks. */
2575+
SysRes VG_(am_mmap_client_heap) ( SizeT length, Int prot )
2576+
{
2577+
SysRes res = VG_(am_mmap_anon_float_client)(length, prot);
2578+
2579+
if (! sr_isError(res)) {
2580+
Addr addr = sr_Res(res);
2581+
Int ix = find_nsegment_idx(addr);
2582+
2583+
nsegments[ix].isCH = True;
2584+
}
2585+
return res;
2586+
}
2587+
25712588
/* --- --- munmap helper --- --- */
25722589

25732590
static
@@ -2684,33 +2701,15 @@ Bool VG_(am_change_ownership_v_to_c)( Addr start, SizeT len )
26842701
return True;
26852702
}
26862703

2687-
/* 'seg' must have been obtained from VG_(am_find_nsegment), and still valid.
2688-
If it denotes a SkAnonC (anonymous client mapping) area, set the .isCH
2689-
(is-client-heap) flag for that area. Otherwise do nothing.
2690-
(Bizarre interface so that the same code works for both Linux and
2691-
AIX and does not impose inefficiencies on the Linux version.) */
2692-
void VG_(am_set_segment_isCH_if_SkAnonC)( const NSegment* seg )
2704+
/* Set the 'hasT' bit on the segment containing ADDR indicating that
2705+
translations have or may have been taken from this segment. ADDR is
2706+
expected to belong to a client segment. */
2707+
void VG_(am_set_segment_hasT)( Addr addr )
26932708
{
2694-
aspacem_assert(seg != NULL);
2695-
Int i = segAddr_to_index( seg );
2696-
if (nsegments[i].kind == SkAnonC) {
2697-
nsegments[i].isCH = True;
2698-
} else {
2699-
aspacem_assert(nsegments[i].isCH == False);
2700-
}
2701-
}
2702-
2703-
/* Same idea as VG_(am_set_segment_isCH_if_SkAnonC), except set the
2704-
segment's hasT bit (has-cached-code) if this is a client segment,
2705-
i.e. SkFileC, SkAnonC, or SkShmC. */
2706-
void VG_(am_set_segment_hasT_if_client_segment)( const NSegment* seg )
2707-
{
2708-
aspacem_assert(seg != NULL);
2709-
Int i = segAddr_to_index( seg );
2710-
if (nsegments[i].kind == SkAnonC || nsegments[i].kind == SkFileC ||
2711-
nsegments[i].kind == SkShmC) {
2712-
nsegments[i].hasT = True;
2713-
}
2709+
Int i = find_nsegment_idx(addr);
2710+
SegKind kind = nsegments[i].kind;
2711+
aspacem_assert(kind == SkAnonC || kind == SkFileC || kind == SkShmC);
2712+
nsegments[i].hasT = True;
27142713
}
27152714

27162715

‎coregrind/m_mallocfree.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -853,15 +853,11 @@ Superblock* newSuperblock ( Arena* a, SizeT cszB )
853853

854854
if (a->clientmem) {
855855
// client allocation -- return 0 to client if it fails
856-
sres = VG_(am_mmap_anon_float_client)
856+
sres = VG_(am_mmap_client_heap)
857857
( cszB, VKI_PROT_READ|VKI_PROT_WRITE|VKI_PROT_EXEC );
858858
if (sr_isError(sres))
859859
return 0;
860860
sb = (Superblock*)(Addr)sr_Res(sres);
861-
// Mark this segment as containing client heap. The leak
862-
// checker needs to be able to identify such segments so as not
863-
// to use them as sources of roots during leak checks.
864-
VG_(am_set_segment_isCH_if_SkAnonC)( VG_(am_find_nsegment)( (Addr)sb ) );
865861
} else {
866862
// non-client allocation -- abort if it fails
867863
sres = VG_(am_mmap_anon_float_valgrind)( cszB );

‎coregrind/m_translate.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1765,21 +1765,12 @@ Bool VG_(translate) ( ThreadId tid,
17651765
vg_assert(tres.n_sc_extents >= 0 && tres.n_sc_extents <= 3);
17661766
vg_assert(tmpbuf_used <= N_TMPBUF);
17671767
vg_assert(tmpbuf_used > 0);
1768-
1769-
/* Tell aspacem of all segments that have had translations taken
1770-
from them. Optimisation: don't re-look up vge.base[0] since seg
1771-
should already point to it. */
1772-
1773-
vg_assert( vge.base[0] == addr );
1774-
/* set 'translations taken from this segment' flag */
1775-
VG_(am_set_segment_hasT_if_client_segment)( seg );
17761768
} /* END new scope specially for 'seg' */
17771769

1778-
for (i = 1; i < vge.n_used; i++) {
1779-
NSegment const* seg
1780-
= VG_(am_find_nsegment)( vge.base[i] );
1781-
/* set 'translations taken from this segment' flag */
1782-
VG_(am_set_segment_hasT_if_client_segment)( seg );
1770+
/* Tell aspacem of all segments that have had translations taken
1771+
from them. */
1772+
for (i = 0; i < vge.n_used; i++) {
1773+
VG_(am_set_segment_hasT)( vge.base[i] );
17831774
}
17841775

17851776
/* Copy data at trans_addr into the translation cache. */

‎coregrind/pub_core_aspacemgr.h

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,10 @@ extern SysRes VG_(am_mmap_file_float_valgrind)
231231
extern SysRes VG_(am_shared_mmap_file_float_valgrind)
232232
( SizeT length, UInt prot, Int fd, Off64T offset );
233233

234+
/* Convenience wrapper around VG_(am_mmap_anon_float_client) which also
235+
marks the segment as containing the client heap. */
236+
extern SysRes VG_(am_mmap_client_heap) ( SizeT length, Int prot );
237+
234238
/* Unmap the given address range and update the segment array
235239
accordingly. This fails if the range isn't valid for the client.
236240
If *need_discard is True after a successful return, the caller
@@ -245,18 +249,10 @@ extern SysRes VG_(am_munmap_client)( /*OUT*/Bool* need_discard,
245249
suitable segment. */
246250
extern Bool VG_(am_change_ownership_v_to_c)( Addr start, SizeT len );
247251

248-
/* 'seg' must be NULL or have been obtained from
249-
VG_(am_find_nsegment), and still valid. If non-NULL, and if it
250-
denotes a SkAnonC (anonymous client mapping) area, set the .isCH
251-
(is-client-heap) flag for that area. Otherwise do nothing.
252-
(Bizarre interface so that the same code works for both Linux and
253-
AIX and does not impose inefficiencies on the Linux version.) */
254-
extern void VG_(am_set_segment_isCH_if_SkAnonC)( const NSegment* seg );
255-
256-
/* Same idea as VG_(am_set_segment_isCH_if_SkAnonC), except set the
257-
segment's hasT bit (has-cached-code) if this is a client segment,
258-
i.e. SkFileC, SkAnonC, or SkShmC. */
259-
extern void VG_(am_set_segment_hasT_if_client_segment)( const NSegment* );
252+
/* Set the 'hasT' bit on the segment containing ADDR indicating that
253+
translations have or may have been taken from this segment. ADDR is
254+
expected to belong to a client segment. */
255+
extern void VG_(am_set_segment_hasT)( Addr addr );
260256

261257
/* --- --- --- reservations --- --- --- */
262258

0 commit comments

Comments
 (0)
Please sign in to comment.