blob: 19e281b057d108c76d103c2f07aa50e976e28132 [file] [log] [blame]
David 'Digit' Turnerc1bd5592012-06-19 11:21:29 +02001/*
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
Elliott Hughes46882792012-08-03 16:49:39 -070040#ifdef __cplusplus
41extern "C" {
42#endif
43
David 'Digit' Turnerc1bd5592012-06-19 11:21:29 +020044/* See linker_phdr.c for all usage documentation */
45
46int
47phdr_table_load(int fd,
48 Elf32_Addr phdr_offset,
49 Elf32_Half phdr_num,
50 void** phdr_mmap,
51 Elf32_Addr* phdr_size,
52 const Elf32_Phdr** phdr_table);
53
54void
55phdr_table_unload(void* phdr_mmap, Elf32_Addr phdr_memsize);
56
57Elf32_Addr
58phdr_table_get_load_size(const Elf32_Phdr* phdr_table,
Elliott Hughes46882792012-08-03 16:49:39 -070059 size_t phdr_count);
David 'Digit' Turnerc1bd5592012-06-19 11:21:29 +020060
61int
62phdr_table_reserve_memory(const Elf32_Phdr* phdr_table,
Elliott Hughes46882792012-08-03 16:49:39 -070063 size_t phdr_count,
Pawit Pornkitprasan2200dea2012-11-23 12:27:25 +070064 Elf32_Addr required_base,
Elliott Hughes46882792012-08-03 16:49:39 -070065 void** load_start,
66 Elf32_Addr* load_size,
67 Elf32_Addr* load_bias);
David 'Digit' Turnerc1bd5592012-06-19 11:21:29 +020068
69int
70phdr_table_load_segments(const Elf32_Phdr* phdr_table,
71 int phdr_count,
David 'Digit' Turnerc1bd5592012-06-19 11:21:29 +020072 Elf32_Addr load_bias,
73 int fd);
74
75int
76phdr_table_protect_segments(const Elf32_Phdr* phdr_table,
77 int phdr_count,
78 Elf32_Addr load_bias);
79
80int
81phdr_table_unprotect_segments(const Elf32_Phdr* phdr_table,
82 int phdr_count,
83 Elf32_Addr load_bias);
84
85int
86phdr_table_protect_gnu_relro(const Elf32_Phdr* phdr_table,
87 int phdr_count,
88 Elf32_Addr load_bias);
89
David 'Digit' Turnerc1bd5592012-06-19 11:21:29 +020090const Elf32_Phdr*
91phdr_table_get_loaded_phdr(const Elf32_Phdr* phdr_table,
92 int phdr_count,
93 Elf32_Addr load_bias);
94
95#ifdef ANDROID_ARM_LINKER
96int
97phdr_table_get_arm_exidx(const Elf32_Phdr* phdr_table,
98 int phdr_count,
99 Elf32_Addr load_bias,
100 Elf32_Addr** arm_exidx,
101 unsigned* arm_exidix_count);
102#endif
103
Ard Biesheuvel12c78bb2012-08-14 12:30:09 +0200104void
David 'Digit' Turnerc1bd5592012-06-19 11:21:29 +0200105phdr_table_get_dynamic_section(const Elf32_Phdr* phdr_table,
106 int phdr_count,
Ard Biesheuvel12c78bb2012-08-14 12:30:09 +0200107 Elf32_Addr load_bias,
108 Elf32_Addr** dynamic,
109 size_t* dynamic_count);
David 'Digit' Turnerc1bd5592012-06-19 11:21:29 +0200110
Elliott Hughes46882792012-08-03 16:49:39 -0700111#ifdef __cplusplus
112};
113#endif
114
David 'Digit' Turnerc1bd5592012-06-19 11:21:29 +0200115#endif /* LINKER_PHDR_H */