summaryrefslogtreecommitdiffstats
path: root/courgette/assembly_program.h
diff options
context:
space:
mode:
authorgrt <grt@chromium.org>2015-11-06 15:06:57 -0800
committerCommit bot <commit-bot@chromium.org>2015-11-06 23:07:42 +0000
commit825b91ff0d8891c18fe9ee6016c6cde40c9ee983 (patch)
tree37e5d34216a1853eb1e6e8240217bc26e0aae6b9 /courgette/assembly_program.h
parent38cb27903aa3f5a88148e48e4bf3430c5040e3aa (diff)
downloadchromium_src-825b91ff0d8891c18fe9ee6016c6cde40c9ee983.zip
chromium_src-825b91ff0d8891c18fe9ee6016c6cde40c9ee983.tar.gz
chromium_src-825b91ff0d8891c18fe9ee6016c6cde40c9ee983.tar.bz2
Use base::UncheckedMalloc rather than std::nothrow in courgette.
Allocating via std::nothrow will still crash the process if there's insufficient ram. BUG=530624 Review URL: https://codereview.chromium.org/1429243002 Cr-Commit-Position: refs/heads/master@{#358439}
Diffstat (limited to 'courgette/assembly_program.h')
-rw-r--r--courgette/assembly_program.h45
1 files changed, 40 insertions, 5 deletions
diff --git a/courgette/assembly_program.h b/courgette/assembly_program.h
index 096cc4d..ba7ad59f18 100644
--- a/courgette/assembly_program.h
+++ b/courgette/assembly_program.h
@@ -18,9 +18,6 @@
namespace courgette {
class EncodedProgram;
-class Instruction;
-
-typedef NoThrowBuffer<Instruction*> InstructionVector;
// A Label is a symbolic reference to an address. Unlike a conventional
// assembly language, we always know the address. The address will later be
@@ -41,6 +38,40 @@ class Label {
typedef std::map<RVA, Label*> RVAToLabel;
+// Opcodes of simple assembly language
+enum OP {
+ ORIGIN, // ORIGIN <rva> - set current address for assembly.
+ MAKEPERELOCS, // Generates a base relocation table.
+ MAKEELFRELOCS, // Generates a base relocation table.
+ DEFBYTE, // DEFBYTE <value> - emit a byte literal.
+ REL32, // REL32 <label> - emit a rel32 encoded reference to 'label'.
+ ABS32, // ABS32 <label> - emit an abs32 encoded reference to 'label'.
+ REL32ARM, // REL32ARM <c_op> <label> - arm-specific rel32 reference
+ MAKEELFARMRELOCS, // Generates a base relocation table.
+ DEFBYTES, // Emits any number of byte literals
+ ABS64, // ABS64 <label> - emit an abs64 encoded reference to 'label'.
+ LAST_OP
+};
+
+// Base class for instructions. Because we have so many instructions we want to
+// keep them as small as possible. For this reason we avoid virtual functions.
+class Instruction {
+ public:
+ OP op() const { return static_cast<OP>(op_); }
+
+ protected:
+ explicit Instruction(OP op) : op_(op), info_(0) {}
+ Instruction(OP op, unsigned int info) : op_(op), info_(info) {}
+
+ uint32 op_ : 4; // A few bits to store the OP code.
+ uint32 info_ : 28; // Remaining bits in first word available to subclass.
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(Instruction);
+};
+
+typedef NoThrowBuffer<Instruction*> InstructionVector;
+
// An AssemblyProgram is the result of disassembling an executable file.
//
// * The disassembler creates labels in the AssemblyProgram and emits
@@ -137,9 +168,13 @@ class AssemblyProgram {
CheckBool TrimLabels();
private:
+ using ScopedInstruction =
+ scoped_ptr<Instruction, UncheckedDeleter<Instruction>>;
+
ExecutableType kind_;
- CheckBool Emit(Instruction* instruction) WARN_UNUSED_RESULT;
+ CheckBool Emit(ScopedInstruction instruction) WARN_UNUSED_RESULT;
+ CheckBool EmitShared(Instruction* instruction) WARN_UNUSED_RESULT;
static const int kLabelLowerLimit;
@@ -153,7 +188,7 @@ class AssemblyProgram {
// Sharing instructions that emit a single byte saves a lot of space.
Instruction* GetByteInstruction(uint8 byte);
- scoped_ptr<Instruction*[]> byte_instruction_cache_;
+ scoped_ptr<Instruction* [], base::FreeDeleter> byte_instruction_cache_;
uint64 image_base_; // Desired or mandated base address of image.