Adds support for physical addresses to offline dr$sim traces. To support simulators wanting both virtual and physical addresses, and to simplify post-processing where the virtual PC values are needed, the regular trace entries remain all virtual. A new marker type TRACE_MARKER_TYPE_PHYSICAL_ADDRESS listing the corresponding physical address is added. The mappings are assumed to not change, allowing just one marker for each newly-observed page. This is done per-thread.
An explicit TRACE_MARKER_TYPE_PHYSICAL_ADDRESS_NOT_AVAILABLE marker is inserted on failure to translate, to prevent analyzers from having to infer this due to the lack of the already-sparse markers.
Separately emitted pairs of virtual and physical address markers were considered, with raw2trace inserting the physical at the right place, but that presents complexities with buffer handoff and with the first buffer. Instead, the physical are inserted via memmove directly into the buffer. This does not seem to be a performance concern: the translation lookup is the bottleneck.
Adds support for the new markers to the view tool.
Adds a Linux x86_64 test that runs a tiny asm app and ensures a physical address marker is inserted. The test needs to run as sudo, along with its pre- and post- commands. Currently it is enabled everywhere, so a user running interactive tests will have it pause while it waits for input. This might cause issues with manually running the test suite.
A number of items remain for further work:
- Performance is poor: the hashtable and caching need improvement.
- There is a hardcoded limit on how many markers can be added per buffer. Once this is exceeded, further markers are dropped. We should split the buffer to handle this.
- We may want to add a mode that checks for mapping changes.
- Missing privileges results in every physical address being 0 instead of showing the failure. We need to check the capabilities to distinguish.
- Better testing that we're actually getting physical addresses for online tests.
- Better offline testing with larger apps.
- Basic blocks that cross a page have only the first one translated.
- A file descriptor per thread is used, which will not scale well with DR's descriptor protection and might hit rlimits.
Issue: #4014