blob: a50844e697d3a0fa1920e07b57d5bbc4b4af4896 [file] [log] [blame]
Jeff Brown501edd22011-10-19 20:35:35 -07001/*
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 Hughescac5d8c2014-01-10 14:40:53 -080022#include <elf.h>
Jeff Brown501edd22011-10-19 20:35:35 -070023#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;
Ben Cheng0015a422012-12-10 14:51:32 -080032 uint32_t elf_phentsize_ehsize;
33 uint32_t elf_shentsize_phnum;
Jeff Brownf0c58722011-11-03 17:58:44 -070034 if (try_get_word_ptrace(pid, mi->start + offsetof(Elf32_Ehdr, e_phoff), &elf_phoff)
Ben Cheng0015a422012-12-10 14:51:32 -080035 && try_get_word_ptrace(pid, mi->start + offsetof(Elf32_Ehdr, e_ehsize),
36 &elf_phentsize_ehsize)
Jeff Brownf0c58722011-11-03 17:58:44 -070037 && try_get_word_ptrace(pid, mi->start + offsetof(Elf32_Ehdr, e_phnum),
Ben Cheng0015a422012-12-10 14:51:32 -080038 &elf_shentsize_phnum)) {
39 uint32_t elf_phentsize = elf_phentsize_ehsize >> 16;
40 uint32_t elf_phnum = elf_shentsize_phnum & 0xffff;
Jeff Brown501edd22011-10-19 20:35:35 -070041 for (uint32_t i = 0; i < elf_phnum; i++) {
Jeff Brownf0c58722011-11-03 17:58:44 -070042 uintptr_t elf_phdr = mi->start + elf_phoff + i * elf_phentsize;
Jeff Brown501edd22011-10-19 20:35:35 -070043 uint32_t elf_phdr_type;
Jeff Brownf0c58722011-11-03 17:58:44 -070044 if (!try_get_word_ptrace(pid, elf_phdr + offsetof(Elf32_Phdr, p_type), &elf_phdr_type)) {
Jeff Brown501edd22011-10-19 20:35:35 -070045 break;
46 }
47 if (elf_phdr_type == PT_ARM_EXIDX) {
48 uint32_t elf_phdr_offset;
49 uint32_t elf_phdr_filesz;
Jeff Brownf0c58722011-11-03 17:58:44 -070050 if (!try_get_word_ptrace(pid, elf_phdr + offsetof(Elf32_Phdr, p_offset),
Jeff Brown501edd22011-10-19 20:35:35 -070051 &elf_phdr_offset)
Jeff Brownf0c58722011-11-03 17:58:44 -070052 || !try_get_word_ptrace(pid, elf_phdr + offsetof(Elf32_Phdr, p_filesz),
Jeff Brown501edd22011-10-19 20:35:35 -070053 &elf_phdr_filesz)) {
54 break;
55 }
56 *out_exidx_start = mi->start + elf_phdr_offset;
Jeff Brownf0c58722011-11-03 17:58:44 -070057 *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 Brown501edd22011-10-19 20:35:35 -070060 return;
61 }
62 }
63 }
64 *out_exidx_start = 0;
65 *out_exidx_size = 0;
66}
67
68void 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
72void free_ptrace_map_info_data_arch(map_info_t* mi, map_info_data_t* data) {
73}