Browse Source

fesvr: elfloader: replace asserts after open and mmap by exceptions

Asserts (especially without a message) aren't human readable way of
error reporting. So, replace them by exceptions with messages with
errno string.
pull/1261/head
Viktor Prutyanov 3 years ago
parent
commit
fe2e84e0ff
  1. 6
      fesvr/elfloader.cc

6
fesvr/elfloader.cc

@ -21,13 +21,15 @@ std::map<std::string, uint64_t> load_elf(const char* fn, memif_t* memif, reg_t*
{ {
int fd = open(fn, O_RDONLY); int fd = open(fn, O_RDONLY);
struct stat s; struct stat s;
assert(fd != -1); if (fd == -1)
throw std::invalid_argument(std::string("Specified ELF can't be opened: ") + strerror(errno));
if (fstat(fd, &s) < 0) if (fstat(fd, &s) < 0)
abort(); abort();
size_t size = s.st_size; size_t size = s.st_size;
char* buf = (char*)mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0); char* buf = (char*)mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
assert(buf != MAP_FAILED); if (buf == MAP_FAILED)
throw std::invalid_argument(std::string("Specified ELF can't be mapped: ") + strerror(errno));
close(fd); close(fd);
assert(size >= sizeof(Elf64_Ehdr)); assert(size >= sizeof(Elf64_Ehdr));

Loading…
Cancel
Save