using namespace std;
ObjectFile *
-AoutObject::tryFile(const string &fname, int fd, size_t len, uint8_t *data)
+AoutObject::tryFile(const string &fname, size_t len, uint8_t *data)
{
if (!N_BADMAG(*(aout_exechdr *)data)) {
// right now this is only used for Alpha PAL code
- return new AoutObject(fname, fd, len, data,
+ return new AoutObject(fname, len, data,
ObjectFile::Alpha, ObjectFile::UnknownOpSys);
}
else {
}
-AoutObject::AoutObject(const string &_filename, int _fd,
+AoutObject::AoutObject(const string &_filename,
size_t _len, uint8_t *_data,
Arch _arch, OpSys _opSys)
- : ObjectFile(_filename, _fd, _len, _data, _arch, _opSys)
+ : ObjectFile(_filename, _len, _data, _arch, _opSys)
{
execHdr = (aout_exechdr *)fileData;
protected:
aout_exechdr *execHdr;
- AoutObject(const std::string &_filename, int _fd,
+ AoutObject(const std::string &_filename,
size_t _len, uint8_t *_data,
Arch _arch, OpSys _opSys);
virtual bool loadLocalSymbols(SymbolTable *symtab, Addr addrMask =
std::numeric_limits<Addr>::max());
- static ObjectFile *tryFile(const std::string &fname, int fd,
+ static ObjectFile *tryFile(const std::string &fname,
size_t len, uint8_t *data);
};
#include "libfdt.h"
ObjectFile *
-DtbObject::tryFile(const std::string &fname, int fd, size_t len, uint8_t *data)
+DtbObject::tryFile(const std::string &fname, size_t len, uint8_t *data)
{
// Check if this is a FDT file by looking for magic number
if (fdt_magic((void*)data) == FDT_MAGIC) {
- return new DtbObject(fname, fd, len, data,
+ return new DtbObject(fname, len, data,
ObjectFile::UnknownArch, ObjectFile::UnknownOpSys);
} else {
return NULL;
}
}
-DtbObject::DtbObject(const std::string &_filename, int _fd,
- size_t _len, uint8_t *_data,
+DtbObject::DtbObject(const std::string &_filename, size_t _len, uint8_t *_data,
Arch _arch, OpSys _opSys)
- : ObjectFile(_filename, _fd, _len, _data, _arch, _opSys)
+ : ObjectFile(_filename, _len, _data, _arch, _opSys)
{
text.baseAddr = 0;
text.size = len;
DtbObject::~DtbObject()
{
- if (descriptor >= 0) {
- ::close(descriptor);
- descriptor = -1;
- }
-
// Make sure to clean up memory properly depending
// on how buffer was allocated.
if (fileData && !fileDataMmapped) {
class DtbObject : public ObjectFile
{
protected:
- DtbObject(const std::string &_filename, int _fd,
- size_t _len, uint8_t *_data,
+ DtbObject(const std::string &_filename, size_t _len, uint8_t *_data,
Arch _arch, OpSys _opSys);
/** Bool marking if this dtb file has replaced the original
/** Static function that tries to load file as a
* flattened device tree blob.
* @param fname path to file
- * @param fd file descriptor of object file
* @param len length of file
* @param data mmap'ed data buffer containing file contents
* @return ObjectFile representing closest match of file type
*/
- static ObjectFile *tryFile(const std::string &fname, int fd,
+ static ObjectFile *tryFile(const std::string &fname,
size_t len, uint8_t *data);
};
using namespace std;
ObjectFile *
-EcoffObject::tryFile(const string &fname, int fd, size_t len, uint8_t *data)
+EcoffObject::tryFile(const string &fname, size_t len, uint8_t *data)
{
if (((ecoff_filehdr *)data)->f_magic == ECOFF_MAGIC_ALPHA) {
// it's Alpha ECOFF
- return new EcoffObject(fname, fd, len, data,
+ return new EcoffObject(fname, len, data,
ObjectFile::Alpha, ObjectFile::Tru64);
}
else {
}
-EcoffObject::EcoffObject(const string &_filename, int _fd,
- size_t _len, uint8_t *_data,
+EcoffObject::EcoffObject(const string &_filename, size_t _len, uint8_t *_data,
Arch _arch, OpSys _opSys)
- : ObjectFile(_filename, _fd, _len, _data, _arch, _opSys)
+ : ObjectFile(_filename, _len, _data, _arch, _opSys)
{
execHdr = (ecoff_exechdr *)fileData;
fileHdr = &(execHdr->f);
ecoff_filehdr *fileHdr;
ecoff_aouthdr *aoutHdr;
- EcoffObject(const std::string &_filename, int _fd,
- size_t _len, uint8_t *_data,
+ EcoffObject(const std::string &_filename, size_t _len, uint8_t *_data,
Arch _arch, OpSys _opSys);
public:
virtual bool loadLocalSymbols(SymbolTable *symtab, Addr addrMask =
std::numeric_limits<Addr>::max());
- static ObjectFile *tryFile(const std::string &fname, int fd,
+ static ObjectFile *tryFile(const std::string &fname,
size_t len, uint8_t *data);
};
using namespace std;
ObjectFile *
-ElfObject::tryFile(const string &fname, int fd, size_t len, uint8_t *data)
+ElfObject::tryFile(const string &fname, size_t len, uint8_t *data)
{
Elf *elf;
GElf_Ehdr ehdr;
// get a pointer to elf structure
elf = elf_memory((char*)data,len);
- // will only fail if fd is invalid
assert(elf != NULL);
// Check that we actually have a elf file
} // while sections
}
- ElfObject * result = new ElfObject(fname, fd, len, data, arch, opSys);
+ ElfObject * result = new ElfObject(fname, len, data, arch, opSys);
//The number of headers in the file
result->_programHeaderCount = ehdr.e_phnum;
}
-ElfObject::ElfObject(const string &_filename, int _fd,
- size_t _len, uint8_t *_data,
+ElfObject::ElfObject(const string &_filename, size_t _len, uint8_t *_data,
Arch _arch, OpSys _opSys)
- : ObjectFile(_filename, _fd, _len, _data, _arch, _opSys),
+ : ObjectFile(_filename, _len, _data, _arch, _opSys),
_programHeaderTable(0), _programHeaderSize(0), _programHeaderCount(0)
{
// get a pointer to elf structure
elf = elf_memory((char*)fileData,len);
- // will only fail if fd is invalid
assert(elf != NULL);
// Check that we actually have a elf file
/// Helper functions for loadGlobalSymbols() and loadLocalSymbols().
bool loadSomeSymbols(SymbolTable *symtab, int binding, Addr mask);
- ElfObject(const std::string &_filename, int _fd,
- size_t _len, uint8_t *_data,
+ ElfObject(const std::string &_filename, size_t _len, uint8_t *_data,
Arch _arch, OpSys _opSys);
void getSections();
virtual bool isDynamic() { return sectionExists(".interp"); }
virtual bool hasTLS() { return sectionExists(".tbss"); }
- static ObjectFile *tryFile(const std::string &fname, int fd,
+ static ObjectFile *tryFile(const std::string &fname,
size_t len, uint8_t *data);
Addr programHeaderTable() {return _programHeaderTable;}
uint16_t programHeaderSize() {return _programHeaderSize;}
using namespace std;
-ObjectFile::ObjectFile(const string &_filename, int _fd,
+ObjectFile::ObjectFile(const string &_filename,
size_t _len, uint8_t *_data,
Arch _arch, OpSys _opSys)
- : filename(_filename), descriptor(_fd), fileData(_data), len(_len),
+ : filename(_filename), fileData(_data), len(_len),
arch(_arch), opSys(_opSys), entry(0), globalPtr(0),
text{0, nullptr, 0}, data{0, nullptr, 0}, bss{0, nullptr, 0}
{
void
ObjectFile::close()
{
- if (descriptor >= 0) {
- ::close(descriptor);
- descriptor = -1;
- }
-
if (fileData) {
::munmap((char*)fileData, len);
fileData = NULL;
// mmap the whole shebang
uint8_t *fileData =
(uint8_t *)mmap(NULL, len, PROT_READ, MAP_SHARED, fd, 0);
+ close(fd);
if (fileData == MAP_FAILED) {
- close(fd);
return NULL;
}
ObjectFile *fileObj = NULL;
// figure out what we have here
- if ((fileObj = EcoffObject::tryFile(fname, fd, len, fileData)) != NULL) {
+ if ((fileObj = ElfObject::tryFile(fname, len, fileData)) != NULL) {
return fileObj;
}
- if ((fileObj = AoutObject::tryFile(fname, fd, len, fileData)) != NULL) {
+ if ((fileObj = EcoffObject::tryFile(fname, len, fileData)) != NULL) {
return fileObj;
}
- if ((fileObj = ElfObject::tryFile(fname, fd, len, fileData)) != NULL) {
+ if ((fileObj = AoutObject::tryFile(fname, len, fileData)) != NULL) {
return fileObj;
}
- if ((fileObj = DtbObject::tryFile(fname, fd, len, fileData)) != NULL) {
+ if ((fileObj = DtbObject::tryFile(fname, len, fileData)) != NULL) {
return fileObj;
}
if (raw)
- return RawObject::tryFile(fname, fd, len, fileData);
+ return RawObject::tryFile(fname, len, fileData);
// don't know what it is
- close(fd);
munmap((char*)fileData, len);
return NULL;
}
protected:
const std::string filename;
- int descriptor;
uint8_t *fileData;
size_t len;
Arch arch;
OpSys opSys;
- ObjectFile(const std::string &_filename, int _fd,
- size_t _len, uint8_t *_data,
+ ObjectFile(const std::string &_filename, size_t _len, uint8_t *_data,
Arch _arch, OpSys _opSys);
public:
#include "debug/Loader.hh"
ObjectFile *
-RawObject::tryFile(const std::string &fname, int fd, size_t len, uint8_t *data)
+RawObject::tryFile(const std::string &fname, size_t len, uint8_t *data)
{
- return new RawObject(fname, fd, len, data, ObjectFile::UnknownArch,
+ return new RawObject(fname, len, data, ObjectFile::UnknownArch,
ObjectFile::UnknownOpSys);
}
-RawObject::RawObject(const std::string &_filename, int _fd, size_t _len,
+RawObject::RawObject(const std::string &_filename, size_t _len,
uint8_t *_data, Arch _arch, OpSys _opSys)
- : ObjectFile(_filename, _fd, _len, _data, _arch, _opSys)
+ : ObjectFile(_filename, _len, _data, _arch, _opSys)
{
text.baseAddr = 0;
text.size = len;
class RawObject: public ObjectFile
{
protected:
- RawObject(const std::string &_filename, int _fd, size_t _len,
+ RawObject(const std::string &_filename, size_t _len,
uint8_t *_data, Arch _arch, OpSys _opSys);
public:
virtual ~RawObject() {}
virtual bool loadLocalSymbols(SymbolTable *symtab, Addr addrMask =
std::numeric_limits<Addr>::max());
- static ObjectFile *tryFile(const std::string &fname, int fd, size_t len,
+ static ObjectFile *tryFile(const std::string &fname, size_t len,
uint8_t *data);
};