Jeff Brown | 501edd2 | 2011-10-19 20:35:35 -0700 | [diff] [blame] | 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 | |
Elliott Hughes | cac5d8c | 2014-01-10 14:40:53 -0800 | [diff] [blame] | 22 | #include <elf.h> |
Jeff Brown | 501edd2 | 2011-10-19 20:35:35 -0700 | [diff] [blame] | 23 | #include <cutils/log.h> |
| 24 | |
| 25 | #ifndef PT_ARM_EXIDX |
| 26 | #define PT_ARM_EXIDX 0x70000001 |
| 27 | #endif |
| 28 | |
| 29 | static 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; |
Ben Cheng | 0015a42 | 2012-12-10 14:51:32 -0800 | [diff] [blame] | 32 | uint32_t elf_phentsize_ehsize; |
| 33 | uint32_t elf_shentsize_phnum; |
Jeff Brown | f0c5872 | 2011-11-03 17:58:44 -0700 | [diff] [blame] | 34 | if (try_get_word_ptrace(pid, mi->start + offsetof(Elf32_Ehdr, e_phoff), &elf_phoff) |
Ben Cheng | 0015a42 | 2012-12-10 14:51:32 -0800 | [diff] [blame] | 35 | && try_get_word_ptrace(pid, mi->start + offsetof(Elf32_Ehdr, e_ehsize), |
| 36 | &elf_phentsize_ehsize) |
Jeff Brown | f0c5872 | 2011-11-03 17:58:44 -0700 | [diff] [blame] | 37 | && try_get_word_ptrace(pid, mi->start + offsetof(Elf32_Ehdr, e_phnum), |
Ben Cheng | 0015a42 | 2012-12-10 14:51:32 -0800 | [diff] [blame] | 38 | &elf_shentsize_phnum)) { |
| 39 | uint32_t elf_phentsize = elf_phentsize_ehsize >> 16; |
| 40 | uint32_t elf_phnum = elf_shentsize_phnum & 0xffff; |
Jeff Brown | 501edd2 | 2011-10-19 20:35:35 -0700 | [diff] [blame] | 41 | for (uint32_t i = 0; i < elf_phnum; i++) { |
Jeff Brown | f0c5872 | 2011-11-03 17:58:44 -0700 | [diff] [blame] | 42 | uintptr_t elf_phdr = mi->start + elf_phoff + i * elf_phentsize; |
Jeff Brown | 501edd2 | 2011-10-19 20:35:35 -0700 | [diff] [blame] | 43 | uint32_t elf_phdr_type; |
Jeff Brown | f0c5872 | 2011-11-03 17:58:44 -0700 | [diff] [blame] | 44 | if (!try_get_word_ptrace(pid, elf_phdr + offsetof(Elf32_Phdr, p_type), &elf_phdr_type)) { |
Jeff Brown | 501edd2 | 2011-10-19 20:35:35 -0700 | [diff] [blame] | 45 | break; |
| 46 | } |
| 47 | if (elf_phdr_type == PT_ARM_EXIDX) { |
| 48 | uint32_t elf_phdr_offset; |
| 49 | uint32_t elf_phdr_filesz; |
Jeff Brown | f0c5872 | 2011-11-03 17:58:44 -0700 | [diff] [blame] | 50 | if (!try_get_word_ptrace(pid, elf_phdr + offsetof(Elf32_Phdr, p_offset), |
Jeff Brown | 501edd2 | 2011-10-19 20:35:35 -0700 | [diff] [blame] | 51 | &elf_phdr_offset) |
Jeff Brown | f0c5872 | 2011-11-03 17:58:44 -0700 | [diff] [blame] | 52 | || !try_get_word_ptrace(pid, elf_phdr + offsetof(Elf32_Phdr, p_filesz), |
Jeff Brown | 501edd2 | 2011-10-19 20:35:35 -0700 | [diff] [blame] | 53 | &elf_phdr_filesz)) { |
| 54 | break; |
| 55 | } |
| 56 | *out_exidx_start = mi->start + elf_phdr_offset; |
Jeff Brown | f0c5872 | 2011-11-03 17:58:44 -0700 | [diff] [blame] | 57 | *out_exidx_size = elf_phdr_filesz / 8; |
| 58 | ALOGV("Parsed EXIDX header info for %s: start=0x%08x, size=%d", mi->name, |
| 59 | *out_exidx_start, *out_exidx_size); |
Jeff Brown | 501edd2 | 2011-10-19 20:35:35 -0700 | [diff] [blame] | 60 | return; |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | *out_exidx_start = 0; |
| 65 | *out_exidx_size = 0; |
| 66 | } |
| 67 | |
| 68 | void load_ptrace_map_info_data_arch(pid_t pid, map_info_t* mi, map_info_data_t* data) { |
| 69 | load_exidx_header(pid, mi, &data->exidx_start, &data->exidx_size); |
| 70 | } |
| 71 | |
| 72 | void free_ptrace_map_info_data_arch(map_info_t* mi, map_info_data_t* data) { |
| 73 | } |