Deleted Added
sdiff udiff text old ( 10422:148b96b7bc77 ) new ( 10880:61a56f76222b )
full compact
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,
54 size_t _len, uint8_t *_data,
55 Arch _arch, OpSys _opSys)
56 : filename(_filename), descriptor(_fd), 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{
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);
127 if (fileData == MAP_FAILED) {
128 close(fd);
129 return NULL;
130 }
131
132 ObjectFile *fileObj = NULL;
133
134 // figure out what we have here
135 if ((fileObj = EcoffObject::tryFile(fname, fd, len, fileData)) != NULL) {
136 return fileObj;
137 }
138
139 if ((fileObj = AoutObject::tryFile(fname, fd, len, fileData)) != NULL) {
140 return fileObj;
141 }
142
143 if ((fileObj = ElfObject::tryFile(fname, fd, len, fileData)) != NULL) {
144 return fileObj;
145 }
146
147 if ((fileObj = DtbObject::tryFile(fname, fd, len, fileData)) != NULL) {
148 return fileObj;
149 }
150
151 if (raw)
152 return RawObject::tryFile(fname, fd, len, fileData);
153
154 // don't know what it is
155 close(fd);
156 munmap((char*)fileData, len);
157 return NULL;
158}