Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1778)

Unified Diff: courgette/image_utils.h

Issue 1676683002: [Courgette] Clean up Disassembler; fix ELF Memory leaks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: courgette/image_utils.h
diff --git a/courgette/image_utils.h b/courgette/image_utils.h
index f958cc12f8f3b01db9bb1d2005b2ec64d2f289fa..0162b75d32bfd9b41fb40b51b0535e3c06ec1715 100644
--- a/courgette/image_utils.h
+++ b/courgette/image_utils.h
@@ -14,8 +14,40 @@
namespace courgette {
-typedef uint32_t RVA;
+// There are several ways to reason about addresses in an image:
+// - File Offset: Position relative to start of image.
+// - VA (Virtual Address): Virtual memory address of a loaded image. This is
+// subject to relocation by the OS.
+// - RVA (Relative Virtual Address): VA relative to base address, and is the
+// preferred address for pointers in an image.
+// In Courgette we are mostly interested in FILE Offsets and RVAs.
+
+using RVA = uint32_t;
const RVA kUnassignedRVA = 0xFFFFFFFFU;
+const RVA kNoRVA = 0xFFFFFFFFU;
+
+using FileOffset = size_t;
grt (UTC plus 2) 2016/02/11 16:55:34 is ptrdiff_t (the type resulting from subtracting
huangs 2016/02/12 01:08:42 Seems more correct. However, when I implement thi
+const FileOffset kNoFileOffset = 0xFFFFFFFFU;
grt (UTC plus 2) 2016/02/11 16:55:34 this should be something like PTRDIFF_MAX (if File
huangs 2016/02/12 01:08:42 Done (UINTPTR_MAX for size_t).
+
+// An interface for {RVA, File Offset, pointer to image data} translation.
+class AddressTranslator {
grt (UTC plus 2) 2016/02/11 16:55:34 will this eventually: - be implemented by types ot
huangs 2016/02/12 01:08:42 Yes. The plan is to create multiple subclasses ( p
+ public:
+ // Returns the RVA corresponding to |file_offset|, or kNoRVA if nonexistent.
+ virtual RVA FileOffsetToRVA(FileOffset file_offset) const = 0;
+
+ // Returns the file offset corresponding to |rva|, or kFileNoOffset if
+ // nonexistent.
+ virtual FileOffset RVAToFileOffset(RVA rva) const = 0;
+
+ // Returns the pointer to the image data for |file_offset|. Assumes that
+ // 0 <= |file_offset| <= image size. We allow |file_offset| == image size to
+ // enable "end" bound for iteration.
+ virtual const uint8_t* FileOffsetToPointer(FileOffset file_offset) const = 0;
+
+ // Returns the pointer to the image data for |rva|, or null if |rva| is
+ // invalid.
+ virtual const uint8_t* RVAToPointer(RVA rva) const = 0;
+};
// A Label is a symbolic reference to an address. Unlike a conventional
// assembly language, we always know the address. The address will later be

Powered by Google App Engine
This is Rietveld 408576698