Path: blob/master/src/hotspot/share/utilities/elfFuncDescTable.cpp
40949 views
/*1* Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 2012, 2013 SAP SE. All rights reserved.3* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.4*5* This code is free software; you can redistribute it and/or modify it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*23*/2425#include "precompiled.hpp"2627#if !defined(_WINDOWS) && !defined(__APPLE__)2829#include "memory/allocation.inline.hpp"30#include "utilities/elfFuncDescTable.hpp"3132ElfFuncDescTable::ElfFuncDescTable(FILE* file, Elf_Shdr shdr, int index) :33_section(file, shdr), _file(file), _index(index) {34assert(file, "null file handle");35// The actual function address (i.e. function entry point) is always the36// first value in the function descriptor (on IA64 and PPC64 they look as follows):37// PPC64: [function entry point, TOC pointer, environment pointer]38// IA64 : [function entry point, GP (global pointer) value]39// Unfortunately 'shdr.sh_entsize' doesn't always seem to contain this size (it's zero on PPC64) so we can't assert40// assert(IA64_ONLY(2) PPC64_ONLY(3) * sizeof(address) == shdr.sh_entsize, "Size mismatch for '.opd' section entries");4142_status = _section.status();43}4445ElfFuncDescTable::~ElfFuncDescTable() {46}4748address ElfFuncDescTable::lookup(Elf_Word index) {49if (NullDecoder::is_error(_status)) {50return NULL;51}5253address* func_descs = cached_func_descs();54const Elf_Shdr* shdr = _section.section_header();55if (!(shdr->sh_size > 0 && shdr->sh_addr <= index && index <= shdr->sh_addr + shdr->sh_size)) {56// don't put the whole decoder in error mode if we just tried a wrong index57return NULL;58}5960if (func_descs != NULL) {61return func_descs[(index - shdr->sh_addr) / sizeof(address)];62} else {63MarkedFileReader mfd(_file);64address addr;65if (!mfd.has_mark() ||66!mfd.set_position(shdr->sh_offset + index - shdr->sh_addr) ||67!mfd.read((void*)&addr, sizeof(addr))) {68_status = NullDecoder::file_invalid;69return NULL;70}71return addr;72}73}7475#endif // !_WINDOWS && !__APPLE__767778