diff options
author | Viktor Prutyanov <viktor.prutyanov@phystech.edu> | 2023-02-24 00:33:58 +0300 |
---|---|---|
committer | Viktor Prutyanov <viktor.prutyanov@phystech.edu> | 2023-02-24 00:45:01 +0300 |
commit | fe2e84e0ff3d0d0cf3e6355f9cf5feb65e1d067f (patch) | |
tree | 60b5b00daa15c627cd7aa297898f0243361a4f6a /fesvr | |
parent | 0d1a48c0c0e97521c0081b130e97b1352f27380a (diff) | |
download | spike-fe2e84e0ff3d0d0cf3e6355f9cf5feb65e1d067f.zip spike-fe2e84e0ff3d0d0cf3e6355f9cf5feb65e1d067f.tar.gz spike-fe2e84e0ff3d0d0cf3e6355f9cf5feb65e1d067f.tar.bz2 |
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.
Diffstat (limited to 'fesvr')
-rw-r--r-- | fesvr/elfloader.cc | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/fesvr/elfloader.cc b/fesvr/elfloader.cc index eef19b4..c70de12 100644 --- a/fesvr/elfloader.cc +++ b/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); 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) abort(); size_t size = s.st_size; 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); assert(size >= sizeof(Elf64_Ehdr)); |