| 1 | /* |
| 2 | * Copyright (c) 1997, 2019, Oracle and/or its affiliates. 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 it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | * accompanied this code). |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License version |
| 16 | * 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 USA |
| 20 | * or visit www.oracle.com if you need additional information or have any |
| 21 | * questions. |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | #ifndef SHARE_UTILITIES_ELFSTRINGTABLE_HPP |
| 26 | #define SHARE_UTILITIES_ELFSTRINGTABLE_HPP |
| 27 | |
| 28 | #if !defined(_WINDOWS) && !defined(__APPLE__) |
| 29 | |
| 30 | #include "memory/allocation.hpp" |
| 31 | #include "utilities/decoder.hpp" |
| 32 | #include "utilities/elfFile.hpp" |
| 33 | |
| 34 | |
| 35 | // The string table represents a string table section in an elf file. |
| 36 | // Whenever there is enough memory, it will load whole string table as |
| 37 | // one blob. Otherwise, it will load string from file when requested. |
| 38 | class ElfStringTable: CHeapObj<mtInternal> { |
| 39 | friend class ElfFile; |
| 40 | private: |
| 41 | ElfStringTable* _next; |
| 42 | int _index; // section index |
| 43 | ElfSection _section; |
| 44 | FILE* const _fd; |
| 45 | NullDecoder::decoder_status _status; |
| 46 | |
| 47 | public: |
| 48 | ElfStringTable(FILE* const file, Elf_Shdr& shdr, int index); |
| 49 | ~ElfStringTable(); |
| 50 | |
| 51 | // section index |
| 52 | int index() const { return _index; }; |
| 53 | |
| 54 | // get string at specified offset |
| 55 | bool string_at(size_t offset, char* buf, int buflen); |
| 56 | |
| 57 | // get status code |
| 58 | NullDecoder::decoder_status get_status() const { |
| 59 | return _status; |
| 60 | } |
| 61 | |
| 62 | private: |
| 63 | void set_next(ElfStringTable* next) { |
| 64 | _next = next; |
| 65 | } |
| 66 | |
| 67 | ElfStringTable* next() const { |
| 68 | return _next; |
| 69 | } |
| 70 | }; |
| 71 | |
| 72 | #endif // !_WINDOWS && !__APPLE__ |
| 73 | |
| 74 | #endif // SHARE_UTILITIES_ELFSTRINGTABLE_HPP |
| 75 | |