dtb_object.cc (10508:aa46a8ae3487) | dtb_object.cc (10880:61a56f76222b) |
---|---|
1/* 2 * Copyright (c) 2013 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; --- 26 unchanged lines hidden (view full) --- 35#include <cassert> 36 37#include "base/loader/dtb_object.hh" 38#include "sim/byteswap.hh" 39#include "fdt.h" 40#include "libfdt.h" 41 42ObjectFile * | 1/* 2 * Copyright (c) 2013 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; --- 26 unchanged lines hidden (view full) --- 35#include <cassert> 36 37#include "base/loader/dtb_object.hh" 38#include "sim/byteswap.hh" 39#include "fdt.h" 40#include "libfdt.h" 41 42ObjectFile * |
43DtbObject::tryFile(const std::string &fname, int fd, size_t len, uint8_t *data) | 43DtbObject::tryFile(const std::string &fname, size_t len, uint8_t *data) |
44{ 45 // Check if this is a FDT file by looking for magic number 46 if (fdt_magic((void*)data) == FDT_MAGIC) { | 44{ 45 // Check if this is a FDT file by looking for magic number 46 if (fdt_magic((void*)data) == FDT_MAGIC) { |
47 return new DtbObject(fname, fd, len, data, | 47 return new DtbObject(fname, len, data, |
48 ObjectFile::UnknownArch, ObjectFile::UnknownOpSys); 49 } else { 50 return NULL; 51 } 52} 53 | 48 ObjectFile::UnknownArch, ObjectFile::UnknownOpSys); 49 } else { 50 return NULL; 51 } 52} 53 |
54DtbObject::DtbObject(const std::string &_filename, int _fd, 55 size_t _len, uint8_t *_data, | 54DtbObject::DtbObject(const std::string &_filename, size_t _len, uint8_t *_data, |
56 Arch _arch, OpSys _opSys) | 55 Arch _arch, OpSys _opSys) |
57 : ObjectFile(_filename, _fd, _len, _data, _arch, _opSys) | 56 : ObjectFile(_filename, _len, _data, _arch, _opSys) |
58{ 59 text.baseAddr = 0; 60 text.size = len; 61 text.fileImage = fileData; 62 63 data.baseAddr = 0; 64 data.size = 0; 65 data.fileImage = NULL; 66 67 bss.baseAddr = 0; 68 bss.size = 0; 69 bss.fileImage = NULL; 70 71 fileDataMmapped = true; 72} 73 74DtbObject::~DtbObject() 75{ | 57{ 58 text.baseAddr = 0; 59 text.size = len; 60 text.fileImage = fileData; 61 62 data.baseAddr = 0; 63 data.size = 0; 64 data.fileImage = NULL; 65 66 bss.baseAddr = 0; 67 bss.size = 0; 68 bss.fileImage = NULL; 69 70 fileDataMmapped = true; 71} 72 73DtbObject::~DtbObject() 74{ |
76 if (descriptor >= 0) { 77 ::close(descriptor); 78 descriptor = -1; 79 } 80 | |
81 // Make sure to clean up memory properly depending 82 // on how buffer was allocated. 83 if (fileData && !fileDataMmapped) { 84 delete [] fileData; 85 fileData = NULL; 86 } else if (fileData) { 87 munmap(fileData, len); 88 fileData = NULL; --- 102 unchanged lines hidden --- | 75 // Make sure to clean up memory properly depending 76 // on how buffer was allocated. 77 if (fileData && !fileDataMmapped) { 78 delete [] fileData; 79 fileData = NULL; 80 } else if (fileData) { 81 munmap(fileData, len); 82 fileData = NULL; --- 102 unchanged lines hidden --- |