MCPcopy Create free account
hub / github.com/apple/foundationdb / Init

Method Init

contrib/stacktrace/stacktrace.amalgamation.cpp:2412–2533  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2410}
2411
2412void ElfMemImage::Init(const void* base) {
2413 ehdr_ = nullptr;
2414 dynsym_ = nullptr;
2415 dynstr_ = nullptr;
2416 versym_ = nullptr;
2417 verdef_ = nullptr;
2418 hash_ = nullptr;
2419 strsize_ = 0;
2420 verdefnum_ = 0;
2421 link_base_ = ~0L; // Sentinel: PT_LOAD .p_vaddr can't possibly be this.
2422 if (!base) {
2423 return;
2424 }
2425 const intptr_t base_as_uintptr_t = reinterpret_cast<uintptr_t>(base);
2426 // Fake VDSO has low bit set.
2427 const bool fake_vdso = ((base_as_uintptr_t & 1) != 0);
2428 base = reinterpret_cast<const void*>(base_as_uintptr_t & ~1);
2429 const char* const base_as_char = reinterpret_cast<const char*>(base);
2430 if (base_as_char[EI_MAG0] != ELFMAG0 || base_as_char[EI_MAG1] != ELFMAG1 || base_as_char[EI_MAG2] != ELFMAG2 ||
2431 base_as_char[EI_MAG3] != ELFMAG3) {
2432 assert(false);
2433 return;
2434 }
2435 int elf_class = base_as_char[EI_CLASS];
2436 if (elf_class != kElfClass) {
2437 assert(false);
2438 return;
2439 }
2440 switch (base_as_char[EI_DATA]) {
2441 case ELFDATA2LSB: {
2442 if (__LITTLE_ENDIAN != __BYTE_ORDER) {
2443 assert(false);
2444 return;
2445 }
2446 break;
2447 }
2448 case ELFDATA2MSB: {
2449 if (__BIG_ENDIAN != __BYTE_ORDER) {
2450 assert(false);
2451 return;
2452 }
2453 break;
2454 }
2455 default: {
2456 assert(false);
2457 return;
2458 }
2459 }
2460
2461 ehdr_ = reinterpret_cast<const ElfW(Ehdr)*>(base);
2462 const ElfW(Phdr)* dynamic_program_header = nullptr;
2463 for (int i = 0; i < ehdr_->e_phnum; ++i) {
2464 const ElfW(Phdr)* const program_header = GetPhdr(i);
2465 switch (program_header->p_type) {
2466 case PT_LOAD:
2467 if (!~link_base_) {
2468 link_base_ = program_header->p_vaddr;
2469 }

Callers 1

SetBaseMethod · 0.45

Calls 7

RunningOnValgrindFunction · 0.85
LookupSymbolMethod · 0.80
openFunction · 0.50
readFunction · 0.50
closeFunction · 0.50
loadMethod · 0.45
storeMethod · 0.45

Tested by

no test coverage detected