Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/utilities/elfFile.hpp
32285 views
/*1* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_VM_UTILITIES_ELF_FILE_HPP25#define SHARE_VM_UTILITIES_ELF_FILE_HPP2627#if !defined(_WINDOWS) && !defined(__APPLE__)2829#if defined(__OpenBSD__)30#include <sys/exec_elf.h>31#else32#include <elf.h>33#endif34#include <stdio.h>3536#ifdef _LP643738typedef Elf64_Half Elf_Half;39typedef Elf64_Word Elf_Word;40typedef Elf64_Off Elf_Off;41typedef Elf64_Addr Elf_Addr;4243typedef Elf64_Ehdr Elf_Ehdr;44typedef Elf64_Shdr Elf_Shdr;45typedef Elf64_Phdr Elf_Phdr;46typedef Elf64_Sym Elf_Sym;4748#if !defined(__ANDROID__) && (!defined(_ALLBSD_SOURCE) || defined(__APPLE__))49#define ELF_ST_TYPE ELF64_ST_TYPE50#endif5152#else5354typedef Elf32_Half Elf_Half;55typedef Elf32_Word Elf_Word;56typedef Elf32_Off Elf_Off;57typedef Elf32_Addr Elf_Addr;585960typedef Elf32_Ehdr Elf_Ehdr;61typedef Elf32_Shdr Elf_Shdr;62typedef Elf32_Phdr Elf_Phdr;63typedef Elf32_Sym Elf_Sym;6465#if !defined(__ANDROID__) && (!defined(_ALLBSD_SOURCE) || defined(__APPLE__))66#define ELF_ST_TYPE ELF32_ST_TYPE67#endif68#endif6970#include "globalDefinitions.hpp"71#include "memory/allocation.hpp"72#include "utilities/decoder.hpp"737475class ElfStringTable;76class ElfSymbolTable;77class ElfFuncDescTable;787980// On Solaris/Linux platforms, libjvm.so does contain all private symbols.81// ElfFile is basically an elf file parser, which can lookup the symbol82// that is the nearest to the given address.83// Beware, this code is called from vm error reporting code, when vm is already84// in "error" state, so there are scenarios, lookup will fail. We want this85// part of code to be very defensive, and bait out if anything went wrong.8687class ElfFile: public CHeapObj<mtInternal> {88friend class ElfDecoder;89public:90ElfFile(const char* filepath);91~ElfFile();9293bool decode(address addr, char* buf, int buflen, int* offset);94const char* filepath() {95return m_filepath;96}9798bool same_elf_file(const char* filepath) {99assert(filepath, "null file path");100assert(m_filepath, "already out of memory");101return (m_filepath && !strcmp(filepath, m_filepath));102}103104NullDecoder::decoder_status get_status() {105return m_status;106}107108private:109// sanity check, if the file is a real elf file110bool is_elf_file(Elf_Ehdr&);111112// load string tables from the elf file113bool load_tables();114115// string tables are stored in a linked list116void add_string_table(ElfStringTable* table);117118// symbol tables are stored in a linked list119void add_symbol_table(ElfSymbolTable* table);120121// return a string table at specified section index122ElfStringTable* get_string_table(int index);123124protected:125ElfFile* next() const { return m_next; }126void set_next(ElfFile* file) { m_next = file; }127128public:129// Returns true if the elf file is marked NOT to require an executable stack,130// or if the file could not be opened.131// Returns false if the elf file requires an executable stack, the stack flag132// is not set at all, or if the file can not be read.133// On systems other than linux it always returns false.134bool specifies_noexecstack() NOT_LINUX({ return false; });135136protected:137ElfFile* m_next;138139private:140// file141const char* m_filepath;142FILE* m_file;143144// Elf header145Elf_Ehdr m_elfHdr;146147// symbol tables148ElfSymbolTable* m_symbol_tables;149150// string tables151ElfStringTable* m_string_tables;152153// function descriptors table154ElfFuncDescTable* m_funcDesc_table;155156NullDecoder::decoder_status m_status;157};158159#endif // !_WINDOWS && !__APPLE__160161#endif // SHARE_VM_UTILITIES_ELF_FILE_HPP162163164