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
load_exidx_header(pid_t pid,map_info_t * mi,uintptr_t * out_exidx_start,size_t * out_exidx_size)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;
32 uint32_t elf_phentsize_ehsize;
33 uint32_t elf_shentsize_phnum;
34 if (try_get_word_ptrace(pid, mi->start + offsetof(Elf32_Ehdr, e_phoff), &elf_phoff)
35 && try_get_word_ptrace(pid, mi->start + offsetof(Elf32_Ehdr, e_ehsize),
36 &elf_phentsize_ehsize)
37 && try_get_word_ptrace(pid, mi->start + offsetof(Elf32_Ehdr, e_phnum),
38 &elf_shentsize_phnum)) {
39 uint32_t elf_phentsize = elf_phentsize_ehsize >> 16;
40 uint32_t elf_phnum = elf_shentsize_phnum & 0xffff;
41 for (uint32_t i = 0; i < elf_phnum; i++) {
42 uintptr_t elf_phdr = mi->start + elf_phoff + i * elf_phentsize;
43 uint32_t elf_phdr_type;
44 if (!try_get_word_ptrace(pid, elf_phdr + offsetof(Elf32_Phdr, p_type), &elf_phdr_type)) {
45 break;
46 }
47 if (elf_phdr_type == PT_ARM_EXIDX) {
48 uint32_t elf_phdr_offset;
49 uint32_t elf_phdr_filesz;
50 if (!try_get_word_ptrace(pid, elf_phdr + offsetof(Elf32_Phdr, p_offset),
51 &elf_phdr_offset)
52 || !try_get_word_ptrace(pid, elf_phdr + offsetof(Elf32_Phdr, p_filesz),
53 &elf_phdr_filesz)) {
54 break;
55 }
56 *out_exidx_start = mi->start + elf_phdr_offset;
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);
60 return;
61 }
62 }
63 }
64 *out_exidx_start = 0;
65 *out_exidx_size = 0;
66 }
67
load_ptrace_map_info_data_arch(pid_t pid,map_info_t * mi,map_info_data_t * data)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
free_ptrace_map_info_data_arch(map_info_t * mi,map_info_data_t * data)72 void free_ptrace_map_info_data_arch(map_info_t* mi, map_info_data_t* data) {
73 }
74