Skip to content

Commit

Permalink
Identifying call sites that need to handle out of memory situations i…
Browse files Browse the repository at this point in the history
…n Courgette.

There's no functional change here, only interface changes:
* Change methods that are known to fail out in the field to return bool instead of void.
* Where those methods are called, check the return value and report errors
* In debug builds use a specialized template class that forces callers to check return values (this is possible at compile time in gcc, but unfortunately not in VS).

The next step will be to change the implementation to not use STL containers.

TEST=Run courgette tests.
BUG=74777
Review URL: http://codereview.chromium.org/6716006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79030 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
tommi@chromium.org committed Mar 22, 2011
1 parent d64abe1 commit c8240b1
Show file tree
Hide file tree
Showing 11 changed files with 313 additions and 169 deletions.
47 changes: 31 additions & 16 deletions courgette/assembly_program.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <vector>

#include "base/logging.h"
#include "base/scoped_ptr.h"

#include "courgette/courgette.h"
#include "courgette/encoded_program.h"
Expand Down Expand Up @@ -287,26 +288,35 @@ void AssemblyProgram::AssignRemainingIndexes(RVAToLabel* labels) {
<< " infill " << fill_infill_count;
}

typedef void (EncodedProgram::*DefineLabelMethod)(int index, RVA value);
typedef CheckBool (EncodedProgram::*DefineLabelMethod)(int index, RVA value);

#if defined(OS_WIN)
__declspec(noinline)
#endif
static void DefineLabels(const RVAToLabel& labels,
EncodedProgram* encoded_format,
DefineLabelMethod define_label) {
for (RVAToLabel::const_iterator p = labels.begin(); p != labels.end(); ++p) {
static CheckBool DefineLabels(const RVAToLabel& labels,
EncodedProgram* encoded_format,
DefineLabelMethod define_label) {
bool ok = true;
for (RVAToLabel::const_iterator p = labels.begin();
ok && p != labels.end();
++p) {
Label* label = p->second;
(encoded_format->*define_label)(label->index_, label->rva_);
ok = (encoded_format->*define_label)(label->index_, label->rva_);
}
return ok;
}

EncodedProgram* AssemblyProgram::Encode() const {
EncodedProgram* encoded = new EncodedProgram();

scoped_ptr<EncodedProgram> encoded(new EncodedProgram());
encoded->set_image_base(image_base_);
DefineLabels(abs32_labels_, encoded, &EncodedProgram::DefineAbs32Label);
DefineLabels(rel32_labels_, encoded, &EncodedProgram::DefineRel32Label);

if (!DefineLabels(abs32_labels_, encoded.get(),
&EncodedProgram::DefineAbs32Label) ||
!DefineLabels(rel32_labels_, encoded.get(),
&EncodedProgram::DefineRel32Label)) {
return NULL;
}

encoded->EndLabels();

for (size_t i = 0; i < instructions_.size(); ++i) {
Expand All @@ -315,26 +325,31 @@ EncodedProgram* AssemblyProgram::Encode() const {
switch (instruction->op()) {
case ORIGIN: {
OriginInstruction* org = static_cast<OriginInstruction*>(instruction);
encoded->AddOrigin(org->origin_rva());
if (!encoded->AddOrigin(org->origin_rva()))
return NULL;
break;
}
case DEFBYTE: {
uint8 b = static_cast<ByteInstruction*>(instruction)->byte_value();
encoded->AddCopy(1, &b);
if (!encoded->AddCopy(1, &b))
return NULL;
break;
}
case REL32: {
Label* label = static_cast<InstructionWithLabel*>(instruction)->label();
encoded->AddRel32(label->index_);
if (!encoded->AddRel32(label->index_))
return NULL;
break;
}
case ABS32: {
Label* label = static_cast<InstructionWithLabel*>(instruction)->label();
encoded->AddAbs32(label->index_);
if (!encoded->AddAbs32(label->index_))
return NULL;
break;
}
case MAKERELOCS: {
encoded->AddMakeRelocs();
if (!encoded->AddMakeRelocs())
return NULL;
break;
}
default: {
Expand All @@ -343,7 +358,7 @@ EncodedProgram* AssemblyProgram::Encode() const {
}
}

return encoded;
return encoded.release();
}

Instruction* AssemblyProgram::GetByteInstruction(uint8 byte) {
Expand Down
Loading

0 comments on commit c8240b1

Please sign in to comment.