/* Perform binary difference on all monitored ranges */ void check_monitored_ranges() { /* incremental update */ for(MemIntervalSet::const_iterator i=persistent.begin(); i!=persistent.end(); ++i) { /* Check whether range is already stored */ FlightRecStorage::iterator j = stored.find(*i); if(j == stored.end()) { /* Not in storage at all, write whole block. */ //printf("Not in storage at all, write whole block.\n"); write_mem_range(i->start, i->end); /* Copy memory block to newly allocated storage, * so that we can compare against it later. */ void *block = malloc(i->end - i->start); memcpy(block, (void*)i->start, i->end - i->start); stored.insert(std::make_pair(*i, block)); } else { if(j->first.start != i->start || j->first.end != i->end) { /* Huh? Not exactly the same range, could do an intersection here but * currently this is not supported, write the entire range */ //printf("Warning: stored block mismatch start1=%p start2=%p end1=%p end2=%p\n", j->first.start, i->start, j->first.end, i->end); write_mem_range(i->start, i->end); } else { /* compare ranges and write differences */ /* copy new values to storage */ bdiff((size_t)j->second, i->start, i->end - i->start, diff_granularity); memcpy(j->second, (void*)i->start, i->end - i->start); } } } }
~FlightRecorder() { if(valid) { close(fd); pthread_mutex_destroy(&mutex); // Free comparison blocks in stored for(FlightRecStorage::iterator i=stored.begin(); i!=stored.end(); ++i) { free(i->second); } } }