linker_phdr.h revision c1bd559d5b0fdcc25db2b6ae2705914103b24699
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
40/* See linker_phdr.c for all usage documentation */
41
42int
43phdr_table_load(int                fd,
44                Elf32_Addr         phdr_offset,
45                Elf32_Half         phdr_num,
46                void**             phdr_mmap,
47                Elf32_Addr*        phdr_size,
48                const Elf32_Phdr** phdr_table);
49
50void
51phdr_table_unload(void* phdr_mmap, Elf32_Addr phdr_memsize);
52
53Elf32_Addr
54phdr_table_get_load_size(const Elf32_Phdr* phdr_table,
55                         int               phdr_count);
56
57int
58phdr_table_reserve_memory(const Elf32_Phdr* phdr_table,
59                          int               phdr_count,
60                          Elf32_Addr        required_base,
61                          void**            load_start,
62                          Elf32_Addr*       load_size,
63                          Elf32_Addr*       load_bias);
64
65int
66phdr_table_load_segments(const Elf32_Phdr* phdr_table,
67                         int               phdr_count,
68                         void*             load_start,
69                         Elf32_Addr        load_size,
70                         Elf32_Addr        load_bias,
71                         int               fd);
72
73int
74phdr_table_protect_segments(const Elf32_Phdr* phdr_table,
75                            int               phdr_count,
76                            Elf32_Addr        load_bias);
77
78int
79phdr_table_unprotect_segments(const Elf32_Phdr* phdr_table,
80                              int               phdr_count,
81                              Elf32_Addr        load_bias);
82
83int
84phdr_table_protect_gnu_relro(const Elf32_Phdr* phdr_table,
85                             int               phdr_count,
86                             Elf32_Addr        load_bias);
87
88int
89phdr_table_unprotect_gnu_relro(const Elf32_Phdr* phdr_table,
90                               int               phdr_count,
91                               Elf32_Addr        load_bias);
92
93const Elf32_Phdr*
94phdr_table_get_loaded_phdr(const Elf32_Phdr*   phdr_table,
95                           int                 phdr_count,
96                           Elf32_Addr          load_bias);
97
98#ifdef ANDROID_ARM_LINKER
99int
100phdr_table_get_arm_exidx(const Elf32_Phdr* phdr_table,
101                         int               phdr_count,
102                         Elf32_Addr        load_bias,
103                         Elf32_Addr**      arm_exidx,
104                         unsigned*         arm_exidix_count);
105#endif
106
107Elf32_Addr*
108phdr_table_get_dynamic_section(const Elf32_Phdr* phdr_table,
109                               int               phdr_count,
110                               Elf32_Addr        load_bias);
111
112#endif /* LINKER_PHDR_H */
113