Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/utilities/elfFuncDescTable.cpp
32285 views
/*1* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.2* Copyright 2012, 2013 SAP AG. 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) {33assert(file, "null file handle");34// The actual function address (i.e. function entry point) is always the35// first value in the function descriptor (on IA64 and PPC64 they look as follows):36// PPC64: [function entry point, TOC pointer, environment pointer]37// IA64 : [function entry point, GP (global pointer) value]38// Unfortunately 'shdr.sh_entsize' doesn't always seem to contain this size (it's zero on PPC64) so we can't assert39// assert(IA64_ONLY(2) PPC64_ONLY(3) * sizeof(address) == shdr.sh_entsize, "Size mismatch for '.opd' section entries");4041m_funcDescs = NULL;42m_file = file;43m_index = index;44m_status = NullDecoder::no_error;4546// try to load the function descriptor table47long cur_offset = ftell(file);48if (cur_offset != -1) {49// call malloc so we can back up if memory allocation fails.50m_funcDescs = (address*)os::malloc(shdr.sh_size, mtInternal);51if (m_funcDescs) {52if (fseek(file, shdr.sh_offset, SEEK_SET) ||53fread((void*)m_funcDescs, shdr.sh_size, 1, file) != 1 ||54fseek(file, cur_offset, SEEK_SET)) {55m_status = NullDecoder::file_invalid;56os::free(m_funcDescs);57m_funcDescs = NULL;58}59}60if (!NullDecoder::is_error(m_status)) {61memcpy(&m_shdr, &shdr, sizeof(Elf_Shdr));62}63} else {64m_status = NullDecoder::file_invalid;65}66}6768ElfFuncDescTable::~ElfFuncDescTable() {69if (m_funcDescs != NULL) {70os::free(m_funcDescs);71}72}7374address ElfFuncDescTable::lookup(Elf_Word index) {75if (NullDecoder::is_error(m_status)) {76return NULL;77}7879if (m_funcDescs != NULL) {80if (m_shdr.sh_size > 0 && m_shdr.sh_addr <= index && index <= m_shdr.sh_addr + m_shdr.sh_size) {81// Notice that 'index' is a byte-offset into the function descriptor table.82return m_funcDescs[(index - m_shdr.sh_addr) / sizeof(address)];83}84return NULL;85} else {86long cur_pos;87address addr;88if (!(m_shdr.sh_size > 0 && m_shdr.sh_addr <= index && index <= m_shdr.sh_addr + m_shdr.sh_size)) {89// don't put the whole decoder in error mode if we just tried a wrong index90return NULL;91}92if ((cur_pos = ftell(m_file)) == -1 ||93fseek(m_file, m_shdr.sh_offset + index - m_shdr.sh_addr, SEEK_SET) ||94fread(&addr, sizeof(addr), 1, m_file) != 1 ||95fseek(m_file, cur_pos, SEEK_SET)) {96m_status = NullDecoder::file_invalid;97return NULL;98}99return addr;100}101}102103#endif // !_WINDOWS && !__APPLE__104105106