linker_phdr.h revision 12c78bbded8ec03f821dfa09174464c04836e4ea
1c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner/* 2c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner * Copyright (C) 2012 The Android Open Source Project 3c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner * All rights reserved. 4c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner * 5c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner * Redistribution and use in source and binary forms, with or without 6c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner * modification, are permitted provided that the following conditions 7c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner * are met: 8c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner * * Redistributions of source code must retain the above copyright 9c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner * notice, this list of conditions and the following disclaimer. 10c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner * * Redistributions in binary form must reproduce the above copyright 11c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner * notice, this list of conditions and the following disclaimer in 12c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner * the documentation and/or other materials provided with the 13c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner * distribution. 14c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner * 15c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 18c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 21c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 22c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 23c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 25c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner * SUCH DAMAGE. 27c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner */ 28c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner#ifndef LINKER_PHDR_H 29c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner#define LINKER_PHDR_H 30c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner 31c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner/* Declarations related to the ELF program header table and segments. 32c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner * 33c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner * The design goal is to provide an API that is as close as possible 34c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner * to the ELF spec, and does not depend on linker-specific data 35c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner * structures (e.g. the exact layout of struct soinfo). 36c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner */ 37c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner 38c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner#include "linker.h" 39c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner 404688279db5dcc4004941e7f133c4a1c3617d842cElliott Hughes#ifdef __cplusplus 414688279db5dcc4004941e7f133c4a1c3617d842cElliott Hughesextern "C" { 424688279db5dcc4004941e7f133c4a1c3617d842cElliott Hughes#endif 434688279db5dcc4004941e7f133c4a1c3617d842cElliott Hughes 44c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner/* See linker_phdr.c for all usage documentation */ 45c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner 46c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turnerint 47c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turnerphdr_table_load(int fd, 48c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner Elf32_Addr phdr_offset, 49c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner Elf32_Half phdr_num, 50c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner void** phdr_mmap, 51c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner Elf32_Addr* phdr_size, 52c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner const Elf32_Phdr** phdr_table); 53c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner 54c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turnervoid 55c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turnerphdr_table_unload(void* phdr_mmap, Elf32_Addr phdr_memsize); 56c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner 57c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' TurnerElf32_Addr 58c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turnerphdr_table_get_load_size(const Elf32_Phdr* phdr_table, 594688279db5dcc4004941e7f133c4a1c3617d842cElliott Hughes size_t phdr_count); 60c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner 61c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turnerint 62c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turnerphdr_table_reserve_memory(const Elf32_Phdr* phdr_table, 634688279db5dcc4004941e7f133c4a1c3617d842cElliott Hughes size_t phdr_count, 644688279db5dcc4004941e7f133c4a1c3617d842cElliott Hughes void** load_start, 654688279db5dcc4004941e7f133c4a1c3617d842cElliott Hughes Elf32_Addr* load_size, 664688279db5dcc4004941e7f133c4a1c3617d842cElliott Hughes Elf32_Addr* load_bias); 67c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner 68c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turnerint 69c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turnerphdr_table_load_segments(const Elf32_Phdr* phdr_table, 70c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner int phdr_count, 71c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner Elf32_Addr load_bias, 72c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner int fd); 73c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner 74c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turnerint 75c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turnerphdr_table_protect_segments(const Elf32_Phdr* phdr_table, 76c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner int phdr_count, 77c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner Elf32_Addr load_bias); 78c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner 79c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turnerint 80c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turnerphdr_table_unprotect_segments(const Elf32_Phdr* phdr_table, 81c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner int phdr_count, 82c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner Elf32_Addr load_bias); 83c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner 84c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turnerint 85c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turnerphdr_table_protect_gnu_relro(const Elf32_Phdr* phdr_table, 86c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner int phdr_count, 87c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner Elf32_Addr load_bias); 88c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner 89c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turnerconst Elf32_Phdr* 90c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turnerphdr_table_get_loaded_phdr(const Elf32_Phdr* phdr_table, 91c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner int phdr_count, 92c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner Elf32_Addr load_bias); 93c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner 94c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner#ifdef ANDROID_ARM_LINKER 95c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turnerint 96c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turnerphdr_table_get_arm_exidx(const Elf32_Phdr* phdr_table, 97c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner int phdr_count, 98c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner Elf32_Addr load_bias, 99c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner Elf32_Addr** arm_exidx, 100c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner unsigned* arm_exidix_count); 101c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner#endif 102c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner 10312c78bbded8ec03f821dfa09174464c04836e4eaArd Biesheuvelvoid 104c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turnerphdr_table_get_dynamic_section(const Elf32_Phdr* phdr_table, 105c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner int phdr_count, 10612c78bbded8ec03f821dfa09174464c04836e4eaArd Biesheuvel Elf32_Addr load_bias, 10712c78bbded8ec03f821dfa09174464c04836e4eaArd Biesheuvel Elf32_Addr** dynamic, 10812c78bbded8ec03f821dfa09174464c04836e4eaArd Biesheuvel size_t* dynamic_count); 109c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner 1104688279db5dcc4004941e7f133c4a1c3617d842cElliott Hughes#ifdef __cplusplus 1114688279db5dcc4004941e7f133c4a1c3617d842cElliott Hughes}; 1124688279db5dcc4004941e7f133c4a1c3617d842cElliott Hughes#endif 1134688279db5dcc4004941e7f133c4a1c3617d842cElliott Hughes 114c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner#endif /* LINKER_PHDR_H */ 115