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_phentsize_phnum;
33    if (try_get_word_ptrace(pid, mi->start + offsetof(Elf32_Ehdr, e_phoff), &elf_phoff)
34            && try_get_word_ptrace(pid, mi->start + offsetof(Elf32_Ehdr, e_phnum),
35                    &elf_phentsize_phnum)) {
36        uint32_t elf_phentsize = elf_phentsize_phnum >> 16;
37        uint32_t elf_phnum = elf_phentsize_phnum & 0xffff;
38        for (uint32_t i = 0; i < elf_phnum; i++) {
39            uintptr_t elf_phdr = mi->start + elf_phoff + i * elf_phentsize;
40            uint32_t elf_phdr_type;
41            if (!try_get_word_ptrace(pid, elf_phdr + offsetof(Elf32_Phdr, p_type), &elf_phdr_type)) {
42                break;
43            }
44            if (elf_phdr_type == PT_ARM_EXIDX) {
45                uint32_t elf_phdr_offset;
46                uint32_t elf_phdr_filesz;
47                if (!try_get_word_ptrace(pid, elf_phdr + offsetof(Elf32_Phdr, p_offset),
48                        &elf_phdr_offset)
49                        || !try_get_word_ptrace(pid, elf_phdr + offsetof(Elf32_Phdr, p_filesz),
50                                &elf_phdr_filesz)) {
51                    break;
52                }
53                *out_exidx_start = mi->start + elf_phdr_offset;
54                *out_exidx_size = elf_phdr_filesz / 8;
55                ALOGV("Parsed EXIDX header info for %s: start=0x%08x, size=%d", mi->name,
56                        *out_exidx_start, *out_exidx_size);
57                return;
58            }
59        }
60    }
61    *out_exidx_start = 0;
62    *out_exidx_size = 0;
63}
64
65void load_ptrace_map_info_data_arch(pid_t pid, map_info_t* mi, map_info_data_t* data) {
66    load_exidx_header(pid, mi, &data->exidx_start, &data->exidx_size);
67}
68
69void free_ptrace_map_info_data_arch(map_info_t* mi, map_info_data_t* data) {
70}
71