src/hotspot/os/linux/decoder_linux.cpp
changeset 48975 2c35fd3c5789
parent 47765 b7c7428eaab9
equal deleted inserted replaced
48974:66173ef5fbbf 48975:2c35fd3c5789
     1 /*
     1 /*
     2  * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    22  *
    22  *
    23  */
    23  */
    24 
    24 
    25 #include "jvm.h"
    25 #include "jvm.h"
    26 #include "utilities/decoder_elf.hpp"
    26 #include "utilities/decoder_elf.hpp"
       
    27 #include "utilities/elfFile.hpp"
    27 
    28 
    28 #include <cxxabi.h>
    29 #include <cxxabi.h>
    29 
    30 
    30 bool ElfDecoder::demangle(const char* symbol, char *buf, int buflen) {
    31 bool ElfDecoder::demangle(const char* symbol, char *buf, int buflen) {
    31   int   status;
    32   int   status;
    48       return true;
    49       return true;
    49   }
    50   }
    50   return false;
    51   return false;
    51 }
    52 }
    52 
    53 
       
    54 // Returns true if the elf file is marked NOT to require an executable stack,
       
    55 // or if the file could not be opened.
       
    56 // Returns false if the elf file requires an executable stack, the stack flag
       
    57 // is not set at all, or if the file can not be read.
       
    58 bool ElfFile::specifies_noexecstack(const char* filepath) {
       
    59   if (filepath == NULL) return true;
       
    60 
       
    61   FILE* file = fopen(filepath, "r");
       
    62   if (file == NULL)  return true;
       
    63 
       
    64   // AARCH64 defaults to noexecstack. All others default to execstack.
       
    65   bool result = AARCH64_ONLY(true) NOT_AARCH64(false);
       
    66 
       
    67   // Read file header
       
    68   Elf_Ehdr head;
       
    69   if (fread(&head, sizeof(Elf_Ehdr), 1, file) == 1 &&
       
    70       is_elf_file(head) &&
       
    71       fseek(file, head.e_phoff, SEEK_SET) == 0) {
       
    72 
       
    73     // Read program header table
       
    74     Elf_Phdr phdr;
       
    75     for (int index = 0; index < head.e_phnum; index ++) {
       
    76       if (fread((void*)&phdr, sizeof(Elf_Phdr), 1, file) != 1) {
       
    77         result = false;
       
    78         break;
       
    79       }
       
    80       if (phdr.p_type == PT_GNU_STACK) {
       
    81         result = (phdr.p_flags == (PF_R | PF_W));
       
    82         break;
       
    83       }
       
    84     }
       
    85   }
       
    86   fclose(file);
       
    87   return result;
       
    88 }