summaryrefslogtreecommitdiffstats
path: root/courgette/encoded_program.h
diff options
context:
space:
mode:
authorsra@chromium.org <sra@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-08 23:00:29 +0000
committersra@chromium.org <sra@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-08 23:00:29 +0000
commit04ca1bc65afb76ea30698c25f24599d20119e3d2 (patch)
tree2bb65e974d478f4d607b83f6a84a56c01f501ac0 /courgette/encoded_program.h
parent9adf1dcf3281408560267787eddcc767566b425f (diff)
downloadchromium_src-04ca1bc65afb76ea30698c25f24599d20119e3d2.zip
chromium_src-04ca1bc65afb76ea30698c25f24599d20119e3d2.tar.gz
chromium_src-04ca1bc65afb76ea30698c25f24599d20119e3d2.tar.bz2
Move Courgette
from src\third_party\courgette to src\courgette and src\courgette\third_party Fixed #includes Added properties to ignore generated files: C:\c5\src>svn pg svn:ignore courgette courgette.xcodeproj courgette.sln courgette_fuzz.vcproj courgette_lib.vcproj courgette_minimal_tool.vcproj courgette_tool.vcproj courgette.vcproj courgette_unittests.vcproj SConstruct courgette_fuzz.scons courgette_lib.scons courgette_main.scons courgette_minimal_tool.scons courgette.scons courgette_tool.scons courgette_unittests.scons Review URL: http://codereview.chromium.org/115062 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15692 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'courgette/encoded_program.h')
-rw-r--r--courgette/encoded_program.h83
1 files changed, 83 insertions, 0 deletions
diff --git a/courgette/encoded_program.h b/courgette/encoded_program.h
new file mode 100644
index 0000000..df1119c
--- /dev/null
+++ b/courgette/encoded_program.h
@@ -0,0 +1,83 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COURGETTE_ENCODED_PROGRAM_H_
+#define COURGETTE_ENCODED_PROGRAM_H_
+
+#include <vector>
+
+#include "base/basictypes.h"
+#include "courgette/image_info.h"
+
+namespace courgette {
+
+class SinkStream;
+class SinkStreamSet;
+class SourceStreamSet;
+
+// An EncodedProgram is a set of tables that contain a simple 'binary assembly
+// language' that can be assembled to produce a sequence of bytes, for example,
+// a Windows 32-bit executable.
+//
+class EncodedProgram {
+ public:
+ EncodedProgram();
+ ~EncodedProgram();
+
+ // Generating an EncodedProgram:
+ //
+ // (1) The image base can be specified at any time.
+ void set_image_base(uint64 base) { image_base_ = base; }
+
+ // (2) Address tables and indexes defined first.
+ void DefineRel32Label(int index, RVA address);
+ void DefineAbs32Label(int index, RVA address);
+ void EndLabels();
+
+ // (3) Add instructions in the order needed to generate bytes of file.
+ void AddOrigin(RVA rva);
+ void AddCopy(int count, const void* bytes);
+ void AddRel32(int label_index);
+ void AddAbs32(int label_index);
+ void AddMakeRelocs();
+
+ // (3) Serialize binary assembly language tables to a set of streams.
+ void WriteTo(SinkStreamSet *streams);
+
+ // Using an EncodedProgram to generate a byte stream:
+ //
+ // (4) Deserializes a fresh EncodedProgram from a set of streams.
+ bool ReadFrom(SourceStreamSet *streams);
+
+ // (5) Assembles the 'binary assembly language' into final file.
+ bool AssembleTo(SinkStream *buffer);
+
+ private:
+ enum OP; // Binary assembly language operations.
+
+ void DebuggingSummary();
+ void GenerateBaseRelocations(SinkStream *buffer);
+ void DefineLabelCommon(std::vector<RVA>*, int, RVA);
+ void FinishLabelsCommon(std::vector<RVA>* addresses);
+
+ // Binary assembly language tables.
+ uint64 image_base_;
+ std::vector<RVA> rel32_rva_;
+ std::vector<RVA> abs32_rva_;
+ std::vector<OP> ops_;
+ std::vector<RVA> origins_;
+ std::vector<int> copy_counts_;
+ std::vector<uint8> copy_bytes_;
+ std::vector<uint32> rel32_ix_;
+ std::vector<uint32> abs32_ix_;
+
+ // Table of the addresses containing abs32 relocations; computed during
+ // assembly, used to generate base relocation table.
+ std::vector<uint32> abs32_relocs_;
+
+ DISALLOW_COPY_AND_ASSIGN(EncodedProgram);
+};
+
+} // namespace courgette
+#endif // COURGETTE_ENCODED_FORMAT_H_