1 /* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #define LOG_TAG "Corkscrew" 18 //#define LOG_NDEBUG 0 19 20 #include "../ptrace-arch.h" 21 22 #include <stddef.h> 23 #include <elf.h> 24 #include <cutils/log.h> 25 26 static void load_eh_frame_hdr(pid_t pid, map_info_t* mi, uintptr_t *eh_frame_hdr) { 27 uint32_t elf_phoff; 28 uint32_t elf_phentsize_ehsize; 29 uint32_t elf_shentsize_phnum; 30 if (try_get_word_ptrace(pid, mi->start + offsetof(Elf32_Ehdr, e_phoff), &elf_phoff) 31 && try_get_word_ptrace(pid, mi->start + offsetof(Elf32_Ehdr, e_ehsize), 32 &elf_phentsize_ehsize) 33 && try_get_word_ptrace(pid, mi->start + offsetof(Elf32_Ehdr, e_phnum), 34 &elf_shentsize_phnum)) { 35 uint32_t elf_phentsize = elf_phentsize_ehsize >> 16; 36 uint32_t elf_phnum = elf_shentsize_phnum & 0xffff; 37 for (uint32_t i = 0; i < elf_phnum; i++) { 38 uintptr_t elf_phdr = mi->start + elf_phoff + i * elf_phentsize; 39 uint32_t elf_phdr_type; 40 if (!try_get_word_ptrace(pid, elf_phdr + offsetof(Elf32_Phdr, p_type), &elf_phdr_type)) { 41 break; 42 } 43 if (elf_phdr_type == PT_GNU_EH_FRAME) { 44 uint32_t elf_phdr_offset; 45 if (!try_get_word_ptrace(pid, elf_phdr + offsetof(Elf32_Phdr, p_offset), 46 &elf_phdr_offset)) { 47 break; 48 } 49 *eh_frame_hdr = mi->start + elf_phdr_offset; 50 ALOGV("Parsed .eh_frame_hdr info for %s: start=0x%08x", mi->name, *eh_frame_hdr); 51 return; 52 } 53 } 54 } 55 *eh_frame_hdr = 0; 56 } 57 58 void load_ptrace_map_info_data_arch(pid_t pid, map_info_t* mi, map_info_data_t* data) { 59 load_eh_frame_hdr(pid, mi, &data->eh_frame_hdr); 60 } 61 62 void free_ptrace_map_info_data_arch(map_info_t* mi __attribute__((unused)), 63 map_info_data_t* data __attribute__((unused))) { 64 } 65