|
From: <sv...@va...> - 2005-09-20 12:07:19
|
Author: sewardj
Date: 2005-09-20 13:07:14 +0100 (Tue, 20 Sep 2005)
New Revision: 4699
Log:
amd64-linux: transfer ownership of the (incorrectly named) trampoline
area from V to C, so translations can be made from it.
Modified:
branches/ASPACEM/coregrind/m_aspacemgr/aspacemgr.c
branches/ASPACEM/coregrind/m_main.c
branches/ASPACEM/coregrind/m_redir.c
branches/ASPACEM/coregrind/m_trampoline.S
branches/ASPACEM/coregrind/pub_core_aspacemgr.h
branches/ASPACEM/coregrind/pub_core_redir.h
Modified: branches/ASPACEM/coregrind/m_aspacemgr/aspacemgr.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- branches/ASPACEM/coregrind/m_aspacemgr/aspacemgr.c 2005-09-20 12:05:3=
9 UTC (rev 4698)
+++ branches/ASPACEM/coregrind/m_aspacemgr/aspacemgr.c 2005-09-20 12:07:1=
4 UTC (rev 4699)
@@ -2069,7 +2069,47 @@
return am_munmap_both_wrk( start, len, False/*valgrind*/ );
}
=20
+/* Let (start,len) denote an area within a single Valgrind-owned
+ segment (anon or file). Change the ownership of [start, start+len)
+ to the client instead. Fails if (start,len) does not denote a
+ suitable segment. */
=20
+Bool VG_(am_change_ownership_v_to_c)( Addr start, SizeT len )
+{
+ Int i, iLo, iHi;
+
+ if (len =3D=3D 0)
+ return True;
+ if (start + len < start)
+ return False;
+ if (!VG_IS_PAGE_ALIGNED(start) || !VG_IS_PAGE_ALIGNED(len))
+ return False;
+
+ i =3D find_nsegment_idx(start);
+ if (nsegments[i].kind !=3D SkFileV && nsegments[i].kind !=3D SkAnonV)
+ return False;
+ if (start+len-1 > nsegments[i].end)
+ return False;
+
+ aspacem_assert(start >=3D nsegments[i].start);
+ aspacem_assert(start+len-1 <=3D nsegments[i].end);
+
+ /* This scheme is like how mprotect works: split the to-be-changed
+ range into its own segment(s), then mess with them (it). There
+ should be only one. */
+ split_nsegments_lo_and_hi( start, start+len-1, &iLo, &iHi );
+ aspacem_assert(iLo =3D=3D iHi);
+ switch (nsegments[iLo].kind) {
+ case SkFileV: nsegments[iLo].kind =3D SkFileC; break;
+ case SkAnonV: nsegments[iLo].kind =3D SkAnonC; break;
+ default: aspacem_assert(0); /* can't happen - guarded above */
+ }
+
+ preen_nsegments();
+ return True;
+}
+
+
/* --- --- --- reservations --- --- --- */
=20
/* Create a reservation from START .. START+LENGTH-1, with the given
Modified: branches/ASPACEM/coregrind/m_main.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- branches/ASPACEM/coregrind/m_main.c 2005-09-20 12:05:39 UTC (rev 4698=
)
+++ branches/ASPACEM/coregrind/m_main.c 2005-09-20 12:07:14 UTC (rev 4699=
)
@@ -2222,9 +2222,12 @@
//--------------------------------------------------------------
// Initialise the redirect table.
// p: init_tt_tc [so it can call VG_(search_transtab) safely]
+ // p: aspacem [so can change ownership of sysinfo pages]
//--------------------------------------------------------------
VG_(debugLog)(1, "main", "Initialise redirects\n");
- VG_(setup_code_redirect_table)();
+ { Bool setup_redirects_succeeded =3D VG_(setup_code_redirect_table)()=
;
+ vg_assert(setup_redirects_succeeded);
+ }
=20
//--------------------------------------------------------------
// setup file descriptors
Modified: branches/ASPACEM/coregrind/m_redir.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- branches/ASPACEM/coregrind/m_redir.c 2005-09-20 12:05:39 UTC (rev 469=
8)
+++ branches/ASPACEM/coregrind/m_redir.c 2005-09-20 12:07:14 UTC (rev 469=
9)
@@ -31,6 +31,8 @@
*/
=20
#include "pub_core_basics.h"
+#include "pub_core_debuglog.h"
+#include "pub_core_aspacemgr.h" // VG_(am_change_ownership_v_to_c)
#include "pub_core_debuginfo.h"
#include "pub_core_libcbase.h"
#include "pub_core_libcassert.h"
@@ -340,7 +342,7 @@
return r->to_addr;
}
=20
-void VG_(setup_code_redirect_table) ( void )
+Bool VG_(setup_code_redirect_table) ( void )
{
#if defined(VGP_x86_linux)
/* Redirect _dl_sysinfo_int80, which is glibc's default system call
@@ -364,6 +366,15 @@
(Addr)&VG_(amd64_linux_REDIR_FOR_vtime)=20
);
=20
+ { Addr co_start =3D VG_PGROUNDDN( (Addr)&VG_(trampoline_stuff_start=
) );
+ Addr co_endPlus =3D VG_PGROUNDUP( (Addr)&VG_(trampoline_stuff_end) =
);
+ VG_(debugLog)(1,"redir",
+ "transfer ownership V -> C of 0x%llx .. 0x%llx\n",
+ (ULong)co_start, (ULong)co_endPlus-1 );
+ return=20
+ VG_(am_change_ownership_v_to_c)( co_start, co_endPlus - co_start=
);
+ }
+
#elif defined(VGP_ppc32_linux)
=20
//CAB: TODO
Modified: branches/ASPACEM/coregrind/m_trampoline.S
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- branches/ASPACEM/coregrind/m_trampoline.S 2005-09-20 12:05:39 UTC (re=
v 4698)
+++ branches/ASPACEM/coregrind/m_trampoline.S 2005-09-20 12:07:14 UTC (re=
v 4699)
@@ -73,6 +73,15 @@
#else
#if defined(VGP_amd64_linux)
=20
+# define UD2_16 ud2 ; ud2 ; ud2 ; ud2 ;ud2 ; ud2 ; ud2 ; ud2
+# define UD2_64 UD2_16 ; UD2_16 ; UD2_16 ; UD2_16
+# define UD2_256 UD2_64 ; UD2_64 ; UD2_64 ; UD2_64
+# define UD2_1024 UD2_256 ; UD2_256 ; UD2_256 ; UD2_256
+# define UD2_PAGE UD2_1024 ; UD2_1024 ; UD2_1024 ; UD2_1024 =20
+
+ /* a leading page of unexecutable code */
+ UD2_PAGE
+=09
.global VG_(trampoline_stuff_start)
VG_(trampoline_stuff_start):
=20
@@ -99,7 +108,16 @@
.global VG_(trampoline_stuff_end)
VG_(trampoline_stuff_end):
=20
+ /* and a trailing page of unexecutable code */
+ UD2_PAGE
=20
+# undef UD2_16
+# undef UD2_64
+# undef UD2_256
+# undef UD2_1024
+# undef UD2_PAGE
+
+
/*---------------- ppc32-linux ----------------*/
#else
#if defined(VGP_ppc32_linux)
Modified: branches/ASPACEM/coregrind/pub_core_aspacemgr.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- branches/ASPACEM/coregrind/pub_core_aspacemgr.h 2005-09-20 12:05:39 U=
TC (rev 4698)
+++ branches/ASPACEM/coregrind/pub_core_aspacemgr.h 2005-09-20 12:07:14 U=
TC (rev 4699)
@@ -230,6 +230,12 @@
accordingly. This fails if the range isn't valid for valgrind. */
extern SysRes VG_(am_munmap_valgrind)( Addr start, SizeT length );
=20
+/* Let (start,len) denote an area within a single Valgrind-owned
+ segment (anon or file). Change the ownership of [start, start+len)
+ to the client instead. Fails if (start,len) does not denote a
+ suitable segment. */
+extern Bool VG_(am_change_ownership_v_to_c)( Addr start, SizeT len );
+
/* --- --- --- reservations --- --- --- */
=20
/* Create a reservation from START .. START+LENGTH-1, with the given
Modified: branches/ASPACEM/coregrind/pub_core_redir.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- branches/ASPACEM/coregrind/pub_core_redir.h 2005-09-20 12:05:39 UTC (=
rev 4698)
+++ branches/ASPACEM/coregrind/pub_core_redir.h 2005-09-20 12:07:14 UTC (=
rev 4699)
@@ -68,8 +68,9 @@
// before translating a basic block.
extern Addr VG_(code_redirect) ( Addr orig );
=20
-/* Set up some default redirects */
-extern void VG_(setup_code_redirect_table) ( void );
+/* Set up some default redirects. Returns False if failed, in which
+ case the start-up of Valgrind can be considered to have failed. */
+extern Bool VG_(setup_code_redirect_table) ( void );
=20
extern void VG_(resolve_existing_redirs_with_seginfo)(SegInfo *si);
=20
|