aboutsummaryrefslogtreecommitdiff
path: root/fesvr/elfloader.cc
AgeCommit message (Collapse)AuthorFilesLines
2023-02-24fesvr: elfloader: replace asserts after open and mmap by exceptionsViktor Prutyanov1-2/+4
Asserts (especially without a message) aren't human readable way of error reporting. So, replace them by exceptions with messages with errno string.
2022-12-15Add config.h includes directly to source files instead of relying on header ↵Jerry Zhao1-0/+1
chaining This step is to ensure that removing config.h out of headers will not cause regressions.
2022-12-15Rename memif_endianness_t to endianness_tJerry Zhao1-2/+2
2022-10-25Remove set_target_endianness | add --big-endian flagJerry Zhao1-2/+6
Set target endianess in constructors
2022-09-20detects the loading of isa-incompatible (i.e. 32 bit code to 64bit HART) ↵Iman Hosseini1-1/+5
code and emits an error message to help avoid unintentionally loading wrong elf.
2021-08-26fesvr: replace use of `std::vector::operator[0]`Saleem Abdulrasool1-1/+1
This replaces multiple uses of `std::vector::operator[]` where the parameter is a constant `0` with the use of C++11's `std::vector::data` method. This fixes the root cause of invalid memory accesses. `std::vector::operator[]` is an unchecked memory access, and when the buffers are zero-sized (that is the buffer container is empty) either due to a 0 padding in the case of elfloader or NULL parameters to syscalls where permitted, the unchecked access may cause an invalid memory access. The use of `std::vector::data` is permitted even in such a case, though the returned memory may not be dereferenced. The general usage of the returned pointer is to pass to `memif_t`, which is careful about 0-sized buffer accesses, and so passing the result of `std::vector::data` is safe. This is theoretically a better access pattern as it also avoids having the compiler to re-materialize the pointer from the de-referenced location.
2021-08-26fesvr: avoid an invalid memory accessSaleem Abdulrasool1-3/+5
`std::vector::operator[]` does not perform a bounds check when accessing the underlying memory. If the length of the padding is 0, this would access an invalid memory location. Guard against this by ensuring that we have any padding to apply by constant hoisting the length computation and checking the value.
2021-08-26fesvr: format `LOAD_ELF` macro (NFC)Saleem Abdulrasool1-43/+50
This simply uses clang-format to reflow the text of the macro, which makes it easier to read and edit.
2020-11-26Include stdexcept in ELF loader (#603)Daniel Bates1-0/+1
2020-11-07Implement support for big-endian targetsMarcus Comstedt1-5/+18
2020-01-25Allow EM_NONE ELFs, tooAndrew Waterman1-1/+1
2020-01-25Refuse to load non-EXEC/non-RISC-V/non-V1 ELFs (#388)Alexander Lent1-0/+3
Stricter validation of ELF binaries improves usability with informative assertions. This prevents users from loading ELF relocatable files and binaries compiled for their (non-RISC-V) workstations, for example. Without this patch, spike would attempt to load nearly any ELF given, but it would usually fail with an error about debug module accesses, since the given ELF causes accesses in the debug module's memory space. Even if spike successfully loaded the ELF file, it would still misbehave during simulation, for example in the case of ELF relocatable files. ELF magic numbers come from official ELF documents: TIS ELF spec v1.2, via Linux Foundation Referenced Specifications See: https://refspecs.linuxbase.org/ RISC-V magic number comes from official RISC-V ELF documents: See: riscv/riscv-elf-psabi-doc@60c25981b62c0b43d16142f8a12c8b1e98e60d4d
2019-10-28Whithhold BE ELF loading until BE target support is availableMarcus Comstedt1-9/+3
2019-10-28Implement support for big-endian hostsMarcus Comstedt1-33/+41
2019-03-31Add fesvr; only globally install fesvr headers/libsstatic-linkAndrew Waterman1-0/+89