David 'Digit' Turner | c1bd559 | 2012-06-19 11:21:29 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * * Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * * Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in |
| 12 | * the documentation and/or other materials provided with the |
| 13 | * distribution. |
| 14 | * |
| 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 16 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 17 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 18 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 19 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 21 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
| 22 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
| 23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 25 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 26 | * SUCH DAMAGE. |
| 27 | */ |
| 28 | #ifndef LINKER_PHDR_H |
| 29 | #define LINKER_PHDR_H |
| 30 | |
| 31 | /* Declarations related to the ELF program header table and segments. |
| 32 | * |
| 33 | * The design goal is to provide an API that is as close as possible |
| 34 | * to the ELF spec, and does not depend on linker-specific data |
| 35 | * structures (e.g. the exact layout of struct soinfo). |
| 36 | */ |
| 37 | |
| 38 | #include "linker.h" |
| 39 | |
David 'Digit' Turner | c1bd559 | 2012-06-19 11:21:29 +0200 | [diff] [blame] | 40 | int |
| 41 | phdr_table_load(int fd, |
| 42 | Elf32_Addr phdr_offset, |
| 43 | Elf32_Half phdr_num, |
| 44 | void** phdr_mmap, |
| 45 | Elf32_Addr* phdr_size, |
| 46 | const Elf32_Phdr** phdr_table); |
| 47 | |
| 48 | void |
| 49 | phdr_table_unload(void* phdr_mmap, Elf32_Addr phdr_memsize); |
| 50 | |
| 51 | Elf32_Addr |
| 52 | phdr_table_get_load_size(const Elf32_Phdr* phdr_table, |
Elliott Hughes | 4688279 | 2012-08-03 16:49:39 -0700 | [diff] [blame] | 53 | size_t phdr_count); |
David 'Digit' Turner | c1bd559 | 2012-06-19 11:21:29 +0200 | [diff] [blame] | 54 | |
| 55 | int |
| 56 | phdr_table_reserve_memory(const Elf32_Phdr* phdr_table, |
Elliott Hughes | 4688279 | 2012-08-03 16:49:39 -0700 | [diff] [blame] | 57 | size_t phdr_count, |
| 58 | void** load_start, |
| 59 | Elf32_Addr* load_size, |
| 60 | Elf32_Addr* load_bias); |
David 'Digit' Turner | c1bd559 | 2012-06-19 11:21:29 +0200 | [diff] [blame] | 61 | |
| 62 | int |
| 63 | phdr_table_load_segments(const Elf32_Phdr* phdr_table, |
| 64 | int phdr_count, |
David 'Digit' Turner | c1bd559 | 2012-06-19 11:21:29 +0200 | [diff] [blame] | 65 | Elf32_Addr load_bias, |
| 66 | int fd); |
| 67 | |
| 68 | int |
| 69 | phdr_table_protect_segments(const Elf32_Phdr* phdr_table, |
| 70 | int phdr_count, |
| 71 | Elf32_Addr load_bias); |
| 72 | |
| 73 | int |
| 74 | phdr_table_unprotect_segments(const Elf32_Phdr* phdr_table, |
| 75 | int phdr_count, |
| 76 | Elf32_Addr load_bias); |
| 77 | |
| 78 | int |
| 79 | phdr_table_protect_gnu_relro(const Elf32_Phdr* phdr_table, |
| 80 | int phdr_count, |
| 81 | Elf32_Addr load_bias); |
| 82 | |
David 'Digit' Turner | c1bd559 | 2012-06-19 11:21:29 +0200 | [diff] [blame] | 83 | const Elf32_Phdr* |
| 84 | phdr_table_get_loaded_phdr(const Elf32_Phdr* phdr_table, |
| 85 | int phdr_count, |
| 86 | Elf32_Addr load_bias); |
| 87 | |
| 88 | #ifdef ANDROID_ARM_LINKER |
| 89 | int |
| 90 | phdr_table_get_arm_exidx(const Elf32_Phdr* phdr_table, |
| 91 | int phdr_count, |
| 92 | Elf32_Addr load_bias, |
| 93 | Elf32_Addr** arm_exidx, |
| 94 | unsigned* arm_exidix_count); |
| 95 | #endif |
| 96 | |
Ard Biesheuvel | 12c78bb | 2012-08-14 12:30:09 +0200 | [diff] [blame] | 97 | void |
David 'Digit' Turner | c1bd559 | 2012-06-19 11:21:29 +0200 | [diff] [blame] | 98 | phdr_table_get_dynamic_section(const Elf32_Phdr* phdr_table, |
| 99 | int phdr_count, |
Ard Biesheuvel | 12c78bb | 2012-08-14 12:30:09 +0200 | [diff] [blame] | 100 | Elf32_Addr load_bias, |
Brian Carlstrom | d4ee82d | 2013-02-28 15:58:45 -0800 | [diff] [blame^] | 101 | Elf32_Dyn** dynamic, |
Chris Dearman | cf23905 | 2013-01-11 15:32:20 -0800 | [diff] [blame] | 102 | size_t* dynamic_count, |
| 103 | Elf32_Word* dynamic_flags); |
David 'Digit' Turner | c1bd559 | 2012-06-19 11:21:29 +0200 | [diff] [blame] | 104 | |
David 'Digit' Turner | c1bd559 | 2012-06-19 11:21:29 +0200 | [diff] [blame] | 105 | #endif /* LINKER_PHDR_H */ |