src/share/vm/utilities/elfFile.hpp

Wed, 22 Jan 2014 17:42:23 -0800

author
kvn
date
Wed, 22 Jan 2014 17:42:23 -0800
changeset 6503
a9becfeecd1b
parent 6491
e7cbc95179c4
parent 6198
55fb97c4c58d
child 6876
710a3c8b516e
permissions
-rw-r--r--

Merge

zgu@2364 1 /*
mikael@6198 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
zgu@2364 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
zgu@2364 4 *
zgu@2364 5 * This code is free software; you can redistribute it and/or modify it
zgu@2364 6 * under the terms of the GNU General Public License version 2 only, as
zgu@2364 7 * published by the Free Software Foundation.
zgu@2364 8 *
zgu@2364 9 * This code is distributed in the hope that it will be useful, but WITHOUT
zgu@2364 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
zgu@2364 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
zgu@2364 12 * version 2 for more details (a copy is included in the LICENSE file that
zgu@2364 13 * accompanied this code).
zgu@2364 14 *
zgu@2364 15 * You should have received a copy of the GNU General Public License version
zgu@2364 16 * 2 along with this work; if not, write to the Free Software Foundation,
zgu@2364 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
zgu@2364 18 *
zgu@2364 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
zgu@2364 20 * or visit www.oracle.com if you need additional information or have any
zgu@2364 21 * questions.
zgu@2364 22 *
zgu@2364 23 */
zgu@2364 24
zgu@3430 25 #ifndef SHARE_VM_UTILITIES_ELF_FILE_HPP
zgu@3430 26 #define SHARE_VM_UTILITIES_ELF_FILE_HPP
zgu@2364 27
never@3156 28 #if !defined(_WINDOWS) && !defined(__APPLE__)
zgu@2364 29
never@3156 30 #if defined(__OpenBSD__)
never@3156 31 #include <sys/exec_elf.h>
never@3156 32 #else
zgu@2364 33 #include <elf.h>
never@3156 34 #endif
zgu@2364 35 #include <stdio.h>
zgu@2364 36
zgu@2364 37 #ifdef _LP64
zgu@2364 38
zgu@2364 39 typedef Elf64_Half Elf_Half;
zgu@2364 40 typedef Elf64_Word Elf_Word;
zgu@2364 41 typedef Elf64_Off Elf_Off;
zgu@2364 42 typedef Elf64_Addr Elf_Addr;
zgu@2364 43
zgu@2364 44 typedef Elf64_Ehdr Elf_Ehdr;
zgu@2364 45 typedef Elf64_Shdr Elf_Shdr;
iklam@4710 46 typedef Elf64_Phdr Elf_Phdr;
zgu@2364 47 typedef Elf64_Sym Elf_Sym;
zgu@2364 48
never@3156 49 #if !defined(_ALLBSD_SOURCE) || defined(__APPLE__)
zgu@2364 50 #define ELF_ST_TYPE ELF64_ST_TYPE
never@3156 51 #endif
zgu@2364 52
zgu@2364 53 #else
zgu@2364 54
zgu@2364 55 typedef Elf32_Half Elf_Half;
zgu@2364 56 typedef Elf32_Word Elf_Word;
zgu@2364 57 typedef Elf32_Off Elf_Off;
zgu@2364 58 typedef Elf32_Addr Elf_Addr;
zgu@2364 59
zgu@2364 60
zgu@2364 61 typedef Elf32_Ehdr Elf_Ehdr;
zgu@2364 62 typedef Elf32_Shdr Elf_Shdr;
iklam@4710 63 typedef Elf32_Phdr Elf_Phdr;
zgu@2364 64 typedef Elf32_Sym Elf_Sym;
zgu@2364 65
never@3156 66 #if !defined(_ALLBSD_SOURCE) || defined(__APPLE__)
zgu@2364 67 #define ELF_ST_TYPE ELF32_ST_TYPE
zgu@2364 68 #endif
never@3156 69 #endif
zgu@2364 70
zgu@2364 71 #include "globalDefinitions.hpp"
zgu@2364 72 #include "memory/allocation.hpp"
zgu@2364 73 #include "utilities/decoder.hpp"
zgu@2364 74
zgu@2364 75
zgu@2364 76 class ElfStringTable;
zgu@2364 77 class ElfSymbolTable;
simonis@6491 78 class ElfFuncDescTable;
zgu@2364 79
zgu@2364 80
zgu@2364 81 // On Solaris/Linux platforms, libjvm.so does contain all private symbols.
zgu@2364 82 // ElfFile is basically an elf file parser, which can lookup the symbol
zgu@2364 83 // that is the nearest to the given address.
zgu@2364 84 // Beware, this code is called from vm error reporting code, when vm is already
zgu@2364 85 // in "error" state, so there are scenarios, lookup will fail. We want this
zgu@2364 86 // part of code to be very defensive, and bait out if anything went wrong.
zgu@2364 87
zgu@3900 88 class ElfFile: public CHeapObj<mtInternal> {
zgu@3430 89 friend class ElfDecoder;
zgu@2364 90 public:
zgu@2364 91 ElfFile(const char* filepath);
zgu@2364 92 ~ElfFile();
zgu@2364 93
zgu@3430 94 bool decode(address addr, char* buf, int buflen, int* offset);
zgu@2364 95 const char* filepath() {
zgu@2364 96 return m_filepath;
zgu@2364 97 }
zgu@2364 98
zgu@2364 99 bool same_elf_file(const char* filepath) {
zgu@2364 100 assert(filepath, "null file path");
zgu@2364 101 assert(m_filepath, "already out of memory");
zgu@2364 102 return (m_filepath && !strcmp(filepath, m_filepath));
zgu@2364 103 }
zgu@2364 104
zgu@3430 105 NullDecoder::decoder_status get_status() {
zgu@2364 106 return m_status;
zgu@2364 107 }
zgu@2364 108
zgu@2364 109 private:
zgu@2364 110 // sanity check, if the file is a real elf file
zgu@2364 111 bool is_elf_file(Elf_Ehdr&);
zgu@2364 112
zgu@2364 113 // load string tables from the elf file
zgu@2364 114 bool load_tables();
zgu@2364 115
zgu@2364 116 // string tables are stored in a linked list
zgu@2364 117 void add_string_table(ElfStringTable* table);
zgu@2364 118
zgu@2364 119 // symbol tables are stored in a linked list
zgu@2364 120 void add_symbol_table(ElfSymbolTable* table);
zgu@2364 121
zgu@2364 122 // return a string table at specified section index
zgu@2364 123 ElfStringTable* get_string_table(int index);
zgu@2364 124
zgu@3430 125 protected:
zgu@3430 126 ElfFile* next() const { return m_next; }
zgu@3430 127 void set_next(ElfFile* file) { m_next = file; }
zgu@2364 128
iklam@4710 129 public:
iklam@4710 130 // Returns true if the elf file is marked NOT to require an executable stack,
iklam@4710 131 // or if the file could not be opened.
iklam@4710 132 // Returns false if the elf file requires an executable stack, the stack flag
iklam@4710 133 // is not set at all, or if the file can not be read.
iklam@4710 134 // On systems other than linux it always returns false.
iklam@4710 135 bool specifies_noexecstack() NOT_LINUX({ return false; });
iklam@4710 136
zgu@2364 137 protected:
zgu@2364 138 ElfFile* m_next;
zgu@2364 139
zgu@2364 140 private:
zgu@2364 141 // file
zgu@2364 142 const char* m_filepath;
zgu@2364 143 FILE* m_file;
zgu@2364 144
zgu@2364 145 // Elf header
zgu@3430 146 Elf_Ehdr m_elfHdr;
zgu@2364 147
zgu@2364 148 // symbol tables
zgu@3430 149 ElfSymbolTable* m_symbol_tables;
zgu@2364 150
zgu@2364 151 // string tables
zgu@3430 152 ElfStringTable* m_string_tables;
zgu@2364 153
simonis@6491 154 // function descriptors table
simonis@6491 155 ElfFuncDescTable* m_funcDesc_table;
simonis@6491 156
zgu@3430 157 NullDecoder::decoder_status m_status;
zgu@2364 158 };
zgu@2364 159
simonis@6491 160 #endif // !_WINDOWS && !__APPLE__
zgu@2364 161
zgu@3430 162 #endif // SHARE_VM_UTILITIES_ELF_FILE_HPP

mercurial