Be careful not to clobber the "initial"[0] registers in AutoRemoteSyscalls when restore_state_to()ing.
If we're restoring the state multiple times to multiple different processes (e.g. after cloning a checkpoint) clobbering initial_regs.ip with initial_ip will cause us to write replaced_bytes back to the wrong location if the ip did in fact change.
[0] we should rename this.
diff --git a/src/AutoRemoteSyscalls.cc b/src/AutoRemoteSyscalls.cc
index 1eebb3e..07d8402 100644
--- a/src/AutoRemoteSyscalls.cc
+++ b/src/AutoRemoteSyscalls.cc
@@ -188,10 +188,11 @@
t->write_mem(remote_ptr<uint8_t>(initial_regs.ip().to_data_ptr<uint8_t>()),
replaced_bytes.data(), replaced_bytes.size());
}
- initial_regs.set_ip(initial_ip);
- initial_regs.set_sp(initial_sp);
+ auto regs = initial_regs;
+ regs.set_ip(initial_ip);
+ regs.set_sp(initial_sp);
// Restore stomped registers.
- t->set_regs(initial_regs);
+ t->set_regs(regs);
t->set_status(restore_wait_status);
}