mirror of
https://github.com/corda/corda.git
synced 2025-06-17 06:38:21 +00:00
move OutputStream to ObjectWriter constructor in binaryToObject
This commit is contained in:
@ -162,11 +162,13 @@ public:
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
PlatformInfo::Architecture arch;
|
PlatformInfo::Architecture arch;
|
||||||
|
OutputStream* out;
|
||||||
|
|
||||||
ElfObjectWriter(PlatformInfo::Architecture arch):
|
ElfObjectWriter(PlatformInfo::Architecture arch, OutputStream* out):
|
||||||
arch(arch) {}
|
arch(arch),
|
||||||
|
out(out) {}
|
||||||
|
|
||||||
void writeObject(const uint8_t* data, unsigned size, OutputStream* out,
|
void writeObject(const uint8_t* data, unsigned size,
|
||||||
const char* startName, const char* endName,
|
const char* startName, const char* endName,
|
||||||
const char* sectionName, unsigned sectionFlags,
|
const char* sectionName, unsigned sectionFlags,
|
||||||
unsigned alignment, int machine, int encoding)
|
unsigned alignment, int machine, int encoding)
|
||||||
@ -334,7 +336,7 @@ public:
|
|||||||
out->writeChunk(&endSymbol, sizeof(endSymbol));
|
out->writeChunk(&endSymbol, sizeof(endSymbol));
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool write(uint8_t* data, size_t size, OutputStream* out,
|
virtual bool write(uint8_t* data, size_t size,
|
||||||
const char* startName, const char* endName,
|
const char* startName, const char* endName,
|
||||||
unsigned alignment, unsigned accessFlags)
|
unsigned alignment, unsigned accessFlags)
|
||||||
{
|
{
|
||||||
@ -374,7 +376,7 @@ public:
|
|||||||
sectionName = ".rodata";
|
sectionName = ".rodata";
|
||||||
}
|
}
|
||||||
|
|
||||||
writeObject(data, size, out, startName, endName, sectionName, sectionFlags,
|
writeObject(data, size, startName, endName, sectionName, sectionFlags,
|
||||||
alignment, machine, encoding);
|
alignment, machine, encoding);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -388,8 +390,8 @@ public:
|
|||||||
ElfPlatform(PlatformInfo::Architecture arch):
|
ElfPlatform(PlatformInfo::Architecture arch):
|
||||||
Platform(PlatformInfo(PlatformInfo::Linux, arch)) {}
|
Platform(PlatformInfo(PlatformInfo::Linux, arch)) {}
|
||||||
|
|
||||||
virtual ObjectWriter* makeObjectWriter() {
|
virtual ObjectWriter* makeObjectWriter(OutputStream* out) {
|
||||||
return new ElfObjectWriter(info.arch);
|
return new ElfObjectWriter(info.arch, out);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -144,11 +144,13 @@ public:
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
PlatformInfo::Architecture arch;
|
PlatformInfo::Architecture arch;
|
||||||
|
OutputStream* out;
|
||||||
|
|
||||||
MachOObjectWriter(PlatformInfo::Architecture arch):
|
MachOObjectWriter(PlatformInfo::Architecture arch, OutputStream* out):
|
||||||
arch(arch) {}
|
arch(arch),
|
||||||
|
out(out) {}
|
||||||
|
|
||||||
void writeObject(const uint8_t* data, unsigned size, OutputStream* out,
|
void writeObject(const uint8_t* data, unsigned size,
|
||||||
const char* startName, const char* endName,
|
const char* startName, const char* endName,
|
||||||
const char* segmentName, const char* sectionName,
|
const char* segmentName, const char* sectionName,
|
||||||
unsigned alignment, cpu_type_t cpuType, cpu_subtype_t cpuSubType)
|
unsigned alignment, cpu_type_t cpuType, cpu_subtype_t cpuSubType)
|
||||||
@ -258,7 +260,7 @@ public:
|
|||||||
out->writeChunk(endName, endNameLength);
|
out->writeChunk(endName, endNameLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool write(uint8_t* data, size_t size, OutputStream* out,
|
virtual bool write(uint8_t* data, size_t size,
|
||||||
const char* startName, const char* endName,
|
const char* startName, const char* endName,
|
||||||
unsigned alignment, unsigned accessFlags)
|
unsigned alignment, unsigned accessFlags)
|
||||||
{
|
{
|
||||||
@ -307,7 +309,7 @@ public:
|
|||||||
myEndName[0] = '_';
|
myEndName[0] = '_';
|
||||||
memcpy(myEndName + 1, endName, endNameLength + 1);
|
memcpy(myEndName + 1, endName, endNameLength + 1);
|
||||||
|
|
||||||
writeObject(data, size, out, myStartName, myEndName, segmentName,
|
writeObject(data, size, myStartName, myEndName, segmentName,
|
||||||
sectionName, alignment, cpuType, cpuSubType);
|
sectionName, alignment, cpuType, cpuSubType);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -321,8 +323,8 @@ public:
|
|||||||
MachOPlatform(PlatformInfo::Architecture arch):
|
MachOPlatform(PlatformInfo::Architecture arch):
|
||||||
Platform(PlatformInfo(PlatformInfo::Darwin, arch)) {}
|
Platform(PlatformInfo(PlatformInfo::Darwin, arch)) {}
|
||||||
|
|
||||||
virtual ObjectWriter* makeObjectWriter() {
|
virtual ObjectWriter* makeObjectWriter(OutputStream* out) {
|
||||||
return new MachOObjectWriter(info.arch);
|
return new MachOObjectWriter(info.arch, out);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -56,9 +56,9 @@ writeObject(uint8_t* data, unsigned size, OutputStream* out, const char* startNa
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjectWriter* writer = platform->makeObjectWriter();
|
ObjectWriter* writer = platform->makeObjectWriter(out);
|
||||||
|
|
||||||
bool success = writer->write(data, size, out, startName, endName, alignment,
|
bool success = writer->write(data, size, startName, endName, alignment,
|
||||||
ObjectWriter::Readable | (writable ? ObjectWriter::Writable : 0) | (executable ? ObjectWriter::Executable : 0));
|
ObjectWriter::Readable | (writable ? ObjectWriter::Writable : 0) | (executable ? ObjectWriter::Executable : 0));
|
||||||
|
|
||||||
writer->dispose();
|
writer->dispose();
|
||||||
|
@ -172,7 +172,12 @@ public:
|
|||||||
class PEObjectWriter : public ObjectWriter {
|
class PEObjectWriter : public ObjectWriter {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual bool write(uint8_t* data, size_t size, OutputStream* out,
|
OutputStream* out;
|
||||||
|
|
||||||
|
PEObjectWriter(OutputStream* out):
|
||||||
|
out(out) {}
|
||||||
|
|
||||||
|
virtual bool write(uint8_t* data, size_t size,
|
||||||
const char* startName, const char* endName,
|
const char* startName, const char* endName,
|
||||||
unsigned alignment, unsigned accessFlags)
|
unsigned alignment, unsigned accessFlags)
|
||||||
{
|
{
|
||||||
@ -237,8 +242,8 @@ public:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual ObjectWriter* makeObjectWriter() {
|
virtual ObjectWriter* makeObjectWriter(OutputStream* out) {
|
||||||
return new PEObjectWriter();
|
return new PEObjectWriter(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
WindowsPlatform():
|
WindowsPlatform():
|
||||||
|
@ -44,7 +44,7 @@ public:
|
|||||||
Executable = 1 << 2
|
Executable = 1 << 2
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual bool write(uint8_t* data, size_t size, OutputStream* out,
|
virtual bool write(uint8_t* data, size_t size,
|
||||||
const char* startName, const char* endName,
|
const char* startName, const char* endName,
|
||||||
unsigned alignment, unsigned accessFlags) = 0;
|
unsigned alignment, unsigned accessFlags) = 0;
|
||||||
|
|
||||||
@ -98,7 +98,7 @@ public:
|
|||||||
first = this;
|
first = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ObjectWriter* makeObjectWriter() = 0;
|
virtual ObjectWriter* makeObjectWriter(OutputStream* out) = 0;
|
||||||
|
|
||||||
static Platform* getPlatform(PlatformInfo info);
|
static Platform* getPlatform(PlatformInfo info);
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user