DynamicLoader.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. /*
  2. * Copyright (c) 2019-2020, Andrew Kaster <andrewdkaster@gmail.com>
  3. * Copyright (c) 2020, Itamar S. <itamar8910@gmail.com>
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form must reproduce the above copyright notice,
  13. * this list of conditions and the following disclaimer in the documentation
  14. * and/or other materials provided with the distribution.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  17. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  20. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  21. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  22. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  23. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  24. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  25. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #include <AK/StringBuilder.h>
  28. #include <LibELF/DynamicLoader.h>
  29. #include <LibELF/Validation.h>
  30. #include <assert.h>
  31. #include <dlfcn.h>
  32. #include <stdio.h>
  33. #include <stdlib.h>
  34. #include <string.h>
  35. #include <sys/mman.h>
  36. #ifndef DYNAMIC_LOAD_DEBUG
  37. # define DYNAMIC_LOAD_DEBUG
  38. #endif
  39. // #define DYNAMIC_LOAD_VERBOSE
  40. #ifdef DYNAMIC_LOAD_VERBOSE
  41. # define VERBOSE(fmt, ...) dbgprintf(fmt, ##__VA_ARGS__)
  42. #else
  43. # define VERBOSE(fmt, ...) \
  44. do { \
  45. } while (0)
  46. #endif
  47. #ifndef __serenity__
  48. static void* mmap_with_name(void* addr, size_t length, int prot, int flags, int fd, off_t offset, const char*)
  49. {
  50. return mmap(addr, length, prot, flags, fd, offset);
  51. }
  52. #endif
  53. namespace ELF {
  54. static bool s_always_bind_now = false;
  55. NonnullRefPtr<DynamicLoader> DynamicLoader::construct(const char* filename, int fd, size_t size)
  56. {
  57. return adopt(*new DynamicLoader(filename, fd, size));
  58. }
  59. void* DynamicLoader::do_mmap(int fd, size_t size, const String& name)
  60. {
  61. if (size < sizeof(Elf32_Ehdr))
  62. return MAP_FAILED;
  63. String file_mmap_name = String::format("ELF_DYN: %s", name.characters());
  64. return mmap_with_name(nullptr, size, PROT_READ, MAP_PRIVATE, fd, 0, file_mmap_name.characters());
  65. }
  66. DynamicLoader::DynamicLoader(const char* filename, int fd, size_t size)
  67. : m_filename(filename)
  68. , m_file_size(size)
  69. , m_image_fd(fd)
  70. , m_file_mapping(do_mmap(m_image_fd, m_file_size, m_filename))
  71. , m_elf_image((u8*)m_file_mapping, m_file_size)
  72. {
  73. if (m_file_mapping == MAP_FAILED) {
  74. m_valid = false;
  75. return;
  76. }
  77. m_tls_size = calculate_tls_size();
  78. m_valid = validate();
  79. }
  80. RefPtr<DynamicObject> DynamicLoader::dynamic_object_from_image() const
  81. {
  82. VirtualAddress dynamic_section_address;
  83. m_elf_image.for_each_program_header([&dynamic_section_address](auto program_header) {
  84. if (program_header.type() == PT_DYNAMIC) {
  85. dynamic_section_address = VirtualAddress(program_header.raw_data());
  86. }
  87. return IterationDecision::Continue;
  88. });
  89. ASSERT(!dynamic_section_address.is_null());
  90. return ELF::DynamicObject::construct(VirtualAddress(m_elf_image.base_address()), dynamic_section_address);
  91. }
  92. size_t DynamicLoader::calculate_tls_size() const
  93. {
  94. size_t tls_size = 0;
  95. m_elf_image.for_each_program_header([&tls_size](auto program_header) {
  96. if (program_header.type() == PT_TLS) {
  97. tls_size = program_header.size_in_memory();
  98. }
  99. return IterationDecision::Continue;
  100. });
  101. return tls_size;
  102. }
  103. bool DynamicLoader::validate()
  104. {
  105. auto* elf_header = (Elf32_Ehdr*)m_file_mapping;
  106. return validate_elf_header(*elf_header, m_file_size) && validate_program_headers(*elf_header, m_file_size, (u8*)m_file_mapping, m_file_size, &m_program_interpreter);
  107. }
  108. DynamicLoader::~DynamicLoader()
  109. {
  110. if (MAP_FAILED != m_file_mapping)
  111. munmap(m_file_mapping, m_file_size);
  112. close(m_image_fd);
  113. }
  114. void* DynamicLoader::symbol_for_name(const char* name)
  115. {
  116. auto symbol = m_dynamic_object->hash_section().lookup_symbol(name);
  117. if (symbol.is_undefined())
  118. return nullptr;
  119. return m_dynamic_object->base_address().offset(symbol.value()).as_ptr();
  120. }
  121. RefPtr<DynamicObject> DynamicLoader::load_from_image(unsigned flags, size_t total_tls_size)
  122. {
  123. m_valid = m_elf_image.is_valid();
  124. if (!m_valid) {
  125. dbgprintf("DynamicLoader::load_from_image failed: image is invalid\n");
  126. return nullptr;
  127. }
  128. #ifdef DYNAMIC_LOAD_VERBOSE
  129. // m_image->dump();
  130. #endif
  131. load_program_headers();
  132. m_dynamic_object = DynamicObject::construct(m_text_segment_load_address, m_dynamic_section_address);
  133. m_dynamic_object->set_tls_offset(m_tls_offset);
  134. m_dynamic_object->set_tls_size(m_tls_size);
  135. auto rc = load_stage_2(flags, total_tls_size);
  136. if (!rc) {
  137. dbgprintf("DynamicLoader::load_from_image failed at load_stage_2\n");
  138. return nullptr;
  139. }
  140. return m_dynamic_object;
  141. }
  142. bool DynamicLoader::load_stage_2(unsigned flags, size_t total_tls_size)
  143. {
  144. ASSERT(flags & RTLD_GLOBAL);
  145. #ifdef DYNAMIC_LOAD_DEBUG
  146. m_dynamic_object->dump();
  147. #endif
  148. if (m_dynamic_object->has_text_relocations()) {
  149. // dbg() << "Someone linked non -fPIC code into " << m_filename << " :(";
  150. ASSERT(m_text_segment_load_address.get() != 0);
  151. #ifndef AK_OS_MACOS
  152. // Remap this text region as private.
  153. if (mremap(m_text_segment_load_address.as_ptr(), m_text_segment_size, m_text_segment_size, MAP_PRIVATE) == MAP_FAILED) {
  154. perror("mremap .text: MAP_PRIVATE");
  155. return false;
  156. }
  157. #endif
  158. if (0 > mprotect(m_text_segment_load_address.as_ptr(), m_text_segment_size, PROT_READ | PROT_WRITE)) {
  159. perror("mprotect .text: PROT_READ | PROT_WRITE"); // FIXME: dlerror?
  160. return false;
  161. }
  162. }
  163. do_relocations(total_tls_size);
  164. if (flags & RTLD_LAZY) {
  165. setup_plt_trampoline();
  166. }
  167. // Clean up our setting of .text to PROT_READ | PROT_WRITE
  168. if (m_dynamic_object->has_text_relocations()) {
  169. if (0 > mprotect(m_text_segment_load_address.as_ptr(), m_text_segment_size, PROT_READ | PROT_EXEC)) {
  170. perror("mprotect .text: PROT_READ | PROT_EXEC"); // FIXME: dlerror?
  171. return false;
  172. }
  173. }
  174. call_object_init_functions();
  175. VERBOSE("Loaded %s\n", m_filename.characters());
  176. return true;
  177. }
  178. void DynamicLoader::load_program_headers()
  179. {
  180. Vector<ProgramHeaderRegion> program_headers;
  181. ProgramHeaderRegion* text_region_ptr = nullptr;
  182. ProgramHeaderRegion* data_region_ptr = nullptr;
  183. ProgramHeaderRegion* tls_region_ptr = nullptr;
  184. VirtualAddress dynamic_region_desired_vaddr;
  185. m_elf_image.for_each_program_header([&](const Image::ProgramHeader& program_header) {
  186. ProgramHeaderRegion new_region;
  187. new_region.set_program_header(program_header.raw_header());
  188. program_headers.append(move(new_region));
  189. auto& region = program_headers.last();
  190. if (region.is_tls_template())
  191. tls_region_ptr = &region;
  192. else if (region.is_load()) {
  193. if (region.is_executable())
  194. text_region_ptr = &region;
  195. else
  196. data_region_ptr = &region;
  197. } else if (region.is_dynamic()) {
  198. dynamic_region_desired_vaddr = region.desired_load_address();
  199. }
  200. return IterationDecision::Continue;
  201. });
  202. ASSERT(text_region_ptr && data_region_ptr);
  203. // Process regions in order: .text, .data, .tls
  204. auto* region = text_region_ptr;
  205. void* requested_load_address = m_elf_image.is_dynamic() ? nullptr : region->desired_load_address().as_ptr();
  206. ASSERT(!region->is_writable());
  207. void* text_segment_begin = mmap_with_name(
  208. requested_load_address,
  209. region->required_load_size(),
  210. region->mmap_prot(),
  211. MAP_SHARED,
  212. m_image_fd,
  213. region->offset(),
  214. String::format("%s: .text", m_filename.characters()).characters());
  215. if (MAP_FAILED == text_segment_begin) {
  216. ASSERT_NOT_REACHED();
  217. }
  218. ASSERT(requested_load_address == nullptr || requested_load_address == text_segment_begin);
  219. m_text_segment_size = region->required_load_size();
  220. m_text_segment_load_address = VirtualAddress { (FlatPtr)text_segment_begin };
  221. if (m_elf_image.is_dynamic())
  222. m_dynamic_section_address = dynamic_region_desired_vaddr.offset(m_text_segment_load_address.get());
  223. else
  224. m_dynamic_section_address = dynamic_region_desired_vaddr;
  225. region = data_region_ptr;
  226. void* data_segment_begin = mmap_with_name(
  227. (u8*)text_segment_begin + m_text_segment_size,
  228. region->required_load_size(),
  229. region->mmap_prot(),
  230. MAP_ANONYMOUS | MAP_PRIVATE,
  231. 0,
  232. 0,
  233. String::format("%s: .data", m_filename.characters()).characters());
  234. if (MAP_FAILED == data_segment_begin) {
  235. ASSERT_NOT_REACHED();
  236. }
  237. VirtualAddress data_segment_actual_addr;
  238. if (m_elf_image.is_dynamic()) {
  239. data_segment_actual_addr = region->desired_load_address().offset((FlatPtr)text_segment_begin);
  240. } else {
  241. data_segment_actual_addr = region->desired_load_address();
  242. }
  243. memcpy(data_segment_actual_addr.as_ptr(), (u8*)m_file_mapping + region->offset(), region->size_in_image());
  244. // FIXME: Initialize the values in the TLS section. Currently, it is zeroed.
  245. }
  246. void DynamicLoader::do_relocations(size_t total_tls_size)
  247. {
  248. auto main_relocation_section = m_dynamic_object->relocation_section();
  249. main_relocation_section.for_each_relocation([&](ELF::DynamicObject::Relocation relocation) {
  250. VERBOSE("Relocation symbol: %s, type: %d\n", relocation.symbol().name(), relocation.type());
  251. FlatPtr* patch_ptr = nullptr;
  252. if (is_dynamic())
  253. patch_ptr = (FlatPtr*)(m_dynamic_object->base_address().as_ptr() + relocation.offset());
  254. else
  255. patch_ptr = (FlatPtr*)(FlatPtr)relocation.offset();
  256. // VERBOSE("dynamic object name: %s\n", dynamic_object.object_name());
  257. VERBOSE("dynamic object base address: %p\n", m_dynamic_object->base_address());
  258. VERBOSE("relocation offset: 0x%x\n", relocation.offset());
  259. VERBOSE("patch_ptr: %p\n", patch_ptr);
  260. switch (relocation.type()) {
  261. case R_386_NONE:
  262. // Apparently most loaders will just skip these?
  263. // Seems if the 'link editor' generates one something is funky with your code
  264. VERBOSE("None relocation. No symbol, no nothing.\n");
  265. break;
  266. case R_386_32: {
  267. auto symbol = relocation.symbol();
  268. VERBOSE("Absolute relocation: name: '%s', value: %p\n", symbol.name(), symbol.value());
  269. auto res = lookup_symbol(symbol);
  270. if (!res.found) {
  271. dbgln("ERROR: symbol not found: {}", symbol.name());
  272. ASSERT_NOT_REACHED();
  273. }
  274. u32 symbol_address = res.address;
  275. *patch_ptr += symbol_address;
  276. VERBOSE(" Symbol address: %p\n", *patch_ptr);
  277. break;
  278. }
  279. case R_386_PC32: {
  280. auto symbol = relocation.symbol();
  281. VERBOSE("PC-relative relocation: '%s', value: %p\n", symbol.name(), symbol.value());
  282. auto res = lookup_symbol(symbol);
  283. ASSERT(res.found);
  284. u32 relative_offset = (res.address - (FlatPtr)(m_dynamic_object->base_address().as_ptr() + relocation.offset()));
  285. *patch_ptr += relative_offset;
  286. VERBOSE(" Symbol address: %p\n", *patch_ptr);
  287. break;
  288. }
  289. case R_386_GLOB_DAT: {
  290. auto symbol = relocation.symbol();
  291. VERBOSE("Global data relocation: '%s', value: %p\n", symbol.name(), symbol.value());
  292. auto res = lookup_symbol(symbol);
  293. if (!res.found) {
  294. // We do not support these
  295. // TODO: Can we tell gcc not to generate the piece of code that uses these?
  296. // (--disable-tm-clone-registry flag in gcc conifugraion?)
  297. if (!strcmp(symbol.name(), "__deregister_frame_info") || !strcmp(symbol.name(), "_ITM_registerTMCloneTable")
  298. || !strcmp(symbol.name(), "_ITM_deregisterTMCloneTable") || !strcmp(symbol.name(), "__register_frame_info")) {
  299. break;
  300. }
  301. // The "__do_global_dtors_aux" function in libgcc_s.so needs this symbol,
  302. // but we do not use that function so we don't actually need to resolve this symbol.
  303. // The reason we can't resolve it here is that the symbol is defined in libc.so,
  304. // but there's a circular dependency between libgcc_s.so and libc.so,
  305. // we deal with it by first loading libgcc_s and then libc.
  306. // So we cannot find this symbol at this time (libc is not yet loaded).
  307. if (m_filename == "libgcc_s.so" && !strcmp(symbol.name(), "__cxa_finalize")) {
  308. break;
  309. }
  310. // Symbol not found
  311. ASSERT_NOT_REACHED();
  312. }
  313. VERBOSE("was symbol found? %d, address: 0x%x\n", res.found, res.address);
  314. VERBOSE("object: %s\n", m_filename.characters());
  315. if (!res.found) {
  316. // TODO this is a hack
  317. ASSERT(!strcmp(symbol.name(), "__deregister_frame_info") || !strcmp(symbol.name(), "_ITM_registerTMCloneTable")
  318. || !strcmp(symbol.name(), "_ITM_deregisterTMCloneTable") || !strcmp(symbol.name(), "__register_frame_info"));
  319. ASSERT_NOT_REACHED();
  320. return IterationDecision::Continue;
  321. }
  322. // ASSERT(res.found);
  323. u32 symbol_location = res.address;
  324. ASSERT(symbol_location != (FlatPtr)m_dynamic_object->base_address().as_ptr());
  325. *patch_ptr = symbol_location;
  326. VERBOSE(" Symbol address: %p\n", *patch_ptr);
  327. break;
  328. }
  329. case R_386_RELATIVE: {
  330. // FIXME: According to the spec, R_386_relative ones must be done first.
  331. // We could explicitly do them first using m_number_of_relocatoins from DT_RELCOUNT
  332. // However, our compiler is nice enough to put them at the front of the relocations for us :)
  333. VERBOSE("Load address relocation at offset %X\n", relocation.offset());
  334. VERBOSE(" patch ptr == %p, adding load base address (%p) to it and storing %p\n", *patch_ptr, m_dynamic_object->base_address().as_ptr(), *patch_ptr + m_dynamic_object->base_address().as_ptr());
  335. *patch_ptr += (FlatPtr)m_dynamic_object->base_address().as_ptr(); // + addend for RelA (addend for Rel is stored at addr)
  336. break;
  337. }
  338. case R_386_TLS_TPOFF32:
  339. case R_386_TLS_TPOFF: {
  340. VERBOSE("Relocation type: R_386_TLS_TPOFF at offset %X\n", relocation.offset());
  341. auto symbol = relocation.symbol();
  342. // For some reason, LibC has a R_386_TLS_TPOFF that refers to the undefined symbol.. huh
  343. if (relocation.symbol_index() == 0)
  344. break;
  345. VERBOSE("Symbol index: %d\n", symbol.index());
  346. VERBOSE("Symbol is_undefined?: %d\n", symbol.is_undefined());
  347. VERBOSE("TLS relocation: '%s', value: %p\n", symbol.name(), symbol.value());
  348. auto res = lookup_symbol(symbol);
  349. if (!res.found)
  350. break;
  351. ASSERT(res.found);
  352. u32 symbol_value = res.value;
  353. VERBOSE("symbol value: %d\n", symbol_value);
  354. const auto dynamic_object_of_symbol = res.dynamic_object;
  355. ASSERT(dynamic_object_of_symbol);
  356. size_t offset_of_tls_end = dynamic_object_of_symbol->tls_offset().value() + dynamic_object_of_symbol->tls_size().value();
  357. // size_t offset_of_tls_end = tls_offset() + tls_size();
  358. VERBOSE("patch ptr: 0x%x\n", patch_ptr);
  359. VERBOSE("tls end offset: %d, total tls size: %d\n", offset_of_tls_end, total_tls_size);
  360. *patch_ptr = (offset_of_tls_end - total_tls_size - symbol_value - sizeof(Elf32_Addr));
  361. VERBOSE("*patch ptr: %d\n", (i32)*patch_ptr);
  362. break;
  363. }
  364. default:
  365. // Raise the alarm! Someone needs to implement this relocation type
  366. VERBOSE("Found a new exciting relocation type %d\n", relocation.type());
  367. // printf("DynamicLoader: Found unknown relocation type %d\n", relocation.type());
  368. ASSERT_NOT_REACHED();
  369. break;
  370. }
  371. return IterationDecision::Continue;
  372. });
  373. VERBOSE("plt relocations: 0x%x", m_dynamic_object->plt_relocation_section().address());
  374. VERBOSE("plt relocation count: 0x%x", m_dynamic_object->plt_relocation_section().address());
  375. VERBOSE("plt size: %d\n", m_dynamic_object->plt_relocation_section().size());
  376. VERBOSE("plt entry size: 0x%x\n", m_dynamic_object->plt_relocation_section().entry_size());
  377. // Handle PLT Global offset table relocations.
  378. m_dynamic_object->plt_relocation_section().for_each_relocation([&](const DynamicObject::Relocation& relocation) {
  379. // FIXME: Or BIND_NOW flag passed in?
  380. if (m_dynamic_object->must_bind_now() || s_always_bind_now) {
  381. // Eagerly BIND_NOW the PLT entries, doing all the symbol looking goodness
  382. // The patch method returns the address for the LAZY fixup path, but we don't need it here
  383. VERBOSE("patching plt reloaction: 0x%x\n", relocation.offset_in_section());
  384. [[maybe_unused]] auto rc = m_dynamic_object->patch_plt_entry(relocation.offset_in_section());
  385. } else {
  386. ASSERT(relocation.type() == R_386_JMP_SLOT);
  387. u8* relocation_address = relocation.address().as_ptr();
  388. if (m_elf_image.is_dynamic())
  389. *(u32*)relocation_address += (FlatPtr)m_dynamic_object->base_address().as_ptr();
  390. }
  391. return IterationDecision::Continue;
  392. });
  393. VERBOSE("Done relocating!\n");
  394. }
  395. // Defined in <arch>/plt_trampoline.S
  396. extern "C" void _plt_trampoline(void) __attribute__((visibility("hidden")));
  397. void DynamicLoader::setup_plt_trampoline()
  398. {
  399. ASSERT(m_dynamic_object);
  400. VirtualAddress got_address = m_dynamic_object->plt_got_base_address();
  401. FlatPtr* got_ptr = (FlatPtr*)got_address.as_ptr();
  402. got_ptr[1] = (FlatPtr)m_dynamic_object.ptr();
  403. got_ptr[2] = (FlatPtr)&_plt_trampoline;
  404. VERBOSE("Set GOT PLT entries at %p: [0] = %p [1] = %p, [2] = %p\n", got_ptr, (void*)got_ptr[0], (void*)got_ptr[1], (void*)got_ptr[2]);
  405. }
  406. // Called from our ASM routine _plt_trampoline.
  407. // Tell the compiler that it might be called from other places:
  408. extern "C" Elf32_Addr _fixup_plt_entry(DynamicObject* object, u32 relocation_offset);
  409. extern "C" Elf32_Addr _fixup_plt_entry(DynamicObject* object, u32 relocation_offset)
  410. {
  411. return object->patch_plt_entry(relocation_offset);
  412. }
  413. void DynamicLoader::call_object_init_functions()
  414. {
  415. typedef void (*InitFunc)();
  416. if (m_dynamic_object->has_init_section()) {
  417. auto init_function = (InitFunc)(m_dynamic_object->init_section().address().as_ptr());
  418. VERBOSE("Calling DT_INIT at %p\n", init_function);
  419. (init_function)();
  420. }
  421. if (m_dynamic_object->has_init_array_section()) {
  422. auto init_array_section = m_dynamic_object->init_array_section();
  423. InitFunc* init_begin = (InitFunc*)(init_array_section.address().as_ptr());
  424. InitFunc* init_end = init_begin + init_array_section.entry_count();
  425. while (init_begin != init_end) {
  426. // Android sources claim that these can be -1, to be ignored.
  427. // 0 definitely shows up. Apparently 0/-1 are valid? Confusing.
  428. if (!*init_begin || ((FlatPtr)*init_begin == (FlatPtr)-1))
  429. continue;
  430. VERBOSE("Calling DT_INITARRAY entry at %p\n", *init_begin);
  431. (*init_begin)();
  432. ++init_begin;
  433. }
  434. }
  435. }
  436. u32 DynamicLoader::ProgramHeaderRegion::mmap_prot() const
  437. {
  438. int prot = 0;
  439. prot |= is_executable() ? PROT_EXEC : 0;
  440. prot |= is_readable() ? PROT_READ : 0;
  441. prot |= is_writable() ? PROT_WRITE : 0;
  442. return prot;
  443. }
  444. DynamicObject::SymbolLookupResult DynamicLoader::lookup_symbol(const ELF::DynamicObject::Symbol& symbol) const
  445. {
  446. return m_dynamic_object->lookup_symbol(symbol);
  447. }
  448. } // end namespace ELF