ptrace-arm.c revision 501edd29b823ce1301d2effdd3a9e4b6e2b20b76
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 <sys/exec_elf.h> 23#include <cutils/log.h> 24 25#ifndef PT_ARM_EXIDX 26#define PT_ARM_EXIDX 0x70000001 27#endif 28 29static void load_exidx_header(pid_t pid, map_info_t* mi, 30 uintptr_t* out_exidx_start, size_t* out_exidx_size) { 31 uint32_t elf_phoff; 32 uint32_t elf_phnum; 33 if (try_get_word(pid, mi->start + offsetof(Elf32_Ehdr, e_phoff), &elf_phoff) 34 && try_get_word(pid, mi->start + offsetof(Elf32_Ehdr, e_phnum), &elf_phnum)) { 35 for (uint32_t i = 0; i < elf_phnum; i++) { 36 uintptr_t elf_phdr = mi->start + elf_phoff + i * sizeof(Elf32_Phdr); 37 uint32_t elf_phdr_type; 38 if (!try_get_word(pid, elf_phdr + offsetof(Elf32_Phdr, p_type), &elf_phdr_type)) { 39 break; 40 } 41 if (elf_phdr_type == PT_ARM_EXIDX) { 42 uint32_t elf_phdr_offset; 43 uint32_t elf_phdr_filesz; 44 if (!try_get_word(pid, elf_phdr + offsetof(Elf32_Phdr, p_offset), 45 &elf_phdr_offset) 46 || !try_get_word(pid, elf_phdr + offsetof(Elf32_Phdr, p_filesz), 47 &elf_phdr_filesz)) { 48 break; 49 } 50 *out_exidx_start = mi->start + elf_phdr_offset; 51 *out_exidx_size = elf_phdr_filesz; 52 return; 53 } 54 } 55 } 56 *out_exidx_start = 0; 57 *out_exidx_size = 0; 58} 59 60void load_ptrace_map_info_data_arch(pid_t pid, map_info_t* mi, map_info_data_t* data) { 61 load_exidx_header(pid, mi, &data->exidx_start, &data->exidx_size); 62} 63 64void free_ptrace_map_info_data_arch(map_info_t* mi, map_info_data_t* data) { 65} 66