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

Unified Diff: courgette/encoded_program.cc

Issue 1543643002: Switch to standard integer types in courgette/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 5 years 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
« no previous file with comments | « courgette/encoded_program.h ('k') | courgette/encoded_program_fuzz_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: courgette/encoded_program.cc
diff --git a/courgette/encoded_program.cc b/courgette/encoded_program.cc
index a4c00891f09b6eb652e64e871e0bb0b2ef1767a2..209fe2faeb6cd3e3d6ecb115bb66caf4b2b9525c 100644
--- a/courgette/encoded_program.cc
+++ b/courgette/encoded_program.cc
@@ -4,6 +4,9 @@
#include "courgette/encoded_program.h"
+#include <stddef.h>
+#include <stdint.h>
+
#include <algorithm>
#include <map>
#include <string>
@@ -42,7 +45,7 @@ CheckBool WriteVector(const V& items, SinkStream* buffer) {
template<typename V>
bool ReadVector(V* items, SourceStream* buffer) {
- uint32 count;
+ uint32_t count;
if (!buffer->ReadVarint32(&count))
return false;
@@ -50,7 +53,7 @@ bool ReadVector(V* items, SourceStream* buffer) {
bool ok = items->reserve(count);
for (size_t i = 0; ok && i < count; ++i) {
- uint32 item;
+ uint32_t item;
ok = buffer->ReadVarint32(&item);
if (ok)
ok = items->push_back(static_cast<typename V::value_type>(item));
@@ -64,10 +67,10 @@ template<typename V>
CheckBool WriteSigned32Delta(const V& set, SinkStream* buffer) {
size_t count = set.size();
bool ok = buffer->WriteSizeVarint32(count);
- uint32 prev = 0;
+ uint32_t prev = 0;
for (size_t i = 0; ok && i < count; ++i) {
- uint32 current = set[i];
- int32 delta = current - prev;
+ uint32_t current = set[i];
+ int32_t delta = current - prev;
ok = buffer->WriteVarint32Signed(delta);
prev = current;
}
@@ -76,19 +79,19 @@ CheckBool WriteSigned32Delta(const V& set, SinkStream* buffer) {
template <typename V>
static CheckBool ReadSigned32Delta(V* set, SourceStream* buffer) {
- uint32 count;
+ uint32_t count;
if (!buffer->ReadVarint32(&count))
return false;
set->clear();
bool ok = set->reserve(count);
- uint32 prev = 0;
+ uint32_t prev = 0;
for (size_t i = 0; ok && i < count; ++i) {
- int32 delta;
+ int32_t delta;
ok = buffer->ReadVarint32Signed(&delta);
if (ok) {
- uint32 current = static_cast<uint32>(prev + delta);
+ uint32_t current = static_cast<uint32_t>(prev + delta);
ok = set->push_back(current);
prev = current;
}
@@ -116,7 +119,7 @@ CheckBool WriteVectorU8(const V& items, SinkStream* buffer) {
template<typename V>
bool ReadVectorU8(V* items, SourceStream* buffer) {
- uint32 count;
+ uint32_t count;
if (!buffer->ReadVarint32(&count))
return false;
@@ -190,7 +193,7 @@ CheckBool EncodedProgram::AddOrigin(RVA origin) {
}
CheckBool EncodedProgram::AddCopy(size_t count, const void* bytes) {
- const uint8* source = static_cast<const uint8*>(bytes);
+ const uint8_t* source = static_cast<const uint8_t*>(bytes);
bool ok = true;
@@ -240,7 +243,7 @@ CheckBool EncodedProgram::AddRel32(int label_index) {
return ops_.push_back(REL32) && rel32_ix_.push_back(label_index);
}
-CheckBool EncodedProgram::AddRel32ARM(uint16 op, int label_index) {
+CheckBool EncodedProgram::AddRel32ARM(uint16_t op, int label_index) {
return ops_.push_back(static_cast<OP>(op)) &&
rel32_ix_.push_back(label_index);
}
@@ -295,7 +298,7 @@ static FieldSelect GetFieldSelect() {
scoped_ptr<base::Environment> env(base::Environment::Create());
std::string s;
env->GetVar("A_FIELDS", &s);
- uint64 fields;
+ uint64_t fields;
if (!base::StringToUint64(s, &fields))
return static_cast<FieldSelect>(~0);
return static_cast<FieldSelect>(fields);
@@ -314,8 +317,8 @@ CheckBool EncodedProgram::WriteTo(SinkStreamSet* streams) {
// the rest can be interleaved.
if (select & INCLUDE_MISC) {
- uint32 high = static_cast<uint32>(image_base_ >> 32);
- uint32 low = static_cast<uint32>(image_base_ & 0xffffffffU);
+ uint32_t high = static_cast<uint32_t>(image_base_ >> 32);
+ uint32_t low = static_cast<uint32_t>(image_base_ & 0xffffffffU);
if (!streams->stream(kStreamMisc)->WriteVarint32(high) ||
!streams->stream(kStreamMisc)->WriteVarint32(low)) {
@@ -360,14 +363,14 @@ CheckBool EncodedProgram::WriteTo(SinkStreamSet* streams) {
}
bool EncodedProgram::ReadFrom(SourceStreamSet* streams) {
- uint32 high;
- uint32 low;
+ uint32_t high;
+ uint32_t low;
if (!streams->stream(kStreamMisc)->ReadVarint32(&high) ||
!streams->stream(kStreamMisc)->ReadVarint32(&low)) {
return false;
}
- image_base_ = (static_cast<uint64>(high) << 32) | low;
+ image_base_ = (static_cast<uint64_t>(high) << 32) | low;
if (!ReadSigned32Delta(&abs32_rva_, streams->stream(kStreamAbs32Addresses)))
return false;
@@ -411,58 +414,56 @@ CheckBool EncodedProgram::EvaluateRel32ARM(OP op,
SinkStream* output) {
switch (op & 0x0000F000) {
case REL32ARM8: {
- uint32 index;
+ uint32_t index;
if (!VectorAt(rel32_ix_, ix_rel32_ix, &index))
return false;
++ix_rel32_ix;
RVA rva;
if (!VectorAt(rel32_rva_, index, &rva))
return false;
- uint32 decompressed_op;
- if (!DisassemblerElf32ARM::Decompress(ARM_OFF8,
- static_cast<uint16>(op),
- static_cast<uint32>(rva -
- current_rva),
- &decompressed_op)) {
+ uint32_t decompressed_op;
+ if (!DisassemblerElf32ARM::Decompress(
+ ARM_OFF8, static_cast<uint16_t>(op),
+ static_cast<uint32_t>(rva - current_rva), &decompressed_op)) {
return false;
}
- uint16 op16 = static_cast<uint16>(decompressed_op);
+ uint16_t op16 = static_cast<uint16_t>(decompressed_op);
if (!output->Write(&op16, 2))
return false;
current_rva += 2;
break;
}
case REL32ARM11: {
- uint32 index;
+ uint32_t index;
if (!VectorAt(rel32_ix_, ix_rel32_ix, &index))
return false;
++ix_rel32_ix;
RVA rva;
if (!VectorAt(rel32_rva_, index, &rva))
return false;
- uint32 decompressed_op;
- if (!DisassemblerElf32ARM::Decompress(ARM_OFF11, (uint16) op,
- (uint32) (rva - current_rva),
+ uint32_t decompressed_op;
+ if (!DisassemblerElf32ARM::Decompress(ARM_OFF11, (uint16_t)op,
+ (uint32_t)(rva - current_rva),
&decompressed_op)) {
return false;
}
- uint16 op16 = static_cast<uint16>(decompressed_op);
+ uint16_t op16 = static_cast<uint16_t>(decompressed_op);
if (!output->Write(&op16, 2))
return false;
current_rva += 2;
break;
}
case REL32ARM24: {
- uint32 index;
+ uint32_t index;
if (!VectorAt(rel32_ix_, ix_rel32_ix, &index))
return false;
++ix_rel32_ix;
RVA rva;
if (!VectorAt(rel32_rva_, index, &rva))
return false;
- uint32 decompressed_op;
- if (!DisassemblerElf32ARM::Decompress(ARM_OFF24, (uint16) op,
- (uint32) (rva - current_rva),
+ uint32_t decompressed_op;
+ if (!DisassemblerElf32ARM::Decompress(ARM_OFF24, (uint16_t)op,
+ (uint32_t)(rva - current_rva),
&decompressed_op)) {
return false;
}
@@ -472,40 +473,40 @@ CheckBool EncodedProgram::EvaluateRel32ARM(OP op,
break;
}
case REL32ARM25: {
- uint32 index;
+ uint32_t index;
if (!VectorAt(rel32_ix_, ix_rel32_ix, &index))
return false;
++ix_rel32_ix;
RVA rva;
if (!VectorAt(rel32_rva_, index, &rva))
return false;
- uint32 decompressed_op;
- if (!DisassemblerElf32ARM::Decompress(ARM_OFF25, (uint16) op,
- (uint32) (rva - current_rva),
+ uint32_t decompressed_op;
+ if (!DisassemblerElf32ARM::Decompress(ARM_OFF25, (uint16_t)op,
+ (uint32_t)(rva - current_rva),
&decompressed_op)) {
return false;
}
- uint32 words = (decompressed_op << 16) | (decompressed_op >> 16);
+ uint32_t words = (decompressed_op << 16) | (decompressed_op >> 16);
if (!output->Write(&words, 4))
return false;
current_rva += 4;
break;
}
case REL32ARM21: {
- uint32 index;
+ uint32_t index;
if (!VectorAt(rel32_ix_, ix_rel32_ix, &index))
return false;
++ix_rel32_ix;
RVA rva;
if (!VectorAt(rel32_rva_, index, &rva))
return false;
- uint32 decompressed_op;
- if (!DisassemblerElf32ARM::Decompress(ARM_OFF21, (uint16) op,
- (uint32) (rva - current_rva),
+ uint32_t decompressed_op;
+ if (!DisassemblerElf32ARM::Decompress(ARM_OFF21, (uint16_t)op,
+ (uint32_t)(rva - current_rva),
&decompressed_op)) {
return false;
}
- uint32 words = (decompressed_op << 16) | (decompressed_op >> 16);
+ uint32_t words = (decompressed_op << 16) | (decompressed_op >> 16);
if (!output->Write(&words, 4))
return false;
current_rva += 4;
@@ -530,7 +531,7 @@ CheckBool EncodedProgram::AssembleTo(SinkStream* final_buffer) {
RVA current_rva = 0;
bool pending_pe_relocation_table = false;
- uint8 pending_pe_relocation_table_type = 0x03; // IMAGE_REL_BASED_HIGHLOW
+ uint8_t pending_pe_relocation_table_type = 0x03; // IMAGE_REL_BASED_HIGHLOW
Elf32_Word pending_elf_relocation_table_type = 0;
SinkStream bytes_following_relocation_table;
@@ -560,7 +561,7 @@ CheckBool EncodedProgram::AssembleTo(SinkStream* final_buffer) {
return false;
++ix_copy_counts;
for (size_t i = 0; i < count; ++i) {
- uint8 b;
+ uint8_t b;
if (!VectorAt(copy_bytes_, ix_copy_bytes, &b))
return false;
++ix_copy_bytes;
@@ -572,7 +573,7 @@ CheckBool EncodedProgram::AssembleTo(SinkStream* final_buffer) {
}
case COPY1: {
- uint8 b;
+ uint8_t b;
if (!VectorAt(copy_bytes_, ix_copy_bytes, &b))
return false;
++ix_copy_bytes;
@@ -583,14 +584,14 @@ CheckBool EncodedProgram::AssembleTo(SinkStream* final_buffer) {
}
case REL32: {
- uint32 index;
+ uint32_t index;
if (!VectorAt(rel32_ix_, ix_rel32_ix, &index))
return false;
++ix_rel32_ix;
RVA rva;
if (!VectorAt(rel32_rva_, index, &rva))
return false;
- uint32 offset = (rva - (current_rva + 4));
+ uint32_t offset = (rva - (current_rva + 4));
if (!output->Write(&offset, 4))
return false;
current_rva += 4;
@@ -599,7 +600,7 @@ CheckBool EncodedProgram::AssembleTo(SinkStream* final_buffer) {
case ABS32:
case ABS64: {
- uint32 index;
+ uint32_t index;
if (!VectorAt(abs32_ix_, ix_abs32_ix, &index))
return false;
++ix_abs32_ix;
@@ -607,18 +608,18 @@ CheckBool EncodedProgram::AssembleTo(SinkStream* final_buffer) {
if (!VectorAt(abs32_rva_, index, &rva))
return false;
if (op == ABS32) {
- base::CheckedNumeric<uint32> abs32 = image_base_;
+ base::CheckedNumeric<uint32_t> abs32 = image_base_;
abs32 += rva;
- uint32 safe_abs32 = abs32.ValueOrDie();
+ uint32_t safe_abs32 = abs32.ValueOrDie();
if (!abs32_relocs_.push_back(current_rva) ||
!output->Write(&safe_abs32, 4)) {
return false;
}
current_rva += 4;
} else {
- base::CheckedNumeric<uint64> abs64 = image_base_;
+ base::CheckedNumeric<uint64_t> abs64 = image_base_;
abs64 += rva;
- uint64 safe_abs64 = abs64.ValueOrDie();
+ uint64_t safe_abs64 = abs64.ValueOrDie();
if (!abs32_relocs_.push_back(current_rva) ||
!output->Write(&safe_abs64, 8)) {
return false;
@@ -715,9 +716,9 @@ CheckBool EncodedProgram::AssembleTo(SinkStream* final_buffer) {
// table file format.
//
struct RelocBlockPOD {
- uint32 page_rva;
- uint32 block_size;
- uint16 relocs[4096]; // Allow up to one relocation per byte of a 4k page.
+ uint32_t page_rva;
+ uint32_t block_size;
+ uint16_t relocs[4096]; // Allow up to one relocation per byte of a 4k page.
};
static_assert(offsetof(RelocBlockPOD, relocs) == 8, "reloc block header size");
@@ -729,7 +730,7 @@ class RelocBlock {
pod.block_size = 8;
}
- void Add(uint16 item) {
+ void Add(uint16_t item) {
pod.relocs[(pod.block_size-8)/2] = item;
pod.block_size += 2;
}
@@ -749,21 +750,21 @@ class RelocBlock {
};
CheckBool EncodedProgram::GeneratePeRelocations(SinkStream* buffer,
- uint8 type) {
+ uint8_t type) {
std::sort(abs32_relocs_.begin(), abs32_relocs_.end());
RelocBlock block;
bool ok = true;
for (size_t i = 0; ok && i < abs32_relocs_.size(); ++i) {
- uint32 rva = abs32_relocs_[i];
- uint32 page_rva = rva & ~0xFFF;
+ uint32_t rva = abs32_relocs_[i];
+ uint32_t page_rva = rva & ~0xFFF;
if (page_rva != block.pod.page_rva) {
ok &= block.Flush(buffer);
block.pod.page_rva = page_rva;
}
if (ok)
- block.Add(((static_cast<uint16>(type)) << 12) | (rva & 0xFFF));
+ block.Add(((static_cast<uint16_t>(type)) << 12) | (rva & 0xFFF));
}
ok &= block.Flush(buffer);
return ok;
« no previous file with comments | « courgette/encoded_program.h ('k') | courgette/encoded_program_fuzz_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698