Skip to content
Permalink
Browse files

Ensure MappedFileMonitor configuration in replay exactly matches reco…

…rding
  • Loading branch information...
rocallahan committed Apr 26, 2019
1 parent 5312653 commit bce17104ff55118b5e774f079843230af5fdaa89
Showing with 23 additions and 7 deletions.
  1. +8 −2 src/TraceStream.cc
  2. +4 −2 src/TraceStream.h
  3. +3 −1 src/record_syscall.cc
  4. +6 −2 src/replay_syscall.cc
  5. +2 −0 src/rr_trace.capnp
@@ -840,7 +840,8 @@ static bool starts_with(const string& s, const string& with) {

TraceWriter::RecordInTrace TraceWriter::write_mapped_region(
RecordTask* t, const KernelMapping& km, const struct stat& stat,
const vector<TraceRemoteFd>& extra_fds, MappingOrigin origin) {
const vector<TraceRemoteFd>& extra_fds, MappingOrigin origin,
bool skip_monitoring_mapped_fd) {
MallocMessageBuilder map_msg;
trace::MMap::Builder map = map_msg.initRoot<trace::MMap>();
map.setFrameTime(global_time);
@@ -864,6 +865,7 @@ TraceWriter::RecordInTrace TraceWriter::write_mapped_region(
e.setTid(r.tid);
e.setFd(r.fd);
}
map.setSkipMonitoringMappedFd(skip_monitoring_mapped_fd);
auto src = map.getSource();
string backing_file_name;

@@ -981,7 +983,8 @@ void TraceWriter::write_mapped_region_to_alternative_stream(
KernelMapping TraceReader::read_mapped_region(MappedData* data, bool* found,
ValidateSourceFile validate,
TimeConstraint time_constraint,
vector<TraceRemoteFd>* extra_fds) {
vector<TraceRemoteFd>* extra_fds,
bool* skip_monitoring_mapped_fd) {
if (found) {
*found = false;
}
@@ -1019,6 +1022,9 @@ KernelMapping TraceReader::read_mapped_region(MappedData* data, bool* found,
extra_fds->push_back({ f.getTid(), f.getFd() });
}
}
if (skip_monitoring_mapped_fd) {
*skip_monitoring_mapped_fd = map.getSkipMonitoringMappedFd();
}
auto src = map.getSource();
switch (src.which()) {
case trace::MMap::Source::Which::ZERO:
@@ -199,7 +199,8 @@ class TraceWriter : public TraceStream {
RecordInTrace write_mapped_region(RecordTask* t, const KernelMapping& map,
const struct stat& stat,
const std::vector<TraceRemoteFd>& extra_fds,
MappingOrigin origin = SYSCALL_MAPPING);
MappingOrigin origin = SYSCALL_MAPPING,
bool skip_monitoring_mapped_fd = false);

static void write_mapped_region_to_alternative_stream(
CompressedWriter& mmaps, const MappedData& data, const KernelMapping& km);
@@ -325,7 +326,8 @@ class TraceReader : public TraceStream {
MappedData* data = nullptr, bool* found = nullptr,
ValidateSourceFile validate = VALIDATE,
TimeConstraint time_constraint = CURRENT_TIME_ONLY,
std::vector<TraceRemoteFd>* extra_fds = nullptr);
std::vector<TraceRemoteFd>* extra_fds = nullptr,
bool* skip_monitoring_mapped_fd = nullptr);

/**
* Read a task event (clone or exec record) from the trace.
@@ -4712,7 +4712,9 @@ static void process_mmap(RecordTask* t, size_t length, int prot, int flags,
if (flags & MAP_SHARED) {
monitor_this_fd = monitor_fd_for_mapping(t, fd, st, extra_fds);
}
if (t->trace_writer().write_mapped_region(t, km, st, extra_fds) ==
if (t->trace_writer().write_mapped_region(t, km, st, extra_fds,
TraceWriter::SYSCALL_MAPPING,
!monitor_this_fd) ==
TraceWriter::RECORD_IN_TRACE) {
off64_t end = (off64_t)st.st_size - km.file_offset_bytes();
off64_t nbytes = min(end, (off64_t)km.size());
@@ -859,8 +859,10 @@ static void process_mmap(ReplayTask* t, const TraceFrame& trace_frame,
} else {
TraceReader::MappedData data;
vector<TraceRemoteFd> extra_fds;
bool skip_monitoring_mapped_fd;
KernelMapping km = t->trace_reader().read_mapped_region(&data, nullptr,
TraceReader::VALIDATE, TraceReader::CURRENT_TIME_ONLY, &extra_fds);
TraceReader::VALIDATE, TraceReader::CURRENT_TIME_ONLY, &extra_fds,
&skip_monitoring_mapped_fd);

if (data.source == TraceReader::SOURCE_FILE &&
data.file_size_bytes > data.data_offset_bytes) {
@@ -883,7 +885,9 @@ static void process_mmap(ReplayTask* t, const TraceFrame& trace_frame,
}
if (length > 0) {
if (MAP_SHARED & flags) {
extra_fds.push_back({ t->rec_tid, fd });
if (!skip_monitoring_mapped_fd) {
extra_fds.push_back({ t->rec_tid, fd });
}
finish_shared_mmap(t, remote, addr, length, prot, flags, extra_fds,
offset_pages, km, data);
} else {
@@ -115,6 +115,8 @@ struct MMap {
# File descriptors pointing to this mapping, other than the one
# that was mapped (for non-anonymous mappings).
extraFds @17 :List(RemoteFd);
# True if the mapped fd was read-only and should not be monitored
skipMonitoringMappedFd @18 :Bool;
}

# The 'tasks' file is a sequence of these.

0 comments on commit bce1710

Please sign in to comment.
You can’t perform that action at this time.