52 size_t sz = pread(
fd, buf, 2, 0);
53 panic_if(sz != 2,
"Couldn't read magic bytes from object file");
54 return ((buf[0] == 0x1f) && (buf[1] == 0x8b));
60 const size_t blk_sz = 4096;
62 gzFile fdz = gzdopen(
fd,
"rb");
67 size_t tmp_len = strlen(P_tmpdir);
68 char *tmpnam = (
char*) malloc(tmp_len + 20);
69 strcpy(tmpnam, P_tmpdir);
70 strcpy(tmpnam+tmp_len,
"/gem5-gz-obj-XXXXXX");
78 if (unlink(tmpnam) != 0)
79 warn(
"couldn't remove temporary file %s\n", tmpnam);
83 auto buf =
new uint8_t[blk_sz];
85 while ((
r = gzread(fdz, buf, blk_sz)) > 0) {
88 auto sz = write(
fd,
p,
r);
109 int fd = open(fname.c_str(), O_RDONLY);
111 "This error typically occurs when the file path specified is "
112 "incorrect.\n", fname);
117 panic_if(
fd < 0,
"Failed to unzip file %s.\n", fname);
121 off_t off = lseek(
fd, 0, SEEK_END);
122 fatal_if(off < 0,
"Failed to determine size of file %s.\n", fname);
123 _len =
static_cast<size_t>(off);
126 _data = (uint8_t *)mmap(NULL,
_len, PROT_READ, MAP_SHARED,
fd, 0);
129 panic_if(
_data == MAP_FAILED,
"Failed to mmap file %s.\n", fname);
ImageFileData(const std::string &f_name)
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
static bool hasGzipMagic(int fd)
static int doGzipLoad(int fd)
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....