@@ -79,7 +79,7 @@ impl LockInfo {
7979pub struct AllocId ( u64 ) ;
8080
8181#[ derive( Debug ) ]
82- enum AllocIdKind {
82+ pub enum AllocIdKind {
8383 /// We can't ever have more than `usize::max_value` functions at the same time
8484 /// since we never "deallocate" functions
8585 Function ( usize ) ,
@@ -89,7 +89,7 @@ enum AllocIdKind {
8989}
9090
9191impl AllocIdKind {
92- fn into_alloc_id ( self ) -> AllocId {
92+ pub fn into_alloc_id ( self ) -> AllocId {
9393 match self {
9494 AllocIdKind :: Function ( n) => AllocId ( n as u64 ) ,
9595 AllocIdKind :: Runtime ( n) => AllocId ( ( 1 << 63 ) | n) ,
@@ -103,10 +103,10 @@ impl AllocId {
103103 self . 0 >> 63
104104 }
105105 /// Yields everything but the discriminant bits
106- fn index ( self ) -> u64 {
106+ pub fn index ( self ) -> u64 {
107107 self . 0 & ( ( 1 << 63 ) - 1 )
108108 }
109- fn into_alloc_id_kind ( self ) -> AllocIdKind {
109+ pub fn into_alloc_id_kind ( self ) -> AllocIdKind {
110110 match self . discriminant ( ) {
111111 0 => AllocIdKind :: Function ( self . index ( ) as usize ) ,
112112 1 => AllocIdKind :: Runtime ( self . index ( ) ) ,
@@ -1088,6 +1088,17 @@ impl<'a, 'tcx, M: Machine<'tcx>> Memory<'a, 'tcx, M> {
10881088 let dest = dest. to_ptr ( ) ?;
10891089 self . check_relocation_edges ( src, size) ?;
10901090
1091+ // first copy the relocations to a temporary buffer, because
1092+ // `get_bytes_mut` will clear the relocations, which is correct,
1093+ // since we don't want to keep any relocations at the target.
1094+
1095+ let relocations: Vec < _ > = self . relocations ( src, size) ?
1096+ . map ( |( & offset, & alloc_id) | {
1097+ // Update relocation offsets for the new positions in the destination allocation.
1098+ ( offset + dest. offset - src. offset , alloc_id)
1099+ } )
1100+ . collect ( ) ;
1101+
10911102 let src_bytes = self . get_bytes_unchecked ( src, size, align) ?. as_ptr ( ) ;
10921103 let dest_bytes = self . get_bytes_mut ( dest, size, align) ?. as_mut_ptr ( ) ;
10931104
@@ -1113,7 +1124,8 @@ impl<'a, 'tcx, M: Machine<'tcx>> Memory<'a, 'tcx, M> {
11131124 }
11141125
11151126 self . copy_undef_mask ( src, dest, size) ?;
1116- self . copy_relocations ( src, dest, size) ?;
1127+ // copy back the relocations
1128+ self . get_mut ( dest. alloc_id ) ?. relocations . extend ( relocations) ;
11171129
11181130 Ok ( ( ) )
11191131 }
@@ -1388,22 +1400,6 @@ impl<'a, 'tcx, M: Machine<'tcx>> Memory<'a, 'tcx, M> {
13881400 }
13891401 Ok ( ( ) )
13901402 }
1391-
1392- fn copy_relocations (
1393- & mut self ,
1394- src : MemoryPointer ,
1395- dest : MemoryPointer ,
1396- size : u64 ,
1397- ) -> EvalResult < ' tcx > {
1398- let relocations: Vec < _ > = self . relocations ( src, size) ?
1399- . map ( |( & offset, & alloc_id) | {
1400- // Update relocation offsets for the new positions in the destination allocation.
1401- ( offset + dest. offset - src. offset , alloc_id)
1402- } )
1403- . collect ( ) ;
1404- self . get_mut ( dest. alloc_id ) ?. relocations . extend ( relocations) ;
1405- Ok ( ( ) )
1406- }
14071403}
14081404
14091405/// Undefined bytes
0 commit comments