summaryrefslogtreecommitdiffstats
path: root/courgette/image_utils.h
diff options
context:
space:
mode:
authorhuangs <huangs@chromium.org>2016-03-14 09:35:39 -0700
committerCommit bot <commit-bot@chromium.org>2016-03-14 16:37:34 +0000
commitdda11d069213d53aef9bf3bc018b02f3aef7177b (patch)
treeb2149ca828f3231ffc0f647f5903a641c08793bc /courgette/image_utils.h
parentbe97fce59267730f7e657c9321381fa9e11e000c (diff)
downloadchromium_src-dda11d069213d53aef9bf3bc018b02f3aef7177b.zip
chromium_src-dda11d069213d53aef9bf3bc018b02f3aef7177b.tar.gz
chromium_src-dda11d069213d53aef9bf3bc018b02f3aef7177b.tar.bz2
[Courgette] Clean up Disassembler; fix ELF Memory leaks.
Cleaning up code surrounding Disassembler: - Extract AddressTranslator interface to be used across subclasses. - Use FileOffset = size_t by context. - Detailed comments & TODOs in DisassemblerElf32ARM. - Fix DisassemblerElf32ARM memory leaks. - Lots of superficial stylistic changes. Except for AddressTranslator routines and unit tests, shying away from control flow and logic changes. BUG=579206 Committed: https://crrev.com/58b822d441f5c982e879e536fa3c1cbac8fd339a Cr-Commit-Position: refs/heads/master@{#380881} Review URL: https://codereview.chromium.org/1676683002 Cr-Commit-Position: refs/heads/master@{#380987}
Diffstat (limited to 'courgette/image_utils.h')
-rw-r--r--courgette/image_utils.h38
1 files changed, 37 insertions, 1 deletions
diff --git a/courgette/image_utils.h b/courgette/image_utils.h
index f958cc1..cfbfcfe 100644
--- a/courgette/image_utils.h
+++ b/courgette/image_utils.h
@@ -14,8 +14,44 @@
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 some base address. This is
+// the preferred way to specify pointers in an image. Two ways to encode RVA
+// are:
+// - abs32: RVA value is encoded directly.
+// - rel32: RVA is encoded as offset from an instruction address. This is
+// commonly used for relative branch/call opcodes.
+// Courgette operates on File Offsets and RVAs only.
+
+using RVA = uint32_t;
const RVA kUnassignedRVA = 0xFFFFFFFFU;
+const RVA kNoRVA = 0xFFFFFFFFU;
+
+using FileOffset = size_t;
+const FileOffset kNoFileOffset = UINTPTR_MAX;
+
+// An interface for {File Offset, RVA, pointer to image data} translation.
+class AddressTranslator {
+ 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 kNoFileOffset 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. If |file_offset| == image, the resulting
+ // pointer is an end bound for iteration that should never be dereferenced.
+ 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