changeset 61a56f76222b in /z/repo/gem5
details: http://repo.gem5.org/gem5?cmd=changeset;node=61a56f76222b
description:
        base: remove fd from object loaders

        All the object loaders directly examine the (already completely loaded
        by object_file.cc) memory image. There is no current motivation to
        keep the fd around.

diffstat:

 src/base/loader/aout_object.cc  |   8 ++++----
 src/base/loader/aout_object.hh  |   4 ++--
 src/base/loader/dtb_object.cc   |  14 ++++----------
 src/base/loader/dtb_object.hh   |   6 ++----
 src/base/loader/ecoff_object.cc |   9 ++++-----
 src/base/loader/ecoff_object.hh |   5 ++---
 src/base/loader/elf_object.cc   |  11 ++++-------
 src/base/loader/elf_object.hh   |   5 ++---
 src/base/loader/object_file.cc  |  22 ++++++++--------------
 src/base/loader/object_file.hh  |   4 +---
 src/base/loader/raw_object.cc   |   8 ++++----
 src/base/loader/raw_object.hh   |   4 ++--
 12 files changed, 39 insertions(+), 61 deletions(-)

diffs (truncated from 377 to 300 lines):

diff -r 3946aa272087 -r 61a56f76222b src/base/loader/aout_object.cc
--- a/src/base/loader/aout_object.cc    Fri Jul 03 10:14:24 2015 -0400
+++ b/src/base/loader/aout_object.cc    Fri Jul 03 10:14:34 2015 -0400
@@ -39,11 +39,11 @@
 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 {
@@ -52,10 +52,10 @@
 }
 
 
-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;
 
diff -r 3946aa272087 -r 61a56f76222b src/base/loader/aout_object.hh
--- a/src/base/loader/aout_object.hh    Fri Jul 03 10:14:24 2015 -0400
+++ b/src/base/loader/aout_object.hh    Fri Jul 03 10:14:34 2015 -0400
@@ -41,7 +41,7 @@
   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);
 
@@ -53,7 +53,7 @@
     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);
 };
 
diff -r 3946aa272087 -r 61a56f76222b src/base/loader/dtb_object.cc
--- a/src/base/loader/dtb_object.cc     Fri Jul 03 10:14:24 2015 -0400
+++ b/src/base/loader/dtb_object.cc     Fri Jul 03 10:14:34 2015 -0400
@@ -40,21 +40,20 @@
 #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;
@@ -73,11 +72,6 @@
 
 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) {
diff -r 3946aa272087 -r 61a56f76222b src/base/loader/dtb_object.hh
--- a/src/base/loader/dtb_object.hh     Fri Jul 03 10:14:24 2015 -0400
+++ b/src/base/loader/dtb_object.hh     Fri Jul 03 10:14:34 2015 -0400
@@ -41,8 +41,7 @@
 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
@@ -75,12 +74,11 @@
         /** 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);
 };
 
diff -r 3946aa272087 -r 61a56f76222b src/base/loader/ecoff_object.cc
--- a/src/base/loader/ecoff_object.cc   Fri Jul 03 10:14:24 2015 -0400
+++ b/src/base/loader/ecoff_object.cc   Fri Jul 03 10:14:34 2015 -0400
@@ -49,11 +49,11 @@
 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 {
@@ -62,10 +62,9 @@
 }
 
 
-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);
diff -r 3946aa272087 -r 61a56f76222b src/base/loader/ecoff_object.hh
--- a/src/base/loader/ecoff_object.hh   Fri Jul 03 10:14:24 2015 -0400
+++ b/src/base/loader/ecoff_object.hh   Fri Jul 03 10:14:34 2015 -0400
@@ -45,8 +45,7 @@
     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:
@@ -57,7 +56,7 @@
     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);
 };
 
diff -r 3946aa272087 -r 61a56f76222b src/base/loader/elf_object.cc
--- a/src/base/loader/elf_object.cc     Fri Jul 03 10:14:24 2015 -0400
+++ b/src/base/loader/elf_object.cc     Fri Jul 03 10:14:34 2015 -0400
@@ -56,7 +56,7 @@
 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;
@@ -69,7 +69,6 @@
 
     // 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
@@ -213,7 +212,7 @@
             } // 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;
@@ -250,10 +249,9 @@
 }
 
 
-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)
 
 {
@@ -266,7 +264,6 @@
 
     // 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
diff -r 3946aa272087 -r 61a56f76222b src/base/loader/elf_object.hh
--- a/src/base/loader/elf_object.hh     Fri Jul 03 10:14:24 2015 -0400
+++ b/src/base/loader/elf_object.hh     Fri Jul 03 10:14:34 2015 -0400
@@ -65,8 +65,7 @@
     /// 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();
@@ -90,7 +89,7 @@
     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;}
diff -r 3946aa272087 -r 61a56f76222b src/base/loader/object_file.cc
--- a/src/base/loader/object_file.cc    Fri Jul 03 10:14:24 2015 -0400
+++ b/src/base/loader/object_file.cc    Fri Jul 03 10:14:34 2015 -0400
@@ -50,10 +50,10 @@
 
 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}
 {
@@ -95,11 +95,6 @@
 void
 ObjectFile::close()
 {
-    if (descriptor >= 0) {
-        ::close(descriptor);
-        descriptor = -1;
-    }
-
     if (fileData) {
         ::munmap((char*)fileData, len);
         fileData = NULL;
@@ -124,35 +119,34 @@
     // 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) {
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to