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,
54 size_t _len, uint8_t *_data,
55 Arch _arch, OpSys _opSys)
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{
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);
123 if (fileData == MAP_FAILED) {
124 return NULL;
125 }
126
127 ObjectFile *fileObj = NULL;
128
129 // figure out what we have here
130 if ((fileObj = ElfObject::tryFile(fname, len, fileData)) != NULL) {
131 return fileObj;
132 }
133
134 if ((fileObj = EcoffObject::tryFile(fname, len, fileData)) != NULL) {
135 return fileObj;
136 }
137
138 if ((fileObj = AoutObject::tryFile(fname, len, fileData)) != NULL) {
139 return fileObj;
140 }
141
142 if ((fileObj = DtbObject::tryFile(fname, len, fileData)) != NULL) {
143 return fileObj;
144 }
145
146 if (raw)
147 return RawObject::tryFile(fname, len, fileData);
148
149 // don't know what it is
150 munmap((char*)fileData, len);
151 return NULL;
152}