blob: ba3b60a3623fe919612405faea9178e90db51e55 [file] [log] [blame]
Chris Dearman231e3c82012-08-10 17:06:20 -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
Chris Dearman529985782013-12-06 04:29:37 -080022#include <stddef.h>
23#include <elf.h>
Chris Dearman231e3c82012-08-10 17:06:20 -070024#include <cutils/log.h>
25
Chris Dearman529985782013-12-06 04:29:37 -080026static 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
31
32 try_get_word_ptrace(pid, mi->start + offsetof(Elf32_Ehdr, e_phoff), &elf_phoff);
33 ALOGV("reading 0x%08x elf_phoff:%x", mi->start + offsetof(Elf32_Ehdr, e_phoff), elf_phoff);
34 try_get_word_ptrace(pid, mi->start + offsetof(Elf32_Ehdr, e_ehsize), &elf_phentsize_ehsize);
35 ALOGV("reading 0x%08x elf_phentsize_ehsize:%x", mi->start + offsetof(Elf32_Ehdr, e_ehsize), elf_phentsize_ehsize);
36 try_get_word_ptrace(pid, mi->start + offsetof(Elf32_Ehdr, e_phnum), &elf_shentsize_phnum);
37 ALOGV("reading 0x%08x elf_shentsize_phnum:%x", mi->start + offsetof(Elf32_Ehdr, e_phnum), elf_shentsize_phnum);
38
39
40
41 if (try_get_word_ptrace(pid, mi->start + offsetof(Elf32_Ehdr, e_phoff), &elf_phoff)
42 && try_get_word_ptrace(pid, mi->start + offsetof(Elf32_Ehdr, e_ehsize),
43 &elf_phentsize_ehsize)
44 && try_get_word_ptrace(pid, mi->start + offsetof(Elf32_Ehdr, e_phnum),
45 &elf_shentsize_phnum)) {
46 uint32_t elf_phentsize = elf_phentsize_ehsize >> 16;
47 uint32_t elf_phnum = elf_shentsize_phnum & 0xffff;
48 for (uint32_t i = 0; i < elf_phnum; i++) {
49 uintptr_t elf_phdr = mi->start + elf_phoff + i * elf_phentsize;
50 uint32_t elf_phdr_type;
51 if (!try_get_word_ptrace(pid, elf_phdr + offsetof(Elf32_Phdr, p_type), &elf_phdr_type)) {
52 break;
53 }
54 if (elf_phdr_type == PT_GNU_EH_FRAME) {
55 uint32_t elf_phdr_offset;
56 if (!try_get_word_ptrace(pid, elf_phdr + offsetof(Elf32_Phdr, p_offset),
57 &elf_phdr_offset)) {
58 break;
59 }
60 *eh_frame_hdr = mi->start + elf_phdr_offset;
61 ALOGV("Parsed .eh_frame_hdr info for %s: start=0x%08x", mi->name, *eh_frame_hdr);
62 return;
63 }
64 }
65 }
66 *eh_frame_hdr = 0;
Chris Dearman231e3c82012-08-10 17:06:20 -070067}
68
Chris Dearman529985782013-12-06 04:29:37 -080069void load_ptrace_map_info_data_arch(pid_t pid, map_info_t* mi, map_info_data_t* data) {
70 ALOGV("load_ptrace_map_info_data_arch");
71 load_eh_frame_hdr(pid, mi, &data->eh_frame_hdr);
72}
73
74void free_ptrace_map_info_data_arch(map_info_t* mi __attribute__((unused)),
75 map_info_data_t* data __attribute__((unused))) {
76 ALOGV("free_ptrace_map_info_data_arch");
Chris Dearman231e3c82012-08-10 17:06:20 -070077}