#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "base/debug/test_elf_image_builder.h"
#include <cstring>
#include <string_view>
#include <type_traits>
#include <utility>
#include "base/bits.h"
#include "base/check.h"
#include "base/notreached.h"
#include "build/build_config.h"
#if __SIZEOF_POINTER__ == 4
using Dyn = Elf32_Dyn;
using Nhdr = Elf32_Nhdr;
using Shdr = Elf32_Shdr;
#else
Dyn;
Nhdr;
Shdr;
#endif
namespace base {
namespace {
static constexpr size_t kPageSize = …;
static constexpr size_t kPhdrAlign = …;
static constexpr size_t kNoteAlign = …;
static constexpr size_t kLoadAlign = …;
static constexpr size_t kDynamicAlign = …;
}
struct TestElfImageBuilder::LoadSegment { … };
TestElfImage::TestElfImage(std::vector<uint8_t> buffer, const void* elf_start)
: … { … }
TestElfImage::~TestElfImage() = default;
TestElfImage::TestElfImage(TestElfImage&&) = default;
TestElfImage& TestElfImage::operator=(TestElfImage&&) = default;
TestElfImageBuilder::TestElfImageBuilder(MappingType mapping_type)
: … { … }
TestElfImageBuilder::~TestElfImageBuilder() = default;
TestElfImageBuilder& TestElfImageBuilder::AddLoadSegment(Word flags,
size_t size) { … }
TestElfImageBuilder& TestElfImageBuilder::AddNoteSegment(
Word type,
std::string_view name,
span<const uint8_t> desc) { … }
TestElfImageBuilder& TestElfImageBuilder::AddSoName(std::string_view soname) { … }
struct TestElfImageBuilder::ImageMeasures { … };
Addr TestElfImageBuilder::GetVirtualAddressForOffset(
Off offset,
const uint8_t* elf_start) const { … }
TestElfImageBuilder::ImageMeasures TestElfImageBuilder::MeasureSizesAndOffsets()
const { … }
TestElfImage TestElfImageBuilder::Build() { … }
template <typename T>
uint8_t* TestElfImageBuilder::AppendHdr(const T& hdr, uint8_t* loc) { … }
Ehdr TestElfImageBuilder::CreateEhdr(Half phnum) { … }
Phdr TestElfImageBuilder::CreatePhdr(Word type,
Word flags,
size_t align,
Off offset,
Addr vaddr,
size_t size) { … }
}