33 #include <sys/types.h>
53 size_t sz = pread(
fd, buf, 2, 0);
54 panic_if(sz != 2,
"Couldn't read magic bytes from object file");
55 return ((buf[0] == 0x1f) && (buf[1] == 0x8b));
61 const size_t blk_sz = 4096;
63 gzFile fdz = gzdopen(
fd,
"rb");
68 size_t tmp_len = strlen(P_tmpdir);
69 char *tmpnam = (
char*) malloc(tmp_len + 20);
70 strcpy(tmpnam, P_tmpdir);
71 strcpy(tmpnam+tmp_len,
"/gem5-gz-obj-XXXXXX");
79 if (unlink(tmpnam) != 0)
80 warn(
"couldn't remove temporary file %s\n", tmpnam);
84 auto buf =
new uint8_t[blk_sz];
86 while ((
r = gzread(fdz, buf, blk_sz)) > 0) {
89 auto sz = write(
fd,
p,
r);
110 int fd = open(fname.c_str(), O_RDONLY);
112 "This error typically occurs when the file path specified is "
113 "incorrect.\n", fname);
118 panic_if(
fd < 0,
"Failed to unzip file %s.\n", fname);
122 off_t off = lseek(
fd, 0, SEEK_END);
123 fatal_if(off < 0,
"Failed to determine size of file %s.\n", fname);
124 _len =
static_cast<size_t>(off);
127 _data = (uint8_t *)mmap(NULL,
_len, PROT_READ, MAP_SHARED,
fd, 0);
130 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....
GEM5_DEPRECATED_NAMESPACE(GuestABI, guest_abi)