Path: blob/master/src/hotspot/os/linux/decoder_linux.cpp
40951 views
/*1* Copyright (c) 1997, 2018, 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#include "jvm.h"25#include "utilities/decoder_elf.hpp"26#include "utilities/elfFile.hpp"2728#include <cxxabi.h>2930bool ElfDecoder::demangle(const char* symbol, char *buf, int buflen) {31int status;32char* result;33size_t size = (size_t)buflen;3435#ifdef PPC6436// On PPC64 ElfDecoder::decode() may return a dot (.) prefixed name37// (see elfFuncDescTable.hpp for details)38if (symbol && *symbol == '.') symbol += 1;39#endif4041// Don't pass buf to __cxa_demangle. In case of the 'buf' is too small,42// __cxa_demangle will call system "realloc" for additional memory, which43// may use different malloc/realloc mechanism that allocates 'buf'.44if ((result = abi::__cxa_demangle(symbol, NULL, NULL, &status)) != NULL) {45jio_snprintf(buf, buflen, "%s", result);46// call c library's free47::free(result);48return true;49}50return false;51}5253// Returns true if the elf file is marked NOT to require an executable stack,54// or if the file could not be opened.55// Returns false if the elf file requires an executable stack, the stack flag56// is not set at all, or if the file can not be read.57bool ElfFile::specifies_noexecstack(const char* filepath) {58if (filepath == NULL) return true;5960FILE* file = fopen(filepath, "r");61if (file == NULL) return true;6263// AARCH64 defaults to noexecstack. All others default to execstack.64bool result = AARCH64_ONLY(true) NOT_AARCH64(false);6566// Read file header67Elf_Ehdr head;68if (fread(&head, sizeof(Elf_Ehdr), 1, file) == 1 &&69is_elf_file(head) &&70fseek(file, head.e_phoff, SEEK_SET) == 0) {7172// Read program header table73Elf_Phdr phdr;74for (int index = 0; index < head.e_phnum; index ++) {75if (fread((void*)&phdr, sizeof(Elf_Phdr), 1, file) != 1) {76result = false;77break;78}79if (phdr.p_type == PT_GNU_STACK) {80result = (phdr.p_flags == (PF_R | PF_W));81break;82}83}84}85fclose(file);86return result;87}888990