object_file.cc (10422:148b96b7bc77) object_file.cc (10880:61a56f76222b)
1/*
2 * Copyright (c) 2002-2004 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 36 unchanged lines hidden (view full) ---

45#include "base/loader/object_file.hh"
46#include "base/loader/raw_object.hh"
47#include "base/loader/symtab.hh"
48#include "base/cprintf.hh"
49#include "mem/port_proxy.hh"
50
51using namespace std;
52
1/*
2 * Copyright (c) 2002-2004 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 36 unchanged lines hidden (view full) ---

45#include "base/loader/object_file.hh"
46#include "base/loader/raw_object.hh"
47#include "base/loader/symtab.hh"
48#include "base/cprintf.hh"
49#include "mem/port_proxy.hh"
50
51using namespace std;
52
53ObjectFile::ObjectFile(const string &_filename, int _fd,
53ObjectFile::ObjectFile(const string &_filename,
54 size_t _len, uint8_t *_data,
55 Arch _arch, OpSys _opSys)
54 size_t _len, uint8_t *_data,
55 Arch _arch, OpSys _opSys)
56 : filename(_filename), descriptor(_fd), fileData(_data), len(_len),
56 : filename(_filename), fileData(_data), len(_len),
57 arch(_arch), opSys(_opSys), entry(0), globalPtr(0),
58 text{0, nullptr, 0}, data{0, nullptr, 0}, bss{0, nullptr, 0}
59{
60}
61
62
63ObjectFile::~ObjectFile()
64{

--- 25 unchanged lines hidden (view full) ---

90 && loadSection(&data, memProxy, addrMask, offset)
91 && loadSection(&bss, memProxy, addrMask, offset));
92}
93
94
95void
96ObjectFile::close()
97{
57 arch(_arch), opSys(_opSys), entry(0), globalPtr(0),
58 text{0, nullptr, 0}, data{0, nullptr, 0}, bss{0, nullptr, 0}
59{
60}
61
62
63ObjectFile::~ObjectFile()
64{

--- 25 unchanged lines hidden (view full) ---

90 && loadSection(&data, memProxy, addrMask, offset)
91 && loadSection(&bss, memProxy, addrMask, offset));
92}
93
94
95void
96ObjectFile::close()
97{
98 if (descriptor >= 0) {
99 ::close(descriptor);
100 descriptor = -1;
101 }
102
103 if (fileData) {
104 ::munmap((char*)fileData, len);
105 fileData = NULL;
106 }
107}
108
109
110ObjectFile *

--- 8 unchanged lines hidden (view full) ---

119 // find the length of the file by seeking to the end
120 off_t off = lseek(fd, 0, SEEK_END);
121 fatal_if(off < 0, "Failed to determine size of object file %s\n", fname);
122 size_t len = static_cast<size_t>(off);
123
124 // mmap the whole shebang
125 uint8_t *fileData =
126 (uint8_t *)mmap(NULL, len, PROT_READ, MAP_SHARED, fd, 0);
98 if (fileData) {
99 ::munmap((char*)fileData, len);
100 fileData = NULL;
101 }
102}
103
104
105ObjectFile *

--- 8 unchanged lines hidden (view full) ---

114 // find the length of the file by seeking to the end
115 off_t off = lseek(fd, 0, SEEK_END);
116 fatal_if(off < 0, "Failed to determine size of object file %s\n", fname);
117 size_t len = static_cast<size_t>(off);
118
119 // mmap the whole shebang
120 uint8_t *fileData =
121 (uint8_t *)mmap(NULL, len, PROT_READ, MAP_SHARED, fd, 0);
122 close(fd);
127 if (fileData == MAP_FAILED) {
123 if (fileData == MAP_FAILED) {
128 close(fd);
129 return NULL;
130 }
131
132 ObjectFile *fileObj = NULL;
133
134 // figure out what we have here
124 return NULL;
125 }
126
127 ObjectFile *fileObj = NULL;
128
129 // figure out what we have here
135 if ((fileObj = EcoffObject::tryFile(fname, fd, len, fileData)) != NULL) {
130 if ((fileObj = ElfObject::tryFile(fname, len, fileData)) != NULL) {
136 return fileObj;
137 }
138
131 return fileObj;
132 }
133
139 if ((fileObj = AoutObject::tryFile(fname, fd, len, fileData)) != NULL) {
134 if ((fileObj = EcoffObject::tryFile(fname, len, fileData)) != NULL) {
140 return fileObj;
141 }
142
135 return fileObj;
136 }
137
143 if ((fileObj = ElfObject::tryFile(fname, fd, len, fileData)) != NULL) {
138 if ((fileObj = AoutObject::tryFile(fname, len, fileData)) != NULL) {
144 return fileObj;
145 }
146
139 return fileObj;
140 }
141
147 if ((fileObj = DtbObject::tryFile(fname, fd, len, fileData)) != NULL) {
142 if ((fileObj = DtbObject::tryFile(fname, len, fileData)) != NULL) {
148 return fileObj;
149 }
150
151 if (raw)
143 return fileObj;
144 }
145
146 if (raw)
152 return RawObject::tryFile(fname, fd, len, fileData);
147 return RawObject::tryFile(fname, len, fileData);
153
154 // don't know what it is
148
149 // don't know what it is
155 close(fd);
156 munmap((char*)fileData, len);
157 return NULL;
158}
150 munmap((char*)fileData, len);
151 return NULL;
152}