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 std::string tmpnam_str = std::string(P_tmpdir) +
"/gem5-gz-obj-XXXXXX";
68 char *tmpnam =
const_cast<char*
>(tmpnam_str.c_str());
75 if (unlink(tmpnam) != 0)
76 warn(
"couldn't remove temporary file %s\n", tmpnam);
78 auto buf =
new uint8_t[blk_sz];
80 while ((
r = gzread(fdz, buf, blk_sz)) > 0) {
83 auto sz = write(
fd,
p,
r);
104 int fd = open(fname.c_str(), O_RDONLY);
106 "This error typically occurs when the file path specified is "
107 "incorrect.\n", fname);
112 panic_if(
fd < 0,
"Failed to unzip file %s.\n", fname);
116 off_t off = lseek(
fd, 0, SEEK_END);
117 fatal_if(off < 0,
"Failed to determine size of file %s.\n", fname);
118 _len =
static_cast<size_t>(off);
121 _data = (uint8_t *)mmap(NULL,
_len, PROT_READ, MAP_SHARED,
fd, 0);
124 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)
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.